Subversion Repositories DIN Is Noise

Rev

Rev 1806 | Rev 1823 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1528 jag 1
/*
2
* modulator.h
1712 jag 3
* DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath
1713 jag 4
* DIN Is Noise is released under GNU Public License 2.0
1528 jag 5
* For more information, please visit https://dinisnoise.org/
6
*/
7
#ifndef __modulator__
8
#define __modulator__
9
 
10
#include "beat2value.h"
1806 jag 11
#include "chrono.h"
1693 jag 12
 
13
#include <fstream>
1528 jag 14
#include <string>
15
 
16
struct multi_curve;
1693 jag 17
struct drone;
1528 jag 18
 
1708 jag 19
struct mod_params {
1528 jag 20
 
21
  float depth;
1718 jag 22
  beat2value bv; // rate
1708 jag 23
 
1528 jag 24
  float result;
25
 
1718 jag 26
  // drone modulation direction
27
  //
28
  enum {VERTICAL, HORIZONTAL, VELOCITY, ACCELERATION}; // possible modulation directions
29
  int id;
30
  static point<float> vertical, horizontal; // constant directions
31
  float *dirx, *diry; // current modulation direction
1528 jag 32
 
1727 jag 33
  void setdir (int i, float* x, float* y) {
1714 jag 34
    id = i;
1693 jag 35
    dirx = x;
36
    diry = y;
37
  }
38
 
1708 jag 39
  void calcdir (drone& d);
1693 jag 40
 
1680 jag 41
  float initial; // for microtonal range modulation
42
 
43
  mod_params (multi_curve* c, int d, point<float>& p, const std::string& n = "noname");
1806 jag 44
  void calc (double dt);
1718 jag 45
  void clear ();
1528 jag 46
 
47
};
48
 
49
struct modulator {
1688 jag 50
 
51
  enum {AM, FM};
1797 jag 52
 
1688 jag 53
  mod_params am, fm;
1528 jag 54
 
55
  enum {FROZEN=-1, NOT_ACTIVE, ACTIVE};
56
  int active;
57
 
1728 jag 58
  int scrubbed; // used by point_modulator
1528 jag 59
 
1806 jag 60
  double t, dt;
61
 
1728 jag 62
  modulator (multi_curve* fmc, multi_curve* amc) :
63
    am (amc, mod_params::VERTICAL, mod_params::vertical),
64
    fm (fmc, mod_params::HORIZONTAL, mod_params::horizontal)
65
  {
1666 jag 66
    active = scrubbed = 0;
1806 jag 67
    t = ui_clk ();
1808 jag 68
    dt = 0.0;
1666 jag 69
  }
1528 jag 70
 
71
  void clear () {
1688 jag 72
    am.clear ();
1528 jag 73
    fm.clear ();
74
    active = 0;
75
  }
76
 
77
  void calc () {
1806 jag 78
 
79
    double now = ui_clk ();
80
    dt = now - t;
81
    t = now;
82
 
83
    am.calc (dt);
84
    fm.calc (dt);
85
 
1528 jag 86
  }
87
 
88
};
89
 
90
#endif