| @@ -1,5 +1,6 @@ | |||
| from ctypes import * | |||
| import string | |||
| class jack_client_t(Structure): | |||
| pass | |||
| @@ -62,6 +63,13 @@ get_cookie_by_uuid = libjack.jack_get_cookie_by_uuid | |||
| get_cookie_by_uuid.argtypes = [ client_p, c_char_p, c_char_p ] | |||
| get_cookie_by_uuid.restype = c_char_p | |||
| connect = libjack.jack_connect | |||
| connect.argtypes = [ client_p, c_char_p, c_char_p ] | |||
| connect.restype = c_int | |||
| disconnect = libjack.jack_disconnect | |||
| disconnect.argtypes = [ client_p, c_char_p, c_char_p ] | |||
| disconnect.restype = c_int | |||
| PortRegistrationCallback = CFUNCTYPE( None, c_uint, c_int, c_void_p ) | |||
| @@ -104,6 +112,9 @@ class Port( object ): | |||
| def get_connections( self ): | |||
| conns = port_get_all_connections( self.client, self.port_p ) | |||
| if not conns: | |||
| return [] | |||
| i=0 | |||
| retval = [] | |||
| while conns[i]: | |||
| @@ -114,6 +125,23 @@ class Port( object ): | |||
| return retval | |||
| def connect( self, other ): | |||
| connect( self.client, self.name, other ) | |||
| def disconnect( self, other ): | |||
| disconnect( self.client, self.name, other ) | |||
| def is_input( self ): | |||
| return (port_flags( self.port_p ) & JackPortIsInput) != 0 | |||
| def is_output( self ): | |||
| return (port_flags( self.port_p ) & JackPortIsOutput) != 0 | |||
| def is_audio( self ): | |||
| return (port_type( self.port_p ) == JACK_DEFAULT_AUDIO_TYPE) | |||
| def is_midi( self ): | |||
| return (port_type( self.port_p ) == JACK_DEFAULT_MIDI_TYPE) | |||
| class Client( object ): | |||
| @@ -121,9 +149,30 @@ class Client( object ): | |||
| self.client = client | |||
| self.name = name | |||
| self.ports = [] | |||
| self.commandline = None | |||
| def get_commandline( self ): | |||
| if self.commandline: | |||
| return self.commandline | |||
| else: | |||
| return "" | |||
| def add_port( self, portname ): | |||
| self.ports.append( Port( self.client, portname ) ) | |||
| def rename( self, newname ): | |||
| rename_client( self.client, self.name, self.newname ) | |||
| self.ports = [] | |||
| ports = get_ports( self.client, self.newname+":.*", None, 0 ) | |||
| i=0 | |||
| while(ports[i]): | |||
| self.add_port( ports[i] ) | |||
| i+=1 | |||
| jack_free( ports ) | |||
| class JackGraph( object ): | |||
| def __init__( self, client, ports, uuids=[] ): | |||
| @@ -153,6 +202,24 @@ class JackGraph( object ): | |||
| def get_client_by_uuid( self, uuid ): | |||
| return self.clients[self.uuid_to_name[uuid]] | |||
| def check_client_name( self, client ): | |||
| if not client.name in self.clients.keys(): | |||
| return | |||
| cname_split = client.name.split('-') | |||
| if len(cname_split) == 0: | |||
| cname_prefix = cname_split[0] | |||
| else: | |||
| cname_prefix = string.join( name_split[:-1], '-' ) | |||
| num = 1 | |||
| while ("%s-%d"%(cname_prefix,num)) in self.clients.keys(): | |||
| num+=1 | |||
| # XXX: this might still fail due to race. | |||
| # also needs to lock | |||
| client.rename( "%s-%d"%(cname_prefix,num ) ) | |||
| class JackClient(object): | |||
| @@ -160,6 +227,7 @@ class JackClient(object): | |||
| self.client = client_new( name ) | |||
| self.reg_cb = PortRegistrationCallback( self.port_registration_cb ) | |||
| set_port_registration_callback( self.client, self.reg_cb, None ) | |||
| self.port_queue = Queue() | |||
| activate( self.client ) | |||
| @@ -177,10 +245,8 @@ class JackClient(object): | |||
| raise Exception | |||
| def port_registration_cb( self, port_id, reg, arg ): | |||
| port_t = port_by_id( self.client, port_id ) | |||
| print port_name( port_t ) | |||
| print port_type( port_t ) | |||
| print reg | |||
| port_p = port_by_id( self.client, port_id ) | |||
| self.port_queue.put( (port_p,reg) ) | |||