]> git.0d.be Git - jack_mixer.git/commitdiff
Add jack_mix_box, a minimalistic jack mixer (no UI, controlled by MIDI)
authorFrédéric Péters <fpeters@0d.be>
Sat, 16 Jul 2011 14:34:35 +0000 (16:34 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sat, 16 Jul 2011 14:34:35 +0000 (16:34 +0200)
Makefile.am
NEWS
jack_mix_box.c [new file with mode: 0644]

index 76caaedb7fa3add786e116abbb8f42f4b7e641ad..e920e4485ea0ea34f05dd424f91caf0cb1d35664 100644 (file)
@@ -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 8f89ba1cbd2e2fd84ff5dda1b999cfd972575c5d..37e6b0a9beec4fdb6e6946c7c5e913391673f501 100644 (file)
--- 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 (file)
index 0000000..9f4432a
--- /dev/null
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ *
+ *   This file is part of jack_mixer
+ *
+ *   Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
+ *   Copyright (C) 2009-2011 Frederic Peters <fpeters@0d.be>
+ *
+ *   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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <getopt.h>
+#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;
+}