]> git.0d.be Git - jack_mixer.git/blob - jack_mix_box.c
Ignore SIGHUP
[jack_mixer.git] / jack_mix_box.c
1 /*****************************************************************************
2  *
3  *   This file is part of jack_mixer
4  *
5  *   Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
6  *   Copyright (C) 2009-2011 Frederic Peters <fpeters@0d.be>
7  *
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
11  *
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.
16  *
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.
20  *
21  *****************************************************************************/
22
23 /*
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.
27  *
28  * Usage:
29  *   jack_mix_box [ -n JACK_CLI_NAME ] MIDI_CC_1 MIDI_CC_2 ....
30  */
31
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"
38
39 int
40 main(int argc, char *argv[])
41 {
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;
47
48         while (1) {
49                 int c;
50                 static struct option long_options[] =
51                 {
52                         {"name",  required_argument, 0, 'n'},
53                         {0, 0, 0, 0}
54                 };
55                 int option_index = 0;
56
57                 c = getopt_long (argc, argv, "n:", long_options, &option_index);
58                 if (c == -1)
59                         break;
60
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);
68                 }
69         }
70
71         if (optind == argc) {
72                 fprintf(stderr, "You must specify at least one input channel\n");
73                 exit(1);
74         }
75
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);
80
81         if (jack_cli_name == NULL) {
82                 jack_cli_name = strdup("jack_mix_box");
83         }
84
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);
90
91         channel_index = 0;
92         while (optind < argc) {
93                 char *channel_name;
94                 jack_mixer_channel_t channel;
95
96                 channel_index += 1;
97                 channel_name = malloc(15);
98                 if (snprintf(channel_name, 15, "Channel %d", channel_index) >= 15) {
99                         abort();
100                 }
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);
105                 }
106                 channel_set_volume_midi_cc(channel, atoi(argv[optind++]));
107                 channel_set_midi_scale(channel, scale);
108                 channel_volume_write(channel, 0);
109         }
110
111         while (true) {
112                 sleep(1);
113         }
114
115         return 0;
116 }