-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrobot_behaviors_sound.cpp
126 lines (102 loc) · 2.85 KB
/
robot_behaviors_sound.cpp
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
#include "robot.h"
#include "constants_actions.h"
#include "constants_pitches.h"
RobotSoundBehavior::RobotSoundBehavior() : Behavior() {
int m1notes[] = {
MIDINOTE_C4,
MIDINOTE_G3,
MIDINOTE_G3,
MIDINOTE_A3,
MIDINOTE_G3,
0,
MIDINOTE_B3,
MIDINOTE_C4
};
int m1durations[] = {4, 8, 8, 4,4,4,4,4};
this->melody_one = new Melody(8, m1notes, m1durations);
int m2notes[] = {
0,
MIDINOTE_FS3,
MIDINOTE_GS3,
MIDINOTE_AS3,
MIDINOTE_CS4,
MIDINOTE_DS4,
MIDINOTE_CS4,
MIDINOTE_F4,
MIDINOTE_DS4
};
int m2durations[] = {8,8,8,8,8,16,16,8,8};
this->melody_two= new Melody(9, m2notes, m2durations);
}
void UpdateOutputFromState(State * state, Output * output) {
if (state->sound_state()->anyActingNotes()) {
output->setAmpPower(true) ;
output->tone = state->sound_state()->currentHz();
} else {
output->setAmpPower(false);
}
}
void RobotSoundBehavior::updateBehavior(unsigned short dt, State * state, Output * output) {
this->incrementTimer(dt);
switch(behavior_key)
{
case(MEL1TRIG_CC):
{
this->melody_one->play(dt, state);
UpdateOutputFromState(state, output);
break;
}
case(MEL2TRIG_CC):
{
this->melody_two->play(dt, state);
UpdateOutputFromState(state, output);
break;
}
case(KEYACT_CC):
{
UpdateOutputFromState(state, output);
break;
}
case(MIDIPANIC_CC):
{
state->sound_state()->turnOffAllNotes();
output->setAmpPower(false);
break;
}
default:
{
output->setAmpPower(false);
}
}
// Foo
}
void RobotSoundBehavior::updateBehaviorKey(byte control_number, byte value) {
// Sound behavior keys
if (control_number == MEL1TRIG_CC ||
control_number == MEL2TRIG_CC ||
control_number == KEYACT_CC ||
control_number == MIDIPANIC_CC) {
if (value == 127) {
this->setCurrentBehavior(control_number);
} else {
this->clearCurrentBehavior();
}
}
}
void RobotSoundBehavior::updateState(byte control_number, byte value, State * state) {
if (control_number == MEL1TRIG_CC ||
control_number == MEL2TRIG_CC ||
control_number == KEYACT_CC ||
control_number == MIDIPANIC_CC) {
// Always reset the note state when we change keys
state->sound_state()->turnOffAllNotes();
}
if (control_number == MEL1TRIG_CC) {
this->melody_one->reset();
state->sound_state()->turnOffAllNotes();
}
if (control_number == MEL2TRIG_CC) {
this->melody_two->reset();
state->sound_state()->turnOffAllNotes();
}
}