4444#endif
4545
4646
47- #ifdef ML_SYNTH_INLINE_DECLARATION
4847
48+ #if defined(ML_SYNTH_INLINE_DECLARATION ) || defined(ML_SYNTH_INLINE_DEFINITION )
49+ #ifndef MIDI_INTERFACE_H
50+ #define MIDI_INTERFACE_H
4951
5052#define MIDI_CHANNEL_MASK 0x10
5153#define MIDI_CHANNEL_0 0x01
5860#endif
5961
6062
63+
64+ /*
65+ * structure is used to build the mapping table
66+ */
67+ struct midiControllerMapping
68+ {
69+ uint8_t channel ;
70+ uint8_t data1 ;
71+ const char * desc ;
72+ void (* callback_mid )(uint8_t ch , uint8_t data1 , uint8_t data2 );
73+ #ifdef MIDI_FMT_INT
74+ void (* callback_val )(uint8_t userdata , uint8_t value );
75+ #else
76+ void (* callback_val )(uint8_t userdata , float value );
77+ #endif
78+ uint8_t user_data ;
79+ };
80+
81+ #ifdef MIDI_MAP_FLEX_ENABLED
82+ struct midiMapLookUpEntry
83+ {
84+ const char * desc ;
85+ struct midiControllerMapping * controlMap ;
86+ int controlMapSize ;
87+ };
88+ #endif
89+
90+ struct midiMapping_s
91+ {
92+ void (* rawMsg )(uint8_t * msg );
93+ #ifdef MIDI_FMT_INT
94+ void (* noteOn )(uint8_t ch , uint8_t note , uint8_t vel );
95+ void (* noteOff )(uint8_t ch , uint8_t note );
96+ void (* pitchBend )(uint8_t ch , uint16_t bend );
97+ void (* modWheel )(uint8_t ch , uint8_t value );
98+ #else
99+ void (* noteOn )(uint8_t ch , uint8_t note , float vel );
100+ void (* noteOff )(uint8_t ch , uint8_t note );
101+ void (* pitchBend )(uint8_t ch , float bend );
102+ void (* modWheel )(uint8_t ch , float value );
103+ #endif
104+ void (* programChange )(uint8_t ch , uint8_t program_number );
105+ #ifdef MIDI_CHANNEL_PRESSURE_ENABLED
106+ #ifdef MIDI_FMT_INT
107+ void (* channelPressure )(uint8_t ch , uint8_t pressure );
108+ #else
109+ void (* channelPressure )(uint8_t ch , float pressure );
110+ #endif
111+ #endif
112+ void (* rttMsg )(uint8_t msg );
113+ void (* songPos )(uint16_t pos );
114+
115+ struct midiControllerMapping * controlMapping ;
116+ int mapSize ;
117+
118+ #ifdef MIDI_MAP_FLEX_ENABLED
119+ /* the following map can be changed during runtime */
120+ struct midiControllerMapping * controlMapping_flex ;
121+ int mapSize_flex ;
122+ #endif
123+ };
124+
125+
61126void Midi_Setup (void );
62127void Midi_Process (void );
63128
@@ -79,7 +144,7 @@ void Midi_SendRaw(uint8_t *msg);
79144#endif
80145#endif
81146
82-
147+ #endif /* #ifndef MIDI_INTERFACE_H */
83148#endif /* ML_SYNTH_INLINE_DECLARATION */
84149
85150
@@ -157,66 +222,6 @@ struct midi_port_s MidiPort1;
157222struct midi_port_s MidiPort2 ;
158223#endif
159224
160- /*
161- * structure is used to build the mapping table
162- */
163- struct midiControllerMapping
164- {
165- uint8_t channel ;
166- uint8_t data1 ;
167- const char * desc ;
168- void (* callback_mid )(uint8_t ch , uint8_t data1 , uint8_t data2 );
169- #ifdef MIDI_FMT_INT
170- void (* callback_val )(uint8_t userdata , uint8_t value );
171- #else
172- void (* callback_val )(uint8_t userdata , float value );
173- #endif
174- uint8_t user_data ;
175- };
176-
177- #ifdef MIDI_MAP_FLEX_ENABLED
178- struct midiMapLookUpEntry
179- {
180- const char * desc ;
181- struct midiControllerMapping * controlMap ;
182- int controlMapSize ;
183- };
184- #endif
185-
186- struct midiMapping_s
187- {
188- void (* rawMsg )(uint8_t * msg );
189- #ifdef MIDI_FMT_INT
190- void (* noteOn )(uint8_t ch , uint8_t note , uint8_t vel );
191- void (* noteOff )(uint8_t ch , uint8_t note );
192- void (* pitchBend )(uint8_t ch , uint16_t bend );
193- void (* modWheel )(uint8_t ch , uint8_t value );
194- #else
195- void (* noteOn )(uint8_t ch , uint8_t note , float vel );
196- void (* noteOff )(uint8_t ch , uint8_t note );
197- void (* pitchBend )(uint8_t ch , float bend );
198- void (* modWheel )(uint8_t ch , float value );
199- #endif
200- void (* programChange )(uint8_t ch , uint8_t program_number );
201- #ifdef MIDI_CHANNEL_PRESSURE_ENABLED
202- #ifdef MIDI_FMT_INT
203- void (* channelPressure )(uint8_t ch , uint8_t pressure );
204- #else
205- void (* channelPressure )(uint8_t ch , float pressure );
206- #endif
207- #endif
208- void (* rttMsg )(uint8_t msg );
209- void (* songPos )(uint16_t pos );
210-
211- struct midiControllerMapping * controlMapping ;
212- int mapSize ;
213-
214- #ifdef MIDI_MAP_FLEX_ENABLED
215- /* the following map can be changed during runtime */
216- struct midiControllerMapping * controlMapping_flex ;
217- int mapSize_flex ;
218- #endif
219- };
220225
221226/*
222227 * following variables shall be defined in z_config.ino
@@ -723,6 +728,43 @@ void Midi_SendRaw(uint8_t *msg)
723728 }
724729}
725730#endif /* MIDI_TX2_PIN */
731+
732+ #ifdef MIDI_TX1_PIN
733+ void Midi_SendShortMessage (uint8_t * msg )
734+ {
735+ MidiPort1 .serial -> write (msg , 3 );
736+ }
737+
738+ void Midi_SendRaw (uint8_t * msg )
739+ {
740+ /* sysex */
741+ if (msg [0 ] == 0xF0 )
742+ {
743+ int i = 2 ;
744+ while (msg [i ] != 0xF7 )
745+ {
746+ i ++ ;
747+ }
748+ MidiPort1 .serial -> write (msg , i + 1 );
749+ }
750+ else if ((msg [0 ] & 0xF0 ) == 0xC0 )
751+ {
752+ MidiPort1 .serial -> write (msg , 2 );
753+ }
754+ else if ((msg [0 ] & 0xF0 ) == 0xD0 )
755+ {
756+ MidiPort1 .serial -> write (msg , 2 );
757+ }
758+ else if ((msg [0 ] & 0xF0 ) == 0xF0 )
759+ {
760+ MidiPort1 .serial -> write (msg , 1 );
761+ }
762+ else
763+ {
764+ MidiPort1 .serial -> write (msg , 3 );
765+ }
766+ }
767+ #endif /* MIDI_TX1_PIN */
726768#endif
727769#endif
728770
0 commit comments