def init(self): desc = get_hardware_descriptor() self.hw_actuators = desc.get('actuators', []) self.hw_actuators_uris = tuple(a['uri'] for a in self.hw_actuators) self.pages_nb = desc.get('pages_nb', 0) self.pages_cb = desc.get('pages_cb', 0) self.current_page = 0 # 'hmi_addressings' uses a structure like this: # "/hmi/knob1": {'addrs': [...], 'idx': 0} # so per actuator we get: # - 'addrs': list of addressings # - 'idx' : currently selected addressing (index) self.hmi_addressings = dict((uri, {'addrs': [], 'idx': -1}) for uri in self.hw_actuators_uris) self.cc_addressings = {} self.cc_metadata = {} self.midi_addressings = {} self.virtual_addressings = {kBpmURI: []} # Store all possible HMI hardcoded values self.hmi_hw2uri_map = {} self.hmi_uri2hw_map = {} i = 0 for actuator in self.hw_actuators: uri = actuator['uri'] hw_id = actuator['id'] self.hmi_hw2uri_map[hw_id] = uri self.hmi_uri2hw_map[uri] = hw_id i = i+1
def __init__(self, port, baud_rate, timeout, init_cb, reinit_cb): self.sp = None self.port = port self.baud_rate = baud_rate self.queue = [] self.queue_idle = True self.initialized = False self.need_flush = 0 # 0 means False, otherwise use it as counter self.flush_io = None self.last_write_time = 0 self.timeout = timeout # in seconds self.ioloop = ioloop.IOLoop.instance() self.reinit_cb = reinit_cb self.hw_desc = get_hardware_descriptor() hw_actuators = self.hw_desc.get('actuators', []) self.hw_ids = [actuator['id'] for actuator in hw_actuators] self.init(init_cb)
def control_add(self, data, hw_id, actuator_uri, callback): # instance_id = data['instance_id'] # port = data['port'] label = data['label'] var_type = data['hmitype'] unit = data['unit'] value = data['dividers'] if data.get('tempo') else data['value'] xmin = data['minimum'] xmax = data['maximum'] steps = data['steps'] options = data['options'] label = '"%s"' % label.replace('"', "")[:31].upper() unit = '"%s"' % unit.replace('"', '')[:7] if options: numOpts = len(options) ivalue = int(value) optionsData = [] if numOpts <= 5 or ivalue <= 2: startIndex = 0 elif ivalue + 2 >= numOpts: startIndex = numOpts - 5 else: startIndex = ivalue - 2 for i in range(startIndex, min(startIndex + 5, numOpts)): option = options[i] xdata = '"%s" %f' % (option[1].replace( '"', '')[:31].upper(), float(option[0])) optionsData.append(xdata) options = "%d %s" % (len(optionsData), " ".join(optionsData)) options = options.strip() else: options = "0" def control_add_callback(ok): if not ok: callback(False) return n_controllers = data['addrs_max'] index = data['addrs_idx'] self.control_set_index(hw_id, index, n_controllers, callback) cb = callback hmi_set_index = get_hardware_descriptor().get('hmi_set_index', 0) if not actuator_uri.startswith("/hmi/footswitch") and hmi_set_index: cb = control_add_callback self.send( 'a %d %s %d %s %f %f %f %d %s' % ( hw_id, label, var_type, unit, value, xmax, xmin, steps, options, ), cb, 'boolean')
def control_add(self, data, hw_id, actuator_uri, callback): # instance_id = data['instance_id'] # port = data['port'] label = data['label'] var_type = data['hmitype'] unit = data['unit'] value = data['value'] min = data['minimum'] max = data['maximum'] steps = data['steps'] options = data['options'] # hw_type = actuator[0] # hw_id = actuator[1] # actuator_type = actuator[2] # actuator_id = actuator[3] label = '"%s"' % label.upper().replace('"', "") unit = '"%s"' % unit.replace('"', '') optionsData = [] rmax = max if options: currentNum = 0 numBytesFree = 1024 - 128 for o in options: if currentNum > 50: if value >= currentNum: value = 0 rmax = currentNum break xdata = '"%s" %f' % (o[1].replace('"', '').upper(), float( o[0])) xdataLen = len(xdata) if numBytesFree - xdataLen - 2 < 0: print( "ERROR: Controller out of memory when sending options (stopped at %i)" % currentNum) if value >= currentNum: value = 0.0 rmax = currentNum break currentNum += 1 numBytesFree -= xdataLen + 1 optionsData.append(xdata) options = "%d %s" % (len(optionsData), " ".join(optionsData)) options = options.strip() def control_add_callback(ok): if not ok: callback(False) return n_controllers = data['addrs_max'] index = data['addrs_idx'] self.control_set_index(hw_id, index, n_controllers, callback) cb = callback hmi_set_index = get_hardware_descriptor().get('hmi_set_index', 0) if not actuator_uri.startswith("/hmi/footswitch") and hmi_set_index: cb = control_add_callback self.send('a %d %s %d %s %f %f %f %d %s' % ( hw_id, label, var_type, unit, value, rmax, min, steps, options, ), cb, datatype='boolean')