Skip to content

Commit 892c03e

Browse files
committed
Teensy 4.1 send rtpmidi fix
- moved BeginPacket closer to first write - IPAddress is system header -moved parserReturn to Defs
1 parent a507db8 commit 892c03e

4 files changed

Lines changed: 27 additions & 28 deletions

File tree

src/AppleMIDI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <MIDI.h>
66
using namespace MIDI_NAMESPACE;
77

8-
#include "IPAddress.h"
8+
#include <IPAddress.h>
99

1010
#include "AppleMIDI_Debug.h"
1111

src/AppleMIDI.hpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -599,19 +599,7 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiToAllParticipan
599599

600600
template <class UdpClass, class Settings, class Platform>
601601
void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer(Participant<Settings>* participant)
602-
{
603-
const IPAddress remoteIP = participant->remoteIP;
604-
const uint16_t remotePort = participant->remotePort + 1;
605-
606-
if (!dataPort.beginPacket(remoteIP, remotePort))
607-
{
608-
#ifdef USE_EXT_CALLBACKS
609-
if (nullptr != _exceptionCallback)
610-
_exceptionCallback(ssrc, UdpBeginPacketFailed, 5);
611-
#endif
612-
return;
613-
}
614-
602+
{
615603
Rtp rtp;
616604
rtp.vpxcc = 0b10000000; // TODO: fun with flags
617605
rtp.mpayload = PAYLOADTYPE_RTPMIDI; // TODO: set or unset marker
@@ -647,11 +635,21 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer(Particip
647635
rtp.ssrc = __htonl(rtp.ssrc);
648636
rtp.sequenceNr = __htons(rtp.sequenceNr);
649637

638+
if (!dataPort.beginPacket(participant->remoteIP, participant->remotePort + 1))
639+
{
640+
#ifdef USE_EXT_CALLBACKS
641+
if (nullptr != _exceptionCallback)
642+
_exceptionCallback(ssrc, UdpBeginPacketFailed, 5);
643+
#endif
644+
return;
645+
}
646+
647+
// write rtp header
650648
dataPort.write((uint8_t *)&rtp, sizeof(rtp));
651649

652-
// only now the length is known
653-
auto bufferLen = outMidiBuffer.size();
650+
const auto bufferLen = outMidiBuffer.size();
654651

652+
// Write rtpMIDI section
655653
RtpMIDI_t rtpMidi;
656654

657655
if (bufferLen <= 0x0F)
@@ -673,20 +671,20 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer(Particip
673671
dataPort.write(rtpMidi.flags);
674672
dataPort.write((uint8_t)(bufferLen));
675673
}
676-
674+
677675
// write out the MIDI Section
678676
for (size_t i = 0; i < bufferLen; i++)
679677
dataPort.write(outMidiBuffer[i]);
680678

681679
// *No* journal section (Not supported)
682680

681+
dataPort.endPacket();
682+
dataPort.flush();
683+
683684
#ifdef USE_EXT_CALLBACKS
684685
if (_sentRtpMidiCallback)
685686
_sentRtpMidiCallback(rtpMidi);
686687
#endif
687-
688-
dataPort.endPacket();
689-
dataPort.flush();
690688
}
691689

692690
//

src/AppleMIDI_Defs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ union conversionBuffer
2525
byte buffer[8];
2626
};
2727

28+
29+
enum parserReturn: uint8_t
30+
{
31+
Processed,
32+
NotSureGiveMeMoreData,
33+
NotEnoughData,
34+
UnexpectedData,
35+
};
36+
2837
#if defined(__AVR__)
2938
#define APPLEMIDI_PROGMEM PROGMEM
3039
typedef const __FlashStringHelper* AppleMIDIConstStr;

src/AppleMIDI_Settings.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,4 @@ struct DefaultSettings
4141
static const unsigned long SynchronizationHeartBeat = 10000;
4242
};
4343

44-
enum parserReturn: uint8_t
45-
{
46-
Processed,
47-
NotSureGiveMeMoreData,
48-
NotEnoughData,
49-
UnexpectedData,
50-
};
51-
5244
END_APPLEMIDI_NAMESPACE

0 commit comments

Comments
 (0)