示例#1
0
//beginn jack time master
void JackOutput::initTimeMaster()
{
	if ( ! client ) return;

	Preferences* pref = Preferences::get_instance();
	if ( pref->m_bJackMasterMode == Preferences::USE_JACK_TIME_MASTER) {
		int ret = jack_set_timebase_callback(client, m_bCond, jack_timebase_callback, this);
		if (ret != 0) pref->m_bJackMasterMode = Preferences::NO_JACK_TIME_MASTER;
	} else {
		jack_release_timebase(client);
	}
}
void JackAudioDriver::initTimeMaster()
{
	if ( ! m_pClient ) return;

	Preferences* pref = Preferences::get_instance();
	if ( pref->m_bJackMasterMode == Preferences::USE_JACK_TIME_MASTER) {
		// Defined in jack/transport.h
		// Register as timebase master for the JACK
		// subsystem.
		//
		// The timebase master registers a callback that
		// updates extended position information such as
		// beats or timecode whenever necessary.  Without
		// this extended information, there is no need for
		// this function.
		//
		// There is never more than one master at a time.
		// When a new client takes over, the former @a
		// timebase_callback is no longer called.  Taking
		// over the timebase may be done conditionally, so
		// it fails if there was a master already.
		//
		// @param client the JACK client structure.
		// @param conditional non-zero for a conditional
		// request. 
		// @param timebase_callback is a realtime function
		// that returns position information.
		// @param arg an argument for the @a timebase_callback
		// function. 
		// @return
		//   - 0 on success;
		//   - EBUSY if a conditional request fails because
		// there was already a timebase master;
		//   - other non-zero error code.
		int ret = jack_set_timebase_callback(m_pClient, m_nJackConditionalTakeOver,
						     jack_timebase_callback, this);
		if (ret != 0) pref->m_bJackMasterMode = Preferences::NO_JACK_TIME_MASTER;
	} else {
		// Called by the timebase master to release itself
		// from that responsibility (defined in
		// jack/transport.h).
		jack_release_timebase(m_pClient);
	}
}
示例#3
0
文件: Client.C 项目: 0mk/non
/** Connect to JACK using client name /client_name/. Return a static
 * pointer to actual name as reported by JACK */
    const char *
    Client::init ( const char *client_name, unsigned int opts )
    {
        if (( _client = jack_client_open ( client_name, (jack_options_t)0, NULL )) == 0 )
            return NULL;

#define set_callback( name ) jack_set_ ## name ## _callback( _client, &Client:: name , this )

        set_callback( thread_init );
        set_callback( process );
        set_callback( xrun );
        set_callback( freewheel );
        set_callback( buffer_size );
        set_callback( port_connect );

        jack_set_sample_rate_callback( _client, &Client::sample_rate_changed, this );
  
#ifdef HAVE_JACK_PORT_GET_LATENCY_RANGE
        set_callback( latency );
#endif

        /* FIXME: should we wait to register this until after the project
           has been loaded (and we have disk threads running)? */
        if ( opts & SLOW_SYNC )
            set_callback( sync );

        if ( opts & TIMEBASE_MASTER )
            jack_set_timebase_callback( _client, 0, &Client::timebase, this );

        jack_on_shutdown( _client, &Client::shutdown, this );

        activate();

//        _sample_rate = frame_rate();

        return jack_get_client_name( _client );
    }
