Example #1
0
    def connectOsc(self, addr=None):
        global lo_target, lo_target_name

        if addr is not None:
            self.fOscAddress = addr

        lo_target = Address(self.fOscAddress)
        lo_target_name = self.fOscAddress.rsplit("/", 1)[-1]
        print("Connecting to \"%s\" as '%s'..." %
              (self.fOscAddress, lo_target_name))

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

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

        self.startTimers()
        self.ui.act_file_refresh.setEnabled(True)
Example #2
0
    def connectToAddr(self, addr):
        global lo_target, lo_targetName

        self.lo_address = addr
        lo_target = Address(self.lo_address)
        lo_targetName = self.lo_address.rsplit("/", 1)[-1]
        print("Connecting to \"%s\" as '%s'..." %
              (self.lo_address, lo_targetName))

        try:
            self.lo_server = ControlServer(
                self,
                LO_UDP if self.lo_address.startswith("osc.udp") else LO_TCP)
        except:  # ServerError, err:
            print("Connecting error!")
            #print str(err)
            QMessageBox.critical(
                self, self.tr("Error"),
                self.tr("Failed to connect, operation failed."))
            return

        if self.lo_server:
            self.lo_server.start()
            self.ui.act_file_refresh.setEnabled(True)
            lo_send(lo_target, "/register", self.lo_server.getFullURL())

        self.fIdleTimerFast = self.startTimer(60)
        self.fIdleTimerSlow = self.startTimer(60 * 2)
Example #3
0
    def unregister(self):
        if self.host.lo_server_tcp is not None:
            if self.host.lo_target_tcp is not None:
                try:
                    lo_send(self.host.lo_target_tcp, "/unregister",
                            self.host.lo_server_tcp.getFullURL())
                except:
                    pass
                self.host.lo_target_tcp = None

            while self.host.lo_server_tcp.recv(0):
                pass
            #self.host.lo_server_tcp.free()
            self.host.lo_server_tcp = None

        if self.host.lo_server_udp is not None:
            if self.host.lo_target_udp is not None:
                try:
                    lo_send(self.host.lo_target_udp, "/unregister",
                            self.host.lo_server_udp.getFullURL())
                except:
                    pass
                self.host.lo_target_udp = None

            while self.host.lo_server_udp.recv(0):
                pass
            #self.host.lo_server_udp.free()
            self.host.lo_server_udp = None

        self.host.lo_target_tcp_name = ""
        self.host.lo_target_udp_name = ""
Example #4
0
    def closeEvent(self, event):
        self.saveSettings()

        global lo_target
        if lo_target and self.lo_server:
            lo_send(lo_target, "/unregister")

        QMainWindow.closeEvent(self, event)
Example #5
0
 def send_midi_note(self, pluginId, channel, note, velocity):
     global to_target, lo_targetName
     if velocity:
         lo_path = "/%s/%i/note_on" % (lo_targetName, pluginId)
         lo_send(lo_target, lo_path, channel, note, velocity)
     else:
         lo_path = "/%s/%i/note_off" % (lo_targetName, pluginId)
         lo_send(lo_target, lo_path, channel, note)
Example #6
0
    def closeEvent(self, event):
        self.saveSettings()

        global lo_target
        if lo_target and self.lo_server:
            lo_send(lo_target, "/unregister")

        QMainWindow.closeEvent(self, event)
Example #7
0
 def send_midi_note(self, pluginId, channel, note, velocity):
     global to_target, lo_targetName
     if velocity:
         lo_path = "/%s/%i/note_on" % (lo_targetName, pluginId)
         lo_send(lo_target, lo_path, channel, note, velocity)
     else:
         lo_path = "/%s/%i/note_off" % (lo_targetName, pluginId)
         lo_send(lo_target, lo_path, channel, note)
Example #8
0
    def closeEvent(self, event):
        global lo_target

        self.killTimers()

        if lo_target is not None and self.fOscServer is not None:
            lo_send(lo_target, "/unregister")

        HostWindow.closeEvent(self, event)
