-
Notifications
You must be signed in to change notification settings - Fork 66
/
AVR_Directory.ino
85 lines (69 loc) · 2.54 KB
/
AVR_Directory.ino
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
#include <Ethernet.h>
#define SerialMon Serial
#define USE_DIRECTORY
#include <AppleMIDI.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
unsigned long t1 = millis();
int8_t isConnected = 0;
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void setup()
{
AM_DBG_SETUP(115200);
AM_DBG(F("Booting"));
if (Ethernet.begin(mac) == 0) {
AM_DBG(F("Failed DHCP, check network cable & reboot"));
for (;;);
}
AppleMIDI.directory.push_back(IPAddress(192, 168, 1, 63));
AppleMIDI.directory.push_back(IPAddress(192, 168, 1, 66));
// AppleMIDI.whoCanConnectToMe = APPLEMIDI_NAMESPACE::None;
AppleMIDI.whoCanConnectToMe = APPLEMIDI_NAMESPACE::OnlyComputersInMyDirectory;
// AppleMIDI.whoCanConnectToMe = APPLEMIDI_NAMESPACE::Anyone;
AM_DBG(F("OK, now make sure you an rtpMIDI session that is Enabled"));
AM_DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
AM_DBG(F("Select and then press the Connect button"));
AM_DBG(F("Then open a MIDI listener and monitor incoming notes"));
MIDI.begin();
// Stay informed on connection status
AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
isConnected++;
AM_DBG(F("Connected to session"), ssrc, name);
});
AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
isConnected--;
AM_DBG(F("Disconnected"), ssrc);
});
MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
AM_DBG(F("NoteOn"), note);
});
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
AM_DBG(F("NoteOff"), note);
});
AM_DBG(F("Sending MIDI messages every second"));
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void loop()
{
// Listen to incoming notes
MIDI.read();
// send a note every second
// (dont cáll delay(1000) as it will stall the pipeline)
if ((isConnected > 0) && (millis() - t1) > 1000)
{
t1 = millis();
byte note = random(1, 127);
byte velocity = 55;
byte channel = 1;
MIDI.sendNoteOn(note, velocity, channel);
// MIDI.sendNoteOff(note, velocity, channel);
}
}