예제 #1
0
    def start_jack_client(self):
        self._waiting_jack_client_open = True

        # Sometimes JACK never registers the client
        # and never answers. This thread will allow to exit
        # if JACK didn't answer 5 seconds after register ask
        jack_waiter_thread = threading.Thread(
            target=self.check_jack_client_responding)
        jack_waiter_thread.start()

        #time.sleep(20)
        with suppress_stdout_stderr():
            self.jack_client = jacklib.client_open(
                "ray-patch_to_osc",
                jacklib.JackNoStartServer | jacklib.JackSessionID, None)

        self._waiting_jack_client_open = False
        jack_waiter_thread.join()

        if self.jack_client:
            self.jack_running = True
            self.set_registrations()
            self.get_all_ports_and_connections()
            self.osc_server.set_jack_client(self.jack_client)
            self.samplerate = jacklib.get_sample_rate(self.jack_client)
            self.buffer_size = jacklib.get_buffer_size(self.jack_client)
            self.osc_server.server_restarted()
        else:
            self.jack_running = False
예제 #2
0
    def connect(self, max_attempts=None):
        if max_attempts is None:
            max_attempts = self.connect_max_attempts

        tries = 0
        while True:
            log.debug("Attempting to connect to JACK server...")
            status = jacklib.jack_status_t(0x0)
            self.client = jacklib.client_open(self.client_name,
                                              jacklib.JackNoStartServer,
                                              status)
            tries += 1

            if status.value:
                err = get_jack_status_error_string(status)
                if status.value & jacklib.JackNameNotUnique:
                    log.debug(err)
                elif status.value & jacklib.JackServerStarted:
                    # Should not happen, since we use the JackNoStartServer option
                    log.warning("Unexpected JACK status: %s", err)
                else:
                    log.warning("JACK connection error (attempt %i): %s",
                                tries, err)

            if self.client:
                break

            if max_attempts and tries >= max_attempts:
                log.error(
                    "Maximum number (%i) of connection attempts reached. Aborting.",
                    max_attempts)
                raise RuntimeError(err)

            log.debug("Waiting %.2f seconds to connect again...",
                      self.connect_interval)
            sleep(self.connect_interval)

        name = jacklib.get_client_name(self.client)
        if name is not None:
            self.client_name = name.decode()
        else:
            raise RuntimeError("Could not get JACK client name.")

        jacklib.on_shutdown(self.client, self.shutdown_callback, None)
        log.debug(
            "Client connected, name: %s UUID: %s",
            self.client_name,
            jacklib.client_get_uuid(self.client),
        )
        jacklib.set_port_registration_callback(self.client,
                                               self.port_reg_callback, None)
        jacklib.set_port_rename_callback(self.client,
                                         self.port_rename_callback, None)
        jacklib.set_property_change_callback(self.client,
                                             self.property_callback, None)
        jacklib.activate(self.client)
예제 #3
0
def jack_client():
    status = jacklib.jack_status_t()
    client = jacklib.client_open("pyjacklib", jacklib.JackNoStartServer,
                                 status)

    if status.value:
        err = get_jack_status_error_string(status)

        if status.value & jacklib.JackNameNotUnique:
            print(f"Non-fatal JACK status: {err}", file=sys.stderr)
        elif status.value & jacklib.JackServerStarted:
            # Should not happen, since we use the JackNoStartServer option
            print(f"Unexpected JACK status: {err}", file=sys.stderr)
        else:
            raise OSError(f"Error creating JACK client: {err}")

    yield client

    jacklib.client_close(client)