示例#4
0
static void com_master(char *arg)
{
	int cond = (*arg != '\0');
	if (jack_set_timebase_callback(client, cond, timebase, NULL) != 0)
		fprintf(stderr, "Unable to take over timebase.\n");
}
示例#5
0
bool audioStreamer_JACK::init(const char* clientName,
			      int nInputChannels,
			      int nOutputChannels,
			      SPLPROC proc)
{

    njc = NULL;
    splproc = proc;

    if (client) {
      jack_client_close(client);
      client = NULL;
    }
    if ((client = jack_client_new(clientName)) == 0) {
      fprintf (stderr, "jack server not running?\n");
      return false;
      // exit(20);
    }

    jack_set_process_callback (client, (JackProcessCallback) process_cb, this);

    jack_set_timebase_callback( client, 0, (JackTimebaseCallback) jack_timebase_cb, this );

    if (_out) {
      delete[] _out;
      _out = NULL;
    }
    _out = new jack_port_t*[nOutputChannels];
    if (_outports) {
      delete[] _outports;
      _outports = NULL;
    }
    _outports = new float*[nOutputChannels];
    for (unsigned i=0; i<nOutputChannels; i++) {
      char name[10];
      snprintf(name, sizeof(name), "out%d", i+1);
      _out[i] = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    }

    if (_in) {
      delete[] _in;
      _in = NULL;
    }
    _in = new jack_port_t*[nInputChannels];
    if (_inports) {
      delete[] _inports;
      _inports = NULL;
    }
    _inports = new float*[nInputChannels];
    for (unsigned i=0; i<nInputChannels; i++) {
      char name[10];
      snprintf(name, sizeof(name), "in%d", i+1);
      _in[i] = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
    }

    if (jack_activate (client)) {
      fprintf (stderr, "cannot activate client\n");
      return false;
      //exit(20);
    }

    m_innch = nInputChannels;
    m_outnch = nOutputChannels;
    m_srate = jack_get_sample_rate( client );
    m_bps = 32;
    return true;
}
bool JackTransportClient::init()
{
    // register a jack timebase callback:
    jack_set_timebase_callback(getClient(), 0, timebase, this);
    return JackThreadEventProcessorClient::init();
}
示例#7
0
static void 
init_jack(void)
{
	int i, err;

#ifdef WITH_LASH
	lash_event_t *event;
#endif

	jack_client = jack_client_open(PROGRAM_NAME, JackNoStartServer, NULL);

	if (jack_client == NULL) {
		g_critical("Could not connect to the JACK server; run jackd first?");
		exit(EX_UNAVAILABLE);
	}

#ifdef WITH_LASH
	event = lash_event_new_with_type(LASH_Client_Name);
	assert (event); /* Documentation does not say anything about return value. */
	lash_event_set_string(event, jack_get_client_name(jack_client));
	lash_send_event(lash_client, event);

	lash_jack_client_name(lash_client, jack_get_client_name(jack_client));
#endif

	err = jack_set_process_callback(jack_client, process_callback, 0);
	if (err) {
		g_critical("Could not register JACK process callback.");
		exit(EX_UNAVAILABLE);
	}

	if (use_transport) {
		err = jack_set_sync_callback(jack_client, sync_callback, 0);
		if (err) {
			g_critical("Could not register JACK sync callback.");
			exit(EX_UNAVAILABLE);
		}
#if 0
		err = jack_set_timebase_callback(jack_client, 1, timebase_callback, 0);
		if (err) {
			g_critical("Could not register JACK timebase callback.");
			exit(EX_UNAVAILABLE);
		}
#endif
	}

	jack_on_shutdown(jack_client, jack_shutdown, 0);

	int number_of_tracks;
	if (remote_control) {
		number_of_tracks = 0; // TODO allow more ports
	}
	else {
		assert(smf->number_of_tracks >= 1);
		number_of_tracks = smf->number_of_tracks;
	}

	/* We are allocating number_of_tracks + 1 output ports. */
	for (i = 0; i <= number_of_tracks; i++) {
		char port_name[32];

		if (i == 0)
			snprintf(port_name, sizeof(port_name), "midi_out");
		else
			snprintf(port_name, sizeof(port_name), "track_%d_midi_out", i);

		output_ports[i] = jack_port_register(jack_client, port_name, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);

		if (output_ports[i] == NULL) {
			g_critical("Could not register JACK output port '%s'.", port_name);
			exit(EX_UNAVAILABLE);
		}

		if (just_one_output)
			break;
	}

	if (jack_activate(jack_client)) {
		g_critical("Cannot activate JACK client.");
		exit(EX_UNAVAILABLE);
	}
}