-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiIo.cpp.debug
80 lines (66 loc) · 1.16 KB
/
MidiIo.cpp.debug
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
//#define DEBUG_SERIAL 1
#include <MIDI.h>
#include "MidiIo.h"
BEGIN_MIDI_IO_NAMESPACE
void init(
void (*onStep)(int step, void (*sendNote)(byte note)),
void (*onNote)(byte note),
void (*onStop)(void))
{
_onStep = onStep;
_onNote = onNote;
_onStop = onStop;
Serial.begin(9600);
Serial.println("Starting in debug ...");
Serial.flush();
}
void doTheThing()
{
_onStep(_count, sendNote);
_count++;
}
void sendNote(const byte note)
{
Serial.print("Note off: ");
Serial.print(lastNote);
Serial.print(" -- Note on: ");
Serial.println(note);
Serial.flush();
lastNote = note;
}
void loop()
{
unsigned long t = millis();
if (t - _ticks > 1000)
{
_ticks = t;
doTheThing();
}
}
void handleClock(void)
{
if (_playing && _ticks++ % 6 == 0)
{
doTheThing();
}
}
void handleStart(void)
{
_playing = true;
_ticks = 0;
_count = 0;
}
void handleContinue(void)
{
_playing = true;
_ticks = 0;
}
void handleStop(void)
{
_playing = false;
_ticks = 0;
_onStop();
Serial.print("Note off: ");
Serial.print(lastNote);
}
END_MIDI_IO_NAMESPACE