Skip to content

Commit

Permalink
Merge pull request #84 from lathoub/feat/v2.1.0
Browse files Browse the repository at this point in the history
Feat/v2.1.0
  • Loading branch information
lathoub authored May 3, 2020
2 parents eddc2a6 + fa1fef3 commit e5cbaa4
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 210 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Enables an Arduino with IP/UDP capabilities (Ethernet shield, ESP8266, ESP32, ..
* Send and receive all MIDI messages
* Uses callbacks to receive MIDI commands (no need for polling)
* Automatic instantiation of AppleMIDI object (see at the end of 'AppleMidi.h')
* Compiles on Arduino, MacOS (XCode) and Windows (MSVS)

## Installation
From the Arduino IDE Library Manager, search for AppleMIDI
Expand Down
9 changes: 0 additions & 9 deletions examples/EthernetShield_Bonjour/EthernetShield_Bonjour.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void setup()
// Stay informed on connection status
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
AppleMIDI.setHandleError(OnAppleMidiError);

// and let us know ehen notes come in
MIDI.setHandleNoteOn(OnMidiNoteOn);
Expand Down Expand Up @@ -115,14 +114,6 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
Serial.println(F("Disconnected"));
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Error occorded during processing
// -----------------------------------------------------------------------------
void OnAppleMidiError(const ssrc_t & ssrc, int32_t errorCode) {
Serial.println(F("ERROR"));
exit(1);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand Down
22 changes: 20 additions & 2 deletions examples/EthernetShield_Initiator/EthernetShield_Initiator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ void setup()
// Stay informed on connection status
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
AppleMIDI.setHandleError(OnAppleMidiError);

// and let us know ehen notes come in
MIDI.setHandleNoteOn(OnMidiNoteOn);
MIDI.setHandleNoteOff(OnMidiNoteOff);

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

Serial.println(F("Every second send a random NoteOn/Off"));
Expand Down Expand Up @@ -107,6 +108,23 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
Serial.println(ssrc, HEX);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) {
Serial.print (F("Exception "));
Serial.println(err);
Serial.print (F(" from ssrc 0x"));
Serial.println(ssrc, HEX);

switch (err)
{
case Exception::NoResponseFromConnectionRequestException:
Serial.println(F("xxx:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)"));
break;
}
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand All @@ -129,4 +147,4 @@ static void OnMidiNoteOff(byte channel, byte note, byte velocity) {
Serial.print(note);
Serial.print(F(", velocity: "));
Serial.println(velocity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void setup()
// check: zien we de connecttion binnenkomen?? Anders terug een ref van maken
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
AppleMIDI.setHandleError(OnAppleMidiError);

MIDI.setHandleClock(OnMidiClock);
MIDI.setHandleStart(OnMidiStart);
Expand Down Expand Up @@ -81,14 +80,6 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
Serial.println(name);
}

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

// -----------------------------------------------------------------------------
// rtpMIDI session. Error occorded during processing
// -----------------------------------------------------------------------------
Expand Down
32 changes: 25 additions & 7 deletions examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ETH_Helper.h"

#define APPLEMIDI_INITIATOR
#include <AppleMIDI.h>
USING_NAMESPACE_APPLEMIDI

Expand All @@ -8,8 +9,6 @@ bool isConnected = false;

APPLEMIDI_CREATE_DEFAULTSESSION_ESP32_INSTANCE();

//WiFiServer server(80);

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand All @@ -21,9 +20,6 @@ void setup()

ETH_startup();

// Start TCP (HTTP) server
// server.begin();

MDNS.begin(AppleMIDI.getName());

Serial.print("IP address is ");
Expand All @@ -40,6 +36,7 @@ void setup()

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

MIDI.setHandleNoteOn(OnAppleMidiNoteOn);
MIDI.setHandleNoteOff(OnAppleMidiNoteOff);
Expand All @@ -48,6 +45,10 @@ void setup()
MDNS.addService("http", "tcp", 80);

Serial.println(F("Every second send a random NoteOn/Off"));

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

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -96,7 +97,24 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
}

// -----------------------------------------------------------------------------
//
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) {
Serial.print (F("Exception "));
Serial.print (err);
Serial.print (F(" from ssrc 0x"));
Serial.println(ssrc, HEX);

switch (err)
{
case Exception::NoResponseFromConnectionRequestException:
Serial.println(F("xxx:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)"));
break;
}
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
static void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
Serial.print(F("Incoming NoteOn from channel: "));
Expand All @@ -117,4 +135,4 @@ static void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
Serial.print(note);
Serial.print(F(", velocity: "));
Serial.println(velocity);
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AppleMIDI
version=2.0.5
version=2.1.0
author=lathoub
maintainer=lathoub <[email protected]>
sentence=AppleMIDI (rtpMIDI) protocol for Arduino
Expand Down
26 changes: 13 additions & 13 deletions src/AppleMIDI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ using namespace MIDI_NAMESPACE;

#include "IPAddress.h"

#include "AppleMIDI_PlatformBegin.h"
#include "AppleMIDI_Defs.h"
#include "AppleMIDI_Settings.h"
#include "AppleMIDI_Platform.h"

#include "rtp_Defs.h"
#include "rtpMIDI_Defs.h"
Expand All @@ -22,10 +22,6 @@ using namespace MIDI_NAMESPACE;

#include "AppleMIDI_Namespace.h"

#ifndef UDP_TX_PACKET_MAX_SIZE
#define UDP_TX_PACKET_MAX_SIZE 24
#endif

BEGIN_APPLEMIDI_NAMESPACE

static unsigned long now;
Expand All @@ -37,7 +33,7 @@ struct AppleMIDISettings : public MIDI_NAMESPACE::DefaultSettings
static const bool Use1ByteParsing = false;
};

template <class UdpClass, class _Settings = DefaultSettings, class _Platform = ArduinoPlatform>
template <class UdpClass, class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
class AppleMIDISession
{
typedef _Settings Settings;
Expand All @@ -47,7 +43,6 @@ class AppleMIDISession
// to avoid access by the .ino to internal messages
friend class AppleMIDIParser<UdpClass, Settings, Platform>;
friend class rtpMIDIParser<UdpClass, Settings, Platform>;
friend class MIDI_NAMESPACE::MidiInterface<AppleMIDISession<UdpClass>, AppleMIDISettings>;

public:
AppleMIDISession(const char *name, const uint16_t port = DEFAULT_CONTROL_PORT)
Expand All @@ -58,7 +53,7 @@ class AppleMIDISession

void setHandleConnected(void (*fptr)(const ssrc_t&, const char*)) { _connectedCallback = fptr; }
void setHandleDisconnected(void (*fptr)(const ssrc_t&)) { _disconnectedCallback = fptr; }
void setHandleError(void (*fptr)(const ssrc_t&, int32_t)) { _errorCallback = fptr; }
void setHandleError(void (*fptr)(const ssrc_t&, int32_t)) { _exceptionCallback = fptr; }
void setHandleReceivedRtp(void (*fptr)(const ssrc_t&, const Rtp_t&, const int32_t&)) { _receivedRtpCallback = fptr; }
void setHandleStartReceivedMidi(void (*fptr)(const ssrc_t&)) { _startReceivedMidiByteCallback = fptr; }
void setHandleReceivedMidi(void (*fptr)(const ssrc_t&, byte)) { _receivedMidiByteCallback = fptr; }
Expand All @@ -72,7 +67,7 @@ class AppleMIDISession
#endif
void sendEndSession();

protected:
public:
static const bool thruActivated = false;

void begin()
Expand Down Expand Up @@ -150,8 +145,8 @@ class AppleMIDISession
}
else
{
if (NULL != _errorCallback)
_errorCallback(ssrc, -1);
if (NULL != _exceptionCallback)
_exceptionCallback(ssrc, BufferFullException);
}
}

