Skip to content

Commit a03a079

Browse files
committed
Implements zynthian/zynthian-issue-tracking#1473: Mechanism to unroute from zmops a set of zmip's MIDI channels (ui_midi_channels).
This is used by some ctrldev drivers.
1 parent f4fed76 commit a03a079

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

zynmidirouter.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ int zmip_init(int iz, char *name, uint32_t flags) {
375375
zmips[iz].event.time = 0xFFFFFFFF;
376376
zmips[iz].event_count = 0;
377377
zmips[iz].flags = flags;
378+
zmips[iz].ui_midi_chans = 0;
378379
memset(zmips[iz].last_ctrl_val, 0, 16 * 128);
379380

380381
// Create direct input ring-buffer
@@ -516,6 +517,24 @@ int zmip_get_flag_system_rt(int iz) {
516517
return zmips[ZMIP_DEV0 + iz].flags & (uint32_t)FLAG_ZMIP_SYSTEM_RT;
517518
}
518519

520+
// MIDI chans reserved for UI
521+
int zmip_set_ui_midi_chans(int iz, uint16_t ui_midi_chans) {
522+
if (iz < 0 || iz >= MAX_NUM_ZMIPS) {
523+
fprintf(stderr, "ZynMidiRouter: Bad input port index (%d).\n", iz);
524+
return 0;
525+
}
526+
zmips[iz].ui_midi_chans = ui_midi_chans;
527+
return 1;
528+
}
529+
530+
uint16_t zmip_get_ui_midi_chans(int iz) {
531+
if (iz < 0 || iz >= MAX_NUM_ZMIPS) {
532+
fprintf(stderr, "ZynMidiRouter: Bad input port index (%d).\n", iz);
533+
return 0;
534+
}
535+
return zmips[iz].ui_midi_chans;
536+
}
537+
519538
//Route/unroute a MIDI input device (zmip) to *ALL* chain zmops
520539
int zmip_set_route_chains(int iz, int route) {
521540
if (iz < 0 || iz >= MAX_NUM_ZMIPS) {
@@ -1495,6 +1514,8 @@ int jack_process(jack_nframes_t nframes, void *arg) {
14951514
}
14961515
} else {
14971516
write_zynmidi((event_idev << 24) | (ev->buffer[0] << 16) | (ev->buffer[1] << 8) | (ev->buffer[2]));
1517+
// MIDI chans reserved for UI => Don't route to zmops!
1518+
if (event_type < SYSTEM_EXCLUSIVE && ((zmip->ui_midi_chans >> event_chan) & 0x1)) goto event_processed;
14981519
}
14991520
}
15001521

@@ -1614,6 +1635,7 @@ int jack_process(jack_nframes_t nframes, void *arg) {
16141635
pedal_sent[pedal] |= (1 << izmop);
16151636
else
16161637
pedal_sent[pedal] &= ~(1 << izmop);
1638+
16171639
// Add processed event to MIDI output port buffer
16181640
zmop_push_event(zmop, ev);
16191641

zynmidirouter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct zmip_st {
194194
jack_ringbuffer_t * rbuffer; // Direct input ring buffer => Used when DIRECTIN flag is set
195195

196196
uint32_t flags; // Bitwise flags influencing input behaviour
197+
uint16_t ui_midi_chans; // Bitwise maks of MIDI channels reserved for UI (not routed to zmops!)
197198

198199
uint32_t event_count; // Quantity of events in input event queue (not fake queues)
199200
uint32_t next_event; // Index of the next event to be processed (not fake queues)
@@ -222,6 +223,10 @@ int zmip_get_flag_system(int iz);
222223
int zmip_set_flag_system_rt(int iz, uint8_t flag);
223224
int zmip_get_flag_system_rt(int iz);
224225

226+
// MIDI chans reserved for UI
227+
int zmip_set_ui_midi_chans(int iz, uint16_t ui_midi_chans);
228+
uint16_t zmip_get_ui_midi_chans(int iz);
229+
225230
// Routing
226231
int zmip_set_route_chains(int iz, int route); // Route/un-route a MIDI input port (zmip) to/from *ALL* zmop chains
227232

0 commit comments

Comments
 (0)