Skip to content

Commit

Permalink
Merge pull request #96 from lathoub/v2.2.0_test
Browse files Browse the repository at this point in the history
Bug fixes and enhancements
  • Loading branch information
lathoub committed Dec 20, 2020
2 parents 3b5c368 + cd14937 commit 134967d
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 388 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ install:
- platformio lib -g install 62@5.0.0 870 872

script:
- platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino;
- pio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino;
30 changes: 13 additions & 17 deletions examples/ESP32_Callbacks/ESP32_Callbacks.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
#define SerialMon Serial
#define APPLEMIDI_DEBUG SerialMon
#include <AppleMIDI.h>
USING_NAMESPACE_APPLEMIDI

#include "arduino_secrets.h"
#include "arduino_secrets.h" // contains SECRET_SSID and SECRET_PASS

bool isConnected = false;

APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();

void setup() {
SerialMon.begin(115200);
while (!SerialMon);

DBG_SETUP(115200);
DBG("Booting");

WiFi.begin(SECRET_SSID, SECRET_PASS);
Expand All @@ -28,7 +25,6 @@ void setup() {
DBG(F("Add device named Arduino with Host"), WiFi.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
DBG(F("Then press the Connect button"));
DBG(F("Then open a MIDI listener and monitor incoming notes"));
DBG(F("Listen to incoming MIDI commands"));

AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
Expand Down Expand Up @@ -65,47 +61,47 @@ void loop() {
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
isConnected = true;
DBG(F("Connected to session"), name);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
isConnected = false;
DBG(F("Disconnected"));
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) {
void OnAppleMidiError(const APPLEMIDI_NAMESPACE::ssrc_t& ssrc, int32_t err) {
switch (err)
{
case Exception::BufferFullException:
case APPLEMIDI_NAMESPACE::Exception::BufferFullException:
DBG(F("*** BufferFullException"));
break;
case Exception::ParseException:
case APPLEMIDI_NAMESPACE::Exception::ParseException:
DBG(F("*** ParseException"));
break;
case Exception::TooManyParticipantsException:
case APPLEMIDI_NAMESPACE::Exception::TooManyParticipantsException:
DBG(F("*** TooManyParticipantsException"));
break;
case Exception::UnexpectedInviteException:
case APPLEMIDI_NAMESPACE::Exception::UnexpectedInviteException:
DBG(F("*** UnexpectedInviteException"));
break;
case Exception::ParticipantNotFoundException:
case APPLEMIDI_NAMESPACE::Exception::ParticipantNotFoundException:
DBG(F("*** ParticipantNotFoundException"));
break;
case Exception::ListenerTimeOutException:
case APPLEMIDI_NAMESPACE::Exception::ListenerTimeOutException:
DBG(F("*** ListenerTimeOutException"));
break;
case Exception::MaxAttemptsException:
case APPLEMIDI_NAMESPACE::Exception::MaxAttemptsException:
DBG(F("*** MaxAttemptsException"));
break;
case Exception::NoResponseFromConnectionRequestException:
case APPLEMIDI_NAMESPACE::Exception::NoResponseFromConnectionRequestException:
DBG(F("***:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)"));
break;
}
Expand Down
66 changes: 16 additions & 50 deletions examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define SerialMon Serial
#define APPLEMIDI_DEBUG SerialMon
#include <AppleMIDI.h>
USING_NAMESPACE_APPLEMIDI

char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
Expand All @@ -15,21 +14,12 @@ bool isConnected = false;

APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();

// Forward declaration
void OnAppleMidiConnected(uint32_t ssrc, char* name);
void OnAppleMidiDisconnected(uint32_t ssrc);
void OnMidiNoteOn(byte channel, byte note, byte velocity);
void OnMidiNoteOff(byte channel, byte note, byte velocity);

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void setup()
{
// Serial communications and wait for port to open:
SerialMon.begin(115200);
while (!SerialMon);

DBG_SETUP(115200);
DBG("Booting");

WiFi.begin(ssid, pass);
Expand All @@ -48,11 +38,21 @@ void setup()

MIDI.begin();

AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);

MIDI.setHandleNoteOn(OnMidiNoteOn);
MIDI.setHandleNoteOff(OnMidiNoteOff);
AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
isConnected = true;
DBG(F("Connected to session"), name);
});
AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
isConnected = false;
DBG(F("Disconnected"));
});

MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
DBG(F("NoteOn"), note);
});
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
DBG(F("NoteOff"), note);
});

DBG(F("Sending NoteOn/Off of note 45, every second"));
}
Expand All @@ -79,37 +79,3 @@ void loop()
MIDI.sendNoteOff(note, velocity, channel);
}
}