Example #9
0
    def closeEvent(self, event):
        global lo_target

        self.killTimers()

        if lo_target is not None and self.fOscServer is not None:
            lo_send(lo_target, "/unregister")

        HostWindow.closeEvent(self, event)
Example #10
0
    def slot_fileRefresh(self):
        global lo_target

        if lo_target is None or self.fOscServer is None:
            return

        self.killTimers()
        lo_send(lo_target, "/unregister")
        self.removeAllPlugins()
        lo_send(lo_target, "/register", self.fOscServer.getFullURL())
        self.startTimers()
Example #11
0
    def slot_fileRefresh(self):
        global lo_target

        if lo_target is None or self.fOscServer is None:
            return

        self.killTimers()
        lo_send(lo_target, "/unregister")
        self.removeAllPlugins()
        lo_send(lo_target, "/register", self.fOscServer.getFullURL())
        self.startTimers()
Example #12
0
    def disconnectOsc(self):
        global lo_target, lo_target_name

        self.killTimers()
        self.ui.act_file_refresh.setEnabled(False)

        if lo_target is not None:
            lo_send(lo_target, "/unregister")

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

        self.removeAllPlugins()

        lo_target        = None
        lo_target_name   = ""
        self.fOscAddress = ""
Example #13
0
    def disconnectOsc(self):
        global lo_target, lo_target_name

        self.killTimers()
        self.ui.act_file_refresh.setEnabled(False)

        if lo_target is not None:
            lo_send(lo_target, "/unregister")

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

        self.removeAllPlugins()

        lo_target = None
        lo_target_name = ""
        self.fOscAddress = ""
Example #14
0
    def connectOsc(self, addr = None):
        global lo_target, lo_target_name

        if addr is not None:
            self.fOscAddress = addr

        lo_target      = Address(self.fOscAddress)
        lo_target_name = self.fOscAddress.rsplit("/", 1)[-1]
        print("Connecting to \"%s\" as '%s'..." % (self.fOscAddress, lo_target_name))

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

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

        self.startTimers()
        self.ui.act_file_refresh.setEnabled(True)
Example #15
0
    def connectToAddr(self, addr):
        global lo_target, lo_targetName

        self.lo_address = addr
        lo_target       = Address(self.lo_address)
        lo_targetName   = self.lo_address.rsplit("/", 1)[-1]
        print("Connecting to \"%s\" as '%s'..." % (self.lo_address, lo_targetName))

        try:
            self.lo_server = ControlServer(self, LO_UDP if self.lo_address.startswith("osc.udp") else LO_TCP)
        except: # ServerError, err:
            print("Connecting error!")
            #print str(err)
            QMessageBox.critical(self, self.tr("Error"), self.tr("Failed to connect, operation failed."))
            return

        if self.lo_server:
            self.lo_server.start()
            self.ui.act_file_refresh.setEnabled(True)
            lo_send(lo_target, "/register", self.lo_server.getFullURL())

        self.fIdleTimerFast = self.startTimer(60)
        self.fIdleTimerSlow = self.startTimer(60*2)
Example #16
0
    def disconnectOsc(self):
        global lo_target, lo_target_name

        self.killTimers()
        self.ui.act_file_refresh.setEnabled(False)

        if lo_target is not None:
            try:
                lo_send(lo_target, "/unregister")
            except:
                pass

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

        if self.fOscServer is not None:
            del self.fOscServer
            self.fOscServer = None

        self.removeAllPlugins()

        lo_target = None
        lo_target_name = ""
        self.fOscAddress = ""
Example #17
0
    def disconnectOsc(self):
        global lo_target, lo_target_name

        self.killTimers()
        self.ui.act_file_refresh.setEnabled(False)

        if lo_target is not None:
            try:
                lo_send(lo_target, "/unregister")
            except:
                pass

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

        if self.fOscServer is not None:
            del self.fOscServer
            self.fOscServer = None

        self.removeAllPlugins()

        lo_target        = None
        lo_target_name   = ""
        self.fOscAddress = ""
