Rev 2311 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
964 | jag | 1 | /* |
2 | * beat2value.cc |
||
2302 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1479 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
964 | jag | 6 | */ |
7 | |||
8 | #include "beat2value.h" |
||
9 | #include "utils.h" |
||
2055 | jag | 10 | #include "console.h" |
964 | jag | 11 | #include <string> |
12 | using namespace std; |
||
13 | |||
987 | jag | 14 | extern int SAMPLE_RATE; |
15 | |||
964 | jag | 16 | beat2value::beat2value (const string& n, const string& c) : name (n), crvname (c) { |
17 | crv = new multi_curve (c); |
||
18 | crv_made_here = 1; |
||
2264 | jag | 19 | swing = 0; |
964 | jag | 20 | setup (); |
21 | } |
||
22 | |||
2264 | jag | 23 | beat2value::beat2value () { crv = 0; crv_made_here = 0; swing = 0;} |
964 | jag | 24 | |
25 | void beat2value::setup (int delta_mult) { |
||
26 | min_bpm = 0; |
||
27 | bpm = 45; |
||
987 | jag | 28 | delta = 0; |
964 | jag | 29 | set_bpm (bpm, delta_mult); |
30 | style = "loop"; |
||
31 | xmin = &_loopmin; |
||
32 | xmax = &_loopmax; |
||
33 | sol (crv); |
||
34 | now = sol.firstx; |
||
35 | } |
||
36 | |||
2055 | jag | 37 | void beat2value::reverse () { |
2057 | jag | 38 | delta = -delta; |
2055 | jag | 39 | if (style == "loop") { |
2057 | jag | 40 | if (delta < 0) { |
41 | xmin = &_tomax; |
||
42 | xmax = &_atmax; |
||
43 | } else { |
||
44 | xmax = &_tomin; |
||
45 | xmin = &_atmin; |
||
46 | } |
||
47 | } /* else { |
||
2097 | jag | 48 | // nothing todo for pong |
2057 | jag | 49 | }*/ |
2055 | jag | 50 | } |
51 | |||
964 | jag | 52 | beat2value::~beat2value () { |
53 | if (crv_made_here) { |
||
54 | crv->save (crvname); |
||
55 | delete crv; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | int beat2value::gen_and_mix (float* soln, float* mixb, float* mixa, int n) { |
||
2161 | jag | 60 | //xmax->called = 0; |
2264 | jag | 61 | |
2265 | jag | 62 | |
63 | float now1 = now, delta1 = delta; |
||
2311 | jag | 64 | /*if (swing) { |
2264 | jag | 65 | swingsol (now, delta, n, soln, *xmin, *xmax); |
66 | sol (soln, n); |
||
2311 | jag | 67 | } else {*/ |
2264 | jag | 68 | sol (now, delta, n, soln, *xmin, *xmax); |
2311 | jag | 69 | //} |
2264 | jag | 70 | |
2161 | jag | 71 | /*if (xmax->called == 1) { |
2129 | jag | 72 | xmax->called = 0; |
73 | cons ("beatend"); |
||
2161 | jag | 74 | }*/ |
2264 | jag | 75 | |
964 | jag | 76 | if (mixer.active) { |
77 | mixer.gen_mix (mixb, n, *xmin, *xmax); |
||
78 | mixer.do_mix (soln, mixb, mixa, n); |
||
79 | } |
||
2264 | jag | 80 | |
2311 | jag | 81 | /*if (accent) { |
2265 | jag | 82 | accentsol (now1, delta1, n, mixb, *xmin, *xmax); |
83 | multiply (soln, mixb, n); |
||
2311 | jag | 84 | }*/ |
2265 | jag | 85 | |
964 | jag | 86 | return mixer.active; |
87 | } |
||
88 | |||
89 | int beat2value::modulate_and_mix (float* in, float* mixb, float* mixa, int n, float depth) { |
||
90 | sol (now, delta, n, in, *xmin, *xmax); |
||
91 | multiply (in, n, depth); |
||
92 | if (mixer.active) { |
||
93 | mixer.gen_mix (mixb, n, *xmin, *xmax); |
||
94 | multiply (mixb, n, depth); |
||
95 | mixer.do_mix (in, mixb, mixa, n); |
||
96 | } |
||
97 | return mixer.active; |
||
98 | } |
||
99 | |||
100 | int beat2value::modulate_and_mix (float* in, float* mixb, float* mixa, int n, float* depth) { |
||
101 | sol (now, delta, n, in, *xmin, *xmax); |
||
102 | multiply (in, depth, n); |
||
103 | if (mixer.active) { |
||
104 | mixer.gen_mix (mixb, n, *xmin, *xmax); |
||
105 | multiply (mixb, depth, n); |
||
106 | mixer.do_mix (in, mixb, mixa, n); |
||
107 | } |
||
108 | return mixer.active; |
||
109 | } |
||
110 | |||
111 | |||
1193 | jag | 112 | float beat2value::set_bpm (float n, int nsamples) { |
964 | jag | 113 | |
114 | if (n < min_bpm) n = min_bpm; |
||
115 | |||
116 | bpm = n; |
||
1658 | jag | 117 | bps = bpm / 60.0f; |
964 | jag | 118 | |
1193 | jag | 119 | // delta used in solvers |
2060 | jag | 120 | int sgn = 1; |
121 | if (delta < 0) sgn = -1; |
||
2096 | jag | 122 | delta = sgn * bps * nsamples * 1.0f / SAMPLE_RATE; |
964 | jag | 123 | |
124 | return bpm; |
||
125 | |||
126 | } |
||
127 | |||
128 | float beat2value::get_bpm () { |
||
129 | return bpm; |
||
130 | } |
||
131 | |||
1799 | jag | 132 | void beat2value::set_mix (multi_curve& c, const string& nam) { |
964 | jag | 133 | mixer.setup (c, now, delta); |
1799 | jag | 134 | mixer.name = nam; |
964 | jag | 135 | } |
2264 | jag | 136 | |
137 | void beat2value::setswing (multi_curve& sw) { |
||
138 | swing = &sw; |
||
139 | swingsol (swing); |
||
140 | } |
||
2265 | jag | 141 | |
142 | |||
143 | void beat2value::setaccent (multi_curve& ac) { |
||
144 | accent = ∾ |
||
145 | accentsol (accent); |
||
146 | } |
||
2335 | jag | 147 | |
148 | void powbeat (const string& name, beat2value& bv, float p) { |
||
149 | float b = bv.get_bpm () * p; |
||
150 | bv.set_bpm (b); |
||
151 | cons << GREEN << name << " bpm = " << b << eol; |
||
152 | } |
||
153 |