Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified src/pythonx32/OSC.py
100644 → 100755
Empty file.
Empty file modified src/pythonx32/__init__.py
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions src/pythonx32/dumpmessages.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python
"""

This software is licensed under the Modified BSD License:
Expand Down
51 changes: 36 additions & 15 deletions src/pythonx32/x32.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python
"""

This software is licensed under the Modified BSD License:
Expand Down Expand Up @@ -32,8 +33,8 @@
import time
import threading
import Queue
from collections import namedtuple
from pythonx32.x32parameters import get_settings
from collections import namedtuple, OrderedDict
from x32parameters import get_settings
import json
import sys
import math
Expand Down Expand Up @@ -61,7 +62,7 @@ class TimeoutError(StandardError):
pass

class BehringerX32(object):
def __init__(self, x32_address, server_port, verbose, timeout=10):
def __init__(self, x32_address, server_port, verbose, timeout=1):
self._verbose = verbose
self._timeout = timeout
self._server = OSC.OSCServer(("", server_port))
Expand All @@ -81,8 +82,18 @@ def get_value(self, path):
self._input_queue.get_nowait()
except Queue.Empty:
break
self._client.send(OSC.OSCMessage(path))
return self._input_queue.get(timeout=self._timeout).data
try:
self._client.send(OSC.OSCMessage(path))
return self._input_queue.get(timeout=self._timeout).data
except:
while True:
try:
self._input_queue.get_nowait()
except Queue.Empty:
break
self._client.send(OSC.OSCMessage(path))
return self._input_queue.get(timeout=self._timeout).data


def set_value(self, path, value, readback=True):
self._client.send(OSC.OSCMessage(path, value))
Expand All @@ -97,17 +108,27 @@ def set_value(self, path, value, readback=True):
if read_back_value == value:
break
if time.time() - start_time > self._timeout:
raise TimeoutError("Timeout while readback of path %s, value=%s, read_back_value=%s" % (path, value, read_back_value))
print("Timeout while readback of path %s, value=%s, read_back_value=%s" % (path, value, read_back_value))
break
time.sleep(0.0001)

def get_state(self):
state = {}
state = OrderedDict()
for index, path in enumerate(setting_paths):
if self._verbose and index % 100 == 0:
print "Reading parameter %d of %d from x32" % (index, len(setting_paths))
value = self.get_value(path)
assert len(value) == 1
state[path] = value[0]
if self._verbose:
print "Reading parameter %d of %d (%s) from x32" % (index, len(setting_paths), path)
try:
value = self.get_value(path)
if self._verbose:
print "value returned: %s" % value
if value:
assert len(value) == 1
state[path] = value[0]
if self._verbose:
print "adding state: %s : %s" % (path, value[0])
except:
print "caught error trying to retrieve key: %s" % path

return state

def set_state(self, state):
Expand All @@ -130,10 +151,10 @@ def set_state(self, state):
def save_state_to_file(self, outputfile, state):
my_dict = {"x32_state": state,
}
json.dump(my_dict, outputfile, sort_keys=True, indent=4)
json.dump(my_dict, outputfile, indent=4)

def read_state_from_file(self, inputfile):
my_dict = json.load(inputfile)
my_dict = OrderedDict(json.load(inputfile))
return my_dict["x32_state"]

usage = """This is a utility to load or save the settings of a Behringer X32 mixing desk. All document settings are loaded/stored, and some undocumented.
Expand All @@ -147,7 +168,7 @@ def read_state_from_file(self, inputfile):
import argparse

parser = argparse.ArgumentParser(description=usage)
parser.add_argument('--address', default="192.168.208.99",
parser.add_argument('--address', default="192.168.0.51",
help='name/ip-address of Behringer X32 mixing desk')
parser.add_argument('--filename', default = None, required=True,
help='Filename')
Expand Down
Loading