forked from melodyians/melodyian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
components_sound_state.cpp
52 lines (36 loc) · 1.01 KB
/
components_sound_state.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
#include "components.h"
unsigned int FrequencyFromMidiNote (float note) {
return (unsigned int) (pow(2, (note - 69.0) / 12.0) * 440.0);
};
SoundState::SoundState(unsigned int num_notes) {
this->num_notes = num_notes;
this->last_note_on = 60; // default value
this->acting_notes = new bool[this->num_notes];
this->turnOffAllNotes();
}
void SoundState::turnOffAllNotes() {
for (int i = 0; i < this->num_notes; i++) {
this->acting_notes[i] = false;
}
}
bool SoundState::anyActingNotes() {
for (int i = 0; i < this->num_notes; i++) {
if (this->acting_notes[i]) {
return true;
}
}
return false;
}
unsigned int SoundState::currentHz() {
return FrequencyFromMidiNote(this->last_note_on);
}
void SoundState::turnNoteOn(int note) {
this->acting_notes[note] = true;
this->last_note_on = note;
}
void SoundState::turnNoteOff(int note) {
this->acting_notes[note] = false;
}
bool SoundState::isNoteOn(int note) {
return this->acting_notes[note];
}