Skip to content

Commit

Permalink
Honor MIDI CC value/range inversion for feedback -- closes pantherb#50
Browse files Browse the repository at this point in the history
  • Loading branch information
x42 committed Mar 26, 2018
1 parent 9309bd4 commit ff4b07b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 6 additions & 2 deletions b_synth/lv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,17 @@ static void mctl_cb(int fnid, const char *fn, unsigned char val, midiCCmap *mm,
#endif
if (b3s->midiout && mm) {
while (mm) {
unsigned char v = val & 0x7f;
if (getCtrlFlag (b3s->inst->midicfg, mm->channel, mm->param) & MFLAG_INV) {
v = 127 - v;
}
#ifdef DEBUGPRINT
fprintf(stderr, "MIDI FEEDBACK %d %d %d\n", mm->channel, mm->param, val);
fprintf(stderr, "MIDI FEEDBACK %d %d %d\n", mm->channel, mm->param, v);
#endif
uint8_t msg[3];
msg[0] = 0xb0 | (mm->channel&0x0f); // Control Change
msg[1] = mm->param;
msg[2] = val;
msg[2] = v;
forge_midimessage(&b3s->forge, &b3s->uris, msg, 3);
mm = mm->next;
}
Expand Down
9 changes: 7 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,20 @@ static int queued_events_end = 0;
static void mctl_cb (int fnid, const char *fn, unsigned char val, midiCCmap *mm, void *arg) {
while (mm) {

// printf("MIDI FEEDBACK chn:%d param:%d val:%d\n", mm->channel, mm->param, val);
unsigned char v = val & 0x7f;
if (getCtrlFlag (inst.midicfg, mm->channel, mm->param) & MFLAG_INV) {
v = 127 - v;
}

// printf("MIDI FEEDBACK chn:%d param:%d val:%d\n", mm->channel, mm->param, v);

if (((queued_events_start + 1) % JACK_MIDI_QUEUE_SIZE) == queued_events_end) {
return;
}
event_queue[queued_events_start].size = 3;
event_queue[queued_events_start].buffer[0] = 0xb0 | (mm->channel & 0x0f);
event_queue[queued_events_start].buffer[1] = (mm->param & 0x7f);
event_queue[queued_events_start].buffer[2] = (val & 0x7f);
event_queue[queued_events_start].buffer[2] = v;
queued_events_start = (queued_events_start + 1) % JACK_MIDI_QUEUE_SIZE;

mm = mm->next;
Expand Down
7 changes: 6 additions & 1 deletion src/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ static void assignMIDIControllerFunction (ctrl_function *vec,
}
}

unsigned int getCtrlFlag (void *mcfg, uint8_t channel, uint8_t param) {
struct b_midicfg * m = (struct b_midicfg *) mcfg;
return m->ctrlflg[channel][param];
}

/*
* 26-sep-2004/FK This is the entry point for modules that wish to register
* functions that accept MIDI controller data. Functions entered through this
Expand Down Expand Up @@ -1310,7 +1315,7 @@ static void dumpCCAssigment(FILE * fp, unsigned char *ctrl, midiccflags_t *flags
fprintf(fp," Controller | Function \n");
for (i=0;i<127;++i) {
if (ctrl[i] != 255) {
fprintf(fp," %03d | %s %s\n", ctrl[i], ccFuncNames[i], (flags[i]&1)?"-":"");
fprintf(fp," %03d | %s %s\n", ctrl[i], ccFuncNames[i], (flags[ctrl[i]] & MFLAG_INV)?"-":"");
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ enum { // 1,2,4,8,.. - adjust ctrlflg once >8 to uint16_t
MFLAG_INV = 1,
};

unsigned int getCtrlFlag (void *mcfg, uint8_t channel, uint8_t param);

void useMIDIControlFunction (void *m, const char * cfname, void (* f) (void *, unsigned char), void *d);
void callMIDIControlFunction (void *m, const char * cfname, unsigned char val);
void notifyControlChangeByName (void *mcfg, const char * cfname, unsigned char val);
Expand Down

0 comments on commit ff4b07b

Please sign in to comment.