Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17357
Modified Files: Tag: desiredata s_audio_jack.c Log Message: cleanup
Index: s_audio_jack.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_audio_jack.c,v retrieving revision 1.5.4.8.2.7.2.8 retrieving revision 1.5.4.8.2.7.2.9 diff -C2 -d -r1.5.4.8.2.7.2.8 -r1.5.4.8.2.7.2.9 *** s_audio_jack.c 10 Jul 2007 15:48:57 -0000 1.5.4.8.2.7.2.8 --- s_audio_jack.c 10 Jul 2007 21:49:16 -0000 1.5.4.8.2.7.2.9 *************** *** 20,24 **** static jack_port_t *output_port[NUM_JACK_PORTS]; static int outport_count = 0; ! static jack_client_t *jack_client = NULL; char *jack_client_names[MAX_CLIENTS]; static int jack_dio_error; --- 20,24 ---- static jack_port_t *output_port[NUM_JACK_PORTS]; static int outport_count = 0; ! static jack_client_t *jack_client = 0; char *jack_client_names[MAX_CLIENTS]; static int jack_dio_error; *************** *** 57,70 **** }
- void sys_peakmeters(); extern int sys_meters; /* true if we're metering */ - extern float sys_inmax; /* max input amplitude */ - extern float sys_outmax; /* max output amplitude */ - static int dspticks_per_jacktick; static void (*copyblock)(t_sample *dst,t_sample *src,int n); static void (*zeroblock)(t_sample *dst,int n); - extern int canvas_dspstate;
--- 57,65 ---- *************** *** 135,150 ****
/* register idle callback in scheduler */ ! static void jack_shutdown (void *arg) {sys_callback(jack_shutdown_handler, NULL, 0);} ! static int jack_graph_order_callback(void* arg) {sys_callback(jack_save_connection_state, NULL, 0); return 0;}
static char** jack_get_clients() { - const char **jack_ports; int num_clients = 0; regex_t port_regex; ! jack_ports = jack_get_ports(jack_client, "", "", 0); regcomp(&port_regex, "^[^:]*", REG_EXTENDED); ! jack_client_names[0] = NULL; /* Build a list of clients from the list of ports */ ! for (int i=0; jack_ports[i] != NULL; i++) { int client_seen; regmatch_t match_info; --- 130,144 ----
/* register idle callback in scheduler */ ! static void jack_shutdown (void *arg) {sys_callback(jack_shutdown_handler,0,0);} ! static int jack_graph_order_callback(void* arg) {sys_callback(jack_save_connection_state,0,0); return 0;}
static char** jack_get_clients() { int num_clients = 0; regex_t port_regex; ! const char **jack_ports = jack_get_ports(jack_client, "", "", 0); regcomp(&port_regex, "^[^:]*", REG_EXTENDED); ! jack_client_names[0] = 0; /* Build a list of clients from the list of ports */ ! for (int i=0; jack_ports[i] != 0; i++) { int client_seen; regmatch_t match_info; *************** *** 159,175 **** if (!client_seen) { jack_client_names[num_clients] = (char*)getbytes(strlen(tmp_client_name) + 1); ! /* The alsa_pcm client should go in spot 0. If this ! * is the alsa_pcm client AND we are NOT about to put ! * it in spot 0 put it in spot 0 and move whatever ! * was already in spot 0 to the end. */ if (strcmp("alsa_pcm",tmp_client_name)==0 && num_clients>0) { /* alsa_pcm goes in spot 0 */ char* tmp = jack_client_names[ num_clients ]; ! jack_client_names[ num_clients ] = jack_client_names[0]; jack_client_names[0] = tmp; strcpy(jack_client_names[0], tmp_client_name); } else { /* put the new client at the end of the client list */ ! strcpy(jack_client_names[ num_clients ], tmp_client_name); } num_clients++; --- 153,167 ---- if (!client_seen) { jack_client_names[num_clients] = (char*)getbytes(strlen(tmp_client_name) + 1); ! /* The alsa_pcm client should go in spot 0. If this is the alsa_pcm client AND we are NOT about to put ! it in spot 0 put it in spot 0 and move whatever was already in spot 0 to the end. */ if (strcmp("alsa_pcm",tmp_client_name)==0 && num_clients>0) { /* alsa_pcm goes in spot 0 */ char* tmp = jack_client_names[ num_clients ]; ! jack_client_names[num_clients] = jack_client_names[0]; jack_client_names[0] = tmp; strcpy(jack_client_names[0], tmp_client_name); } else { /* put the new client at the end of the client list */ ! strcpy(jack_client_names[num_clients], tmp_client_name); } num_clients++; *************** *** 183,188 **** /* Wire up all the ports of one client. */ static int jack_connect_ports(char *client) { ! char regex_pattern[100]; /* its always the same, ... */ ! const char **jack_ports; static int entered = 0; if (entered) return 0; --- 175,179 ---- /* Wire up all the ports of one client. */ static int jack_connect_ports(char *client) { ! char regex_pattern[100]; static int entered = 0; if (entered) return 0; *************** *** 190,203 **** if (strlen(client) > 96) return -1; sprintf(regex_pattern, "%s:.*", client); ! jack_ports = jack_get_ports(jack_client, regex_pattern, NULL, JackPortIsOutput); if (jack_ports) ! for (int i=0;jack_ports[i] != NULL && i < sys_inchannels;i++) if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i]))) ! fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i])); ! jack_ports = jack_get_ports(jack_client, regex_pattern, NULL, JackPortIsInput); if (jack_ports) ! for (int i=0;jack_ports[i] != NULL && i < sys_outchannels;i++) if (jack_connect (jack_client, jack_port_name (output_port[i]), jack_ports[i])) ! fprintf (stderr, "cannot connect output ports %s -> %s\n", jack_port_name (output_port[i]),jack_ports[i]); free(jack_ports); return 0; --- 181,195 ---- if (strlen(client) > 96) return -1; sprintf(regex_pattern, "%s:.*", client); ! const char **jack_ports = jack_get_ports(jack_client, regex_pattern, 0, JackPortIsOutput); if (jack_ports) ! for (int i=0;jack_ports[i] != 0 && i < sys_inchannels;i++) if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i]))) ! fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name(input_port[i])); ! free(jack_ports); ! jack_ports = jack_get_ports(jack_client, regex_pattern, 0, JackPortIsInput); if (jack_ports) ! for (int i=0;jack_ports[i] != 0 && i < sys_outchannels;i++) if (jack_connect (jack_client, jack_port_name (output_port[i]), jack_ports[i])) ! fprintf (stderr, "cannot connect output ports %s -> %s\n", jack_port_name(output_port[i]),jack_ports[i]); free(jack_ports); return 0; *************** *** 207,220 ****
int jack_open_audio(int inchans, int outchans, int rate, int scheduler) { char port_name[80] = ""; - int client_iterator = 0; int new_jack = 0; - int srate; - int ret; - jack_dio_error = 0; - if (inchans==0 && outchans==0) { - ret = 0; - goto bailout; - } if (outchans > NUM_JACK_PORTS) { fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS); --- 199,212 ----
int jack_open_audio(int inchans, int outchans, int rate, int scheduler) { + jack_dio_error = 0; + if (inchans==0 && outchans==0) return 0; + int ret = jack_open_audio(inchans,outchans,rate,scheduler); + if (ret) sys_setscheduler(0); + return ret; + } + + int jack_open_audio_2(int inchans, int outchans, int rate, int scheduler) { char port_name[80] = ""; int new_jack = 0; if (outchans > NUM_JACK_PORTS) { fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS); *************** *** 227,231 **** if (jack_client && scheduler != sys_getscheduler()) { jack_client_close(jack_client); ! jack_client = NULL; } sys_setscheduler(scheduler); --- 219,223 ---- if (jack_client && scheduler != sys_getscheduler()) { jack_client_close(jack_client); ! jack_client = 0; } sys_setscheduler(scheduler); *************** *** 241,253 **** /* try to become a client of the JACK server (we allow two pd's)*/ if (!jack_client) { do { sprintf(port_name,"pure_data_%d",client_iterator); client_iterator++; } while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2); ! if (!jack_client) { // jack spits out enough messages already, do not warn ! sys_inchannels = sys_outchannels = 0; ! ret = 1; ! goto bailout; ! } jack_get_clients(); /* tell the JACK server to call `process()' whenever there is work to be done. --- 233,243 ---- /* try to become a client of the JACK server (we allow two pd's)*/ if (!jack_client) { + int client_iterator = 0; do { sprintf(port_name,"pure_data_%d",client_iterator); client_iterator++; } while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2); ! // jack spits out enough messages already, do not warn ! if (!jack_client) {sys_inchannels = sys_outchannels = 0; return 1;} jack_get_clients(); /* tell the JACK server to call `process()' whenever there is work to be done. *************** *** 259,265 **** jack_set_error_function (jack_error); #ifdef JACK_XRUN ! jack_set_xrun_callback (jack_client, jack_xrun, NULL); #endif ! jack_set_graph_order_callback(jack_client, jack_graph_order_callback, NULL); /* tell the JACK server to call `srate()' whenever the sample rate of the system changes. */ jack_set_sample_rate_callback (jack_client, jack_srate, 0); --- 249,255 ---- jack_set_error_function (jack_error); #ifdef JACK_XRUN ! jack_set_xrun_callback (jack_client, jack_xrun, 0); #endif ! jack_set_graph_order_callback(jack_client, jack_graph_order_callback, 0); /* tell the JACK server to call `srate()' whenever the sample rate of the system changes. */ jack_set_sample_rate_callback (jack_client, jack_srate, 0); *************** *** 268,273 **** jack_on_shutdown (jack_client, jack_shutdown, 0); for (int j=0;j<NUM_JACK_PORTS;j++) { ! input_port[j]=NULL; ! output_port[j] = NULL; } new_jack = 1; --- 258,263 ---- jack_on_shutdown (jack_client, jack_shutdown, 0); for (int j=0;j<NUM_JACK_PORTS;j++) { ! input_port[j]=0; ! output_port[j]=0; } new_jack = 1; *************** *** 275,288 **** /* display the current sample rate. once the client is activated (see below), you should rely on your own sample rate callback (see above) for this value. */ ! srate = jack_get_sample_rate (jack_client); sys_dacsr = srate; /* create the ports */ for (int j = 0; j < inchans; j++) { sprintf(port_name, "input%d", j); ! if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); } for (int j = 0; j < outchans; j++) { sprintf(port_name, "output%d", j); ! if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } outport_count = outchans; --- 265,278 ---- /* display the current sample rate. once the client is activated (see below), you should rely on your own sample rate callback (see above) for this value. */ ! int srate = jack_get_sample_rate (jack_client); sys_dacsr = srate; /* create the ports */ for (int j = 0; j < inchans; j++) { sprintf(port_name, "input%d", j); ! if (!input_port[j]) input_port[j] = jack_port_register(jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); } for (int j = 0; j < outchans; j++) { sprintf(port_name, "output%d", j); ! if (!output_port[j]) output_port[j] = jack_port_register(jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } outport_count = outchans; *************** *** 290,310 **** if (new_jack) { if (jack_activate (jack_client)) { ! fprintf (stderr, "cannot activate client\n"); ! sys_inchannels = sys_outchannels = 0; ! ret = 1; ! goto bailout; ! } memset(jack_outbuf,0,sizeof(jack_outbuf)); if (jack_client_names[0]) jack_connect_ports(jack_client_names[0]); ! pthread_mutex_init(&jack_mutex,NULL); ! pthread_cond_init(&jack_sem,NULL); } /* tb: get advance from jack server */ sys_schedadvance = int((float)jack_port_get_total_latency(jack_client,output_port[0]) * 1000. / sys_dacsr * 1000); return 0; - bailout: - /* tb: if we can't start jack, go to traditional scheduler */ - sys_setscheduler(0); - return ret; }
--- 280,292 ---- if (new_jack) { if (jack_activate (jack_client)) { ! fprintf (stderr, "cannot activate client\n"); sys_inchannels = sys_outchannels = 0; return 1;} memset(jack_outbuf,0,sizeof(jack_outbuf)); if (jack_client_names[0]) jack_connect_ports(jack_client_names[0]); ! pthread_mutex_init(&jack_mutex,0); ! pthread_cond_init(&jack_sem,0); } /* tb: get advance from jack server */ sys_schedadvance = int((float)jack_port_get_total_latency(jack_client,output_port[0]) * 1000. / sys_dacsr * 1000); return 0; }
*************** *** 314,321 **** jack_started = 0; jack_client_close(jack_client); ! jack_client = NULL; for (int i = 0; i <NUM_JACK_PORTS; i++) { ! input_port[i] = NULL; ! output_port[i] = NULL; } } --- 296,303 ---- jack_started = 0; jack_client_close(jack_client); ! jack_client = 0; for (int i = 0; i <NUM_JACK_PORTS; i++) { ! input_port[i] = 0; ! output_port[i] = 0; } }