Skip to content

Commit aa89204

Browse files
author
lathoub
committed
Added Settings to set Use1ByteParsing to false
- Packet based protocols prefer the entire message to be parsed as a whole. - Journal section minimum size is 3
1 parent 285542b commit aa89204

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/AppleMIDI.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ BEGIN_APPLEMIDI_NAMESPACE
3030

3131
static unsigned long now;
3232

33+
struct AppleMIDISettings : public MIDI_NAMESPACE::DefaultSettings
34+
{
35+
// Packet based protocols prefer the entire message to be parsed
36+
// as a whole.
37+
static const bool Use1ByteParsing = false;
38+
};
39+
3340
template <class UdpClass, class _Settings = DefaultSettings, class _Platform = ArduinoPlatform>
3441
class AppleMIDISession
3542
{
@@ -40,7 +47,7 @@ class AppleMIDISession
4047
// to avoid access by the .ino to internal messages
4148
friend class AppleMIDIParser<UdpClass, Settings, Platform>;
4249
friend class rtpMIDIParser<UdpClass, Settings, Platform>;
43-
friend class MIDI_NAMESPACE::MidiInterface<AppleMIDISession<UdpClass>>;
50+
friend class MIDI_NAMESPACE::MidiInterface<AppleMIDISession<UdpClass>, AppleMIDISettings>;
4451

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

6875
protected:
69-
static const bool thruActivated = false;
76+
static const bool thruActivated = false;
7077

7178
void begin()
7279
{
@@ -280,17 +287,16 @@ class AppleMIDISession
280287
Participant<Settings>* getParticipantByInitiatorToken(const uint32_t initiatorToken);
281288
};
282289

290+
END_APPLEMIDI_NAMESPACE
291+
292+
#include "AppleMIDI.hpp"
293+
283294
#define APPLEMIDI_CREATE_INSTANCE(Type, Name, SessionName, Port) \
284295
APPLEMIDI_NAMESPACE::AppleMIDISession<Type> Apple##Name(SessionName, Port); \
285-
MIDI_NAMESPACE::MidiInterface<APPLEMIDI_NAMESPACE::AppleMIDISession<Type>> Name((APPLEMIDI_NAMESPACE::AppleMIDISession<Type>&)Apple##Name);
296+
MIDI_NAMESPACE::MidiInterface<APPLEMIDI_NAMESPACE::AppleMIDISession<Type>, AppleMIDISettings> Name((APPLEMIDI_NAMESPACE::AppleMIDISession<Type>&)Apple##Name);
286297

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

290301
#define APPLEMIDI_CREATE_DEFAULTSESSION_ESP32_INSTANCE() \
291302
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, MIDI, "ESP32", DEFAULT_CONTROL_PORT);
292-
293-
END_APPLEMIDI_NAMESPACE
294-
295-
#include "AppleMIDI.hpp"
296-

src/rtpMIDI_Parser_JournalSection.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,14 @@ parserReturn decodeJournalSection(RtpBuffer_t &buffer)
2727
{
2828
size_t i = 0;
2929

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

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

37-
// sequenceNr
38-
minimumLen += 2;
39-
if (buffer.size() < minimumLen)
40-
return parserReturn::NotEnoughData;
41-
42-
if ((flags & RTP_MIDI_JS_FLAG_Y) == 0 && (flags & RTP_MIDI_JS_FLAG_A) == 0)
43-
{
44-
while (minimumLen-- > 0)
45-
buffer.pop_front();
46-
return parserReturn::Processed;
47-
}
48-
4938
// The 16-bit Checkpoint Packet Seqnum header field codes the sequence
5039
// number of the checkpoint packet for this journal, in network byte
5140
// order (big-endian). The choice of the checkpoint packet sets the
@@ -61,6 +50,18 @@ parserReturn decodeJournalSection(RtpBuffer_t &buffer)
6150
cb.buffer[1] = buffer[i++];
6251
uint16_t checkPoint = ntohs(cb.value16);
6352

53+
// (RFC 4695, 5 Recovery Journal Format)
54+
// If A and Y are both zero, the recovery journal only contains its 3-
55+
// octet header and is considered to be an "empty" journal.
56+
if ((flags & RTP_MIDI_JS_FLAG_Y) == 0 && (flags & RTP_MIDI_JS_FLAG_A) == 0)
57+
{
58+
// Big fixed by @hugbug
59+
while (minimumLen-- > 0)
60+
buffer.pop_front();
61+
62+
return parserReturn::Processed;
63+
}
64+
6465
// By default, the payload format does not use enhanced Chapter C
6566
// encoding. In this default case, the H bit MUST be set to 0 for all
6667
// packets in the stream.

0 commit comments

Comments
 (0)