Example #18
0
    def slot_fileRefresh(self):
        if None in (self.host.lo_server_tcp, self.host.lo_server_udp,
                    self.host.lo_target_tcp, self.host.lo_target_udp):
            return

        lo_send(self.host.lo_target_udp, "/unregister",
                self.host.lo_server_udp.getFullURL())
        while self.host.lo_server_udp.recv(0):
            pass
        #self.host.lo_server_udp.free()

        lo_send(self.host.lo_target_tcp, "/unregister",
                self.host.lo_server_tcp.getFullURL())
        while self.host.lo_server_tcp.recv(0):
            pass
        #self.host.lo_server_tcp.free()

        self.removeAllPlugins()
        patchcanvas.clear()

        self.host.lo_server_tcp = CarlaControlServerTCP(
            self.host, self.fOscReportedHost)
        self.host.lo_server_udp = CarlaControlServerUDP(
            self.host, self.fOscReportedHost)

        try:
            lo_send(self.host.lo_target_tcp, "/register",
                    self.host.lo_server_tcp.getFullURL())
        except:
            self.disconnectOsc()
            return

        try:
            lo_send(self.host.lo_target_udp, "/register",
                    self.host.lo_server_udp.getFullURL())
        except:
            self.disconnectOsc()
            return
Example #19
0
    def sendMsg(self, lines):
        if len(lines) < 1:
            return self.printAndReturnError("not enough arguments")

        method = lines.pop(0)

        if method == "set_engine_option":
            return True

        if self.lo_target_tcp is None:
            return self.printAndReturnError("lo_target_tcp is None")
        if self.lo_target_tcp_name is None:
            return self.printAndReturnError("lo_target_tcp_name is None")

        if method in (
                "clear_engine_xruns",
                "cancel_engine_action",
                #"load_file",
                #"load_project",
                #"save_project",
                #"clear_project_filename",
                "patchbay_connect",
                "patchbay_disconnect",
                "patchbay_set_group_pos",
                "patchbay_refresh",
                "transport_play",
                "transport_pause",
                "transport_bpm",
                "transport_relocate",
                "add_plugin",
                "remove_plugin",
                "remove_all_plugins",
                "rename_plugin",
                "clone_plugin",
                "replace_plugin",
                "switch_plugins",
                #"load_plugin_state",
                #"save_plugin_state",
        ):
            path = "/ctrl/" + method
            needResp = True

        elif method in (  #"set_option",
                "set_active",
                "set_drywet",
                "set_volume",
                "set_balance_left",
                "set_balance_right",
                "set_panning",
                #"set_ctrl_channel",
                "set_parameter_value",
                "set_parameter_midi_channel",
                "set_parameter_midi_cc",
                "set_program",
                "set_midi_program",
                #"set_custom_data",
                #"set_chunk_data",
                #"prepare_for_save",
                #"reset_parameters",
                #"randomize_parameters",
        ):
            pluginId = lines.pop(0)
            needResp = False
            path = "/%s/%i/%s" % (self.lo_target_tcp_name, pluginId, method)

        elif method == "send_midi_note":
            pluginId = lines.pop(0)
            needResp = False
            channel, note, velocity = lines

            if velocity:
                path = "/%s/%i/note_on" % (self.lo_target_tcp_name, pluginId)
            else:
                path = "/%s/%i/note_off" % (self.lo_target_tcp_name, pluginId)
                lines.pop(2)

        else:
            return self.printAndReturnError("invalid method '%s'" % method)

        if len(self.pendingMessages) != 0:
            return self.printAndReturnError(
                "A previous operation is still pending, please wait")

        args = [
            int(line) if isinstance(line, bool) else line for line in lines
        ]
        #print(path, args)

        if not needResp:
            lo_send(self.lo_target_tcp, path, *args)
            return True

        messageId = self.lastMessageId
        self.lastMessageId += 1
        self.pendingMessages.append(messageId)

        lo_send(self.lo_target_tcp, path, messageId, *args)

        while messageId in self.pendingMessages:
            QApplication.processEvents(QEventLoop.AllEvents, 100)

        error = self.responses.pop(messageId)

        if not error:
            return True

        self.fLastError = error
        return False