Expand Down Expand Up @@ -204,14 +199,17 @@ class AppleMIDISession
return byte;
};

private:
protected:
UdpClass controlPort;
UdpClass dataPort;

private:
// reading from the network
RtpBuffer_t controlBuffer;
RtpBuffer_t dataBuffer;

byte packetBuffer[Settings::UdpTxPacketMaxSize];

AppleMIDIParser<UdpClass, Settings, Platform> _appleMIDIParser;
rtpMIDIParser<UdpClass, Settings, Platform> _rtpMIDIParser;

Expand All @@ -221,7 +219,7 @@ class AppleMIDISession
endReceivedMidiByteCallback _endReceivedMidiByteCallback = nullptr;
receivedRtpCallback _receivedRtpCallback = nullptr;
disconnectedCallback _disconnectedCallback = nullptr;
errorCallback _errorCallback = nullptr;
exceptionCallback _exceptionCallback = nullptr;

// buffer for incoming and outgoing MIDI messages
MidiBuffer_t inMidiBuffer;
Expand Down Expand Up @@ -300,3 +298,5 @@ APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "Arduino", DEFAULT_CONTROL_PORT);

#define APPLEMIDI_CREATE_DEFAULTSESSION_ESP32_INSTANCE() \
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, MIDI, "ESP32", DEFAULT_CONTROL_PORT);

#include "AppleMIDI_PlatformEnd.h"
Loading

0 comments on commit e5cbaa4

Please sign in to comment.