-
Notifications
You must be signed in to change notification settings - Fork 1
/
WaveGen.h
139 lines (100 loc) · 2.9 KB
/
WaveGen.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
#ifndef LIB_WAVEGEN_H_
#define LIB_WAVEGEN_H_
#include <Arduino.h>
#define PIN_INTERRUPT 18 //pin 46
//#define PIN_INTERRUPT 2 //Interrupt pin
//#define PIN_LATCH 10 //SPI Latch Pin
#define QUEUE_SIZE 10
#define PITCHBENDRANGE 1
#define NOTESTATE_OFF 0
#define NOTESTATE_ATTACK 1
#define NOTESTATE_SUSTAIN 2
#define NOTESTATE_RELEASE 3
#define ARPSTYLE_ASPLAYED 0
#define ARPSTYLE_UP 1
#define ARPSTYLE_DOWN 2
#define ARPSTYLE_UPDOWN 3
#define ARPSTYLE_CONVERGE 4
#define ARPSTYLE_DIVERGE 5
#define ARPSTYLE_CONVERGEDIVERGE 6
#define ARPSTYLE_RANDOM 7
#define LFOMODE_DISABLE 0
#define LFOMODE_ARP 1
#define LFOMODE_MOD 2
#define MODWAVEFORM_SINE 1
#define MODWAVEFORM_SQUARE 2
#define MODWAVEFORM_SAW 3
#define MODWAVEFORM_NOISE 4
#define MOD_TREMALO 0
#define MOD_VIBRATO 1
class WaveGen {
public:
void handleNoteOn(byte,byte,byte);
void handleNoteOff(byte,byte,byte);
void handlePitchBend(byte,int);
//protected:
uint16_t _wavelength;
uint8_t _currentNote;
int _currentBend;
int _notesPressed;
uint8_t _noteQueue[QUEUE_SIZE];
uint8_t _noteQueue_UP[QUEUE_SIZE];
int _noteOffset;
uint8_t _dutyCycleValue; //0-3
uint8_t _volume; //0-15
uint8_t _currentVolume; //0-15
int _fineDetune;
uint8_t _noteState;
unsigned long _timer_applyAttack;
unsigned long _cycle_applyAttack;
unsigned long _timer_applyRelease;
unsigned long _cycle_applyRelease;
unsigned long _timer_applyMod;
unsigned long _cycle_applyMod;
uint8_t _LFOMode;
unsigned long _LFOMillis;
unsigned long _risingEdgeMicros;
uint8_t _modDepth;
uint8_t _modWaveForm;
uint8_t _arpNoteQueuePosition;
boolean _arpDirectionAscend;
uint8_t _arpStyle;
boolean _risingEdgeModFlag;
boolean _fallingEdgeModFlag;
uint8_t _modMode;
void init();
void _sendAddrData(uint8_t,uint8_t);
void _pushNoteOnQueue(uint8_t);
void _removeNoteFromQueue(uint8_t);
uint8_t _getLastNoteInQueue();
uint8_t _getNoteLowByte(uint8_t);
uint8_t _getNoteHighByte(uint8_t);
void _playNote(uint8_t);
void _setDutyCycle(uint8_t);
uint8_t _getDutyCycle();
void _setVolume(uint8_t);
uint8_t _getVolume();
void _setAttack(uint8_t);
void _setRelease(uint8_t);
void _setNoteOffset(int);
int _getNoteOffset();
//void _setFineDetune(uint8_t);
//uint8_t _getFineDetune();
//uint16_t _getFineDetuneAmount(uint16_t);
virtual void _setWavelength(uint16_t,bool);
virtual void _stop();
virtual uint8_t _getWaveDataMessage();
virtual void _sendWaveDataMessage();
virtual void _applyAttack();
virtual void _applyRelease();
void _handleNoteStates();
void _applyMod();
//unsigned long _cycleCheck(unsigned long, unsigned long);
bool _cycleCheck(unsigned long *, unsigned long);
bool _cycleCheck_millis(unsigned long *, unsigned long);
void _runLFO();
void setLFOMillis(unsigned long);
unsigned long getModCycle();
void createSortedQueues();
};
#endif