Skip to content

Commit

Permalink
Added Settings to set Use1ByteParsing to false
Browse files Browse the repository at this point in the history
- Packet based protocols prefer the entire message to be parsed as a whole.
- Journal section minimum size is 3
  • Loading branch information
lathoub committed May 1, 2020
1 parent 285542b commit aa89204
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
22 changes: 14 additions & 8 deletions src/AppleMIDI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ BEGIN_APPLEMIDI_NAMESPACE

static unsigned long now;

struct AppleMIDISettings : public MIDI_NAMESPACE::DefaultSettings
{
// Packet based protocols prefer the entire message to be parsed
// as a whole.
static const bool Use1ByteParsing = false;
};

template <class UdpClass, class _Settings = DefaultSettings, class _Platform = ArduinoPlatform>
class AppleMIDISession
{
Expand All @@ -40,7 +47,7 @@ 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>>;
friend class MIDI_NAMESPACE::MidiInterface<AppleMIDISession<UdpClass>, AppleMIDISettings>;

public:
AppleMIDISession(const char *name, const uint16_t port = DEFAULT_CONTROL_PORT)
Expand All @@ -66,7 +73,7 @@ class AppleMIDISession
void sendEndSession();

protected:
static const bool thruActivated = false;
static const bool thruActivated = false;

void begin()
{
Expand Down Expand Up @@ -280,17 +287,16 @@ class AppleMIDISession
Participant<Settings>* getParticipantByInitiatorToken(const uint32_t initiatorToken);
};

END_APPLEMIDI_NAMESPACE

#include "AppleMIDI.hpp"

#define APPLEMIDI_CREATE_INSTANCE(Type, Name, SessionName, Port) \
APPLEMIDI_NAMESPACE::AppleMIDISession<Type> Apple##Name(SessionName, Port); \
MIDI_NAMESPACE::MidiInterface<APPLEMIDI_NAMESPACE::AppleMIDISession<Type>> Name((APPLEMIDI_NAMESPACE::AppleMIDISession<Type>&)Apple##Name);
MIDI_NAMESPACE::MidiInterface<APPLEMIDI_NAMESPACE::AppleMIDISession<Type>, AppleMIDISettings> Name((APPLEMIDI_NAMESPACE::AppleMIDISession<Type>&)Apple##Name);

#define APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE() \
APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "Arduino", DEFAULT_CONTROL_PORT);

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

END_APPLEMIDI_NAMESPACE

#include "AppleMIDI.hpp"

27 changes: 14 additions & 13 deletions src/rtpMIDI_Parser_JournalSection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,14 @@ parserReturn decodeJournalSection(RtpBuffer_t &buffer)
{
size_t i = 0;

minimumLen += 1;
// Minimum size for the Journal section is 3
minimumLen += 3;
if (buffer.size() < minimumLen)
return parserReturn::NotEnoughData;

/* lets get the main flags from the recovery journal header */
uint8_t flags = buffer[i++];

// sequenceNr
minimumLen += 2;
if (buffer.size() < minimumLen)
return parserReturn::NotEnoughData;

if ((flags & RTP_MIDI_JS_FLAG_Y) == 0 && (flags & RTP_MIDI_JS_FLAG_A) == 0)
{
while (minimumLen-- > 0)
buffer.pop_front();
return parserReturn::Processed;
}

// The 16-bit Checkpoint Packet Seqnum header field codes the sequence
// number of the checkpoint packet for this journal, in network byte
// order (big-endian). The choice of the checkpoint packet sets the
Expand All @@ -61,6 +50,18 @@ parserReturn decodeJournalSection(RtpBuffer_t &buffer)
cb.buffer[1] = buffer[i++];
uint16_t checkPoint = ntohs(cb.value16);

// (RFC 4695, 5 Recovery Journal Format)
// If A and Y are both zero, the recovery journal only contains its 3-
// octet header and is considered to be an "empty" journal.
if ((flags & RTP_MIDI_JS_FLAG_Y) == 0 && (flags & RTP_MIDI_JS_FLAG_A) == 0)
{
// Big fixed by @hugbug
while (minimumLen-- > 0)
buffer.pop_front();

return parserReturn::Processed;
}

// By default, the payload format does not use enhanced Chapter C
// encoding. In this default case, the H bit MUST be set to 0 for all
// packets in the stream.
Expand Down

0 comments on commit aa89204

Please sign in to comment.