fixed uninstall target, now using debug flag properly in qt
[jackctlmmc.git] / main.c
blob4d4a151aa1c434a1242308830bafe91cc98e2b30
1 /* -*- Mode: C ; c-basic-offset: 3 -*- */
2 /*
3 * Control JACK transport using MMC (MIDI)
5 * Copyright (c) 2006,2007,2008 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (c) 2008 Alex Montgomery <apmontgomery@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License as published by the Free Software
10 * Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <signal.h>
22 #include <unistd.h>
23 #include <stdio.h>
24 #include <stdlib.h>
26 #include "common.h"
28 void printMMCMessage(const char* message, ...)
30 va_list args;
31 va_start(args, message);
33 vprintf(message, args);
35 va_end(args);
38 /* the signal handler */
39 void signalled(int signal)
41 g_quit = 1;
44 // foward declares
45 void process_command_line(int argc, char *argv[], uint32_t* device_frame_rate, uint32_t* jitter_tolerance, int* verbose, uint8_t* device_id);
46 void cleanup();
48 int main(int argc, char *argv[])
50 int ret = 0;
52 // frame rate (frames per second) of the MMC controlling device
53 uint32_t device_frame_rate = 30; // command line equivalent: -f 30
55 // jitter tolerance in milliseconds
56 uint32_t jitter_tolerance = 50; //command line: -t 50
58 uint8_t device_id = 0x7f; // command line -d 7f
60 int verbose = 0; // pass -v on the command line to turn this on
62 // read the jitter tolerance, verbose setting, and device frame rate from command line
63 process_command_line(argc, argv, &device_frame_rate, &jitter_tolerance, &verbose, &device_id);
65 printf("%s starting with a jitter tolerance of %d milliseconds and a device frame rate of %d per second listening for device %x.\n\n",
66 argv[0], jitter_tolerance, device_frame_rate, device_id);
68 // setup our signal handler signalled() above, so we can exit cleanly
69 signal(SIGINT, signalled);
71 ret = init_alsa_sequencer("jackctlmmc");
72 if (ret < 0)
74 cleanup();
75 exit(0);
78 if (init_jack("jackctlmmc") < 0)
80 printf("couldn't connect to jack server. Either it's not running or the client name is already taken\n");
81 cleanup();
82 exit(0);
85 #if LASH_SUPPORT
86 init_lash(argc, argv);
87 #endif // LASH_SUPPORT
89 activate_jack();
91 // start listening for and handling MMC events, stops when g_quit is true (SIGINT)
92 listen_loop(device_frame_rate, jitter_tolerance, verbose, device_id);
94 // so we shall quit, eh? ok, cleanup time. otherwise jack would probably produce an xrun on shutdown
95 cleanup();
97 if (verbose)
98 printf("exited normally\n");
100 return 0;
104 void process_command_line(int argc, char *argv[], // IN parameters
105 uint32_t* device_frame_rate, uint32_t* jitter_tolerance, int* verbose, uint8_t* device_id) // OUT parameters
107 int parameter;
108 long value;
109 while ((parameter = getopt(argc, argv, "f:t:d:v")) != -1)
111 switch (parameter)
113 case 'v':
114 *verbose = 1;
115 break;
116 case 'f':
117 value = strtol(optarg, 0, 10);
118 *device_frame_rate = (uint32_t)value;
119 break;
120 case 't':
121 value = strtol(optarg, 0, 10);
122 *jitter_tolerance = (uint32_t)value;
123 break;
124 case 'd':
125 value = strtol(optarg, 0, 16);
126 if (value >= 0 && value <= 255)
127 *device_id = (uint8_t)value;
128 break;
129 case '?':
130 fprintf(stderr, "usage: %s -f <device_frames_per_second> -t <jitter_tolerance_in_ms> -d <device_id_in_hexadecimal>\n", argv[0]);
131 exit(1);
132 break;
137 void cleanup()
139 printf("cleaning up...\n");
140 cleanup_globals();