Ejemplo n.º 1
0
// Return port flags (an integer)
static PyObject* get_port_flags(PyObject* self, PyObject* args)
{
    char* pname;
    jack_port_t* jp;
    int i;

    pyjack_client_t * client = self_or_global_client(self);
    if(client->pjc == NULL) {
        PyErr_SetString(JackNotConnectedError, "Jack connection has not yet been established.");
        return NULL;
    }

    if (! PyArg_ParseTuple(args, "s", &pname))
        return NULL;

    jp = jack_port_by_name(client->pjc, pname);
    if(jp == NULL) {
        PyErr_SetString(JackError, "Bad port name.");
        return NULL;
    }

    i = jack_port_flags(jp);
    if(i < 0) {
        PyErr_SetString(JackError, "Error getting port flags.");
        return NULL;
    }

    return Py_BuildValue("i", i);
}
Ejemplo n.º 2
0
static int _list_ports(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj* const *objv) {
  if (argc != 2) return fw_error_str(interp, "jack-client list-ports");
  _t *dp = (_t *)clientData;
  Tcl_Obj *dict = Tcl_NewDictObj();
  const char **portv[] = {
    jack_get_ports (dp->fw.client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0),
    jack_get_ports (dp->fw.client, NULL, JACK_DEFAULT_MIDI_TYPE, 0)
  };
  for (int p = 0; p < 2; p += 1)
    if (portv[p] != NULL) {
      for (int i = 0; portv[p][i] != NULL; i += 1) {
	jack_port_t *port = jack_port_by_name(dp->fw.client, portv[p][i]);
	if (port != NULL) {
	  Tcl_Obj *pdict = Tcl_NewDictObj();
	  int flags = jack_port_flags(port);
	  Tcl_DictObjPut(interp, pdict, Tcl_NewStringObj("direction", -1), flags & JackPortIsInput ? Tcl_NewStringObj("input", -1) : Tcl_NewStringObj("output", -1) );
	  Tcl_DictObjPut(interp, pdict, Tcl_NewStringObj("physical", -1), Tcl_NewIntObj(flags & JackPortIsPhysical ? 1 : 0));
	  Tcl_DictObjPut(interp, pdict, Tcl_NewStringObj("type", -1), p == 0 ? Tcl_NewStringObj("audio", -1) : Tcl_NewStringObj("midi", -1));
	  const char **connv = jack_port_get_all_connections(dp->fw.client, port);
	  Tcl_Obj *list = Tcl_NewListObj(0, NULL);
	  if (connv != NULL) {
	    for (int j = 0; connv[j] != NULL; j += 1)
	      Tcl_ListObjAppendElement(interp, list, Tcl_NewStringObj(connv[j], -1));
	    jack_free(connv);
	  }
	  Tcl_DictObjPut(interp, pdict, Tcl_NewStringObj("connections", -1), list);
	  Tcl_DictObjPut(interp, dict, Tcl_NewStringObj(portv[p][i], -1), pdict);
	}
      }
      jack_free(portv[p]);
    }
  Tcl_SetObjResult(interp, dict);
  return TCL_OK;
}
Ejemplo n.º 3
0
unsigned long getTipoByName(const char* name)
{
    jack_port_t* jp;
    jp = jack_port_by_name(client, name);
    if (jp != NULL) 
		return jack_port_flags(jp);
    return 0;
}
Ejemplo n.º 4
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())));
  }
}
Ejemplo n.º 5
0
void JackAudioSystem::auto_connect_ports() {
	if (!(client && g.s.bJackAutoConnect)) {
		return;
	}

	disconnect_ports();

	const char **ports = NULL;
	const int wanted_out_flags = JackPortIsPhysical | JackPortIsOutput;
	const int wanted_in_flags = JackPortIsPhysical | JackPortIsInput;
	int err;
	unsigned int connected_out_ports = 0;
	unsigned int connected_in_ports = 0;

	ports = jack_get_ports(client, 0, "audio", JackPortIsPhysical);
	if (ports != NULL) {
		int i = 0;
		while (ports[i] != NULL) {
			jack_port_t * const port = jack_port_by_name(client, ports[i]);
			if (port == NULL)  {
				qWarning("JackAudioSystem: jack_port_by_name() returned an invalid port - skipping it");
				continue;
			}

			const int port_flags = jack_port_flags(port);

			if (bInputIsGood && (port_flags & wanted_out_flags) == wanted_out_flags && connected_in_ports < 1) {
				err = jack_connect(client, ports[i], jack_port_name(in_port));
				if (err != 0) {
					qWarning("JackAudioSystem: unable to connect port '%s' to '%s' - jack_connect() returned %i", ports[i], jack_port_name(in_port), err);
				} else {
					connected_in_ports++;
				}
			} else if (bOutputIsGood && (port_flags & wanted_in_flags) == wanted_in_flags && connected_out_ports < iOutPorts) {
				err = jack_connect(client, jack_port_name(out_ports[connected_out_ports]), ports[i]);
				if (err != 0) {
					qWarning("JackAudioSystem: unable to connect port '%s' to '%s' - jack_connect() returned %i", jack_port_name(out_ports[connected_out_ports]), ports[i], err);
				} else {
					connected_out_ports++;
				}
			}

			++i;
		}
	}
}
Ejemplo n.º 6
0
QList<QString> JackAudio::inputPorts()
      {
      const char** ports = jack_get_ports(client, 0, 0, 0);
      QList<QString> clientList;
      for (const char** p = ports; p && *p; ++p) {
            jack_port_t* port = jack_port_by_name(client, *p);
            int flags = jack_port_flags(port);
            if (!(flags & JackPortIsInput))
                  continue;
            char buffer[128];
            strncpy(buffer, *p, 128);
            if (strncmp(buffer, "Mscore", 6) == 0)
                  continue;
            clientList.append(QString(buffer));
            }
      return clientList;
      }
