Browse Source

carla-control: handle osc messages on the main thread

tags/1.9.7
falkTX 8 years ago
parent
commit
bdf1439f22
1 changed files with 46 additions and 6 deletions
  1. +46
    -6
      source/carla_control.py

+ 46
- 6
source/carla_control.py View File

@@ -24,7 +24,7 @@ from carla_host import *
# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# Imports (liblo) # Imports (liblo)


from liblo import make_method, Address, ServerError, ServerThread
from liblo import make_method, Address, ServerError, Server
from liblo import send as lo_send from liblo import send as lo_send
from liblo import TCP as LO_TCP from liblo import TCP as LO_TCP
from liblo import UDP as LO_UDP from liblo import UDP as LO_UDP
@@ -137,18 +137,25 @@ class CarlaHostOSC(CarlaHostQtPlugin):
# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# OSC Control server # OSC Control server


class CarlaControlServerThread(ServerThread):
class CarlaControlServer(Server):
def __init__(self, host, mode): def __init__(self, host, mode):
ServerThread.__init__(self, 8998 + int(random()*9000), mode)
Server.__init__(self, 8998 + int(random()*9000), mode)


self.host = host self.host = host


def idle(self):
self.fReceivedMsgs = False

while self.recv(0) and self.fReceivedMsgs:
pass

def getFullURL(self): def getFullURL(self):
return "%scarla-control" % self.get_url() return "%scarla-control" % self.get_url()


@make_method('/carla-control/add_plugin_start', 'is') # FIXME skip name @make_method('/carla-control/add_plugin_start', 'is') # FIXME skip name
def add_plugin_start_callback(self, path, args): def add_plugin_start_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, pluginName = args pluginId, pluginName = args
self.host._add(pluginId) self.host._add(pluginId)
self.host._set_pluginInfoUpdate(pluginId, {'name': pluginName}) self.host._set_pluginInfoUpdate(pluginId, {'name': pluginName})
@@ -156,18 +163,21 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/add_plugin_end', 'i') # FIXME skip name @make_method('/carla-control/add_plugin_end', 'i') # FIXME skip name
def add_plugin_end_callback(self, path, args): def add_plugin_end_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, = args pluginId, = args
self.host.PluginAddedCallback.emit(pluginId, "") #self.fPluginsInfo[pluginId].pluginInfo['name']) self.host.PluginAddedCallback.emit(pluginId, "") #self.fPluginsInfo[pluginId].pluginInfo['name'])


@make_method('/carla-control/remove_plugin', 'i') @make_method('/carla-control/remove_plugin', 'i')
def remove_plugin_callback(self, path, args): def remove_plugin_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, = args pluginId, = args
self.host.PluginRemovedCallback.emit(pluginId) self.host.PluginRemovedCallback.emit(pluginId)


@make_method('/carla-control/set_plugin_info1', 'iiiih') @make_method('/carla-control/set_plugin_info1', 'iiiih')
def set_plugin_info1_callback(self, path, args): def set_plugin_info1_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, type_, category, hints, uniqueId = args # , optsAvail, optsEnabled pluginId, type_, category, hints, uniqueId = args # , optsAvail, optsEnabled
optsAvail = optsEnabled = 0x0 # FIXME optsAvail = optsEnabled = 0x0 # FIXME


@@ -187,6 +197,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_plugin_info2', 'issss') @make_method('/carla-control/set_plugin_info2', 'issss')
def set_plugin_info2_callback(self, path, args): def set_plugin_info2_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, realName, label, maker, copyright = args # , filename, name, iconName pluginId, realName, label, maker, copyright = args # , filename, name, iconName
filename = name = iconName = "" # FIXME filename = name = iconName = "" # FIXME


@@ -205,18 +216,21 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_audio_count', 'iii') @make_method('/carla-control/set_audio_count', 'iii')
def set_audio_count_callback(self, path, args): def set_audio_count_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, ins, outs = args pluginId, ins, outs = args
self.host._set_audioCountInfo(pluginId, {'ins': ins, 'outs': outs}) self.host._set_audioCountInfo(pluginId, {'ins': ins, 'outs': outs})


@make_method('/carla-control/set_midi_count', 'iii') @make_method('/carla-control/set_midi_count', 'iii')
def set_midi_count_callback(self, path, args): def set_midi_count_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, ins, outs = args pluginId, ins, outs = args
self.host._set_midiCountInfo(pluginId, {'ins': ins, 'outs': outs}) self.host._set_midiCountInfo(pluginId, {'ins': ins, 'outs': outs})


@make_method('/carla-control/set_parameter_count', 'iii') # FIXME @make_method('/carla-control/set_parameter_count', 'iii') # FIXME
def set_parameter_count_callback(self, path, args): def set_parameter_count_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, ins, outs = args # , count pluginId, ins, outs = args # , count
count = ins + outs count = ins + outs
self.host._set_parameterCountInfo(pluginId, count, {'ins': ins, 'outs': outs}) self.host._set_parameterCountInfo(pluginId, count, {'ins': ins, 'outs': outs})
@@ -224,18 +238,21 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_program_count', 'ii') @make_method('/carla-control/set_program_count', 'ii')
def set_program_count_callback(self, path, args): def set_program_count_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, count = args pluginId, count = args
self.host._set_programCount(pluginId, count) self.host._set_programCount(pluginId, count)


