Make it possible to specify exactly which ports MIDI pass-through should be applied to.

master
Albert Graef 2018-09-18 22:31:12 +02:00
parent 5e284565df
commit 5a87c30f66
5 changed files with 48 additions and 15 deletions

View File

@ -151,7 +151,7 @@ process_midi_input(JACK_SEQ* seq,jack_nframes_t nframes)
void *port_buffer = jack_port_get_buffer(seq->input_port[k], nframes); void *port_buffer = jack_port_get_buffer(seq->input_port[k], nframes);
// this is used for direct pass-through of system messages // this is used for direct pass-through of system messages
void *out_buffer = seq->passthrough && k < seq->n_out? void *out_buffer = seq->passthrough[k] && k < seq->n_out?
jack_port_get_buffer(seq->output_port[k], nframes):0; jack_port_get_buffer(seq->output_port[k], nframes):0;
if (port_buffer == NULL) if (port_buffer == NULL)
{ {
@ -233,7 +233,7 @@ process_midi_output(JACK_SEQ* seq,jack_nframes_t nframes)
return; return;
} }
if (!seq->passthrough) if (!seq->passthrough[k])
{ {
#ifdef JACK_MIDI_NEEDS_NFRAMES #ifdef JACK_MIDI_NEEDS_NFRAMES
jack_midi_clear_buffer(port_buffer, nframes); jack_midi_clear_buffer(port_buffer, nframes);

View File

@ -11,7 +11,7 @@ typedef struct _jseq
jack_client_t *jack_client; jack_client_t *jack_client;
jack_port_t **output_port; jack_port_t **output_port;
jack_port_t **input_port; jack_port_t **input_port;
uint8_t n_in, n_out, passthrough; uint8_t n_in, n_out, passthrough[2];
} JACK_SEQ; } JACK_SEQ;
extern int jack_quit; extern int jack_quit;

View File