Example #20
0
    def sendMsg(self, lines):
        global lo_target, lo_target_name

        if lo_target is None:
            return self.printAndReturnError("lo_target is None")
        if lo_target_name is None:
            return self.printAndReturnError("lo_target_name is None")
        if len(lines) < 2:
            return self.printAndReturnError("not enough arguments")

        method = lines.pop(0)

        if method not in (
                #"set_option",
                "set_active",
                "set_drywet",
                "set_volume",
                "set_balance_left",
                "set_balance_right",
                "set_panning",
                #"set_ctrl_channel",
                "set_parameter_value",
                "set_parameter_midi_channel",
                "set_parameter_midi_cc",
                "set_program",
                "set_midi_program",
                #"set_custom_data",
                #"set_chunk_data",
                #"prepare_for_save",
                #"reset_parameters",
                #"randomize_parameters",
                "send_midi_note"):
            return self.printAndReturnError("invalid method '%s'" % method)

        pluginId = lines.pop(0)

        args = []

        if method == "send_midi_note":
            channel, note, velocity = lines

            if velocity:
                method = "note_on"
                args = [channel, note, velocity]
            else:
                method = "note_off"
                args = [channel, note]

        else:
            for line in lines:
                if isinstance(line, bool):
                    args.append(int(line))
                else:
                    args.append(line)

        path = "/%s/%i/%s" % (lo_target_name, pluginId, method)

        print(path, args)

        lo_send(lo_target, path, *args)
        return True
Example #21
0
 def slot_fileRefresh(self):
     global lo_target
     if lo_target and self.lo_server:
         self.removeAll()
         lo_send(lo_target, "/unregister")
         lo_send(lo_target, "/register", self.lo_server.getFullURL())
Example #22
0
 def set_option(self, pluginId, option, yesNo):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_option" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, option, yesNo)
Example #23
0
 def set_active(self, pluginId, onoff):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_active" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, 1 if onoff else 0)
Example #24
0
 def set_midi_program(self, pluginId, midiProgramId):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_midi_program" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, midiProgramId)
Example #25
0
 def slot_fileRefresh(self):
     global lo_target
     if lo_target and self.lo_server:
         self.removeAll()
         lo_send(lo_target, "/unregister")
         lo_send(lo_target, "/register", self.lo_server.getFullURL())
Example #26
0
 def set_balance_right(self, pluginId, value):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_balance_right" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, value)
Example #27
0
 def set_panning(self, pluginId, value):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_panning" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, value)
Example #28
0
 def set_balance_right(self, pluginId, value):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_balance_right" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, value)
Example #29
0
 def set_panning(self, pluginId, value):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_panning" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, value)
Example #30
0
 def set_ctrl_channel(self, pluginId, channel):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_ctrl_channel" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, channel)
