|
23 | 23 | * THE SOFTWARE.
|
24 | 24 | */
|
25 | 25 |
|
| 26 | +#if defined (DEBUG_ARM_LTCMIDISYSTEMREALTIME) |
| 27 | +# undef NDEBUG |
| 28 | +#endif |
| 29 | + |
26 | 30 | #pragma GCC push_options
|
27 | 31 | #pragma GCC optimize ("O2")
|
28 | 32 | #pragma GCC optimize ("no-tree-loop-distribute-patterns")
|
@@ -74,7 +78,7 @@ static void timer_handler() {
|
74 | 78 | #endif
|
75 | 79 |
|
76 | 80 | void LtcMidiSystemRealtime::Start() {
|
77 |
| - m_nHandle = Network::Get()->Begin(udp::PORT); |
| 81 | + m_nHandle = Network::Get()->Begin(udp::PORT, staticCallbackFunctionInput); |
78 | 82 | assert(m_nHandle != -1);
|
79 | 83 | }
|
80 | 84 |
|
@@ -104,67 +108,61 @@ void LtcMidiSystemRealtime::SetBPM(uint32_t nBPM) {
|
104 | 108 | }
|
105 | 109 | }
|
106 | 110 |
|
107 |
| -void LtcMidiSystemRealtime::Run() { |
108 |
| - uint32_t nIPAddressFrom; |
109 |
| - uint16_t nForeignPort; |
110 |
| - |
111 |
| - auto nBytesReceived = Network::Get()->RecvFrom(m_nHandle, const_cast<const void **>(reinterpret_cast<void **>(&s_pUdpBuffer)), &nIPAddressFrom, &nForeignPort); |
112 |
| - |
113 |
| - if (__builtin_expect((nBytesReceived < 9), 1)) { |
114 |
| - return; |
115 |
| - } |
116 |
| - |
117 |
| - if (__builtin_expect((memcmp("midi!", s_pUdpBuffer, 5) != 0), 0)) { |
| 111 | +void LtcMidiSystemRealtime::Input(const uint8_t *pBuffer, uint32_t nSize, [[maybe_unused]] uint32_t nFromIp, [[maybe_unused]] uint16_t nFromPort) { |
| 112 | + if (__builtin_expect((memcmp("midi!", pBuffer, 5) != 0), 0)) { |
118 | 113 | return;
|
119 | 114 | }
|
120 | 115 |
|
121 |
| - if (s_pUdpBuffer[nBytesReceived - 1] == '\n') { |
122 |
| - nBytesReceived--; |
| 116 | + if (pBuffer[nSize - 1] == '\n') { |
| 117 | + nSize--; |
123 | 118 | }
|
124 | 119 |
|
125 |
| - debug_dump(s_pUdpBuffer, nBytesReceived); |
| 120 | + debug_dump(pBuffer, nSize); |
126 | 121 |
|
127 |
| - if (nBytesReceived == (5 + length::START)) { |
128 |
| - if (memcmp(&s_pUdpBuffer[5], cmd::START, length::START) == 0) { |
| 122 | + if (nSize == (5 + length::START)) { |
| 123 | + if (memcmp(&pBuffer[5], cmd::START, length::START) == 0) { |
129 | 124 | SendStart();
|
130 | 125 | DEBUG_PUTS("Start");
|
131 | 126 | return;
|
132 | 127 | }
|
133 | 128 | }
|
134 | 129 |
|
135 |
| - if (nBytesReceived == (5 + length::STOP)) { |
136 |
| - if (memcmp(&s_pUdpBuffer[5], cmd::STOP, length::STOP) == 0) { |
| 130 | + if (nSize == (5 + length::STOP)) { |
| 131 | + if (memcmp(&pBuffer[5], cmd::STOP, length::STOP) == 0) { |
137 | 132 | SendStop();
|
138 | 133 | DEBUG_PUTS("Stop");
|
139 | 134 | return;
|
140 | 135 | }
|
141 | 136 | }
|
142 | 137 |
|
143 |
| - if (nBytesReceived == (5 + length::CONTINUE)) { |
144 |
| - if (memcmp(&s_pUdpBuffer[5], cmd::CONTINUE, length::CONTINUE) == 0) { |
| 138 | + if (nSize == (5 + length::CONTINUE)) { |
| 139 | + if (memcmp(&pBuffer[5], cmd::CONTINUE, length::CONTINUE) == 0) { |
145 | 140 | SendContinue();
|
146 | 141 | DEBUG_PUTS("Continue");
|
147 | 142 | return;
|
148 | 143 | }
|
149 | 144 | }
|
150 | 145 |
|
151 |
| - if (nBytesReceived == (5 + length::BPM + 3)) { |
152 |
| - if (memcmp(&s_pUdpBuffer[5], cmd::BPM, length::BPM) == 0) { |
| 146 | + if (nSize == (5 + length::BPM + 3)) { |
| 147 | + if (memcmp(&pBuffer[5], cmd::BPM, length::BPM) == 0) { |
153 | 148 | uint32_t nOfffset = 5 + length::BPM;
|
154 | 149 | uint32_t nBPM;
|
155 | 150 |
|
156 |
| - if (isdigit(s_pUdpBuffer[nOfffset])) { |
157 |
| - nBPM = 100U * static_cast<uint32_t>(s_pUdpBuffer[nOfffset++] - '0'); |
158 |
| - if (isdigit(s_pUdpBuffer[nOfffset])) { |
159 |
| - nBPM += 10U * static_cast<uint32_t>(s_pUdpBuffer[nOfffset++] - '0'); |
160 |
| - if (isdigit(s_pUdpBuffer[nOfffset])) { |
161 |
| - nBPM += static_cast<uint32_t>(s_pUdpBuffer[nOfffset++] - '0'); |
| 151 | + if (isdigit(pBuffer[nOfffset])) { |
| 152 | + nBPM = 100U * static_cast<uint32_t>(pBuffer[nOfffset++] - '0'); |
| 153 | + |
| 154 | + if (isdigit(pBuffer[nOfffset])) { |
| 155 | + nBPM += 10U * static_cast<uint32_t>(pBuffer[nOfffset++] - '0'); |
| 156 | + |
| 157 | + if (isdigit(pBuffer[nOfffset])) { |
| 158 | + nBPM += static_cast<uint32_t>(pBuffer[nOfffset++] - '0'); |
162 | 159 | SetBPM(nBPM);
|
163 | 160 | ShowBPM(nBPM);
|
164 | 161 | DEBUG_PRINTF("BPM: %u", nBPM);
|
165 | 162 | }
|
166 | 163 | }
|
167 | 164 | }
|
| 165 | + |
168 | 166 | return;
|
169 | 167 | }
|
170 | 168 | }
|
|
0 commit comments