Skip to content

Commit

Permalink
added setHandleException handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Jan 17, 2021
1 parent 4308012 commit cb72859
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
// * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * W A R N I N G * * * * * * *
// logging messages to the Serial port in callback
// can result in dropped UDP messages!
// * * * * * * * * * * * * * * * * * * * * * *

#define SerialMon Serial
#define USE_EXT_CALLBACKS
#define APPLEMIDI_DEBUG SerialMon
#include <AppleMIDI.h>

Expand All @@ -9,6 +16,8 @@ int8_t isConnected = 0;

APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();

void OnAppleMidiException(const APPLEMIDI_NAMESPACE::ssrc_t&, const APPLEMIDI_NAMESPACE::Exception&, const int32_t);

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -38,6 +47,7 @@ void setup()
isConnected--;
DBG(F("Disconnected"), ssrc);
});
AppleMIDI.setHandleException(OnAppleMidiException);

MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
DBG(F("NoteOn"), note);
Expand Down Expand Up @@ -71,3 +81,49 @@ void loop()
// MIDI.sendNoteOff(note, velocity, channel);
}
}


// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnAppleMidiException(const APPLEMIDI_NAMESPACE::ssrc_t& ssrc, const APPLEMIDI_NAMESPACE::Exception& e, const int32_t value ) {
switch (e)
{
case APPLEMIDI_NAMESPACE::Exception::BufferFullException:
DBG(F("*** BufferFullException"));
break;
case APPLEMIDI_NAMESPACE::Exception::ParseException:
DBG(F("*** ParseException"));
break;
case APPLEMIDI_NAMESPACE::Exception::TooManyParticipantsException:
DBG(F("*** TooManyParticipantsException"));
break;
case APPLEMIDI_NAMESPACE::Exception::UnexpectedInviteException:
DBG(F("*** UnexpectedInviteException"));
break;
case APPLEMIDI_NAMESPACE::Exception::ParticipantNotFoundException:
DBG(F("*** ParticipantNotFoundException"), value);
break;
case APPLEMIDI_NAMESPACE::Exception::ComputerNotInDirectory:
DBG(F("*** ComputerNotInDirectory"), value);
break;
case APPLEMIDI_NAMESPACE::Exception::NotAcceptingAnyone:
DBG(F("*** NotAcceptingAnyone"), value);
break;
case APPLEMIDI_NAMESPACE::Exception::ListenerTimeOutException:
DBG(F("*** ListenerTimeOutException"));
break;
case APPLEMIDI_NAMESPACE::Exception::MaxAttemptsException:
DBG(F("*** MaxAttemptsException"));
break;
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;
case APPLEMIDI_NAMESPACE::Exception::SendPacketsDropped:
DBG(F("*** SendPacketsDropped"), value);
break;
case APPLEMIDI_NAMESPACE::Exception::ReceivedPacketsDropped:
DBG(F("*** ReceivedPacketsDropped"), value);
break;
}
}

0 comments on commit cb72859

Please sign in to comment.