static void unbind_jacks_from_mididev(struct umidi_mididev *mididev) { if ((mididev->flags & FWRITE) && mididev->out_jack) close_jack(mididev->out_jack); if ((mididev->flags & FREAD) && mididev->in_jack) close_jack(mididev->in_jack); if (mididev->out_jack) mididev->out_jack->binded = 0; if (mididev->in_jack) mididev->in_jack->binded = 0; mididev->out_jack = mididev->in_jack = NULL; }
void umidi_close(void *addr) { int s; struct umidi_mididev *mididev = addr; s = splusb(); if ((mididev->flags & FWRITE) && mididev->out_jack) close_jack(mididev->out_jack); if ((mididev->flags & FREAD) && mididev->in_jack) close_jack(mididev->in_jack); mididev->opened = 0; splx(s); }
void xapi_open_ltc(void *d) { #if defined (HAVE_LTCSMPTE) || defined (HAVE_LTC) #ifdef HAVE_MIDI midi_close(); #endif close_jack(); open_ltcjack((char *) d); // TODO: autoconnect if (ltcjack_connected()) remote_printf(100,"opened LTC jack port."); else remote_printf(405,"failed to connect to jack server"); #else remote_printf(499,"LTC-jack is not available."); #endif }
static int oscb_jackdisconnect (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data){ close_jack(); return(0); }
void xapi_close_jack(void *d) { close_jack(); remote_printf(100,"closed jack connection"); }
static int open_jack(out123_handle *ao) { jack_handle_t *handle=NULL; jack_options_t jopt = JackNullOption|JackNoStartServer; jack_status_t jstat = 0; unsigned int i; char *realname; debug("jack open"); if(!ao) return -1; /* Return if already open*/ if(ao->userptr) { if(!AOQUIET) error("audio device is already open."); return -1; } /* The initial open lets me choose the settings. */ if (ao->format==-1) { ao->format = MPG123_ENC_FLOAT_32; ao->channels = 2; /* Really need a framesize defined for callback. */ ao->framesize = 2*4; } else if(!(ao->format & MPG123_ENC_FLOAT)) { if(!AOQUIET) error("JACK only wants float!"); return -1; } /* Create some storage for ourselves*/ if((handle = alloc_jack_handle(ao)) == NULL) return -1; ao->userptr = (void*)handle; /* Register with Jack*/ if((handle->client = jack_client_open(ao->name, jopt, &jstat)) == 0) { if(!AOQUIET) error1("Failed to open jack client: 0x%x", jstat); close_jack(ao); return -1; } realname = jack_get_client_name(handle->client); /* Display the unique client name allocated to us */ if(AOVERBOSE(1)) fprintf( stderr, "Registered as JACK client %s.\n" , realname ? realname : "<nil>" ); /* Just make sure. */ ao->rate = jack_get_sample_rate(handle->client); /* Check the sample rate is correct*/ if (jack_get_sample_rate( handle->client ) != (jack_nframes_t)ao->rate) { if(!AOQUIET) error("JACK Sample Rate is different to sample rate of file."); close_jack(ao); return -1; } /* Register ports with Jack*/ if(handle->channels > 0 && handle->channels < 100) { for(i=0;i<handle->channels;++i) { char numbuf[3]; /* two digits, zero byte */ sprintf(numbuf, "%d", i+1); if( !(handle->ports[i] = jack_port_register( handle->client , numbuf, JACK_DEFAULT_AUDIO_TYPE , JackPortIsOutput, 0 )) ) { if(!AOQUIET) error1("Cannot register JACK output port '%s'.", numbuf); close_jack(ao); return -1; } } } else { if(!AOQUIET) error1("excessive number of output channels (%d).", handle->channels); close_jack(ao); return -1; } /* Use device_buffer parameter for ring buffer, but ensure that two JACK buffers fit in there. We do not support that buffer increasing later on. */ handle->rb_size = (size_t)( ao->device_buffer * jack_get_sample_rate(handle->client) + 0.5 ); /* PCM frames */ handle->procbuf_frames = jack_get_buffer_size(handle->client); if(handle->rb_size < 2*handle->procbuf_frames) handle->rb_size = 2*handle->procbuf_frames; debug1("JACK ringbuffer for %"SIZE_P" PCM frames", (size_p)handle->rb_size); /* Convert to bytes. */ handle->rb_size *= handle->framesize; handle->rb = jack_ringbuffer_create(handle->rb_size); handle->procbuf = malloc(handle->procbuf_frames*handle->framesize); if(!handle->rb || !handle->procbuf) { if(!AOQUIET) error("failed to allocate buffers"); close_jack(ao); return -1; } /* Set the callbacks*/ jack_set_process_callback(handle->client, process_callback, (void*)handle); jack_on_shutdown(handle->client, shutdown_callback, (void*)handle); handle->alive = 1; /* Activate client*/ if(jack_activate(handle->client)) { if(!AOQUIET) error("Can't activate client."); close_jack(ao); return -1; } /* Connect up the portsm, return */ if(!connect_jack_ports(ao, handle)) { /* deregistering of ports will not work but should just fail, then, and let the rest clean up */ close_jack(ao); return -1; } debug("Jack open successful.\n"); ao->realname = compat_strdup(realname); return 0; }