示例#1
0
static void
setup_ports (int sources, char *source_names[], jack_thread_info_t *info)
{
	unsigned int i;
	size_t in_size;

	/* Allocate data structures that depend on the number of ports. */
	nports = sources;
	ports = (jack_port_t **) malloc (sizeof (jack_port_t *) * nports);
	in_size =  nports * sizeof (jack_default_audio_sample_t *);
	in = (jack_default_audio_sample_t **) malloc (in_size);
	rb = jack_ringbuffer_create (nports * sample_size * info->rb_size);

	/* When JACK is running realtime, jack_activate() will have
	 * called mlockall() to lock our pages into memory.  But, we
	 * still need to touch any newly allocated pages before
	 * process() starts using them.  Otherwise, a page fault could
	 * create a delay that would force JACK to shut us down. */
	memset(in, 0, in_size);
	memset(rb->buf, 0, rb->size);

	for (i = 0; i < nports; i++) {
		char name[64];

		sprintf (name, "input%d", i+1);

		if ((ports[i] = jack_port_register (info->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)) == 0) {
			fprintf (stderr, "cannot register input port \"%s\"!\n", name);
			jack_client_close (info->client);
			exit (1);
		}
	}

	for (i = 0; i < nports; i++) {
		if (jack_connect (info->client, source_names[i], jack_port_name (ports[i]))) {
			fprintf (stderr, "cannot connect input port %s to %s\n", jack_port_name (ports[i]), source_names[i]);
			jack_client_close (info->client);
			exit (1);
		}
	}

	info->can_process = 1;		/* process() can start, now */
}
示例#2
0
void JackCpp::AudioIO::connectFrom(unsigned int index, std::string sourcePortName)
	throw(std::range_error, std::runtime_error)
{
	int connect_ret;
	if (mJackState != active)
		throw std::runtime_error("client must be active before connecting ports");
	if(index < mInputPorts.size()){
		connect_ret = jack_connect(mJackClient, sourcePortName.c_str(), jack_port_name(mInputPorts[index]));
		if(connect_ret != 0 && connect_ret != EEXIST){
			std::string ret_string("cannot connect source: ");
			ret_string.append(sourcePortName);
			ret_string.append(" to dest: ");
			ret_string.append(jack_port_name(mInputPorts[index]));
			ret_string.append(" does source exist?");
			throw std::range_error(ret_string);
		}
	} else
		throw std::range_error("inport index out of range");
}
示例#3
0
    void JackProxyDriver::ConnectPorts()
    {
        jack_log("JackProxyDriver::ConnectPorts");
        const char** ports = jack_get_ports(fClient, NULL, JACK_DEFAULT_AUDIO_TYPE, JackPortIsPhysical | JackPortIsOutput);
        if (ports != NULL) {
            for (int i = 0; i < fCaptureChannels && ports[i]; i++) {
                jack_connect(fClient, ports[i], jack_port_name(fUpstreamPlaybackPorts[i]));
            }
            jack_free(ports);
        }

        ports = jack_get_ports(fClient, NULL, JACK_DEFAULT_AUDIO_TYPE, JackPortIsPhysical | JackPortIsInput);
        if (ports != NULL) {
            for (int i = 0; i < fPlaybackChannels && ports[i]; i++) {
                jack_connect(fClient, jack_port_name(fUpstreamCapturePorts[i]), ports[i]);
            }
            jack_free(ports);
        }
    }
    int JackAudioSystem::activate(QString *err_msg)
    {
	assert(_client);
	assert(_port[0]);
	assert(_port[1]);
	int rv = 0;

	jack_activate(_client);

	if( _config->autoconnect() ) {
	    // Autoconnection to first two ports we find.
	    const char** ports = jack_get_ports( _client,
						 0,
						 JACK_DEFAULT_AUDIO_TYPE,
						 JackPortIsInput
		);
	    int k;
	    for( k=0 ; ports && ports[k] != 0 ; ++k ) {
		if(k==0) {
		    rv = jack_connect( _client,
				       jack_port_name(_port[0]),
				       ports[k] );
		} else if (k==1) {
		    rv = jack_connect( _client,
				       jack_port_name(_port[1]),
				       ports[k] );
		} else {
		    break;
		}
		if( rv && err_msg ) {
		    *err_msg = "Could not connect output ports";
		}
	    }
	    if(k==0 && err_msg) {
		*err_msg = "There were no output ports to connect to.";
		rv = 1;
	    }
	    if(ports) {
		free(ports);
	    }
	}
	return rv;
    }
