2828#define LOG_X 2
2929#define COMM_EXTRA_X 17
3030#define PITCH_X 6
31+ #define CHANGE_X (PITCH_X + 4)
3132
3233#define ROUTING_X 1
3334#define ROUTING_Y (MAX_EFFECTIVE_Y - 2)
5859#define LED_TILE_OFF_OFFSET (LED_TILE_COUNT)
5960#define LOAD_TILE_Y (MAX_EFFECTIVE_Y + 1)
6061
62+ #define UI_CHANGE_TTL (50 * 3)
63+
6164static const char HEADER [] = "Mega Drive MIDI Interface" ;
6265static const char MIDI_CH_TEXT [16 ][3 ] = { " 1" , " 2" , " 3" , " 4" , " 5" , " 6" , " 7" , " 8" , " 9" ,
6366 "10" , "11" , "12" , "13" , "14" , "15" , "16" };
@@ -91,15 +94,25 @@ static void print_routing_mode(bool enabled);
9194static void print_mappings_if_dirty (u8 * midiChans );
9295static void print_mappings (void );
9396static void update (u16 delta );
97+ static void midi_change_callback (MidiChangeEvent event );
9498
9599static u8 lastPitches [DEV_PHYSICAL_CHANS ] = { 0 };
96100
101+ typedef struct MidiUiChange {
102+ MidiChangeType type ;
103+ u8 value ;
104+ u16 ttl ;
105+ } MidiUiChange ;
106+
107+ static MidiUiChange lastMidiChangeEvent [DEV_PHYSICAL_CHANS ] = { 0 };
108+
97109static u16 loadPercentSum = 0 ;
98110static bool commInited = false;
99111
100112void ui_init (void )
101113{
102114 scheduler_addFrameHandler (update );
115+ midi_register_change_callback (midi_change_callback );
103116 SPR_init ();
104117
105118 // 0x0000A0 = blue
@@ -125,6 +138,21 @@ void ui_init(void)
125138 ui_fm_init ();
126139}
127140
141+ static void midi_change_callback (MidiChangeEvent event )
142+ {
143+ u8 midiChannel = event .chan ;
144+ DeviceChannel * devChans = midi_channel_mappings ();
145+ for (u8 i = 0 ; i < DEV_PHYSICAL_CHANS ; i ++ ) {
146+ if (devChans [i ].midiChannel == midiChannel ) {
147+ lastMidiChangeEvent [i ] = (MidiUiChange ) {
148+ .type = event .type ,
149+ .value = event .value ,
150+ .ttl = UI_CHANGE_TTL ,
151+ };
152+ }
153+ }
154+ }
155+
128156static void update_ch3sp (bool enabled )
129157{
130158 if (enabled ) {
@@ -202,9 +230,40 @@ static void print_ticks(void)
202230
203231static bool lastCh3SpecialMode = false;
204232
233+ static void print_midi_changes (void )
234+ {
235+ for (u8 chan = 0 ; chan < DEV_PHYSICAL_CHANS ; chan ++ ) {
236+ MidiUiChange * change = & lastMidiChangeEvent [chan ];
237+ if (change -> type == MidiChangeType_None ) {
238+ continue ;
239+ }
240+ if (change -> ttl == 0 ) {
241+ change -> type = MidiChangeType_None ;
242+ VDP_clearTextArea (CHANGE_X + MARGIN_X , MARGIN_Y + MIDI_Y + (chan * 2 ), 6 , 1 );
243+ continue ;
244+ }
245+ if (change -> ttl == UI_CHANGE_TTL ) {
246+ VDP_setTextPalette (PAL2 );
247+ switch (change -> type ) {
248+ case MidiChangeType_Program : {
249+ char text [7 ];
250+ sprintf (text , "Pr=%-3d" , change -> value );
251+ draw_text (text , CHANGE_X , MIDI_Y + (chan * 2 ));
252+ break ;
253+ }
254+ default :
255+ break ;
256+ }
257+ VDP_setTextPalette (PAL0 );
258+ }
259+ change -> ttl -- ;
260+ }
261+ }
262+
205263static void update (u16 delta )
206264{
207265 update_key_on_off ();
266+ print_midi_changes ();
208267
209268 static u16 activityFrame = 0 ;
210269 activityFrame += delta ;
0 commit comments