@make_method('/carla-control/set_midi_program_count', 'ii') @make_method('/carla-control/set_midi_program_count', 'ii')
def set_midi_program_count_callback(self, path, args): def set_midi_program_count_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, count = args pluginId, count = args
self.host._set_midiProgramCount(pluginId, count) self.host._set_midiProgramCount(pluginId, count)


@make_method('/carla-control/set_parameter_data', 'iiiiss') @make_method('/carla-control/set_parameter_data', 'iiiiss')
def set_parameter_data_callback(self, path, args): def set_parameter_data_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, paramId, type_, hints, name, unit = args pluginId, paramId, type_, hints, name, unit = args


hints &= ~(PARAMETER_USES_SCALEPOINTS | PARAMETER_USES_CUSTOM_TEXT) hints &= ~(PARAMETER_USES_SCALEPOINTS | PARAMETER_USES_CUSTOM_TEXT)
@@ -261,6 +278,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_parameter_ranges1', 'iifff') @make_method('/carla-control/set_parameter_ranges1', 'iifff')
def set_parameter_ranges1_callback(self, path, args): def set_parameter_ranges1_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, paramId, def_, min_, max_ = args pluginId, paramId, def_, min_, max_ = args


paramRanges = { paramRanges = {
@@ -274,6 +292,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_parameter_ranges2', 'iifff') @make_method('/carla-control/set_parameter_ranges2', 'iifff')
def set_parameter_ranges2_callback(self, path, args): def set_parameter_ranges2_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, paramId, step, stepSmall, stepLarge = args pluginId, paramId, step, stepSmall, stepLarge = args


paramRanges = { paramRanges = {
@@ -287,6 +306,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_parameter_midi_cc', 'iii') @make_method('/carla-control/set_parameter_midi_cc', 'iii')
def set_parameter_midi_cc_callback(self, path, args): def set_parameter_midi_cc_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, paramId, cc = args pluginId, paramId, cc = args
self.host._set_parameterMidiCC(pluginId, paramId, cc) self.host._set_parameterMidiCC(pluginId, paramId, cc)
self.host.ParameterMidiCcChangedCallback.emit(pluginId, paramId, cc) self.host.ParameterMidiCcChangedCallback.emit(pluginId, paramId, cc)
@@ -294,6 +314,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_parameter_midi_channel', 'iii') @make_method('/carla-control/set_parameter_midi_channel', 'iii')
def set_parameter_midi_channel_callback(self, path, args): def set_parameter_midi_channel_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, paramId, channel = args pluginId, paramId, channel = args
self.host._set_parameterMidiChannel(pluginId, paramId, channel) self.host._set_parameterMidiChannel(pluginId, paramId, channel)
self.host.ParameterMidiChannelChangedCallback.emit(pluginId, paramId, channel) self.host.ParameterMidiChannelChangedCallback.emit(pluginId, paramId, channel)
@@ -312,6 +333,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_default_value', 'iif') @make_method('/carla-control/set_default_value', 'iif')
def set_default_value_callback(self, path, args): def set_default_value_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, paramId, paramValue = args pluginId, paramId, paramValue = args
self.host._set_parameterDefault(pluginId, paramId, paramValue) self.host._set_parameterDefault(pluginId, paramId, paramValue)
self.host.ParameterDefaultChangedCallback.emit(pluginId, paramId, paramValue) self.host.ParameterDefaultChangedCallback.emit(pluginId, paramId, paramValue)
@@ -319,6 +341,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_current_program', 'ii') @make_method('/carla-control/set_current_program', 'ii')
def set_current_program_callback(self, path, args): def set_current_program_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, current = args pluginId, current = args
self.host._set_currentProgram(pluginId, current) self.host._set_currentProgram(pluginId, current)
self.host.ProgramChangedCallback.emit(current) self.host.ProgramChangedCallback.emit(current)
@@ -326,6 +349,7 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_current_midi_program', 'ii') @make_method('/carla-control/set_current_midi_program', 'ii')
def set_current_midi_program_callback(self, path, args): def set_current_midi_program_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, current = args pluginId, current = args
self.host._set_currentMidiProgram(pluginId, current) self.host._set_currentMidiProgram(pluginId, current)
#self.host.MidiProgramChangedCallback.emit() # FIXME #self.host.MidiProgramChangedCallback.emit() # FIXME
@@ -333,40 +357,47 @@ class CarlaControlServerThread(ServerThread):
@make_method('/carla-control/set_program_name', 'iis') @make_method('/carla-control/set_program_name', 'iis')
def set_program_name_callback(self, path, args): def set_program_name_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, progId, progName = args pluginId, progId, progName = args
self.host._set_programName(pluginId, progId, progName) self.host._set_programName(pluginId, progId, progName)


@make_method('/carla-control/set_midi_program_data', 'iiiis') @make_method('/carla-control/set_midi_program_data', 'iiiis')
def set_midi_program_data_callback(self, path, args): def set_midi_program_data_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, midiProgId, bank, program, name = args pluginId, midiProgId, bank, program, name = args
self.host._set_midiProgramData(pluginId, midiProgId, {'bank': bank, 'program': program, 'name': name}) self.host._set_midiProgramData(pluginId, midiProgId, {'bank': bank, 'program': program, 'name': name})


@make_method('/carla-control/note_on', 'iiii') @make_method('/carla-control/note_on', 'iiii')
def set_note_on_callback(self, path, args): def set_note_on_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, channel, note, velocity = args pluginId, channel, note, velocity = args
self.host.NoteOnCallback.emit(pluginId, channel, note, velocity) self.host.NoteOnCallback.emit(pluginId, channel, note, velocity)


@make_method('/carla-control/note_off', 'iii') @make_method('/carla-control/note_off', 'iii')
def set_note_off_callback(self, path, args): def set_note_off_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
pluginId, channel, note = args pluginId, channel, note = args
self.host.NoteOffCallback.emit(pluginId, channel, note) self.host.NoteOffCallback.emit(pluginId, channel, note)


@make_method('/carla-control/set_peaks', 'iffff') @make_method('/carla-control/set_peaks', 'iffff')
def set_peaks_callback(self, path, args): def set_peaks_callback(self, path, args):
self.fReceivedMsgs = True
pluginId, in1, in2, out1, out2 = args pluginId, in1, in2, out1, out2 = args
self.host._set_peaks(pluginId, in1, in2, out1, out2) self.host._set_peaks(pluginId, in1, in2, out1, out2)


@make_method('/carla-control/exit', '') @make_method('/carla-control/exit', '')
def set_exit_callback(self, path, args): def set_exit_callback(self, path, args):
print(path, args) print(path, args)
self.fReceivedMsgs = True
self.host.QuitCallback.emit() self.host.QuitCallback.emit()


@make_method(None, None) @make_method(None, None)
def fallback(self, path, args): def fallback(self, path, args):
print("ControlServer::fallback(\"%s\") - unknown message, args =" % path, args) print("ControlServer::fallback(\"%s\") - unknown message, args =" % path, args)
self.fReceivedMsgs = True


# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# Main Window # Main Window
@@ -384,6 +415,7 @@ class HostWindowOSC(HostWindow):
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
# Internal stuff # Internal stuff


self.fIdleTimer = 0
self.fOscAddress = oscAddr self.fOscAddress = oscAddr
self.fOscServer = None self.fOscServer = None


@@ -415,12 +447,12 @@ class HostWindowOSC(HostWindow):
print("Connecting to \"%s\" as '%s'..." % (self.fOscAddress, lo_target_name)) print("Connecting to \"%s\" as '%s'..." % (self.fOscAddress, lo_target_name))


try: try:
self.fOscServer = CarlaControlServerThread(self.host, LO_UDP if self.fOscAddress.startswith("osc.udp") else LO_TCP)
self.fOscServer = CarlaControlServer(self.host, LO_UDP if self.fOscAddress.startswith("osc.udp") else LO_TCP)
except: # ServerError as err: except: # ServerError as err:
QMessageBox.critical(self, self.tr("Error"), self.tr("Failed to connect, operation failed.")) QMessageBox.critical(self, self.tr("Error"), self.tr("Failed to connect, operation failed."))
return return


self.fOscServer.start()
self.fIdleTimer = self.startTimer(20)
lo_send(lo_target, "/register", self.fOscServer.getFullURL()) lo_send(lo_target, "/register", self.fOscServer.getFullURL())


self.startTimers() self.startTimers()
@@ -435,8 +467,11 @@ class HostWindowOSC(HostWindow):
if lo_target is not None: if lo_target is not None:
lo_send(lo_target, "/unregister") lo_send(lo_target, "/unregister")


self.killTimer(self.fIdleTimer)
self.fIdleTimer = 0

if self.fOscServer is not None: if self.fOscServer is not None:
self.fOscServer.stop()
del self.fOscServer
self.fOscServer = None self.fOscServer = None


self.removeAllPlugins() self.removeAllPlugins()
@@ -483,6 +518,11 @@ class HostWindowOSC(HostWindow):
def slot_handleQuitCallback(self): def slot_handleQuitCallback(self):
self.disconnectOsc() self.disconnectOsc()


def timerEvent(self, event):
if event.timerId() == self.fIdleTimer:
self.fOscServer.idle()
HostWindow.timerEvent(self, event)

def closeEvent(self, event): def closeEvent(self, event):
global lo_target global lo_target




Loading…
Cancel
Save