示例#5
0
文件: ports.c 项目: alex1818/aqualung
void
tree_out_nb_selection_changed(GtkObject * tree, gpointer * data) {

	GtkTreeIter iter;
        GtkTreeModel * model;
	GtkTreeSelection * selection;
        gchar * str;
	const gchar * label;
	char fullname[MAXLEN];

	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
        if (gtk_tree_selection_get_selected(selection, &model, &iter)) {

                gtk_tree_model_get(model, &iter, 0, &str, -1);
		label = gtk_label_get_text(GTK_LABEL(nb_out_labels[GPOINTER_TO_INT(data)]));
		sprintf(fullname, "%s:%s", label, str);
		g_free(str);

		if (out_selector == 0) {
			if (jack_connect(jack_client, jack_port_name(out_L_port), fullname)) {
				fprintf(stderr, "Cannot connect %s to out_L. "
					"These ports are probably already connected.\n", fullname);
			} else {
				gtk_list_store_clear(store_out_L);
				scan_connections(out_L_port, store_out_L);
				out_selector = 1;
				set_active(GTK_WIDGET(column_out_L->button), 0);
				set_active(GTK_WIDGET(column_out_R->button), 1);
			}
		} else {
			if (jack_connect(jack_client, jack_port_name(out_R_port), fullname)) {
				fprintf(stderr, "Cannot connect %s to out_R. "
					"These ports are probably already connected.\n", fullname);
			} else {
				gtk_list_store_clear(store_out_R);
				scan_connections(out_R_port, store_out_R);
				out_selector = 0;
				set_active(GTK_WIDGET(column_out_L->button), 1);
				set_active(GTK_WIDGET(column_out_R->button), 0);
			}
		}
        }
}
示例#6
0
static int jack_connect_ports(char* client)
{
    char  regex_pattern[100]; /* its always the same, ... */
    int i;
    const char **jack_ports;

    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 (i = 0;jack_ports[i] != NULL && i < sys_inchannels; i++)
        {
            if (jack_connect(jack_client, jack_ports[i],
                    jack_port_name(input_port[i]))) 
            {
                error("JACK: cannot connect input ports %s -> %s",
                    jack_ports[i],jack_port_name (input_port[i]));
            }
        }
    }
  
    jack_ports = jack_get_ports( jack_client, regex_pattern,
                                 NULL, JackPortIsInput);
    if (jack_ports) 
    {
        for (i = 0;jack_ports[i] != NULL && i < sys_outchannels; i++)
        {
            if (jack_connect (jack_client,
                    jack_port_name(output_port[i]), jack_ports[i]))
            {
                error("JACK: cannot connect output ports %s -> %s",
                    jack_port_name (output_port[i]),jack_ports[i]);
            }
        }
    }
  
    free(jack_ports);
    return 0;
}
示例#7
0
void setup_ports (int nports, char *source_names[], jack_thread_info_t *info) {
	unsigned int i;
	const size_t in_size =  nports * sizeof(jack_default_audio_sample_t *);

	info->peak = (float*) malloc(sizeof(float) * nports);
	info->pcur = (float*) malloc(sizeof(float) * nports);
	info->pmax = (float*) malloc(sizeof(float) * nports);
	info->ptme = (int*) malloc(sizeof(int  ) * nports);

	/* Allocate data structures that depend on the number of ports. */
	ports = (jack_port_t **) malloc(sizeof(jack_port_t *) * nports);
	in = (jack_default_audio_sample_t **) malloc(in_size);
	memset(in, 0, in_size);

	for (i = 0; i < nports; i++) {
		char name[64];
		info->peak[i]=0.0;
		info->pcur[i]=0.0;
		info->ptme[i]=0;

		sprintf(name, "input%d", i+1);

		if ((ports[i] = jack_port_register(info->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)) == 0) {
			fprintf(stderr, "cannot register input port \"%s\"!\n", name);
			jack_client_close(info->client);
			cleanup(info);
			exit(1);
		}
	}

	for (i = 0; i < nports; i++) {
		if (jack_connect(info->client, source_names[i], jack_port_name(ports[i]))) {
			fprintf(stderr, "cannot connect input port %s to %s\n", jack_port_name(ports[i]), source_names[i]);
#if 0 /* not fatal - connect manually */
			jack_client_close(info->client);
			exit(1);
#endif
		}
	}

	/* process() can start, now */
	info->can_process = 1;
}
示例#8
0
static void JACKconnect(GError** error) {
	dbg(1, "...");

	j_client = jack_client_open("samplecat", (jack_options_t) 0, NULL);

	if(!j_client) {
		*error = g_error_new_literal(g_quark_from_static_string(AUDITIONER_DOMAIN), 1, "could not connect to JACK");
		return;
	}

	jack_on_shutdown(j_client, jack_shutdown_callback, NULL);
	jack_set_process_callback(j_client, jack_audio_callback, NULL);

#ifdef JACK_MIDI
	jack_midi_port = jack_port_register(j_client, "Midi in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput , 0);
	if (jack_midi_port == NULL) {
		 dbg(0, "can't register jack-midi-port\n");
	}

	midi_thread_run = 1;
	pthread_create(&midi_thread_id, NULL, jack_midi_thread, NULL);
	sched_yield();
#endif

	jack_activate(j_client);
	if(_debug_) printf("jack activated\n");

#ifdef JACK_MIDI
	char *jack_midiconnect = play->config.jack_midiconnect;
	if(!jack_midiconnect || strlen(jack_midiconnect) < 1) {
		jack_midiconnect = NULL;
	} else if(!strncmp(jack_midiconnect, "DISABLE", 7)) {
		jack_midiconnect = NULL;
	}
	if(jack_midiconnect) {
		dbg(1, "MIDI autoconnect '%s' -> '%s'", jack_midiconnect, jack_port_name(jack_midi_port));
		if(jack_connect(j_client, jack_midiconnect, jack_port_name(jack_midi_port))) {
			dbg(0, "Auto-connect jack midi port failed.");
		}
	}
#endif
}
示例#9
0
文件: audio_jack.cpp 项目: K0F/FreeJ
/////////////////////////////////////////////////////////////////////////////////////////////
// Input means input of SSM, so this connects jack sources to the plugin outputs
void JackClient::ConnectInput(int n, const std::string &JackPort) {
    if(!IsAttached()) return;

    //cerr<<"JackClient::ConnectInput: connecting source ["<<JackPort<<"] to dest ["<<m_InputPortMap[n]->Name<<"]"<<endl;

    if(m_InputPortMap[n]->ConnectedTo != "") {
        if(jack_disconnect(m_Client, m_InputPortMap[n]->ConnectedTo.c_str(), jack_port_name(m_InputPortMap[n]->Port)))
            error("Audio Jack ConnectInput: cannot disconnect input port [%s] from [%s]",
                  m_InputPortMap[n]->ConnectedTo.c_str(), m_InputPortMap[n]->Name.c_str());
    }

    m_InputPortMap[n]->ConnectedTo = JackPort;

    if(jack_connect(m_Client, JackPort.c_str(),
                    jack_port_name(m_InputPortMap[n]->Port)))

        error("JackClient::ConnectInput: cannot connect input port [%s] to [%s]",
              JackPort.c_str(), m_InputPortMap[n]->Name.c_str());

    m_InputPortMap[n]->Connected = true;
}
示例#10
0
文件: main.c 项目: dbkaplun/mictomidi
void jack_start() {
	jack_set_error_function(error);

	client = jack_client_open("MicToMIDI", JackNullOption, NULL);
	if (client == 0) {
		fprintf(stderr, "jack server not running?\n");
		exit(1);
	}

	jack_set_process_callback(client, process, 0);
	jack_set_sample_rate_callback(client, sample_rate, 0);
	jack_on_shutdown(client, jack_shutdown, 0);

	input_port = jack_port_register(client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
	output_port = jack_port_register(client, "output", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);

	if(jack_activate(client)) {
		fprintf(stderr, "cannot activate client");
		exit(1);
	}
	atexit(jack_stop);

	const char **ports;
	if((ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical | JackPortIsOutput)) == NULL)
	{
		fprintf(stderr, "cannot find any physical capture ports\n");
		exit(1);
	}
	if(jack_connect(client, ports[0], jack_port_name(input_port)))
		fprintf(stderr, "cannot connect to physical capture port\n");

	jack_free(ports);
	if((ports = jack_get_ports(client, NULL, "midi", JackPortIsInput)) == NULL)
	{
		fprintf(stderr, "cannot find any MIDI playback ports\n");
		exit(1);
	}
	if(jack_connect(client, jack_port_name(output_port), ports[0]))
		fprintf(stderr, "cannot connect to MIDI playback port\n");
}
示例#11
0
void JackToShmdata::on_port(jack_port_t* port) {
  int flags = jack_port_flags(port);
  if (!(flags & JackPortIsOutput)) return;
  auto it = std::find(ports_to_connect_.begin(), ports_to_connect_.end(), jack_port_name(port));
  if (ports_to_connect_.end() == it) return;
  {
    std::lock_guard<std::mutex> lock_port_connect(port_to_connect_in_jack_process_mutex_);
    std::lock_guard<std::mutex> lock_input_port(input_ports_mutex_);
    port_to_connect_in_jack_process_.push_back(std::make_pair(
        *it,
        std::string(client_name_ + ":" + input_ports_[it - ports_to_connect_.begin()].get_name())));
  }
}
示例#12
0
void reconfigure_send_ch_count(struct state_jack *s, int ch_count)
{
        const char **ports;
        int i;

        s->out_channel_count = s->out_channel_count_req = ch_count;

        if ((ports = jack_get_ports (s->client, s->out_port_pattern, NULL, JackPortIsInput)) == NULL) {
                fprintf(stderr, "Cannot find any ports matching pattern '%s'\n", s->out_port_pattern);
                s->out_channel_count = 0;
                return;
        }
        for (i = 0; i < s->record.ch_count; ++i) {
                jack_disconnect(s->client, jack_port_name (s->output_port[i]), ports[i]);
                free(s->play_buffer[i]);
        }

        i = 0;
        while (ports[i]) ++i;

        if(i < s->out_channel_count) {
                fprintf(stderr, "Not enought output ports found matching pattern '%s': "
                                "%d requested, %d found\n", s->out_port_pattern, s->record.ch_count, i);
                fprintf(stderr, "Reducing port count to %d\n", i);
                s->out_channel_count = i;
        }
         
        for(i = 0; i < s->out_channel_count; ++i) {
                fprintf(stderr, "%s\n\n\n", ports[i]);
                if (jack_connect (s->client, jack_port_name (s->output_port[i]), ports[i])) {
                        fprintf (stderr, "cannot connect output ports\n");
                }
                s->play_buffer[i] = malloc(BUFF_SIZE);
        }
        
        fprintf(stderr, "[JACK] Sending %d output audio streams (ports).\n", s->out_channel_count);
 
        free (ports);
}
示例#13
0
文件: jack.c 项目: rknLA/rove
int rove_jack_activate() {
	jack_client_t *client = state.client;
	int i, group_count;
	rove_group_t *g;

	if( jack_activate(client) ) {
		fprintf(stderr, "client could not be activated\n");
		return -1;
	}
	
	connect_to_outports(client);
	
	group_count = state.group_count;
	for( i = 0; i < group_count; i++ ) {
		g = &state.groups[i];
		
		jack_connect(client, jack_port_name(g->outport_l), jack_port_name(group_mix_inport_l));
		jack_connect(client, jack_port_name(g->outport_r), jack_port_name(group_mix_inport_r));
	}
	
	return 0;
}
示例#14
0
/* Connect the chosen port to ours */
static
void connect_jack_port( jack_client_t *client, jack_port_t *port, const char* out )
{
	const char* in = jack_port_name( port );
	int err;
		
	if (!quiet) printf("Connecting %s to %s\n", out, in);
	
	if ((err = jack_connect(client, out, in)) != 0) {
		fprintf(stderr, "connect_jack_port(): failed to jack_connect() ports: %d\n",err);
		exit(1);
	}
}
示例#15
0
文件: audio_jack.cpp 项目: K0F/FreeJ
/////////////////////////////////////////////////////////////////////////////////////////////
// Output means output of SSM, so this connects plugin inputs to a jack destination
void JackClient::DisconnectOutput(int n) {
    if(!IsAttached()) return;
    //cerr<<"JackClient::DisconnectInput: Disconnecting input "<<n<<endl;

    if(m_OutputPortMap[n]->ConnectedTo != "") {
        if(jack_disconnect(m_Client, jack_port_name(m_OutputPortMap[n]->Port), m_OutputPortMap[n]->ConnectedTo.c_str()))
            error("JackClient::ConnectOutput: cannot disconnect output port [%s] from [%s]",
                  m_OutputPortMap[n]->ConnectedTo.c_str(),
                  m_OutputPortMap[n]->Name.c_str());
    }

    m_OutputPortMap[n]->Connected = false;
}
示例#16
0
void midiInitialize(char *inputDevice, char *outputDevice) {
  jack_begin(); // create a new jack client

  // register the midi-send ports
  jack_midi_input_port = jack_port_register (jack_client, "input", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
  if (jack_midi_input_port == NULL) {
    fprintf (stderr, "cannot create input port\n");
    exit(1);
  }

  jack_midi_output_port = jack_port_register (jack_client, "output", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
  if (jack_midi_output_port == NULL) {
      fprintf (stderr, "cannot create output port\n");
      exit(1);
  }

  // activate
  if (jack_activate (jack_client)) {
    fprintf (stderr, "cannot activate client");
    exit(1);
  }

  // connect ports to specified devices

  printf("connecting %s to %s\n", jack_port_name(jack_midi_output_port), inputDevice);
  printf("connecting %s to %s\n", outputDevice, jack_port_name(jack_midi_input_port));

  int err;
  if ((err=jack_connect (jack_client, outputDevice, jack_port_name(jack_midi_input_port)))) {
    fprintf (stderr, "cannot connect input port: %s\n", strerror(err));
    exit(1);
  }
  if ((err=jack_connect (jack_client, jack_port_name(jack_midi_output_port), inputDevice))) {
    fprintf (stderr, "cannot connect output port: %s\n", strerror(err));
    exit(1);
  }

}
示例#17
0
文件: Port.C 项目: harryhaaren/non
    int
    Port::disconnect ( const char *from )
    {
        const char *name = jack_port_name( _port );

        if ( _direction == Output )
        {  
            return jack_disconnect( _client->jack_client(), name, from );
        }
        else
        {
            return jack_disconnect( _client->jack_client(), from, name );
        }
    }
示例#18
0
JackPort*
JackClient::PortByName(const char* name)
{
	JackPort* port;
	JackPortList* lst = GetOutputPorts();
	for (int i = 0; i < lst->CountItems(); i++) {
		port = lst->ItemAt(i);
		BString str(name);
		if (str.Compare(jack_port_name((jack_port_t*)port)) == 0)
			return port;
	}

	return NULL;
}
示例#19
0
文件: Port.C 项目: harryhaaren/non
    int
    Port::connect ( const char *to )
    {
        const char *name = jack_port_name( _port );

        if ( _direction == Output )
        {  
            return jack_connect( _client->jack_client(), name, to );
        }
        else
        {
            return jack_connect( _client->jack_client(), to, name );
        }
    }
int main(int argc, char *argv[]) {
  jack_client_t *client;
  const char **ports;
  const char* name = (argc>1) ? argv[1] : "StereoDecoder";
  char s[63];
  int i;

  if ((client = jack_client_open(name, JackNullOption, NULL)) == 0) {
    fprintf(stderr, "jack server not running?\n");
    return 1;
  }

  jack_set_process_callback(client, process, 0);
  jack_on_shutdown(client, jack_shutdown, 0);

  for(i=0; i<INPORTS; i++) {
    sprintf(s, "input_%d", i);
    input_ports[i] = jack_port_register(client, s,
          JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  }

  for(i=0; i<OUTPORTS; i++) {
    sprintf(s, "output_%d", i);
    output_ports[i] = jack_port_register(client, s,
          JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  }

  if (jack_activate(client)) {
    fprintf(stderr, "cannot activate client");
    return 1;
  }

  if ((ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
    fprintf(stderr, "Cannot find any physical playback ports\n");
    return 1;
  }

  for(i=0; i<OUTPORTS; i++) {
    if (ports[i]==NULL ||
          jack_connect(client, jack_port_name(output_ports[i]), ports[i])) {
      fprintf(stderr, "cannot connect output ports\n");
    }
  }

  free(ports);

  while (1) {
    sleep(10);
  }
}
示例#21
0
文件: jack.c 项目: doctaweeks/rotter
// Connect one Jack port to another
int connect_jack_port( const char* out, jack_port_t *port )
{
  const char* in = jack_port_name( port );
  int err;

  rotter_info("Connecting '%s' to '%s'", out, in);

  if ((err = jack_connect(client, out, in)) != 0) {
    rotter_fatal("connect_jack_port(): failed to jack_connect() ports: %d", err);
    return err;
  }

  // Success
  return 0;
}
示例#22
0
void AudioJack::startProcessing()
{
	m_stopped = false;

	if( m_active || m_client == NULL )
	{
		return;
	}

	if( jack_activate( m_client ) )
	{
		printf( "cannot activate client\n" );
		return;
	}

	m_active = true;


	// try to sync JACK's and LMMS's buffer-size
//	jack_set_buffer_size( m_client, mixer()->framesPerPeriod() );



	const char * * ports = jack_get_ports( m_client, NULL, NULL,
						JackPortIsPhysical |
						JackPortIsInput );
	if( ports == NULL )
	{
		printf( "no physical playback ports. you'll have to do "
			"connections at your own!\n" );
	}
	else
	{
		for( ch_cnt_t ch = 0; ch < channels(); ++ch )
		{
			if( jack_connect( m_client, jack_port_name(
							m_outputPorts[ch] ),
								ports[ch] ) )
			{
				printf( "cannot connect output ports. you'll "
					"have to do connections at your own!\n"
									);
			}
		}
	}

	free( ports );
}
示例#23
0
static void
cbjack_connect_ports (cubeb_stream * stream)
{
  const char **physical_ports = jack_get_ports (stream->context->jack_client,
      NULL, NULL, JackPortIsInput | JackPortIsPhysical);
  if (physical_ports == NULL) {
    return;
  }

  // Connect to all physical ports
  for (unsigned int c = 0; c < stream->params.channels && physical_ports[c]; c++) {
    const char *src_port = jack_port_name (stream->output_ports[c]);

    jack_connect (stream->context->jack_client, src_port, physical_ports[c]);
  }
  jack_free(physical_ports);
}
示例#24
0
文件: jack_output.hpp 项目: jemc/seqr
int JackOutputNode::activate(VALUE jc)
{
  const char**   ports;
  jack_client_t* client;
  
  client = store_jclient(jc)->jclient;
  if(!this->jack_is_ready()) return 1;
  
  this->port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  
  ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput);
  if(!ports || jack_connect(client, jack_port_name(this->port), ports[0]))
    return 1;
  free(ports);
  
  return 0;
}
示例#25
0
文件: jack.c 项目: Deslon/Supernova
/* connect to jack ports named in the NULL-terminated wishlist */
static int real_connect_jack_ports(out123_handle *ao
,	jack_handle_t* handle, const char** wishlist)
{
	const char **wish = wishlist;
	int ch, err;
	int ch_wrap = 0, wish_wrap = 0;

	if(!wish)
		return 0;
	if(wish != NULL && *wish == NULL)
		return 1; /* success, nothing connected as wanted */
	ch=0;
	/* Connect things as long as there are sources or sinks left. */
	while(!wish_wrap || !ch_wrap)
	{
		const char* in = jack_port_name(handle->ports[ch]);

		if((err = jack_connect(handle->client, in, *wish)) != 0 && err != EEXIST)
		{
			if(!AOQUIET)
				error4( "connect_jack_ports(): failed to jack_connect() ch%i (%s) to %s: %d"
				,	ch, in ? in : "<nil>", *wish, err );
			return 0;
		}
		/*
			Increment channel and wishlist, both possibly wrapping around, to
			ensure we connected all channels to some output port and provided
			some input to all ports in the wishlist. Both cases of less channels
			than output ports (splitting) and more channels	than output ports
			(downmix) are sensible.
		*/
		if(++ch == handle->channels)
		{
			ch = 0;
			++ch_wrap;
		}
		if(!*(++wish))
		{
			wish = wishlist;
			++wish_wrap;
		}
	}

	return 1;
}
示例#26
0
status_t
ClientNode::PrepareToConnect(const media_source &src,
                             const media_destination &dst,
                             media_format *format, media_source *out_source,
                             char *name)
{
    printf("ClientNode::PrepareToConnect\n");

    if (dst.port == ControlPort())
        return B_MEDIA_BAD_SOURCE;

    if (src.port != ControlPort() || src.id != 0)
        return B_MEDIA_BAD_SOURCE;

    if (format->type != B_MEDIA_RAW_AUDIO
            && format->type != B_MEDIA_UNKNOWN_TYPE) {
        return B_MEDIA_BAD_FORMAT;
    }

    JackPort* port;
    JackPortList* outputs = fOwner->GetOutputPorts();

    for (int i = 0; i < outputs->CountItems(); i++) {
        port = outputs->ItemAt(i);

        media_output* output = port->MediaOutput();
        if (output->source.id == src.id
                && output->destination.id == dst.id) {

            if (port->IsConnected())
                return B_MEDIA_ALREADY_CONNECTED;

            *out_source = src;

            BString portName(jack_port_name((jack_port_t*) port));
            portName.CopyInto(name, 0, portName.Length());

            printf("Connecting to %s\n", name);
            format->SpecializeTo(&fFormat);
            return B_OK;
        }
    }

    return B_MEDIA_BAD_SOURCE;
}
示例#27
0
文件: ports.c 项目: alex1818/aqualung
void
tree_out_R_selection_changed(GtkTreeSelection *selection, gpointer * data) {

	GtkTreeIter iter;
        GtkTreeModel * model;
        gchar * str;
	int res;

        if (gtk_tree_selection_get_selected(selection, &model, &iter)) {

                gtk_tree_model_get(model, &iter, 0, &str, -1);
		if ((res = jack_disconnect(jack_client, jack_port_name(out_R_port), str)) != 0) {
			fprintf(stderr, "ERROR: jack_disconnect() returned %d\n", res);
		}
		g_free(str);
		timeout_tag = aqualung_timeout_add(100, ports_timeout_callback, (gpointer)2);
        }
}
示例#28
0
void RtMidiOutJack :: openPort( unsigned int portNumber, const std::string portName )
{
  JackMidiData *data = static_cast<JackMidiData *> (apiData_);

  // Creating new port
  if ( data->port == NULL )
    data->port = jack_port_register( data->client, portName.c_str(),
      JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0 );

  if ( data->port == NULL ) {
    errorString_ = "RtMidiOut::openVirtualPort: JACK error creating virtual port";
    error( RtError::DRIVER_ERROR );
  }

  // Connecting to the output
  std::string name = getPortName( portNumber );
  jack_connect( data->client, jack_port_name( data->port ), name.c_str() );
}
示例#29
0
int
connect_to_output_port (const char * port)
{
   int ret = jack_port_disconnect(jack_client, input_port);
   if (ret)
   {
      g_warning("Cannot disconnect MIDI port.");
      return -3;
   }
   ret = jack_connect(jack_client, port, jack_port_name(input_port));
   if (ret)
   {
      g_warning("Cannot connect to %s.", port);
      return -4;
   }
   g_warning("Connected to %s.", port);
   return 0;
}
示例#30
0
bool JackClient::autoConnectPortsToMPG123()
{
    const char **pp_ports;
    int retval;

    // connect left channel
    pp_ports = jack_get_ports(m_p_jackClient,
                  s_portNameToConnectLeftChannelRegex.c_str(),
                  NULL, JackPortIsOutput);
    if (pp_ports == NULL) {
        DEBUG_PRINT("[!] no output port with name %s found (regex)",
                    s_portNameToConnectLeftChannelRegex.c_str());
    return false;
    }
    retval = jack_connect(m_p_jackClient, pp_ports[0],
                  jack_port_name(m_p_leftChannelInputPort));
    free(pp_ports);
    if (retval) {
        DEBUG_PRINT("[!] cannot connect input port %s (%d)",
                jack_port_name(m_p_leftChannelInputPort), retval);
    return false;
    } else {
        DEBUG_PRINT("successfully connected %s to %s",
                s_portNameToConnectLeftChannelRegex.c_str(),
                jack_port_name(m_p_leftChannelInputPort));
    }

    // connect right channel
    pp_ports = jack_get_ports(m_p_jackClient,
                  s_portNameToConnectRightChannelRegex.c_str(),
                  NULL, JackPortIsOutput);
    if (pp_ports == NULL) {
        DEBUG_PRINT("[!] no output port with name %s found (regex)",
                s_portNameToConnectRightChannelRegex.c_str());
    return false;
    }
    retval = jack_connect(m_p_jackClient, pp_ports[0],
                  jack_port_name(m_p_rightChannelInputPort));
    free(pp_ports);
    if (retval) {
        DEBUG_PRINT("[!] cannot connect input port %s (%d)",
                jack_port_name(m_p_rightChannelInputPort), retval);
    return false;
    } else {
        DEBUG_PRINT("successfully connected %s to %s",
                s_portNameToConnectRightChannelRegex.c_str(),
                jack_port_name(m_p_rightChannelInputPort));
    }

    return true;
}