예제 #4
0
    app = QCoreApplication(sys.argv)
    app.setApplicationName("SooperLooperNSM")
    app.setOrganizationName("SooperLooperNSM")

    timer = QTimer()
    timer.setInterval(200)
    timer.timeout.connect(lambda: None)
    timer.start()

    signaler = nsm_client.NSMSignaler()

    server = SlOSCThread('sooperlooper_nsm', signaler, daemon_address, False)

    if len(sys.argv) > 1 and sys.argv[1] == '--transport_workaround':
        jack_client = jacklib.client_open(
            "sooper_ray_wk", jacklib.JackNoStartServer | jacklib.JackSessionID,
            None)
    else:
        jack_client = None

    general_object = GeneralObject()

    server.start()
    server.announce('SooperLooper', ':optional-gui:switch:',
                    'sooperlooper_nsm')

    app.exec()

    server.stop()

    del server
예제 #5
0
    for i in range(len(sys.argv)):
        if i == 0: continue

        argv = sys.argv[i]

        if argv == "--zita":
            useZita = True
        elif argv.startswith("--channels="):
            chStr = argv.replace("--channels=", "")

            if chStr.isdigit():
                channels = int(chStr)

    # Init JACK client
    client = jacklib.client_open("cadence-aloop-daemon", jacklib.JackUseExactName, None)

    if not client:
        print("cadence-aloop-daemon is already running, delete \"/tmp/.cadence-aloop-daemon.x\" to close it")
        quit()

    if jacklib.JACK2:
        jacklib.set_client_registration_callback(client, client_registration_callback, None)

    jacklib.set_buffer_size_callback(client, buffer_size_callback, None)
    jacklib.set_sample_rate_callback(client, sample_rate_callback, None)
    jacklib.on_shutdown(client, shutdown_callback, None)
    jacklib.activate(client)

    # Quit when requested
    signal(SIGINT, signal_handler)
예제 #6
0
    file.close()

    NSMServer.saveReply()

    setDirtyClean()

