This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
forked from jsr606/CFO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequencer.h
253 lines (185 loc) · 6.06 KB
/
Sequencer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
Sequencer.h - Friction Music library
Copyright (c) 2014 Science Friction.
All right reserved.
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your optionosc1modShape_ptr) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser Public License for more details.
You should have received a copy of the GNU Lesser Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ author: gauthiier
+ contact: [email protected]
*/
#pragma once
#define MAX_SEQ 128
#define MAX_STEPS 128
#define TICKS_PER_QUARTER_NOTE 24 //
enum SUBDIV {
NOTE_0,
NOTE_1 = (TICKS_PER_QUARTER_NOTE * 4),
NOTE_1DOT = (TICKS_PER_QUARTER_NOTE * 3),
NOTE_2 = (TICKS_PER_QUARTER_NOTE * 2),
NOTE_3 = ((TICKS_PER_QUARTER_NOTE * 3) / 2),
NOTE_4 = (TICKS_PER_QUARTER_NOTE * 1),
NOTE_6 = ((TICKS_PER_QUARTER_NOTE * 2) / 3),
NOTE_8 = (TICKS_PER_QUARTER_NOTE / 2),
NOTE_12 = (TICKS_PER_QUARTER_NOTE / 3),
NOTE_16 = (TICKS_PER_QUARTER_NOTE / 4),
NOTE_24 = (TICKS_PER_QUARTER_NOTE / 6),
NOTE_32 = (TICKS_PER_QUARTER_NOTE / 8),
NOTE_48 = (TICKS_PER_QUARTER_NOTE / 12),
NOTE_64 = (TICKS_PER_QUARTER_NOTE / 16),
NOTE_96 = (TICKS_PER_QUARTER_NOTE / 24)
// NOTE_128 = (TICKS_PER_QUARTER_NOTE / 32),
// NOTE_192 = (TICKS_PER_QUARTER_NOTE / 48),
// NOTE_256 = (TICKS_PER_QUARTER_NOTE / 64),
// NOTE_384 = (TICKS_PER_QUARTER_NOTE / 96)
};
enum SEQ_TYPE {
NOTE = 0,
VELOCITY = 1,
CCNUMBER = 2,
CCVALUE = 3
};
enum SEQ_LOOP_TYPE {
ONCE = 0,
LOOP = 1,
PINGPONG = 2 // not implemented yet
};
#define REVERSE true
typedef void (*func_cb)(void);
class seq;
class MSequencer {
public:
void init(int bpm);
void update();
void internalClock();
void midiClock();
void midiStart();
void midiContinue();
void midiStop();
void clock();
void stop();
void start();
void continues();
int newSequence(SUBDIV subdiv, func_cb cb);
int newSequence(SUBDIV subdiv, int steps, int channel);
int newSequence(SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop);
int newSequence(SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop, bool reverse);
bool stopSequence(int index);
bool startSequence(int index);
bool continueSequence(int index);
void setInternalClock(bool i);
bool getInternalClock();
void setbpm(int v);
int getbpm();
bool setChannel(int index, int c);
int getChannel(int index);
bool setSteps(int index, int s);
int getSteps(int index);
bool setPosition(int index, int p);
int getPosition(int index);
bool setBegin(int index, int b);
int getBegin(int index);
bool setEnd(int index, int e);
int getEnd(int index);
bool setReverse(int index, bool r);
bool getReverse(int index);
bool setInternal(int index, bool i);
bool getInternal(int index);
bool setExternal(int index, bool e);
bool getExternal(int index);
bool setSubdiv(int index, SUBDIV subdiv);
int getSubdiv(int index);
bool setLoopType(int index, SEQ_LOOP_TYPE loop);
int getLoopType(int index);
bool setCallback(int index, func_cb cb);
func_cb getCallback(int index);
bool insertNotes(int index, int notes[], int numNotes, int newPosition);
bool selectSequence(int s);
int getSelectedSequence();
bool selectIndex(int i);
int getSelectedIndex();
bool selectSequenceType(SEQ_TYPE type);
bool selectSequenceType(int type);
SEQ_TYPE getSelectedSequenceType();
bool setValue(int seq, SEQ_TYPE type, int index, int val);
bool setValue(int seq, int index, int val);
bool setValue(SEQ_TYPE type, int index, int val);
bool setValue(int index, int val);
bool setValue(int val);
int getValue(int seq, SEQ_TYPE type, int index);
int getValue(int seq, int index);
int getValue(SEQ_TYPE type, int index);
int getValue(int index);
int getValue();
private:
seq* _sequences[MAX_SEQ];
int _bpm;
int _bpmInClockTicks;
bool _internalClock;
unsigned long clockTick;
unsigned long timeNow;
unsigned long lastTime;
unsigned long tickTime;
int _selectedSequence;
int _selectedIndex;
SEQ_TYPE _selectedSequenceType;
};
class seq {
friend class MSequencer;
private:
seq(int id, SUBDIV subdiv, func_cb cb);
seq(int id, SUBDIV subdiv, int steps, int channel);
seq(int id, SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop);
seq(int id, SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop, bool reverse);
int _id;
int _channel;
int _steps;
int _begin;
int _end;
int _position;
int _lastposition;
bool _reverse;
bool _stopped;
bool _internal;
bool _external;
SUBDIV _subdiv;
SEQ_LOOP_TYPE _loop;
int _notes[MAX_STEPS];
int _velocity[MAX_STEPS];
int _ccNumbers[MAX_STEPS];
int _ccValues[MAX_STEPS];
unsigned long step;
void trigger();
void setchannel(int c);
int getchannel();
void setsteps(int s);
int getsteps();
void setposition(int p);
int getposition();
void setbegin(int b);
int getbegin();
void setend(int e);
int getend();
void setreverse(bool r);
bool getreverse();
void setinternal(bool i);
bool getinternal();
void setexternal(bool e);
bool getexternal();
void setsubdiv(SUBDIV v);
SUBDIV getsubdiv();
void setlooptype(SEQ_LOOP_TYPE loop);
SEQ_LOOP_TYPE getlooptype();
void callback(func_cb cb);
func_cb _callback;
void insertnotes(int notes[], int numNotes, int newPosition);
};
extern MSequencer Sequencer;