-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayList.cpp
90 lines (69 loc) · 1.58 KB
/
PlayList.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
#include "PlayList.h"
Note::Note(byte aNote, byte aVelocity) {
note = aNote;
velocity = aVelocity;
previous = NULL;
next = NULL;
}
PlayList::PlayList() {
this->noteList_ = NULL;
}
void PlayList::press(byte note, byte velocity) {
this->appendNote(note, velocity);
}
void PlayList::release(byte note) {
this->removeNote(note);
}
Note *PlayList::getCurrentNote() {
return this->noteList_;
}
bool PlayList::isEmpty() {
return (this->noteList_ == NULL);
}
Note *PlayList::findNote(Note *noteList, byte note) {
if (noteList->note == note) {
return noteList;
} else {
if (noteList->previous != NULL) {
return this->findNote(noteList->previous, note);
} else {
return NULL;
}
}
}
void PlayList::removeNote(byte note) {
if (!this->isEmpty()) {
Note *toRemove = this->findNote(this->noteList_, note);
if (toRemove != NULL) {
Note *previous = toRemove->previous;
Note *next = toRemove->next;
if (previous != NULL) {
previous->next = next;
}
if (next != NULL) {
next->previous = previous;
} else {
this->noteList_ = previous;
}
delete toRemove;
}
}
}
void PlayList::appendNote(byte note, byte velocity) {
Note *newNote = new Note(note, velocity);
if (!this->isEmpty()) {
newNote->previous = this->noteList_;
this->noteList_->next = newNote;
}
this->noteList_ = newNote;
}
void PlayList::printNoteList(char *msg) {
if (!this->isEmpty()) {
Note *previous = this->getCurrentNote();
while(previous != NULL) {
previous = previous->previous;
}
} else {
Serial.println("PlayList::printNoteList -- EMPTY NoteList");
}
}