if __name__ == '__main__':
    NSM_URL = os.getenv('NSM_URL')
    if not NSM_URL:
        sys.stderr.write('Could not register as NSM client.\n')
        sys.exit()

    daemon_address = ray.getLibloAddress(NSM_URL)

    jack_client = jacklib.client_open(
        "ray-patcher",
        jacklib.JackNoStartServer | jacklib.JackSessionID,
        None)

    if not jack_client:
        sys.stderr.write('Unable to make a jack client !\n')
        sys.exit()


    jacklib.set_port_registration_callback(jack_client,
                                           JackPortRegistrationCallback,
                                           None)
    jacklib.set_port_connect_callback(jack_client,
                                      JackPortConnectCallback,
                                      None)
    jacklib.set_port_rename_callback(jack_client,
                                     JackPortRenameCallback,
예제 #7
0
파일: VNA.py 프로젝트: docprofsky/pysdrvna
  def __init__(self,configd=None):
    """Create a VNA object"""

    if configd is None: configd = config.__dict__

    self.printlevel = configd['printlevel']
    self.fftn = configd['fftn']
    self.amp = configd['amp']
    self.warmuptime = configd['warmuptime']
    self.cooldowntime = configd['cooldowntime']
   
    self.docapture = threading.Event()
    self.docapture.set()

    self.xrun = threading.Event()
    self.xrun.clear()

    self.startframe = 0

    #self.jackclient = jacklib.client_open("pysdrvna", jacklib.JackNoStartServer | jacklib.JackSessionID, None)
    self.jackclient = jacklib.client_open("pysdrvna", jacklib.JackSessionID, None)
    
    try:
      self.jackclient.contents
    except:
      print("Problems with Jack")
      return
      #raise

    self.iI = jacklib.port_register(self.jackclient,"iI", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsInput, 0)
    self.iQ = jacklib.port_register(self.jackclient,"iQ", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsInput, 0)    

    self.oI = jacklib.port_register(self.jackclient,"oI", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsOutput, 0)
    self.oQ = jacklib.port_register(self.jackclient,"oQ", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsOutput, 0)
   
    jacklib.set_process_callback(self.jackclient, self.JackProcess, 0)
    jacklib.set_xrun_callback(self.jackclient, self.JackXrun, 0)

    jacklib.activate(self.jackclient)
   
    jacklib.connect(self.jackclient,"pysdrvna:oQ", configd['outQ'])
    jacklib.connect(self.jackclient,"pysdrvna:oI", configd['outI'])    
    
    jacklib.connect(self.jackclient,configd['inQ'],"pysdrvna:iQ")
    jacklib.connect(self.jackclient,configd['inI'],"pysdrvna:iI") 
    
    self.Sr = float(jacklib.get_sample_rate(self.jackclient))
    self.dt = 1.0/self.Sr
      
    ## Align frequency to nearest bin
    self.fftbin = int(round((configd['freq']/self.Sr)*self.fftn))      
    self.freq = (float(self.fftbin)/self.fftn) * self.Sr
    
    ## Windowing function
    #self.fftwindow = np.blackman(self.fftn)
    self.fftwindow = np.hanning(self.fftn)
    #self.fftwindow = np.kaiser(self.fftn,14)
    #self.fftwindow = np.hamming(self.fftn)
    #self.fftwindow = np.bartlett(self.fftn)
    #self.fftwindow = None
      
    ## Latency settings
    jlr = jacklib.jack_latency_range_t()
    jacklib.port_get_latency_range(self.oI,jacklib.JackPlaybackLatency,jlr)
    self.minrtframes = jlr.min
    jacklib.port_get_latency_range(self.iI,jacklib.JackCaptureLatency,jlr)
    self.minrtframes += jlr.min
 
    # The above code does not always work
    # Reasonable estimate is 3 times the buffer size
    ## Compute initial array length
    self.buffersz = int(jacklib.get_buffer_size(self.jackclient))
    if self.minrtframes < (3*self.buffersz):
        self.minrtframes = 3 * self.buffersz


    ## rtframes is the round trip audio latency, or when the received audio signal will start    
    self.rtframes = configd['rtframes'] if configd['rtframes'] else self.minrtframes
    ## delta from rtframes to phase shift sync in frames
    self.rtframes2sync = configd['rtframes2sync']
    ## delta from phase shift sync to fft start in frames
    self.sync2fft = configd['sync2fft']
    ## delta from end of fft to end of audio
    self.fft2end = configd['fft2end']


    if configd['rtframes'] is None:
        ## Loose fit if estimating based on minrtframes
        buffers, remainder = divmod((2*self.rtframes) + self.rtframes2sync + self.sync2fft + self.fftn + self.fft2end,self.buffersz)
    else:
        ## Tight fit if rtframes is defined
        buffers, remainder = divmod(self.rtframes + self.rtframes2sync + self.sync2fft + self.fftn + self.fft2end,self.buffersz)
  
    if remainder > 0: buffers = buffers + 1
    self.synci = self.rtframes
    self.InitJackArrays(self.freq,buffers*self.buffersz)
    
    self.fftia = pyfftw.n_byte_align_empty(self.fftn, 16, 'complex128')
    self.fftoa = pyfftw.n_byte_align_empty(self.fftn, 16, 'complex128')
    ## Create FFT Plan
    self.fft = pyfftw.FFTW(self.fftia,self.fftoa)

    self.OpenSoftRock()
    self.Info()
    for i in range(len(sys.argv)):
        if i == 0: continue

        argv = sys.argv[i]

        if argv == "--zita":
            useZita = True
        elif argv.startswith("--channels="):
            chStr = argv.replace("--channels=", "")

            if chStr.isdigit():
                channels = int(chStr)

    # Init JACK client
    client = jacklib.client_open("cadence-aloop-daemon",
                                 jacklib.JackUseExactName, None)

    if not client:
        print(
            "cadence-aloop-daemon is already running, delete \"/tmp/.cadence-aloop-daemon.x\" to close it"
        )
        quit()

    if jacklib.JACK2:
        jacklib.set_client_registration_callback(client,
                                                 client_registration_callback,
                                                 None)

    jacklib.set_buffer_size_callback(client, buffer_size_callback, None)
    jacklib.set_sample_rate_callback(client, sample_rate_callback, None)
    jacklib.on_shutdown(client, shutdown_callback, None)
예제 #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

import jacklib
from jacklib.helpers import get_jack_status_error_string

if len(sys.argv) == 3:
    portname = sys.argv[1]
    pretty_name = sys.argv[2]
else:
    sys.exit("Usage: %s <port name> <pretty-name>" % sys.argv[0])

status = jacklib.jack_status_t()
client = jacklib.client_open("set-port-pretty-name", jacklib.JackNoStartServer,
                             status)
err = get_jack_status_error_string(status)

if status.value:
    if status.value & jacklib.JackNameNotUnique:
        print("Non-fatal JACK status: %s" % err, file=sys.stderr)
    elif status.value & jacklib.JackServerStarted:
        # Should not happen, since we use the JackNoStartServer option
        print("Unexpected JACK status: %s" % err, file=sys.stderr)
    else:
        sys.exit("Error connecting to JACK server: %s" % err)

res = jacklib.set_port_pretty_name(client, portname, pretty_name)
if res != -1:
    print("Pretty name for port '%s' is now '%s'." % (portname, pretty_name))
예제 #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

from ctypes import pointer
import jacklib
from jacklib.helpers import get_jack_status_error_string

status = jacklib.jack_status_t()
client = jacklib.client_open("transport-query", jacklib.JackNoStartServer,
                             status)
err = get_jack_status_error_string(status)

if status.value:
    if status.value & jacklib.JackNameNotUnique:
        print("Non-fatal JACK status: %s" % err, file=sys.stderr)
    elif status.value & jacklib.JackServerStarted:
        # Should not happen, since we use the JackNoStartServer option
        print("Unexpected JACK status: %s" % err, file=sys.stderr)
    else:
        sys.exit("Error connecting to JACK server: %s" % err)

position = jacklib.jack_position_t()
transport_state = jacklib.transport_query(client, pointer(position))

for name, type_ in sorted(position._fields_):
    value = getattr(position, name)
    if name == 'padding':
        value = list(value)
    print("{}: {}".format(name, value), file=sys.stderr)
예제 #11
0
파일: jackfloppy.py 프로젝트: amstan/floppy
                    elif len(data) == 3:
                        jack_midi_in_data.put_nowait((data[0], data[1], data[2]))

                    if jack_midi_in_data.full():
                        break

            del event
    except Exception as e:
        print e
    return 0


if __name__ == "__main__":
    # Start jack
    jack_client = jacklib.client_open("Floppy Drive", jacklib.NullOption, 0)
    jack_midi_in_port = jacklib.port_register(jack_client, "midi", jacklib.DEFAULT_MIDI_TYPE, jacklib.PortIsInput, 0)
    jacklib.set_process_callback(jack_client, jack_process_callback, 0)

    jacklib.activate(jack_client)

    floppy = Floppy(port=sys.argv[1], reset=True)

    noteplaying = None
    while 1:
        try:
            mode, noteid, velo = jack_midi_in_data.get(True, 1)
            note = Note(noteid)

            if (mode & MIDI_MASK) == MIDI_NOTEON:
                floppy.play(note)
예제 #12
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

import jacklib
from jacklib.helpers import get_jack_status_error_string

status = jacklib.jack_status_t()
client = jacklib.client_open("list-all-properties", jacklib.JackNoStartServer,
                             status)
err = get_jack_status_error_string(status)

if status.value:
    if status.value & jacklib.JackNameNotUnique:
        print("Non-fatal JACK status: %s" % err, file=sys.stderr)
    elif status.value & jacklib.JackServerStarted:
        # Should not happen, since we use the JackNoStartServer option
        print("Unexpected JACK status: %s" % err, file=sys.stderr)
    else:
        sys.exit("Error connecting to JACK server: %s" % err)

properties = jacklib.get_all_properties()

for subject, props in properties.items():
    print("Subject %s:" % subject)

    for prop in props:
        print("* {p.key}: {p.value} (type: {p.type})".format(p=prop))

    print('')