Exemple #1
0
def test_oscclient():
    osc = OSCThreadServer()
    sock = osc.listen()
    port = sock.getsockname()[1]
    acc = []

    def success(*values):
        acc.append(values[0])

    osc.bind(b'/success', success, sock)

    client = OSCClient('localhost', port)

    timeout = time() + 5
    while len(acc) < 50:
        if time() > timeout:
            raise OSError('timeout while waiting for  success message.')

        client.send_message(b'/success', [1])

    while len(acc) < 100:
        if time() > timeout:
            raise OSError('timeout while waiting for  success message.')

        client.send_bundle([(b'/success', [i]) for i in range(10)])
Exemple #2
0
def test_timetag():
    osc = OSCThreadServer(drop_late_bundles=True)
    osc.drop_late_bundles = True
    sock = osc.listen()
    port = sock.getsockname()[1]
    acc = []

    @osc.address(b'/success', sock)
    def success(*values):
        acc.append(True)

    @osc.address(b'/failure', sock)
    def failure(*values):
        acc.append(False)

    client = OSCClient('localhost', port)

    timeout = time() + 5
    while len(acc) < 50:
        if time() > timeout:
            raise OSError('timeout while waiting for success message.')

        client.send_message(b'/success', [1])

    while len(acc) < 100:
        if time() > timeout:
            raise OSError('timeout while waiting for success message.')

        client.send_bundle(
            [(b'/failure', [i]) for i in range(10)],
            timetag=time() - 1,
            safer=True,
        )

        client.send_bundle(
            [(b'/success', [i]) for i in range(10)],
            timetag=time() + .1,
            safer=True,
        )

    assert True in acc
    assert False not in acc
Exemple #3
0
class Interface:
    """
    Interface for QLab
    """
    def __init__(self):
        """
        Create a client connection to QLab
        """
        self.client = OSCClient('127.0.0.1', 53000, encoding='utf8')
        self.server = Listener('127.0.0.1', 53001)
        self.wpid = self.get_wpid()
        self.encoding = 'utf8'

    def get_wpid(self):
        """
        Get a Workspace ID from QLab
        :return: workspace ID from QLab
        """
        self.client.send_message(b'/workspaces', [])
        response = self.server.get_message()
        if response:
            return response.get('data')[0]['uniqueID']

    def bundi(self, messages):
        self.client.send_bundle(messages)

    def set_cue_prop(self, cue_no, name, value):
        """
        Set a cue parameters in QLab
        :param cue_no: cue number, also accept selected
        :param name: changeable parameter name eg.: name
        :param value: parameter value eg.: 120
        :return: return any response from QLab
        """
        self.client.send_message('/cue/{cue_no}/{name}'.format(**locals()),
                                 value)
        """response = self.server.get_message()
        if response:
            return response.get('data')
        """

    def newcue(self, mit='memo'):
        """
        Create new cue in QLab when no parameter default to memo
        :param mit: type of newly created cue
        in QLab 4: Supported strings include:
        audio, mic, video, camera, text, light,
        fade, network, midi, midi file,
        timecode, group, start, stop, pause,
        load, reset, devamp, goto, target, arm,
        disarm, wait, memo, script, list, cuelist,
        cue list, cart, cuecart, or cue cart.
        :return: nothing
        """
        wpid = self.wpid
        self.client.send_message('/workspace/{}/new'.format(wpid), [mit])

    def select_all_cues(self):
        """
        Try to select all cues in current workspace
        :return:
        """
        wpid = self.wpid
        self.client.send_message('/workspace/{}/select/[*]'.format(wpid), [])

    def renumber(self, start, step):
        """
        Try to renumber cues
        :param start: new starting number
        :param step: steps through unmbers
        :return: nothing
        """
        wpid = self.wpid
        self.select_all_cues()
        self.client.send_message('/workspace/{}/renumber'.format(wpid),
                                 [start, step])

    def getques(self):
        """
        Receive quelists information
        :return: a cuelista
        """
        wpid = self.wpid
        self.client.send_message("/workspace/{}/cueLists/shallow".format(wpid),
                                 '')
        response = self.server.get_message()
        if response:
            return response.get('data')