Example #31
0
    def connectOsc(self, addrTCP=None, addrUDP=None, rhost=None):
        if self.fCustomOscAddress is not None:
            addrTCP = self.fCustomOscAddress.replace("osc.udp://",
                                                     "osc.tcp://")
            addrUDP = self.fCustomOscAddress.replace("osc.tcp://",
                                                     "osc.udp://")

        else:
            if addrTCP is not None:
                self.fOscAddressTCP = addrTCP
            if addrUDP is not None:
                self.fOscAddressUDP = addrUDP
            if rhost is not None:
                self.fOscReportedHost = rhost

        lo_target_tcp_name = addrTCP.rsplit("/", 1)[-1]
        lo_target_udp_name = addrUDP.rsplit("/", 1)[-1]

        err = None

        try:
            lo_target_tcp = Address(addrTCP)
            lo_server_tcp = CarlaControlServerTCP(self.host, rhost)
            lo_send(lo_target_tcp, "/register", lo_server_tcp.getFullURL())

            lo_target_udp = Address(addrUDP)
            lo_server_udp = CarlaControlServerUDP(self.host, rhost)
            lo_send(lo_target_udp, "/register", lo_server_udp.getFullURL())

        except AddressError as e:
            err = e
        except OSError as e:
            err = e
        except:
            err = Exception()

        if err is not None:
            fullError = self.tr("Failed to connect to the Carla instance.")

            if len(err.args) > 0:
                fullError += " %s\n%s\n" % (self.tr("Error was:"), err.args[0])

            fullError += "\n"
            fullError += self.tr(
                "Make sure the remote Carla is running and the URL and Port are correct."
            ) + "\n"
            fullError += self.tr(
                "If it still does not work, check your current device and the remote's firewall."
            )

            CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"),
                             self.tr("Connection failed"), fullError,
                             QMessageBox.Ok, QMessageBox.Ok)
            return

        self.host.lo_server_tcp = lo_server_tcp
        self.host.lo_target_tcp = lo_target_tcp
        self.host.lo_target_tcp_name = lo_target_tcp_name

        self.host.lo_server_udp = lo_server_udp
        self.host.lo_target_udp = lo_target_udp
        self.host.lo_target_udp_name = lo_target_udp_name

        self.ui.act_file_refresh.setEnabled(True)

        self.startTimers()
Example #32
0
 def set_midi_program(self, pluginId, midiProgramId):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_midi_program" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, midiProgramId)
Example #33
0
 def set_ctrl_channel(self, pluginId, channel):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_ctrl_channel" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, channel)
Example #34
0
 def set_parameter_value(self, pluginId, parameterId, value):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_parameter_value" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, parameterId, value)
Example #35
0
 def set_parameter_value(self, pluginId, parameterId, value):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_parameter_value" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, parameterId, value)
Example #36
0
 def set_parameter_midi_channel(self, pluginId, parameterId, channel):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_parameter_midi_channel" % (lo_targetName,
                                                      pluginId)
     lo_send(lo_target, lo_path, parameterId, channel)
Example #37
0
 def set_option(self, pluginId, option, yesNo):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_option" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, option, yesNo)
Example #38
0
 def set_parameter_midi_channel(self, pluginId, parameterId, channel):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_parameter_midi_channel" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, parameterId, channel)
Example #39
0
    def sendMsg(self, lines):
        global lo_target, lo_target_name

        if lo_target is None:
            return self.printAndReturnError("lo_target is None")
        if lo_target_name is None:
            return self.printAndReturnError("lo_target_name is None")
        if len(lines) < 2:
            return self.printAndReturnError("not enough arguments")

        method = lines.pop(0)

        if method not in (
                          #"set_option",
                          "set_active",
                          "set_drywet",
                          "set_volume",
                          "set_balance_left",
                          "set_balance_right",
                          "set_panning",
                          #"set_ctrl_channel",
                          "set_parameter_value",
                          "set_parameter_midi_channel",
                          "set_parameter_midi_cc",
                          "set_program",
                          "set_midi_program",
                          #"set_custom_data",
                          #"set_chunk_data",
                          #"prepare_for_save",
                          #"reset_parameters",
                          #"randomize_parameters",
                          "send_midi_note"
                          ):
            return self.printAndReturnError("invalid method '%s'" % method)

        pluginId = lines.pop(0)

        args = []

        if method == "send_midi_note":
            channel, note, velocity = lines

            if velocity:
                method = "note_on"
                args   = [channel, note, velocity]
            else:
                method = "note_off"
                args   = [channel, note]

        else:
            for line in lines:
                if isinstance(line, bool):
                    args.append(int(line))
                else:
                    args.append(line)

        path = "/%s/%i/%s" % (lo_target_name, pluginId, method)

        print(path, args)

        lo_send(lo_target, path, *args)
        return True
Example #40
0
 def set_active(self, pluginId, onoff):
     global to_target, lo_targetName
     lo_path = "/%s/%i/set_active" % (lo_targetName, pluginId)
     lo_send(lo_target, lo_path, 1 if onoff else 0)