@ -21,7 +21,7 @@ Display *display;
JACK_SEQ seq; JACK_SEQ seq;
int jack_num_outputs = 0, debug_jack = 0; int jack_num_outputs = 0, debug_jack = 0;
int auto_feedback = 1, system_passthrough = 0; int auto_feedback = 1, system_passthrough[2] = {-1, -1};
int shift = 0; int shift = 0;
void void
@ -1579,7 +1579,7 @@ handle_event(uint8_t *msg, uint8_t portno, int depth, int recursive)
void help(char *progname) void help(char *progname)
{ {
fprintf(stderr, "Usage: %s [-hkns] [-d[rskmj]] [-o[n]] [-j name] [-P[prio]] [-r rcfile]\n", progname); fprintf(stderr, "Usage: %s [-hkn] [-d[rskmj]] [-os[n]] [-j name] [-P[prio]] [-r rcfile]\n", progname);
fprintf(stderr, "-h print this message\n"); fprintf(stderr, "-h print this message\n");
fprintf(stderr, "-d debug (r = regex, s = strokes, k = keys, m = midi, j = jack; default: all)\n"); fprintf(stderr, "-d debug (r = regex, s = strokes, k = keys, m = midi, j = jack; default: all)\n");
fprintf(stderr, "-j jack client name (default: midizap)\n"); fprintf(stderr, "-j jack client name (default: midizap)\n");
@ -1588,7 +1588,7 @@ void help(char *progname)
fprintf(stderr, "-o set number of MIDI output ports (0-2, default: 1)\n"); fprintf(stderr, "-o set number of MIDI output ports (0-2, default: 1)\n");
fprintf(stderr, "-P set real-time priority (default: 90)\n"); fprintf(stderr, "-P set real-time priority (default: 90)\n");
fprintf(stderr, "-r config file name (default: MIDIZAP_CONFIG_FILE variable or ~/.midizaprc)\n"); fprintf(stderr, "-r config file name (default: MIDIZAP_CONFIG_FILE variable or ~/.midizaprc)\n");
fprintf(stderr, "-s pass-through of system messages\n"); fprintf(stderr, "-s pass-through of system messages (0-2; default: all ports)\n");
} }
uint8_t quit = 0; uint8_t quit = 0;
@ -1665,7 +1665,7 @@ main(int argc, char **argv)
// Start recording the command line to be passed to Jack session management. // Start recording the command line to be passed to Jack session management.
add_command(argv[0], 0); add_command(argv[0], 0);
while ((opt = getopt(argc, argv, "hkno::d::j:r:P::s")) != -1) { while ((opt = getopt(argc, argv, "hkno::d::j:r:P::s::")) != -1) {
switch (opt) { switch (opt) {
case 'h': case 'h':
help(argv[0]); help(argv[0]);
@ -1758,8 +1758,28 @@ main(int argc, char **argv)
} }
break; break;
case 's': case 's':
system_passthrough = 1; if (optarg && *optarg) {
add_command("-s", 1); const char *a = optarg;
if (!strcmp(a, "2")) {
system_passthrough[0] = 0;
system_passthrough[1] = 1;
add_command("-s2", 1);
} else if (!strcmp(a, "1")) {
system_passthrough[0] = 1;
system_passthrough[1] = 0;
add_command("-s1", 1);
} else if (!strcmp(a, "0")) {
system_passthrough[0] = system_passthrough[1] = 0;
add_command("-s0", 1);
} else {
fprintf(stderr, "%s: wrong port number (-s), must be 0, 1 or 2\n", argv[0]);
fprintf(stderr, "Try -h for help.\n");
exit(1);
}
} else {
system_passthrough[0] = system_passthrough[1] = 1;
add_command("-s", 1);
}
break; break;
default: default:
fprintf(stderr, "Try -h for help.\n"); fprintf(stderr, "Try -h for help.\n");
@ -1786,7 +1806,8 @@ main(int argc, char **argv)
seq.client_name = jack_client_name; seq.client_name = jack_client_name;
seq.n_in = jack_num_outputs>1?jack_num_outputs:1; seq.n_in = jack_num_outputs>1?jack_num_outputs:1;
seq.n_out = jack_num_outputs>0?jack_num_outputs:0; seq.n_out = jack_num_outputs>0?jack_num_outputs:0;
seq.passthrough = jack_num_outputs>0?system_passthrough:0; seq.passthrough[0] = jack_num_outputs>0?system_passthrough[0]>0:0;
seq.passthrough[1] = jack_num_outputs>1?system_passthrough[1]>0:0;
if (!init_jack(&seq, debug_jack)) { if (!init_jack(&seq, debug_jack)) {
exit(1); exit(1);
} }

View File

@ -134,6 +134,6 @@ extern int debug_regex, debug_strokes, debug_keys, debug_midi;
extern int default_debug_regex, default_debug_strokes, default_debug_keys, extern int default_debug_regex, default_debug_strokes, default_debug_keys,
default_debug_midi; default_debug_midi;
extern char *config_file_name; extern char *config_file_name;
extern int jack_num_outputs, system_passthrough, auto_feedback; extern int jack_num_outputs, system_passthrough[2], auto_feedback;
extern int midi_octave, shift; extern int midi_octave, shift;
extern char *jack_client_name; extern char *jack_client_name;

View File

@ -1914,10 +1914,6 @@ read_config_file(void)
auto_feedback = 0; // -n auto_feedback = 0; // -n
continue; continue;
} }
if (!strcmp(tok, "SYSTEM_PASSTHROUGH")) {
system_passthrough = 1; // -s
continue;
}
if (!strcmp(tok, "JACK_NAME")) { if (!strcmp(tok, "JACK_NAME")) {
char *a = token(NULL, &delim); char *a = token(NULL, &delim);
if (!jack_client_name) { if (!jack_client_name) {
@ -1939,6 +1935,22 @@ read_config_file(void)
} }
continue; continue;
} }
if (!strcmp(tok, "SYSTEM_PASSTHROUGH")) { // -s
char *a = token(NULL, &delim);
int k, n;
if (a && *a && *a != '#') {
if (sscanf(a, "%d%n", &k, &n) == 1 && !a[n] && k>=0 && k<=2) {
if (system_passthrough[0] < 0) system_passthrough[0] = k==1;
if (system_passthrough[1] < 0) system_passthrough[1] = k==2;
} else {
fprintf(stderr, "invalid port number: %s, must be 0, 1 or 2\n", a);
}
} else {
if (system_passthrough[0] < 0) system_passthrough[0] = 1;
if (system_passthrough[1] < 0) system_passthrough[1] = 1;
}
continue;
}
if (!strncmp(tok, "MIDI_OCTAVE", 11)) { if (!strncmp(tok, "MIDI_OCTAVE", 11)) {
char *a = tok+11; char *a = tok+11;
int k, n; int k, n;