forked from melodyians/melodyian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
components.h
193 lines (134 loc) · 3.41 KB
/
components.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
#pragma once
#include "types.h"
class HardwareInterface {
public:
virtual void writeToLED(byte red, byte green, byte blue) = 0;
virtual void moveMotor(int motor, int motorSpeed, int motorDirection) = 0;
virtual void stopMotors() = 0;
virtual int readBattery() = 0;
virtual void playTone(unsigned int freq) = 0;
virtual void toneOff() = 0;
virtual bool ampIsOn() = 0;
virtual void setAmpPower(bool on) = 0;
};
class InputValues {
private:
byte offset;
byte * input_values;
byte getCCIndex(byte control_number);
public:
InputValues(byte lowest_cc);
void storeInput(byte control_number, byte value);
byte getValue(byte control_number);
};
class Output {
public:
Output();
byte r;
byte g;
byte b;
bool amp_on;
unsigned int tone;
void setColor(byte r, byte g, byte b);
void setColorBlack();
void setAmpPower(bool toggle);
};
class LEDStorage {
private:
int * lightPresetData;
int ** lightPresetArray;
int* getLightPresetPtr(int i);
public:
LEDStorage();
RGBColor getLightPresetColor(int i);
void setPresetColor(int i, byte r, byte g, byte b);
void readFromEEPROM();
void saveToEEPROM(int lightPresetVal);
};
// Output and State
class SoundState {
private:
int num_notes;
int last_note_on;
bool * acting_notes;
public:
SoundState(unsigned int num_notes);
bool anyActingNotes();
unsigned int currentHz();
void turnNoteOn(int note);
void turnNoteOff(int note);
void turnOffAllNotes();
bool isNoteOn(int note);
};
class State {
private:
InputValues * input_values;
LEDStorage * led_storage_; // TODO probably best private
SoundState * sound_state_;
public:
State();
LEDStorage * led_storage();
SoundState * sound_state();
void updateInput(byte control_number, byte value);
// Shared Buttons
bool bypassRandomColor();
bool bypassRandomNote();
float randomness();
unsigned int decay();
int rate();
// LED
byte ledRedValue();
byte ledGreenValue();
byte ledBlueValue();
byte pulseValue();
bool colorOn();
bool recordEEPROMArmed();
bool saveColorOn();
void disarmRecordEEPROM();
void setCurrentLEDValues(byte r, byte g, byte b);
// Sound
bool soundActionOn();
bool melodyOneOn();
bool melodyTwoOn();
bool keyModeOn();
bool midiPanicOn();
// TODO -- Motor
};
class Behavior {
protected:
unsigned short timer;
byte behavior_key;
void setCurrentBehavior(byte behavior_key);
void clearCurrentBehavior();
void resetTimer();
void incrementTimer(unsigned short dt);
void decrementTimer(unsigned short dt);
public:
Behavior();
virtual void updateBehavior(unsigned short dt, State * state, Output * output) = 0;
virtual void updateBehaviorKey(byte control_number, byte value) = 0;
byte getCurrentBehavior();
};
class BatteryReader {
private:
HardwareInterface * hardware;
unsigned short timer;
byte analogVoltageToMidiValue(int analog_value);
public:
BatteryReader(HardwareInterface * hardware);
void readBattery(unsigned short dt, bool midi_read);
};
class Melody {
private:
int length;
int * melody;
int * durations;
int note_position;
int elapsed;
int current_note_duration(int rate);
public:
Melody(int length, int melody[], int durations[]);
void reset();
void play(unsigned short dt, State * robot_state);
int current_note();
};