// ====================================================================================
// Event handlers for incoming MIDI messages
// ====================================================================================

// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
isConnected = true;
DBG(F("Connected to session"), name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
isConnected = false;
DBG(F("Disconnected"));
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnMidiNoteOn(byte channel, byte note, byte velocity) {
DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnMidiNoteOff(byte channel, byte note, byte velocity) {
DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel);
}
76 changes: 24 additions & 52 deletions examples/EthernetShield_Initiator/EthernetShield_Initiator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define APPLEMIDI_DEBUG SerialMon
#define APPLEMIDI_INITIATOR
#include <AppleMIDI.h>
USING_NAMESPACE_APPLEMIDI

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
Expand All @@ -22,8 +21,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
// -----------------------------------------------------------------------------
void setup()
{
SerialMon.begin(115200);
while (!SerialMon);
DBG_SETUP(115200);
DBG("Booting");

if (Ethernet.begin(mac) == 0) {
Expand All @@ -32,26 +30,34 @@ void setup()
}

DBG(F("OK, now make sure you an rtpMIDI session that is Enabled"));
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
DBG(F("Then press the Connect button"));
DBG(F("Then open a MIDI listener and monitor incoming notes"));
DBG(F("Listen to incoming MIDI commands"));

MIDI.begin();

// Stay informed on connection status
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);

// and let us know ehen notes come in
MIDI.setHandleNoteOn(OnMidiNoteOn);
MIDI.setHandleNoteOff(OnMidiNoteOff);
AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
isConnected = true;
DBG(F("Connected to session"), name);
});
AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
isConnected = false;
DBG(F("Disconnected"));
});

MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
DBG(F("NoteOn"), note);
});
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
DBG(F("NoteOff"), note);
});

// Initiate the session
IPAddress remote(192, 168, 1, 4);
IPAddress remote(192, 168, 1, 65);
AppleMIDI.sendInvite(remote, DEFAULT_CONTROL_PORT); // port is 5004 by default

DBG(F("Every second send a random NoteOn/Off"));
DBG(F("Connecting to "), remote, "Port", DEFAULT_CONTROL_PORT, "(Name", AppleMIDI.getName(), ")");
DBG(F("Watch as this session is added to the Participants list"));
DBG(F("Then open a MIDI listener and monitor incoming notes"));

DBG(F("Sending a random NoteOn/Off every second"));
}

// -----------------------------------------------------------------------------
Expand All @@ -72,41 +78,7 @@ void loop()
byte velocity = 55;
byte channel = 1;

MIDI.sendNoteOn(note, velocity, channel);
MIDI.sendNoteOff(note, velocity, channel);
// MIDI.sendNoteOn(note, velocity, channel);
// MIDI.sendNoteOff(note, velocity, channel);
}
}

// ====================================================================================
// Event handlers for incoming MIDI messages
// ====================================================================================

// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
isConnected = true;
DBG(F("Connected to session"), name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
isConnected = false;
DBG(F("Disconnected"));
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
static void OnMidiNoteOn(byte channel, byte note, byte velocity) {
DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
static void OnMidiNoteOff(byte channel, byte note, byte velocity) {
DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#define SerialMon Serial
#define APPLEMIDI_DEBUG SerialMon
#include <AppleMIDI.h>
USING_NAMESPACE_APPLEMIDI

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
Expand All @@ -22,8 +21,7 @@ APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI2, "Arduino2", DEFAULT_CONTROL_PORT +
// -----------------------------------------------------------------------------
void setup()
{
SerialMon.begin(115200);
while (!SerialMon);
DBG_SETUP(115200);
DBG("Booting");

if (Ethernet.begin(mac) == 0) {
Expand All @@ -32,10 +30,10 @@ void setup()
}

DBG(F("OK, now make sure you an rtpMIDI session that is Enabled"));
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI1.getPort(), "(Name", AppleMIDI1.getName(), ")");
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI2.getPort(), "(Name", AppleMIDI2.getName(), ")");
DBG(F("Then press the Connect button"));
DBG(F("Then open a MIDI listener and monitor incoming notes"));
DBG(F("Listen to incoming MIDI commands"));

// Listen for MIDI messages on channel 1
MIDI1.begin(1);
Expand Down Expand Up @@ -84,15 +82,15 @@ void loop()
// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
isConnected = true;
DBG(F("Connected to session"), name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
isConnected = false;
DBG(F("Disconnected"));
}
Expand Down
Loading

0 comments on commit 134967d

Please sign in to comment.