/* Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame 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; either version 2 of the License, or (at your option) any later version. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include #include "types.h" #include "jack.h" #include "JackConstants.h" #include "JackDriverLoader.h" /* This is a simple port of the old jackdmp.cpp file to use the new Jack 2.0 control API. Available options for the server are "hard-coded" in the source. A much better approach would be to use the control API to: - dynamically retrieve available server parameters and then prepare to parse them - get available drivers and their possible parameters, then prepare to parse them. */ #ifdef __APPLE__ #include #include static void notify_server_start(const char* server_name) { // Send notification to be used in the JackRouter plugin CFStringRef ref = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), CFSTR("com.grame.jackserver.start"), ref, NULL, kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); CFRelease(ref); } static void notify_server_stop(const char* server_name) { // Send notification to be used in the JackRouter plugin CFStringRef ref1 = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), CFSTR("com.grame.jackserver.stop"), ref1, NULL, kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); CFRelease(ref1); } #else static void notify_server_start(const char* server_name) {} static void notify_server_stop(const char* server_name) {} #endif static void copyright(FILE* file) { fprintf(file, "jackdmp " VERSION "\n" "Copyright 2001-2005 Paul Davis and others.\n" "Copyright 2004-2009 Grame.\n" "jackdmp comes with ABSOLUTELY NO WARRANTY\n" "This is free software, and you are welcome to redistribute it\n" "under certain conditions; see the file COPYING for details\n"); } static void usage(FILE* file) { fprintf(file, "\n" "usage: jackdmp [ --realtime OR -R [ --realtime-priority OR -P priority ] ]\n" " [ --name OR -n server-name ]\n" " [ --timeout OR -t client-timeout-in-msecs ]\n" " [ --midi OR -X midi-driver ]\n" " [ --verbose OR -v ]\n" #ifdef __linux__ " [ --clocksource OR -c [ c(ycle) | h(pet) | s(ystem) ]\n" #endif " [ --replace-registry OR -r ]\n" " [ --silent OR -s ]\n" " [ --sync OR -S ]\n" " [ --temporary OR -T ]\n" " [ --version OR -V ]\n" " -d audio-driver [ ... driver args ... ]\n" " where driver can be `alsa', `coreaudio', 'portaudio' or `dummy'\n" " jackdmp -d driver --help\n" " to display options for each driver\n\n"); } // To put in the control.h interface?? static jackctl_driver_t * jackctl_server_get_driver( jackctl_server_t *server, const char *driver_name) { const JSList * node_ptr; node_ptr = jackctl_server_get_drivers_list(server); while (node_ptr) { if (strcmp(jackctl_driver_get_name((jackctl_driver_t *)node_ptr->data), driver_name) == 0) { return (jackctl_driver_t *)node_ptr->data; } node_ptr = jack_slist_next(node_ptr); } return NULL; } static jackctl_parameter_t * jackctl_get_parameter( const JSList * parameters_list, const char * parameter_name) { while (parameters_list) { if (strcmp(jackctl_parameter_get_name((jackctl_parameter_t *)parameters_list->data), parameter_name) == 0) { return (jackctl_parameter_t *)parameters_list->data; } parameters_list = jack_slist_next(parameters_list); } return NULL; } int main(int argc, char* argv[]) { jackctl_server_t * server_ctl; const JSList * server_parameters; const char* server_name = "default"; jackctl_driver_t * audio_driver_ctl; jackctl_driver_t * midi_driver_ctl; #ifdef __linux__ const char *options = "-d:X:P:uvrshVRL:STFl:t:mn:p:c:a:"; #else const char *options = "-d:X:P:uvrshVRL:STFl:t:mn:p:a:"; #endif struct option long_options[] = { #ifdef __linux__ { "clock-source", 1, 0, 'c' }, #endif { "audio-driver", 1, 0, 'd' }, { "midi-driver", 1, 0, 'X' }, { "verbose", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { "port-max", 1, 0, 'p' }, { "no-mlock", 0, 0, 'm' }, { "name", 0, 0, 'n' }, { "unlock", 0, 0, 'u' }, { "realtime", 0, 0, 'R' }, { "replace-registry", 0, 0, 'r' }, { "loopback", 0, 0, 'L' }, { "realtime-priority", 1, 0, 'P' }, { "timeout", 1, 0, 't' }, { "temporary", 0, 0, 'T' }, { "version", 0, 0, 'V' }, { "silent", 0, 0, 's' }, { "sync", 0, 0, 'S' }, { "autoconnect", 1, 0, 'a' }, { 0, 0, 0, 0 } }; int i,opt = 0; int option_index = 0; bool seen_audio_driver = false; bool seen_midi_driver = false; char *audio_driver_name = NULL; char **audio_driver_args = NULL; int audio_driver_nargs = 1; char *midi_driver_name = NULL; char **midi_driver_args = NULL; int midi_driver_nargs = 1; int port_max = 512; int do_mlock = 1; int do_unlock = 0; bool show_version = false; sigset_t signals; jackctl_parameter_t* param; union jackctl_parameter_value value; copyright(stdout); server_ctl = jackctl_server_create(NULL, NULL); if (server_ctl == NULL) { fprintf(stderr, "Failed to create server object\n"); return -1; } server_parameters = jackctl_server_get_parameters(server_ctl); opterr = 0; while (!seen_audio_driver && (opt = getopt_long(argc, argv, options, long_options, &option_index)) != EOF) { switch (opt) { #ifdef __linux__ case 'c': param = jackctl_get_parameter(server_parameters, "clock-source"); if (param != NULL) { if (tolower (optarg[0]) == 'h') { value.ui = JACK_TIMER_HPET; jackctl_parameter_set_value(param, &value); } else if (tolower (optarg[0]) == 'c') { value.ui = JACK_TIMER_CYCLE_COUNTER; jackctl_parameter_set_value(param, &value); } else if (tolower (optarg[0]) == 's') { value.ui = JACK_TIMER_SYSTEM_CLOCK; jackctl_parameter_set_value(param, &value); } else { usage(stdout); goto fail_free; } } break; #endif case 'a': param = jackctl_get_parameter(server_parameters, "self-connect-mode"); if (param != NULL) { bool value_valid = false; for (int k=0; k