def index(): ports = None try: ports = jack.get_ports() except (jack.NotConnectedError, jack.Error): try: jack.detach('studio-webapp') jack.attach('studio-webapp') ports = jack.get_ports() except (jack.NotConnectedError, jack.Error): return render_template('jack_device_error.html') inports = [] outports = [] connects = {} for port in ports: if (jack.get_port_flags(port) & jack.IsInput) > 0: inports.append(port) connects[port] = jack.get_connections(port) if (jack.get_port_flags(port) & jack.IsOutput) > 0: outports.append(port) try: otg_systemd_status = subprocess.check_output(['sudo', 'systemctl', 'is-active', 'studio-gaudio_in']) except subprocess.CalledProcessError, e: otg_systemd_status = 'failed'
def establish_connection(pcm, channel): myname = jack.get_client_name() capture_name = pcm + ":capture_" + channel port_name = "in_" + channel connection_name = myname + ":" + port_name print capture_name, port_name, connection_name print "Jack ports (before):", jack.get_ports() jack.register_port(port_name, jack.IsInput) jack.activate() print "Jack ports (after):", jack.get_ports() jack.connect(capture_name, connection_name) print jack.get_connections(connection_name)
def Jack(self): try: for i in xrange(10): selfPort = [port for port in jack.get_ports() if self.unique in port] if not selfPort: time.sleep(.01) else: break if not selfPort: raise jack.UsageError("Test port could not be registered", "Try increasing sleep time") allPorts = jack.get_ports() selfPort = [port for port in allPorts if self.unique in port][0] inPorts = [port for port in allPorts if 'playback' in port] for port in inPorts: jack.connect(selfPort, port) except Exception, e: self.statuses['Jack'] = e
def TestPyJack(self): CHANNELS=len(self.jaoutlist.curselection()) self.fs = float(jack.get_sample_rate()) print(self.jaoutlist.curselection()) for i in range(0,len(self.jaoutlist.curselection())): print(self.jaoutlist.get(self.jaoutlist.curselection()[i])) jack.activate() for i in range(0,len(self.jaoutlist.curselection())): jack.register_port('output_'+str(i), jack.IsOutput) jack.connect('measure:output_'+str(i), self.jaoutlist.get(self.jaoutlist.curselection()[i])) # Dummy Input jack.register_port('dummy_input', jack.IsInput) print(jack.get_ports()) N = jack.get_buffer_size() input = np.zeros((1,len(self.signal)),'f') output = np.array(np.tile(self.signal,(CHANNELS,1)),'f') x = 0 while x < output.shape[1] - N: try: jack.process(output[:,x:x+N], input[:,x:x+N]) x += N except jack.InputSyncError: pass except jack.OutputSyncError: pass for i in range(0,len(self.jaoutlist.curselection())): jack.unregister_port('output_'+str(i)) jack.unregister_port('dummy_input') jack.deactivate()
def arranca_resampler(card, rate, mode): """ mode puede ser: zita-a2j, zita-j2a, alsa_in, alsa_out """ resamplerIsRunning = False if "zita" in mode: # este es el verdadero arranque de zita: resamplerIsRunning = zitaJack(card, rate, mode, log=False) # ver la funcion zitaJack elif "alsa" in mode: resamplerIsRunning = alsaInOut(card, rate, mode) if resamplerIsRunning: # esperamos a que los puertos zita aparezcan en jack jack.attach('tmp') intentos = 8 encontrado = False while intentos: for port in jack.get_ports(): if bareCard(card) in port: encontrado = True if encontrado: print "(soundcards) Se ha reiniciado " + mode + " " + card + " " + rate break intentos -= 1 print "(soundcards) Esperando a " + mode + "." * (8 - intentos + 1) sleep(.25) if not intentos: print "(soundcards) (!) No está disponible el puerto " + bareCard( card) + " en jack" jack.detach() else: print "(soundcards) <!> No se ha podido reiniciar " + mode + " en " + card + " " + rate
def check_if_jack_subclient_running(self): self.attach_to_jack() # this is probably not the best spot for this... myname = jack.get_client_name() ports = jack.get_ports() res = [re.search(self.pcm, p) for p in ports] return any(res)
def get_jack_ports(self): self.jainplist.delete(0,tkinter.END) self.jaoutlist.delete(0,tkinter.END) #jack.attach('measure') for port in jack.get_ports(): if (jack.get_port_flags(port) & jack.IsOutput) > 0: self.jainplist.insert(tkinter.END, port) if (jack.get_port_flags(port) & jack.IsInput) > 0: self.jaoutlist.insert(tkinter.END, port)
def getDisplaysPorts(): puertos = jack.get_ports() displaysPorts = [] for display in displays: for puerto in puertos: if display in puerto: displaysPorts.append(puerto) return displaysPorts
def __init__(self, nscopes, subsamp_factor, length, zoom): self.scopes = range(nscopes) jack.attach("jscope") print(jack.get_ports()) for i in self.scopes: jack.register_port("in_%d" % (i), jack.IsInput) jack.activate() print jack.get_ports() #jack.connect(jack.get_ports()[-2], "jscope:in_1") # CONSTANTS self.N = jack.get_buffer_size() self.Sr = float(jack.get_sample_rate()) self.plotlength = length # plot length in seconds self.abscissa = -np.arange(self.Sr * self.plotlength) / self.Sr self.input_slice = np.zeros((nscopes, self.N), dtype='f') self.output_slice = self.input_slice.copy() self.fig = Figure() self.subsamp_factor = subsamp_factor self.ax = [] self.plot_data = [] self.l_plot_data = [] self.input_ring = [] self.output_ring = [] for i in self.scopes: self.ax.append(self.fig.add_subplot(nscopes, 1, i + 1)) self.ax[i].set_ylim(-zoom, zoom) self.plot_data.append([]) foo, = self.ax[i].plot([], self.plot_data[i]) self.l_plot_data.append(foo) self.input_ring.append(RingBuffer(self.abscissa.size)) self.output_ring.append(RingBuffer(self.abscissa.size)) self.ax[i].set_xlim(self.abscissa[0], self.abscissa[-1]) self.ax[i].grid() FigureCanvas.__init__(self, self.fig) self.fig.canvas.draw() self.timerEvent(None) self.timer = self.startTimer(0)
def __init__(self, nscopes, subsamp_factor, length, zoom): self.scopes = range(nscopes) jack.attach("jscope") print(jack.get_ports()) for i in self.scopes: jack.register_port("in_%d" %(i), jack.IsInput) jack.activate() print jack.get_ports() #jack.connect(jack.get_ports()[-2], "jscope:in_1") # CONSTANTS self.N = jack.get_buffer_size() self.Sr = float(jack.get_sample_rate()) self.plotlength = length # plot length in seconds self.abscissa = -np.arange(self.Sr*self.plotlength) / self.Sr self.input_slice = np.zeros((nscopes, self.N), dtype='f') self.output_slice = self.input_slice.copy() self.fig = Figure() self.subsamp_factor = subsamp_factor self.ax = [] self.plot_data = [] self.l_plot_data = [] self.input_ring = [] self.output_ring = [] for i in self.scopes: self.ax.append(self.fig.add_subplot(nscopes, 1, i+1)) self.ax[i].set_ylim(-zoom, zoom) self.plot_data.append([]) foo, = self.ax[i].plot([], self.plot_data[i]) self.l_plot_data.append(foo) self.input_ring.append(RingBuffer(self.abscissa.size)) self.output_ring.append(RingBuffer(self.abscissa.size)) self.ax[i].set_xlim(self.abscissa[0], self.abscissa[-1]) self.ax[i].grid() FigureCanvas.__init__(self, self.fig) self.fig.canvas.draw() self.timerEvent(None) self.timer = self.startTimer(0)
def open(self): self.client = jack.attach('PythonClient') myname = jack.get_client_name() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.register_port("out", jack.IsOutput) self.client.activate() print "Jack ports (before):", jack.get_ports() jack.connect("system:capture_1", myname+":in_1")
def track_playback_started(self, tl_track): print "Attaching to jack." jack.attach("default") print "Attached." print "Jack ports: %s", jack.get_ports() print "Track playback started. Time for some JACK magic." # Connect the specified JACK ports together. jack.connect("mopidy:out_jackaudiosink0_1","python:in_openob_tx_test-link_1") jack.connect("mopidy:out_jackaudiosink0_2","python:in_openob_tx_test-link_2")
def index(): try: ports = jack.get_ports() except jack.NotConnectedError: jack.attach('studio-webapp') ports = jack.get_ports() inports = [] outports = [] connects = {} for port in ports: if (jack.get_port_flags(port) & jack.IsInput) > 0: inports.append(port) connects[port] = jack.get_connections(port) if (jack.get_port_flags(port) & jack.IsOutput) > 0: outports.append(port) try: otg_systemd_status = subprocess.check_output( ['sudo', 'systemctl', 'is-active', 'studio-gaudio_in']) except subprocess.CalledProcessError, e: otg_systemd_status = 'failed'
def GetPlaybackPorts(self): """ Returns a list of playback ports of other programs. Use GetOutputs to get a list of this instance's playback ports. @retval : a list of playback port names as strings """ ports = jack.get_ports() result = [] prefix = self.__prefix + ":" for p in ports: if jack.get_port_flags(p) & jack.IsOutput: if not p.startswith(prefix): result.append(p) return result
def conecta (a, b, mode="connect"): """ conecta puertos de captura con puertos de playback """ # Lista de puertos A Aports = [x for x in jack.get_ports() if a in x] # y filtramos los de captura Aports = [x for x in Aports if jack.get_port_flags(x) % 2 == 0 ] # Lista de puertos B Bports = [x for x in jack.get_ports() if b in x] # y filtramos los de playback Bports = [x for x in Bports if jack.get_port_flags(x) % 2 == 1 ] # Recorremos A y lo vamos (des)conectando con B while Aports: try: p1 = Aports.pop(0) p2 = Bports.pop(0) #print p1, p2 if mode == 'disconnect': jack.disconnect(p1, p2) else: jack.connect(p1, p2) except: pass
def jackConexiones(nombrePuerto="", direccion="*"): """ direccion: > | < | * Devuelve una lista de tripletas: (puerto, conexion, puerto) """ ports = [] jack.attach("tmp") for puerto in [x for x in jack.get_ports() if nombrePuerto in x]: conexiones = jack.get_connections(puerto) for conexion in conexiones: flags = jack.get_port_flags(conexion) # Returns an integer which is the bitwise-or of all flags for a given port. # haciendo pruebas veamos algunos flags de puertos: # puertos escribibles (playback): 1 21 impares, ultimo bit a 1 # puertos leibles (capture) : 2 18 22 pares, ultimo bit a 0 if flags % 2: direc = ">" else: direc = "<" if direc == direccion or direccion == "*": ports.append((puerto, " --" + direc + "-- ", conexion)) jack.detach() return ports
# -*- coding: utf-8 -*- # Capture 3 seconds of stereo audio from alsa_pcm:capture_1/2; then play it back. # # Copyright 2003, Andrew W. Schmeder # This source code is released under the terms of the GNU Public License. # See LICENSE for the full text of these terms. import numpy import jack import time jack.attach("captest") myname = jack.get_client_name() print "Client:", myname print "Jack ports (before):", jack.get_ports() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.activate() print "Jack ports (after):", jack.get_ports() jack.connect("system:capture_1", myname + ":in_1") jack.connect("system:capture_2", myname + ":in_2") print jack.get_connections(myname + ":in_1") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate())
#!/usr/bin/python # Capture 3 seconds of stereo audio from alsa_pcm:capture_1/2; then play it back. # # Copyright 2003, Andrew W. Schmeder # This source code is released under the terms of the GNU Public License. # See LICENSE for the full text of these terms. import numpy import jack import time jack.attach("captest") myname = jack.get_client_name() print "Client:", myname print jack.get_ports() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.activate() print jack.get_ports() jack.connect("system:capture_1", myname+":in_1") jack.connect("system:capture_2", myname+":in_2") print jack.get_connections(myname+":in_1") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate())
#!/usr/bin/python # -*- coding: utf-8 -*- # Capture 3 seconds of stereo audio from alsa_pcm:capture_1/2; then play it back. # # Copyright 2003, Andrew W. Schmeder # This source code is released under the terms of the GNU Lesser Public License. # See LICENSE for the full text of these terms. import numpy import jack import time jack.attach("captest") print jack.get_ports() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.register_port("out_1", jack.IsOutput) jack.register_port("out_2", jack.IsOutput) jack.activate() print jack.get_ports() jack.connect("system:capture_1", "captest:in_1") jack.connect("system:capture_2", "captest:in_2") jack.connect("captest:out_1", "system:playback_1") jack.connect("captest:out_2", "system:playback_2") print jack.get_connections("captest:in_1")
for i in range(output_n): if channels == 2: jack.register_port('output {} L'.format(i+1), jack.IsOutput) jack.register_port('output {} R'.format(i+1), jack.IsOutput) else: jack.register_port('output {}'.format(i+1), jack.IsOutput) jack.activate() if args.input: if ',' in args.input: capture_ports = args.input.split(',') else: jack_capture_ports = [p for p in jack.get_ports() if jack.get_port_flags(p) & jack.IsOutput] try: request = re.compile(args.input) capture_ports = [s.string for i in jack_capture_ports for s in [re.match(request, i)] if s] except: print 'input ports not valid' i = 0 for p in capture_ports: try: print 'connect {} to {}'.format(p, input_ports[i]) jack.connect(p, input_ports[i]) i += 1 if i >= len(input_ports): i = 0 except Exception as err: print err
# -*- coding: utf-8 -*- # Capture 3 seconds of stereo audio from alsa_pcm:capture_1/2; then play it back. # # Copyright 2003, Andrew W. Schmeder # This source code is released under the terms of the GNU Public License. # See LICENSE for the full text of these terms. import numpy import jack import time jack.attach("captest") myname = jack.get_client_name() print "Client:", myname print "Jack ports (before):", jack.get_ports() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.activate() print "Jack ports (after):", jack.get_ports() jack.connect("system:capture_1", myname+":in_1") jack.connect("system:capture_2", myname+":in_2") print jack.get_connections(myname+":in_1") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate())
def print_ports(): print "Jack ports (before):", jack.get_ports()