Skip to content

Commit

Permalink
Implement zmop fine-grain CC routing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jofemodo committed Mar 6, 2024
1 parent eff82e5 commit a548b43
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
40 changes: 39 additions & 1 deletion zynmidirouter.c
Expand Up @@ -492,6 +492,9 @@ int zmop_init(int iz, char *name, uint32_t flags) {
for (i = 0; i < 16; i++) {
zmops[iz].last_pb_val[i] = 8192;
}
for (i = 0; i < 128; i++) {
zmops[iz].cc_route[i] = 0;
}

// Create direct output ring-buffer
if (flags & FLAG_ZMOP_DIRECTOUT) {
Expand Down Expand Up @@ -993,6 +996,41 @@ int zmop_reset_note_range_transpose(int iz) {
return 1;
}

// CC routing

int zmop_reset_cc_route(int iz) {
if (iz < 0 || iz >= MAX_NUM_ZMOPS) {
fprintf(stderr, "ZynMidiRouter: Bad output port index (%d).\n", iz);
return 0;
}
for (int i = 0; i < 128; i++) {
zmops[iz].cc_route[i] = 0;
}
return 1;
}

int zmop_set_cc_route(int iz, uint8_t *cc_route) {
if (iz < 0 || iz >= MAX_NUM_ZMOPS) {
fprintf(stderr, "ZynMidiRouter: Bad output port index (%d).\n", iz);
return 0;
}
for (int i = 0; i < 128; i++) {
zmops[iz].cc_route[i] = cc_route[i];
}
return 1;
}

int zmop_get_cc_route(int iz, uint8_t *cc_route) {
if (iz < 0 || iz >= MAX_NUM_ZMOPS) {
fprintf(stderr, "ZynMidiRouter: Bad output port index (%d).\n", iz);
return 0;
}
for (int i = 0; i < 128; i++) {
cc_route[i] = zmops[iz].cc_route[i];
}
return 1;
}

//-----------------------------------------------------------------------------
// Jack MIDI processing
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1381,7 +1419,7 @@ int jack_process(jack_nframes_t nframes, void *arg) {
}

// Drop "CC messages" if configured in zmop options, except from internal sources (UI, etc.)
if (event_type == CTRL_CHANGE && (zmop->flags & FLAG_ZMOP_DROPCC) && izmip <= ZMIP_CTRL)
if (event_type == CTRL_CHANGE && (zmop->flags & FLAG_ZMOP_DROPCC && zmop->cc_route[event_num] == 0) && izmip <= ZMIP_CTRL)
goto zmop_event_processed;

// Drop "Program Change" if configured in zmop options, except from internal sources (UI)
Expand Down
5 changes: 5 additions & 0 deletions zynmidirouter.h
Expand Up @@ -302,6 +302,7 @@ struct zmop_st {
int midi_chan; // Single MIDI channel. -1 for using channel translation map.
int midi_chans[16]; // MIDI channel translation map (-1 to disable a MIDI channel)
int route_from_zmips[MAX_NUM_ZMIPS]; // Flags indicating which inputs to route to this output
uint8_t cc_route[128]; // CCs routed to output (0 = blocked, 1 = routed)
uint32_t flags; // Bitwise flags influencing output behaviour
uint8_t note_low; // Note range => Low note
uint8_t note_high; // Note range => High note
Expand Down Expand Up @@ -365,6 +366,10 @@ int8_t zmop_get_transpose_semitone(int iz);
int8_t get_global_transpose();
int zmop_set_note_range_transpose(int iz, uint8_t nlow, uint8_t nhigh, int8_t trans_oct, int8_t trans_semi);
int zmop_reset_note_range_transpose(int iz);
// CC routing
int zmop_reset_cc_route(int iz);
int zmop_set_cc_route(int iz, uint8_t *cc_route);
int zmop_get_cc_route(int iz, uint8_t *cc_route);
// ----------------------------------------------------------------------------
// This is called from jack process!!
void zmop_push_event(struct zmop_st * zmop, jack_midi_event_t * ev); // Add event to MIDI output port
Expand Down

0 comments on commit a548b43

Please sign in to comment.