Ejemplo n.º 7
0
/* nframes is the number of frames to buffer */
    Port::Port ( JACK::Client *client, jack_port_t *port )
    {
        _terminal = 0;
        _connections = NULL;
        _client = client;
        _port = port;
        _name = strdup( jack_port_name( port ) );
        _trackname = NULL;
        _direction = ( jack_port_flags( _port ) & JackPortIsOutput ) ? Output : Input;
        const char *type = jack_port_type( _port );

        _type = Audio;
        if ( strstr( type, "MIDI") )
            _type = MIDI;
        else if ( strstr( type, "CV)") )
            _type = CV;

        _client->port_added( this );

    }
Ejemplo n.º 8
0
void
setup_ports (int sources, char *source_names[], jack_thread_info_t *info)
{
	unsigned int i;
	size_t in_size;
	const char **jack_ports;

	/* 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 *);
	rb =(jack_ringbuffer_t **)malloc(sizeof (jack_ringbuffer_t *) * (sources));
	for(i=0;i<sources;i++){
		rb[i]=jack_ringbuffer_create(info->rb_size);
	}

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

		sprintf (name, "in_%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);
		}
	}

	if (!getFirstTwo) {
		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);
			} 
		}
	}
	else {
		jack_ports = jack_get_ports (info->client, NULL, NULL, 0);

		int portNum = 0;
		for (i = 0; jack_ports[i]; ++i) {
			if (portNum >= 2) {
				break;
			}
			if (strstr(jack_ports[i], portMatch)) {
				jack_port_t *port = jack_port_by_name (info->client, jack_ports[i]);
				if (port) {
					int flags = jack_port_flags (port);
					if (flags & JackPortIsOutput) {
						printf("registering with %s\n", jack_ports[i]);
						if (jack_connect (info->client, jack_ports[i], jack_port_name(ports[portNum]))) {
							fprintf (stderr, "cannot connect input port %s to %s\n", jack_port_name (ports[portNum]), jack_ports[i]);
							jack_client_close (info->client);
							exit (1);
						}
						portNum++;
					}
				}
			}
		}
		if (portNum < 2) {
			printf("Could not find at least two output ports matching (%s)\n", portMatch);
			jack_client_close (info->client);
			exit (1);
		}

	}

	info->can_process = 1;		/* process() can start, now */
}
Ejemplo n.º 9
0
static int refresh_devices_bare(SoundIoPrivate *si) {
    SoundIo *soundio = &si->pub;
    SoundIoJack *sij = &si->backend_data.jack;

    if (sij->is_shutdown)
        return SoundIoErrorBackendDisconnected;


    SoundIoDevicesInfo *devices_info = allocate<SoundIoDevicesInfo>(1);
    if (!devices_info)
        return SoundIoErrorNoMem;

    devices_info->default_output_index = -1;
    devices_info->default_input_index = -1;
    const char **port_names = jack_get_ports(sij->client, nullptr, nullptr, 0);
    if (!port_names) {
        soundio_destroy_devices_info(devices_info);
        return SoundIoErrorNoMem;
    }

    SoundIoList<SoundIoJackClient> clients = {0};
    const char **port_name_ptr = port_names;
    for (; *port_name_ptr; port_name_ptr += 1) {
        const char *client_and_port_name = *port_name_ptr;
        int client_and_port_name_len = strlen(client_and_port_name);
        jack_port_t *jport = jack_port_by_name(sij->client, client_and_port_name);
        if (!jport) {
            // This refresh devices scan is already outdated. Just give up and
            // let refresh_devices be called again.
            jack_free(port_names);
            soundio_destroy_devices_info(devices_info);
            return SoundIoErrorInterrupted;
        }

        int flags = jack_port_flags(jport);
        const char *port_type = jack_port_type(jport);
        if (strcmp(port_type, JACK_DEFAULT_AUDIO_TYPE) != 0) {
            // we don't know how to support such a port
            continue;
        }

        SoundIoDeviceAim aim = (flags & JackPortIsInput) ?
            SoundIoDeviceAimOutput : SoundIoDeviceAimInput;
        bool is_physical = flags & JackPortIsPhysical;

        const char *client_name = nullptr;
        const char *port_name = nullptr;
        int client_name_len;
        int port_name_len;
        split_str(client_and_port_name, client_and_port_name_len, ':',
                &client_name, &client_name_len, &port_name, &port_name_len);
        if (!client_name || !port_name) {
            // device does not have colon, skip it
            continue;
        }
        SoundIoJackClient *client = find_or_create_client(&clients, aim, is_physical,
                client_name, client_name_len);
        if (!client) {
            jack_free(port_names);
            soundio_destroy_devices_info(devices_info);
            return SoundIoErrorNoMem;
        }
        if (client->port_count >= SOUNDIO_MAX_CHANNELS) {
            // we hit the channel limit, skip the leftovers
            continue;
        }
        SoundIoJackPort *port = &client->ports[client->port_count++];
        port->full_name = client_and_port_name;
        port->full_name_len = client_and_port_name_len;
        port->name = port_name;
        port->name_len = port_name_len;
        port->channel_id = soundio_parse_channel_id(port_name, port_name_len);

        jack_latency_callback_mode_t latency_mode = (aim == SoundIoDeviceAimOutput) ?
            JackPlaybackLatency : JackCaptureLatency;
        jack_port_get_latency_range(jport, latency_mode, &port->latency_range);
    }

    for (int i = 0; i < clients.length; i += 1) {
        SoundIoJackClient *client = &clients.at(i);
        if (client->port_count <= 0)
            continue;

        SoundIoDevicePrivate *dev = allocate<SoundIoDevicePrivate>(1);
        if (!dev) {
            jack_free(port_names);
            soundio_destroy_devices_info(devices_info);
            return SoundIoErrorNoMem;
        }
        SoundIoDevice *device = &dev->pub;
        SoundIoDeviceJack *dj = &dev->backend_data.jack;
        int description_len = client->name_len + 3 + 2 * client->port_count;
        for (int port_index = 0; port_index < client->port_count; port_index += 1) {
            SoundIoJackPort *port = &client->ports[port_index];

            description_len += port->name_len;
        }

        dev->destruct = destruct_device;

        device->ref_count = 1;
        device->soundio = soundio;
        device->is_raw = false;
        device->aim = client->aim;
        device->id = soundio_str_dupe(client->name, client->name_len);
        device->name = allocate<char>(description_len);
        device->current_format = SoundIoFormatFloat32NE;
        device->sample_rate_count = 1;
        device->sample_rates = &dev->prealloc_sample_rate_range;
        device->sample_rates[0].min = sij->sample_rate;
        device->sample_rates[0].max = sij->sample_rate;
        device->sample_rate_current = sij->sample_rate;

        device->software_latency_current = sij->period_size / (double) sij->sample_rate;
        device->software_latency_min = sij->period_size / (double) sij->sample_rate;
        device->software_latency_max = sij->period_size / (double) sij->sample_rate;

        dj->port_count = client->port_count;
        dj->ports = allocate<SoundIoDeviceJackPort>(dj->port_count);

        if (!device->id || !device->name || !dj->ports) {
            jack_free(port_names);
            soundio_device_unref(device);
            soundio_destroy_devices_info(devices_info);
            return SoundIoErrorNoMem;
        }

        for (int port_index = 0; port_index < client->port_count; port_index += 1) {
            SoundIoJackPort *port = &client->ports[port_index];
            SoundIoDeviceJackPort *djp = &dj->ports[port_index];
            djp->full_name = soundio_str_dupe(port->full_name, port->full_name_len);
            djp->full_name_len = port->full_name_len;
            djp->channel_id = port->channel_id;
            djp->latency_range = port->latency_range;

            if (!djp->full_name) {
                jack_free(port_names);
                soundio_device_unref(device);
                soundio_destroy_devices_info(devices_info);
                return SoundIoErrorNoMem;
            }
        }

        memcpy(device->name, client->name, client->name_len);
        memcpy(&device->name[client->name_len], ": ", 2);
        int index = client->name_len + 2;
        for (int port_index = 0; port_index < client->port_count; port_index += 1) {
            SoundIoJackPort *port = &client->ports[port_index];
            memcpy(&device->name[index], port->name, port->name_len);
            index += port->name_len;
            if (port_index + 1 < client->port_count) {
                memcpy(&device->name[index], ", ", 2);
                index += 2;
            }
        }

        device->current_layout.channel_count = client->port_count;
        bool any_invalid = false;
        for (int port_index = 0; port_index < client->port_count; port_index += 1) {
            SoundIoJackPort *port = &client->ports[port_index];
            device->current_layout.channels[port_index] = port->channel_id;
            any_invalid = any_invalid || (port->channel_id == SoundIoChannelIdInvalid);
        }
        if (any_invalid) {
            const struct SoundIoChannelLayout *layout = soundio_channel_layout_get_default(client->port_count);
            if (layout)
                device->current_layout = *layout;
        } else {
            soundio_channel_layout_detect_builtin(&device->current_layout);
        }

        device->layout_count = 1;
        device->layouts = &device->current_layout;
        device->format_count = 1;
        device->formats = &dev->prealloc_format;
        device->formats[0] = device->current_format;

        SoundIoList<SoundIoDevice *> *device_list;
        if (device->aim == SoundIoDeviceAimOutput) {
            device_list = &devices_info->output_devices;
            if (devices_info->default_output_index < 0 && client->is_physical)
                devices_info->default_output_index = device_list->length;
        } else {
            assert(device->aim == SoundIoDeviceAimInput);
            device_list = &devices_info->input_devices;
            if (devices_info->default_input_index < 0 && client->is_physical)
                devices_info->default_input_index = device_list->length;
        }

        if (device_list->append(device)) {
            soundio_device_unref(device);
            soundio_destroy_devices_info(devices_info);
            return SoundIoErrorNoMem;
        }

    }
    jack_free(port_names);

    soundio_destroy_devices_info(si->safe_devices_info);
    si->safe_devices_info = devices_info;

    return 0;
}
Ejemplo n.º 10
0
Archivo: connect.c Proyecto: 7890/tools
int
main (int argc, char *argv[])
{
    jack_client_t *client;
    jack_status_t status;
    char *server_name = NULL;
    int c;
    int option_index;
    jack_options_t options = JackNoStartServer;
    char *my_name = strrchr(argv[0], '/');
    jack_port_t *src_port = 0;
    jack_port_t *dst_port = 0;
    jack_port_t *port1 = 0;
    jack_port_t *port2 = 0;
    char portA[300];
    char portB[300];
    int use_uuid=0;
    int connecting, disconnecting;
    int port1_flags, port2_flags;
    int rc = 1;

    struct option long_options[] = {
        { "server", 1, 0, 's' },
        { "help", 0, 0, 'h' },
        { "version", 0, 0, 'v' },
        { "uuid", 0, 0, 'u' },
        { 0, 0, 0, 0 }
    };

    while ((c = getopt_long (argc, argv, "s:hvu", long_options, &option_index)) >= 0) {
        switch (c) {
        case 's':
            server_name = (char *) malloc (sizeof (char) * strlen(optarg));
            strcpy (server_name, optarg);
            options |= JackServerName;
            break;
        case 'u':
            use_uuid = 1;
            break;
        case 'h':
            show_usage (my_name);
            return 1;
            break;
        case 'v':
            show_version (my_name);
            return 1;
            break;
        default:
            show_usage (my_name);
            return 1;
            break;
        }
    }

    connecting = disconnecting = FALSE;
    if (my_name == 0) {
        my_name = argv[0];
    } else {
        my_name ++;
    }

    if (strstr(my_name, "disconnect")) {
        disconnecting = 1;
    } else if (strstr(my_name, "connect")) {
        connecting = 1;
    } else {
        fprintf(stderr, "ERROR! client should be called jack_connect or jack_disconnect. client is called %s\n", my_name);
        return 1;
    }

    if (argc < 3) {
        show_usage(my_name);
        return 1;
    }

    /* try to become a client of the JACK server */

    if ((client = jack_client_open (my_name, options, &status, server_name)) == 0) {
        fprintf (stderr, "jack server not running?\n");
        return 1;
    }

    /* find the two ports */

    if( use_uuid ) {
        char *tmpname;
        char *clientname;
        char *portname;
        tmpname = strdup( argv[argc-1] );
        portname = strchr( tmpname, ':' );
        portname[0] = '\0';
        portname+=1;
        clientname = jack_get_client_name_by_uuid( client, tmpname );
        if( clientname ) {

            snprintf( portA, sizeof(portA), "%s:%s", clientname, portname );
            jack_free( clientname );
        } else {
            snprintf( portA, sizeof(portA), "%s", argv[argc-1] );
        }
        free( tmpname );

        tmpname = strdup( argv[argc-2] );
        portname = strchr( tmpname, ':' );
        portname[0] = '\0';
        portname+=1;
        clientname = jack_get_client_name_by_uuid( client, tmpname );
        if( clientname ) {
            snprintf( portB, sizeof(portB), "%s:%s", clientname, portname );
            jack_free( clientname );
        } else {
            snprintf( portB, sizeof(portB), "%s", argv[argc-2] );
        }

        free( tmpname );

    } else {
        snprintf( portA, sizeof(portA), "%s", argv[argc-1] );
        snprintf( portB, sizeof(portB), "%s", argv[argc-2] );
    }
    if ((port1 = jack_port_by_name(client, portA)) == 0) {
        fprintf (stderr, "ERROR %s not a valid port\n", portA);
        goto exit;
    }
    if ((port2 = jack_port_by_name(client, portB)) == 0) {
        fprintf (stderr, "ERROR %s not a valid port\n", portB);
        goto exit;
    }

    port1_flags = jack_port_flags (port1);
    port2_flags = jack_port_flags (port2);

    if (port1_flags & JackPortIsInput) {
        if (port2_flags & JackPortIsOutput) {
            src_port = port2;
            dst_port = port1;
        }
    } else {
        if (port2_flags & JackPortIsInput) {
            src_port = port1;
            dst_port = port2;
        }
    }

    if (!src_port || !dst_port) {
        fprintf (stderr, "arguments must include 1 input port and 1 output port\n");
        goto exit;
    }

    /* connect the ports. Note: you can't do this before
       the client is activated (this may change in the future).
    */

    if (connecting) {
        if (jack_connect(client, jack_port_name(src_port), jack_port_name(dst_port))) {
            goto exit;
        }
    }
    if (disconnecting) {
        if (jack_disconnect(client, jack_port_name(src_port), jack_port_name(dst_port))) {
            goto exit;
        }
    }

    /* everything was ok, so setting exitcode to 0 */
    rc = 0;

exit:
    jack_client_close (client);
    exit (rc);
}
RString RageSoundDriver_JACK::ConnectPorts()
{
	vector<RString> portNames;
	split(PREFSMAN->m_iSoundDevice.Get(), ",", portNames, true);

	const char *port_out_l = NULL, *port_out_r = NULL;
	const char **ports = NULL;
	if( portNames.size() == 0 )
	{
		// The user has NOT specified any ports to connect to. Search 
		// for all physical sinks and use the first two.
		ports = jack_get_ports( client, NULL, NULL, JackPortIsInput | JackPortIsPhysical );
		if( ports == NULL )
			return "Couldn't get JACK ports";
		if( ports[0] == NULL )
		{
			jack_free( ports );
			return "No physical sinks!";
		}
		port_out_l = ports[0];

		if( ports[1] == NULL )
			// Only one physical sink. We're going mono!
			port_out_r = ports[0];
		else
			port_out_r = ports[1];
	}
	else
	{
		// The user has specified ports to connect to. Loop through
		// them to find two that are valid, then use them. If we find 
		// only one that is valid, connect both channels to it.
		// Use jack_port_by_name to ensure ports exist, then
		// jack_port_name to use their canonical name.  (I'm not sure 
		// if that second step is necessary, I've seen something about 
		// "aliases" in the docs.)
		FOREACH( RString, portNames, portName )
		{
			jack_port_t *out = jack_port_by_name( client, *portName );
			// Make sure the port is a sink.
			if( ! ( jack_port_flags( out ) & JackPortIsInput ) )
				continue;

			if( out != NULL )
			{
				if( port_out_l == NULL )
					port_out_l = jack_port_name( out );
				else
				{
					port_out_r = jack_port_name( out );
					break;
				}
			}
		}
		if( port_out_l == NULL )
			return "All specified sinks are invalid.";
		
		if( port_out_r == NULL )
			// Only found one valid sink. Going mono!
			port_out_r = port_out_l;
	}
Ejemplo n.º 12
0
Archivo: lsp.c Proyecto: Andux/jack2
int
main (int argc, char *argv[])
{
	jack_client_t *client;
	jack_status_t status;
    jack_options_t options = JackNoStartServer;
	const char **ports, **connections;
	unsigned int i, j, k;
	int skip_port;
	int show_aliases = 0;
	int show_con = 0;
	int show_port_latency = 0;
	int show_total_latency = 0;
	int show_properties = 0;
	int show_type = 0;
	int c;
	int option_index;
	char* aliases[2];
	char *server_name = NULL;
	jack_port_t *port;

	struct option long_options[] = {
	    { "server", 1, 0, 's' },
		{ "aliases", 0, 0, 'A' },
		{ "connections", 0, 0, 'c' },
		{ "port-latency", 0, 0, 'l' },
		{ "total-latency", 0, 0, 'L' },
		{ "properties", 0, 0, 'p' },
		{ "type", 0, 0, 't' },
		{ "help", 0, 0, 'h' },
		{ "version", 0, 0, 'v' },
		{ 0, 0, 0, 0 }
	};

	my_name = strrchr(argv[0], '/');
	if (my_name == 0) {
		my_name = argv[0];
	} else {
		my_name ++;
	}

	while ((c = getopt_long (argc, argv, "s:AclLphvt", long_options, &option_index)) >= 0) {
		switch (c) {
		case 's':
            server_name = (char *) malloc (sizeof (char) * strlen(optarg));
            strcpy (server_name, optarg);
            options |= JackServerName;
            break;
		case 'A':
			aliases[0] = (char *) malloc (jack_port_name_size());
			aliases[1] = (char *) malloc (jack_port_name_size());
			show_aliases = 1;
			break;
		case 'c':
			show_con = 1;
			break;
		case 'l':
			show_port_latency = 1;
			break;
		case 'L':
			show_total_latency = 1;
			break;
		case 'p':
			show_properties = 1;
			break;
		case 't':
			show_type = 1;
			break;
		case 'h':
			show_usage ();
			return 1;
			break;
		case 'v':
			show_version ();
			return 1;
			break;
		default:
			show_usage ();
			return 1;
			break;
		}
	}

	/* Open a client connection to the JACK server.  Starting a
	 * new server only to list its ports seems pointless, so we
	 * specify JackNoStartServer. */
	//JOQ: need a new server name option

	client = jack_client_open ("lsp", options, &status, server_name);
	if (client == NULL) {
		if (status & JackServerFailed) {
			fprintf (stderr, "JACK server not running\n");
		} else {
			fprintf (stderr, "jack_client_open() failed, "
				 "status = 0x%2.0x\n", status);
		}
		return 1;
	}

	ports = jack_get_ports (client, NULL, NULL, 0);
    if (!ports)
        goto error;

	for (i = 0; ports && ports[i]; ++i) {
		// skip over any that don't match ALL of the strings presented at command line
		skip_port = 0;
		for(k = optind; k < argc; k++){
			if(strstr(ports[i], argv[k]) == NULL ){
				skip_port = 1;
			}
		}
		if (skip_port) continue;

		printf ("%s\n", ports[i]);
		port = jack_port_by_name (client, ports[i]);

		if (show_aliases) {
			int cnt;
			int i;

			cnt = jack_port_get_aliases (port, aliases);
			for (i = 0; i < cnt; ++i) {
				printf ("   %s\n", aliases[i]);
			}
		}

		if (show_con) {
			if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
				for (j = 0; connections[j]; j++) {
					printf ("   %s\n", connections[j]);
				}
				free (connections);
			}
		}
		if (show_port_latency) {
			if (port) {
				jack_latency_range_t range;
				printf ("	port latency = %" PRIu32 " frames\n",
					jack_port_get_latency (port));

				jack_port_get_latency_range (port, JackPlaybackLatency, &range);
				printf ("	port playback latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
					range.min, range.max);

				jack_port_get_latency_range (port, JackCaptureLatency, &range);
				printf ("	port capture latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
					range.min, range.max);
			}
		}
		if (show_total_latency) {
			if (port) {
				printf ("	total latency = %d frames\n",
					jack_port_get_total_latency (client, port));
			}
		}
		if (show_properties) {
			if (port) {
				int flags = jack_port_flags (port);
				printf ("	properties: ");
				if (flags & JackPortIsInput) {
					fputs ("input,", stdout);
				}
				if (flags & JackPortIsOutput) {
					fputs ("output,", stdout);
				}
				if (flags & JackPortCanMonitor) {
					fputs ("can-monitor,", stdout);
				}
				if (flags & JackPortIsPhysical) {
					fputs ("physical,", stdout);
				}
				if (flags & JackPortIsTerminal) {
					fputs ("terminal,", stdout);
				}

				putc ('\n', stdout);
			}
		}
		if (show_type) {
			if (port) {
				putc ('\t', stdout);
				fputs (jack_port_type (port), stdout);
				putc ('\n', stdout);
			}
		}
	}

error:
    if (show_aliases) {
        free(aliases[0]);
        free(aliases[1]);
    }
    if (ports)
        jack_free (ports);
	jack_client_close (client);
	exit (0);
}