Fix warning: unused parameter ‘pos’
[jackctlmmc.git] / main.c
blob46faeff8cd2f1e30850b680befa1e76e9dcee6f7
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"
29 /* the signal handler */
30 void signalled(int signal)
32 g_quit = 1;
35 // foward declares
36 void process_command_line(int argc, char *argv[], uint32_t* device_frame_rate, uint32_t* jitter_tolerance, int* verbose);
37 void cleanup();
39 int main(int argc, char *argv[])
41 int ret = 0;
43 // frame rate (frames per second) of the MMC controlling device
44 uint32_t device_frame_rate = 30; // command line equivalent: -f 30
46 // jitter tolerance in milliseconds
47 uint32_t jitter_tolerance = 50; //command line: -t 50
49 int verbose = 0; // pass -v on the command line to turn this on
51 // read the jitter tolerance, verbose setting, and device frame rate from command line
52 process_command_line(argc, argv, &device_frame_rate, &jitter_tolerance, &verbose);
54 printf("%s starting with a jitter tolerance of %d milliseconds and a device frame rate of %d per second.\n\n",
55 argv[0], jitter_tolerance, device_frame_rate);
57 // setup our signal handler signalled() above, so we can exit cleanly
58 signal(SIGINT, signalled);
60 ret = init_alsa_sequencer("jackctlmmc");
61 if (ret < 0)
63 cleanup();
64 exit(0);
67 if (init_jack("jackctlmmc") < 0)
69 printf("couldn't connect to jack server. Either it's not running or the client name is already taken\n");
70 cleanup();
71 exit(0);
74 init_lash(argc, argv);
75 activate_jack();
77 // start listening for and handling MMC events, stops when g_quit is true (SIGINT)
78 listen_loop(device_frame_rate, jitter_tolerance, verbose);
80 // so we shall quit, eh? ok, cleanup time. otherwise jack would probably produce an xrun on shutdown
81 cleanup();
83 if (verbose)
84 printf("exited normally\n");
86 return 0;
90 void process_command_line(int argc, char *argv[], // IN parameters
91 uint32_t* device_frame_rate, uint32_t* jitter_tolerance, int* verbose) // OUT parameters
93 int parameter;
94 while ((parameter = getopt(argc, argv, "f:t:v")) != -1)
96 switch (parameter)
98 case 'v':
99 *verbose = 1;
100 break;
101 case 'f':
102 *device_frame_rate = atoi(optarg);
103 break;
104 case 't':
105 *jitter_tolerance = atoi(optarg);
106 break;
107 case '?':
108 fprintf(stderr, "usage: %s -f <device_frames_per_second> -t <jitter_tolerance_in_ms>\n", argv[0]);
109 exit(1);
110 break;
115 void cleanup()
117 printf("cleaning up\n");
118 cleanup_globals();