From: Frédéric Péters Date: Sat, 16 Jul 2011 14:34:35 +0000 (+0200) Subject: Add jack_mix_box, a minimalistic jack mixer (no UI, controlled by MIDI) X-Git-Tag: 10~8 X-Git-Url: https://git.0d.be/?p=jack_mixer.git;a=commitdiff_plain;h=a1b7fa108786d83ae087fc0e3ecbcd3a2d862334 Add jack_mix_box, a minimalistic jack mixer (no UI, controlled by MIDI) --- diff --git a/Makefile.am b/Makefile.am index 76caaed..e920e44 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,9 +45,17 @@ EXTRA_DIST = test.py COPYING jack_mixer.schemas jack_mixer.py NEWS bin_SCRIPTS = $(srcdir)/jack_mixer.py +bin_PROGRAMS = jack_mix_box + jack_mixer_c.so: jack_mixer_c.la ln -nfs .libs/jack_mixer_c.so +jack_mix_box_SOURCES = jack_mix_box.c jack_mixer.c scale.c log.c + +jack_mix_box_CFLAGS = $(JACKMIXER_CFLAGS) + +jack_mix_box_LDADD = $(JACKMIXER_LIBS) -lm + test: _jack_mixer_c.so @./test.py diff --git a/NEWS b/NEWS index 8f89ba1..37e6b0a 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Version 10 * Fixed change of channel settings (#18299) * Added a MIDI out port for feeding back volume levels into motorized controllers + * Added jack_mix_box, a minimalistic (no UI) jack mixer With contributions from John Hedges. diff --git a/jack_mix_box.c b/jack_mix_box.c new file mode 100644 index 0000000..9f4432a --- /dev/null +++ b/jack_mix_box.c @@ -0,0 +1,116 @@ +/***************************************************************************** + * + * This file is part of jack_mixer + * + * Copyright (C) 2006 Nedko Arnaudov + * Copyright (C) 2009-2011 Frederic Peters + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *****************************************************************************/ + +/* + * jack_mix_box is a most minimalistic jack mixer, a set of mono input + * channels, mixed to a single output channel, with the volume of the + * input channels controlled by MIDI control change (CC) codes. + * + * Usage: + * jack_mix_box [ -n JACK_CLI_NAME ] MIDI_CC_1 MIDI_CC_2 .... + */ + +#include +#include +#include +#include +#include +#include "jack_mixer.h" + +int +main(int argc, char *argv[]) +{ + jack_mixer_scale_t scale; + jack_mixer_t mixer; + jack_mixer_channel_t main_mix_channel; + char *jack_cli_name = NULL; + int channel_index; + + while (1) { + int c; + static struct option long_options[] = + { + {"name", required_argument, 0, 'n'}, + {0, 0, 0, 0} + }; + int option_index = 0; + + c = getopt_long (argc, argv, "n:", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'n': + jack_cli_name = strdup(optarg); + break; + default: + fprintf(stderr, "Unknown argument, aborting.\n"); + exit(1); + } + } + + if (optind == argc) { + fprintf(stderr, "You must specify at least one input channel\n"); + exit(1); + } + + scale = scale_create(); + scale_add_threshold(scale, -70.0, 0.0); + scale_add_threshold(scale, 0.0, 1.0); + scale_calculate_coefficients(scale); + + if (jack_cli_name == NULL) { + jack_cli_name = strdup("jack_mix_box"); + } + + mixer = create(jack_cli_name, false); + main_mix_channel = get_main_mix_channel(mixer); + channel_set_midi_scale(main_mix_channel, scale); + channel_volume_write(main_mix_channel, 0); + channel_set_volume_midi_cc(main_mix_channel, 0); + + channel_index = 0; + while (optind < argc) { + char *channel_name; + jack_mixer_channel_t channel; + + channel_index += 1; + channel_name = malloc(15); + if (snprintf(channel_name, 15, "Channel %d", channel_index) >= 15) { + abort(); + } + channel = add_channel(mixer, channel_name, false); + if (channel == NULL) { + fprintf(stderr, "Failed to add channel %d, aborting\n", channel_index); + exit(1); + } + channel_set_volume_midi_cc(channel, atoi(argv[optind++])); + channel_set_midi_scale(channel, scale); + channel_volume_write(channel, 0); + } + + while (true) { + sleep(1); + } + + return 0; +}