Skip to content

Commit 668a274

Browse files
committed
added public setPort method, to be called *before* MIDI.begin
and renamed AM_DBG* => DBG*
1 parent 364a61b commit 668a274

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

src/AppleMIDI.h

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,62 @@ class AppleMIDISession
5959
#endif
6060
};
6161

62-
virtual ~AppleMIDISession(){
63-
};
62+
virtual ~AppleMIDISession(){};
6463

65-
AppleMIDISession& setHandleConnected(void (*fptr)(const ssrc_t &, const char *)) { _connectedCallback = fptr; return *this; }
66-
AppleMIDISession& setHandleDisconnected(void (*fptr)(const ssrc_t &)) { _disconnectedCallback = fptr; return *this; }
64+
AppleMIDISession &setHandleConnected(void (*fptr)(const ssrc_t &, const char *))
65+
{
66+
_connectedCallback = fptr;
67+
return *this;
68+
}
69+
AppleMIDISession &setHandleDisconnected(void (*fptr)(const ssrc_t &))
70+
{
71+
_disconnectedCallback = fptr;
72+
return *this;
73+
}
6774
#ifdef USE_EXT_CALLBACKS
68-
void setHandleException(void (*fptr)(const ssrc_t &, const Exception &, const int32_t value)) { _exceptionCallback = fptr; return *this; }
69-
AppleMIDISession& setHandleReceivedRtp(void (*fptr)(const ssrc_t &, const Rtp_t &, const int32_t &)) { _receivedRtpCallback = fptr; return *this;}
70-
AppleMIDISession& setHandleStartReceivedMidi(void (*fptr)(const ssrc_t &)) { _startReceivedMidiByteCallback = fptr; return *this;}
71-
AppleMIDISession& setHandleReceivedMidi(void (*fptr)(const ssrc_t &, byte)) { _receivedMidiByteCallback = fptr; return *this;}
72-
AppleMIDISession& setHandleEndReceivedMidi(void (*fptr)(const ssrc_t &)) { _endReceivedMidiByteCallback = fptr; return *this;}
73-
AppleMIDISession& setHandleSentRtp(void (*fptr)(const Rtp_t &)) { _sentRtpCallback = fptr; return *this;}
74-
AppleMIDISession& setHandleSentRtpMidi(void (*fptr)(const RtpMIDI_t &)) { _sentRtpMidiCallback = fptr; return *this;}
75+
void setHandleException(void (*fptr)(const ssrc_t &, const Exception &, const int32_t value))
76+
{
77+
_exceptionCallback = fptr;
78+
return *this;
79+
}
80+
AppleMIDISession &setHandleReceivedRtp(void (*fptr)(const ssrc_t &, const Rtp_t &, const int32_t &))
81+
{
82+
_receivedRtpCallback = fptr;
83+
return *this;
84+
}
85+
AppleMIDISession &setHandleStartReceivedMidi(void (*fptr)(const ssrc_t &))
86+
{
87+
_startReceivedMidiByteCallback = fptr;
88+
return *this;
89+
}
90+
AppleMIDISession &setHandleReceivedMidi(void (*fptr)(const ssrc_t &, byte))
91+
{
92+
_receivedMidiByteCallback = fptr;
93+
return *this;
94+
}
95+
AppleMIDISession &setHandleEndReceivedMidi(void (*fptr)(const ssrc_t &))
96+
{
97+
_endReceivedMidiByteCallback = fptr;
98+
return *this;
99+
}
100+
AppleMIDISession &setHandleSentRtp(void (*fptr)(const Rtp_t &))
101+
{
102+
_sentRtpCallback = fptr;
103+
return *this;
104+
}
105+
AppleMIDISession &setHandleSentRtpMidi(void (*fptr)(const RtpMIDI_t &))
106+
{
107+
_sentRtpMidiCallback = fptr;
108+
return *this;
109+
}
75110
#endif
76111

77112
#ifdef KEEP_SESSION_NAME
78113
const char *getName() const
79114
{
80115
return this->localName;
81116
};
82-
AppleMIDISession& setName(const char *sessionName)
117+
AppleMIDISession &setName(const char *sessionName)
83118
{
84119
strncpy(this->localName, sessionName, DefaultSettings::MaxSessionNameLen);
85120
return *this;
@@ -89,12 +124,20 @@ class AppleMIDISession
89124
{
90125
return nullptr;
91126
};
92-
AppleMIDISession& setName(const char *sessionName){ return *this; };
127+
AppleMIDISession &setName(const char *sessionName) { return *this; };
93128
#endif
129+
94130
const uint16_t getPort() const
95131
{
96132
return this->port;
97133
};
134+
135+
// call this method *before* calling begin()
136+
void setPort(const uint16_t port)
137+
{
138+
this->port = port;
139+
}
140+
98141
const ssrc_t getSynchronizationSource() const { return this->ssrc; };
99142

100143
#ifdef APPLEMIDI_INITIATOR

src/AppleMIDI_Debug.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
#pragma once
22

3-
#include "AppleMIDI_Namespace.h"
4-
BEGIN_APPLEMIDI_NAMESPACE
5-
63
#ifdef APPLEMIDI_DEBUG
74
namespace {
8-
static void AM_DBG_SETUP(unsigned long baud) {
5+
static void DBG_SETUP(unsigned long baud) {
96
APPLEMIDI_DEBUG.begin(baud);
107
while (!APPLEMIDI_DEBUG);
118
}
129

1310
template <typename T>
14-
static void AM_DBG_PLAIN(T last) {
11+
static void DBG_PLAIN(T last) {
1512
APPLEMIDI_DEBUG.println(last);
1613
}
1714

1815
template <typename T, typename... Args>
19-
static void AM_DBG_PLAIN(T head, Args... tail) {
16+
static void DBG_PLAIN(T head, Args... tail) {
2017
APPLEMIDI_DEBUG.print(head);
2118
APPLEMIDI_DEBUG.print(' ');
22-
AM_DBG_PLAIN(tail...);
19+
DBG_PLAIN(tail...);
2320
}
2421

2522
template <typename... Args>
26-
static void AM_DBG(Args... args) {
27-
AM_DBG_PLAIN(args...);
23+
static void DBG(Args... args) {
24+
DBG_PLAIN(args...);
2825
}
2926
} // namespace
3027
#else
31-
#define AM_DBG_SETUP(...)
32-
#define AM_DBG_PLAIN(...)
33-
#define AM_DBG(...)
28+
#define DBG_SETUP(...)
29+
#define DBG_PLAIN(...)
30+
#define DBG(...)
3431
#endif
35-
36-
END_APPLEMIDI_NAMESPACE

0 commit comments

Comments
 (0)