gitignore generated files for jack_mix_box
[jack_mixer.git] / jack_mix_box.c
blob9f4432a6a9bf30d0bcbdf0aa53b5225228dbaad5
1 /*****************************************************************************
3 * This file is part of jack_mixer
5 * Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2009-2011 Frederic Peters <fpeters@0d.be>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *****************************************************************************/
24 * jack_mix_box is a most minimalistic jack mixer, a set of mono input
25 * channels, mixed to a single output channel, with the volume of the
26 * input channels controlled by MIDI control change (CC) codes.
28 * Usage:
29 * jack_mix_box [ -n JACK_CLI_NAME ] MIDI_CC_1 MIDI_CC_2 ....
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdbool.h>
36 #include <getopt.h>
37 #include "jack_mixer.h"
39 int
40 main(int argc, char *argv[])
42 jack_mixer_scale_t scale;
43 jack_mixer_t mixer;
44 jack_mixer_channel_t main_mix_channel;
45 char *jack_cli_name = NULL;
46 int channel_index;
48 while (1) {
49 int c;
50 static struct option long_options[] =
52 {"name", required_argument, 0, 'n'},
53 {0, 0, 0, 0}
55 int option_index = 0;
57 c = getopt_long (argc, argv, "n:", long_options, &option_index);
58 if (c == -1)
59 break;
61 switch (c) {
62 case 'n':
63 jack_cli_name = strdup(optarg);
64 break;
65 default:
66 fprintf(stderr, "Unknown argument, aborting.\n");
67 exit(1);
71 if (optind == argc) {
72 fprintf(stderr, "You must specify at least one input channel\n");
73 exit(1);
76 scale = scale_create();
77 scale_add_threshold(scale, -70.0, 0.0);
78 scale_add_threshold(scale, 0.0, 1.0);
79 scale_calculate_coefficients(scale);
81 if (jack_cli_name == NULL) {
82 jack_cli_name = strdup("jack_mix_box");
85 mixer = create(jack_cli_name, false);
86 main_mix_channel = get_main_mix_channel(mixer);
87 channel_set_midi_scale(main_mix_channel, scale);
88 channel_volume_write(main_mix_channel, 0);
89 channel_set_volume_midi_cc(main_mix_channel, 0);
91 channel_index = 0;
92 while (optind < argc) {
93 char *channel_name;
94 jack_mixer_channel_t channel;
96 channel_index += 1;
97 channel_name = malloc(15);
98 if (snprintf(channel_name, 15, "Channel %d", channel_index) >= 15) {
99 abort();
101 channel = add_channel(mixer, channel_name, false);
102 if (channel == NULL) {
103 fprintf(stderr, "Failed to add channel %d, aborting\n", channel_index);
104 exit(1);
106 channel_set_volume_midi_cc(channel, atoi(argv[optind++]));
107 channel_set_midi_scale(channel, scale);
108 channel_volume_write(channel, 0);
111 while (true) {
112 sleep(1);
115 return 0;