3535 *
3636 * @brief This file contains an implementation of a simple MIDI interpreter to parse incoming messages
3737 *
38- * MIDI_DUMP_Serial1_TO_SERIAL <- when active received data will be output as hex on serial(1)
39- * MIDI_SERIAL1_BAUDRATE <- use define to override baud-rate for MIDI, otherwise default of 31250 will be used
40- *
4138 * @see https://www.midi.org/specifications-old/item/table-1-summary-of-midi-message
4239 */
4340
@@ -133,9 +130,9 @@ void Midi_SendRaw(uint8_t *msg);
133130struct midi_port_s
134131{
135132 Stream * serial ; /* this can be software or hardware serial */
136- uint32_t inMsgWd ;
133+ uint32_t inMsgWd ;
137134 uint8_t inMsg [3 ];
138- uint8_t inMsgIndex ;
135+ uint8_t inMsgIndex ;
139136};
140137
141138#if (defined ARDUINO_DAISY_SEED ) || (defined STM32H7xx )
@@ -146,12 +143,6 @@ HardwareSerial Serial2(USART1);
146143HardwareSerial Serial2 (USART2 ); /* PA3 */
147144#endif
148145
149- #if 0
150- #ifdef ARDUINO_GENERIC_F407VGTX
151- HardwareSerial Serial2 (USART3 ); /* PB11 */
152- #endif
153- #endif
154-
155146#ifdef MIDI_PORT_ACTIVE
156147struct midi_port_s MidiPort ;
157148#endif
@@ -215,10 +206,6 @@ struct midiMapping_s
215206 void (* rttMsg )(uint8_t msg );
216207 void (* songPos )(uint16_t pos );
217208
218- #ifdef MIDI_SYSEX_ENABLED
219- void (* sysEx )(uint8_t * msg , uint8_t len );
220- #endif
221-
222209 struct midiControllerMapping * controlMapping ;
223210 int mapSize ;
224211
@@ -283,6 +270,11 @@ inline void Midi_CC_Map(uint8_t channel, uint8_t data1, uint8_t data2, struct mi
283270{
284271 for (int i = 0 ; i < mapSize ; i ++ )
285272 {
273+ /*
274+ * in case channel and control number matches or
275+ * in channel bit 0x10 is set, then the bit of the channel is set too and control number matches
276+ */
277+
286278 if (
287279 ((controlMapping [i ].channel == channel ) && (controlMapping [i ].data1 == data1 ))
288280 || (((controlMapping [i ].channel & 0x10 ) != 0 ) && ((controlMapping [i ].channel & (1 << channel )) != 0 ) && (controlMapping [i ].data1 == data1 ))
@@ -581,13 +573,15 @@ void Midi_Setup()
581573 Serial2 .setRX (MIDI_RX2_PIN );
582574#else
583575 Serial .printf ("Setup Serial2 with %d baud with rx: Serial2.rx\n" , MIDI_SERIAL2_BAUDRATE , PIN_CAPTION );
584- #endif /* MIDI_RX2_PIN */
576+ #endif
585577 Serial2 .begin (MIDI_SERIAL2_BAUDRATE );
578+
586579#endif /* ARDUINO_ARCH_RP2040 */
587580
588581 MidiPort2 .serial = & Serial2 ;
589582 Midi_PortSetup (& MidiPort2 );
590583 Serial .printf ("Setup MidiPort2 using Serial2\n" );
584+
591585#endif /* MIDI_PORT2_ACTIVE */
592586
593587#ifdef USB_MIDI_ENABLED
@@ -610,7 +604,9 @@ void Midi_CheckMidiPort(struct midi_port_s *port, uint8_t cable)
610604 /* ignore live messages */
611605 if ((incomingByte & 0xF0 ) == 0xF0 )
612606 {
613- Midi_RealTimeMessage (incomingByte );
607+ {
608+ Midi_RealTimeMessage (incomingByte );
609+ }
614610 return ;
615611 }
616612
@@ -687,6 +683,8 @@ void Midi_Process()
687683#endif
688684}
689685
686+ #ifndef ARDUINO_SEEED_XIAO_M0
687+ #ifndef SWAP_SERIAL
690688#ifdef MIDI_TX2_PIN
691689void Midi_SendShortMessage (uint8_t * msg )
692690{
@@ -722,42 +720,9 @@ void Midi_SendRaw(uint8_t *msg)
722720 MidiPort2 .serial -> write (msg , 3 );
723721 }
724722}
725- #elif defined(MIDI_TX1_PIN )
726- void Midi_SendShortMessage (uint8_t * msg )
727- {
728- MidiPort1 .serial -> write (msg , 3 );
729- }
730-
731- void Midi_SendRaw (uint8_t * msg )
732- {
733- /* sysex */
734- if (msg [0 ] == 0xF0 )
735- {
736- int i = 2 ;
737- while (msg [i ] != 0xF7 )
738- {
739- i ++ ;
740- }
741- MidiPort1 .serial -> write (msg , i + 1 );
742- }
743- else if ((msg [0 ] & 0xF0 ) == 0xC0 )
744- {
745- MidiPort1 .serial -> write (msg , 2 );
746- }
747- else if ((msg [0 ] & 0xF0 ) == 0xD0 )
748- {
749- MidiPort1 .serial -> write (msg , 2 );
750- }
751- else if ((msg [0 ] & 0xF0 ) == 0xF0 )
752- {
753- MidiPort1 .serial -> write (msg , 1 );
754- }
755- else
756- {
757- MidiPort1 .serial -> write (msg , 3 );
758- }
759- }
760- #endif /* MIDI_TX1_PIN */
723+ #endif /* MIDI_TX2_PIN */
724+ #endif
725+ #endif
761726
762727#ifdef MIDI_MAP_FLEX_ENABLED
763728void Midi_SetMidiMap (struct midiControllerMapping * controlMapping , int mapSize )
0 commit comments