Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

751 lines
26KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ----------------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. from qt_compat import qt_config
  7. if qt_config == 5:
  8. from PyQt5.QtCore import QEventLoop
  9. elif qt_config == 6:
  10. from PyQt6.QtCore import QEventLoop
  11. # ------------------------------------------------------------------------------------------------------------
  12. # Imports (Custom)
  13. import ui_carla_osc_connect
  14. from carla_backend_qt import CarlaHostQtPlugin
  15. from carla_host import *
  16. # ------------------------------------------------------------------------------------------------------------
  17. # Imports (liblo)
  18. try:
  19. from pyliblo3 import (
  20. Address,
  21. AddressError,
  22. ServerError,
  23. Server,
  24. make_method,
  25. send as lo_send,
  26. TCP as LO_TCP,
  27. UDP as LO_UDP,
  28. )
  29. except ModuleNotFoundError:
  30. from liblo import (
  31. Address,
  32. AddressError,
  33. ServerError,
  34. Server,
  35. make_method,
  36. send as lo_send,
  37. TCP as LO_TCP,
  38. UDP as LO_UDP,
  39. )
  40. from random import random
  41. # ------------------------------------------------------------------------------------------------------------
  42. DEBUG = False
  43. # ----------------------------------------------------------------------------------------------------------------------
  44. # OSC connect Dialog
  45. class ConnectDialog(QDialog):
  46. def __init__(self, parent):
  47. QDialog.__init__(self, parent)
  48. self.ui = ui_carla_osc_connect.Ui_Dialog()
  49. self.ui.setupUi(self)
  50. self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
  51. # -------------------------------------------------------------------------------------------------------------
  52. # Load settings
  53. self.loadSettings()
  54. # -------------------------------------------------------------------------------------------------------------
  55. # Set-up connections
  56. self.finished.connect(self.slot_saveSettings)
  57. self.ui.le_host.textChanged.connect(self.slot_hostChanged)
  58. # -----------------------------------------------------------------------------------------------------------------
  59. def getResult(self):
  60. return (self.ui.le_host.text(),
  61. self.ui.sb_tcp_port.value(),
  62. self.ui.sb_udp_port.value())
  63. def checkIfButtonBoxShouldBeEnabled(self, host):
  64. enabled = len(host) > 0
  65. self.ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled)
  66. def loadSettings(self):
  67. settings = QSafeSettings("falkTX", "CarlaOSCConnect")
  68. self.ui.le_host.setText(settings.value("Host", "127.0.0.1", str))
  69. self.ui.sb_tcp_port.setValue(settings.value("TCPPort", CARLA_DEFAULT_OSC_TCP_PORT_NUMBER, int))
  70. self.ui.sb_udp_port.setValue(settings.value("UDPPort", CARLA_DEFAULT_OSC_UDP_PORT_NUMBER, int))
  71. self.checkIfButtonBoxShouldBeEnabled(self.ui.le_host.text())
  72. # ------------------------------------------------------------------------------------------------------------------
  73. @pyqtSlot(str)
  74. def slot_hostChanged(self, text):
  75. self.checkIfButtonBoxShouldBeEnabled(text)
  76. @pyqtSlot()
  77. def slot_saveSettings(self):
  78. settings = QSafeSettings("falkTX", "CarlaOSCConnect")
  79. settings.setValue("Host", self.ui.le_host.text())
  80. settings.setValue("TCPPort", self.ui.sb_tcp_port.value())
  81. settings.setValue("UDPPort", self.ui.sb_udp_port.value())
  82. # ------------------------------------------------------------------------------------------------------------------
  83. def done(self, r):
  84. QDialog.done(self, r)
  85. self.close()
  86. # ------------------------------------------------------------------------------------------------------------
  87. # Host OSC object
  88. class CarlaHostOSC(CarlaHostQtPlugin):
  89. def __init__(self):
  90. CarlaHostQtPlugin.__init__(self)
  91. self.lo_server_tcp = None
  92. self.lo_server_udp = None
  93. self.lo_target_tcp = None
  94. self.lo_target_udp = None
  95. self.lo_target_tcp_name = ""
  96. self.lo_target_udp_name = ""
  97. self.resetPendingMessages()
  98. # -------------------------------------------------------------------
  99. def resetPendingMessages(self):
  100. self.lastMessageId = 1
  101. self.pendingMessages = []
  102. self.responses = {}
  103. def printAndReturnError(self, error):
  104. print(error)
  105. self.fLastError = error
  106. return False
  107. def sendMsg(self, lines):
  108. if len(lines) < 1:
  109. return self.printAndReturnError("not enough arguments")
  110. method = lines.pop(0)
  111. if method == "set_engine_option":
  112. return True
  113. if self.lo_target_tcp is None:
  114. return self.printAndReturnError("lo_target_tcp is None")
  115. if self.lo_target_tcp_name is None:
  116. return self.printAndReturnError("lo_target_tcp_name is None")
  117. if method in ("clear_engine_xruns",
  118. "cancel_engine_action",
  119. #"load_file",
  120. #"load_project",
  121. #"save_project",
  122. #"clear_project_filename",
  123. "patchbay_connect",
  124. "patchbay_disconnect",
  125. "patchbay_set_group_pos",
  126. "patchbay_refresh",
  127. "transport_play",
  128. "transport_pause",
  129. "transport_bpm",
  130. "transport_relocate",
  131. "add_plugin",
  132. "remove_plugin",
  133. "remove_all_plugins",
  134. "rename_plugin",
  135. "clone_plugin",
  136. "replace_plugin",
  137. "switch_plugins",
  138. #"load_plugin_state",
  139. #"save_plugin_state",
  140. ):
  141. path = "/ctrl/" + method
  142. needResp = True
  143. elif method in (#"set_option",
  144. "set_active",
  145. "set_drywet",
  146. "set_volume",
  147. "set_balance_left",
  148. "set_balance_right",
  149. "set_panning",
  150. #"set_ctrl_channel",
  151. "set_parameter_value",
  152. "set_parameter_midi_channel",
  153. "set_parameter_midi_cc",
  154. "set_program",
  155. "set_midi_program",
  156. #"set_custom_data",
  157. #"set_chunk_data",
  158. #"prepare_for_save",
  159. #"reset_parameters",
  160. #"randomize_parameters",
  161. ):
  162. pluginId = lines.pop(0)
  163. needResp = False
  164. path = "/%s/%i/%s" % (self.lo_target_tcp_name, pluginId, method)
  165. elif method == "send_midi_note":
  166. pluginId = lines.pop(0)
  167. needResp = False
  168. channel, note, velocity = lines
  169. if velocity:
  170. path = "/%s/%i/note_on" % (self.lo_target_tcp_name, pluginId)
  171. else:
  172. path = "/%s/%i/note_off" % (self.lo_target_tcp_name, pluginId)
  173. lines.pop(2)
  174. else:
  175. return self.printAndReturnError("invalid method '%s'" % method)
  176. if len(self.pendingMessages) != 0:
  177. return self.printAndReturnError("A previous operation is still pending, please wait")
  178. args = [int(line) if isinstance(line, bool) else line for line in lines]
  179. #print(path, args)
  180. if not needResp:
  181. lo_send(self.lo_target_tcp, path, *args)
  182. return True
  183. messageId = self.lastMessageId
  184. self.lastMessageId += 1
  185. self.pendingMessages.append(messageId)
  186. lo_send(self.lo_target_tcp, path, messageId, *args)
  187. while messageId in self.pendingMessages:
  188. QApplication.processEvents(QEventLoop.AllEvents, 100)
  189. error = self.responses.pop(messageId)
  190. if not error:
  191. return True
  192. self.fLastError = error
  193. return False
  194. def sendMsgAndSetError(self, lines):
  195. return self.sendMsg(lines)
  196. # -------------------------------------------------------------------
  197. def engine_init(self, driverName, clientName):
  198. return self.lo_target_tcp is not None
  199. def engine_close(self):
  200. return True
  201. def engine_idle(self):
  202. return
  203. def is_engine_running(self):
  204. return self.lo_target_tcp is not None
  205. def set_engine_about_to_close(self):
  206. return
  207. # ---------------------------------------------------------------------------------------------------------------------
  208. # OSC Control server
  209. class CarlaControlServerTCP(Server):
  210. def __init__(self, host):
  211. Server.__init__(self, proto=LO_TCP)
  212. if False:
  213. host = CarlaHostOSC()
  214. self.host = host
  215. def idle(self):
  216. self.fReceivedMsgs = False
  217. while self.recv(0) and self.fReceivedMsgs:
  218. pass
  219. def getFullURL(self):
  220. return "%sctrl" % self.get_url()
  221. @make_method('/ctrl/cb', 'iiiiifs')
  222. def carla_cb(self, path, args):
  223. if DEBUG: print(path, args)
  224. self.fReceivedMsgs = True
  225. action, pluginId, value1, value2, value3, valuef, valueStr = args
  226. self.host._setViaCallback(action, pluginId, value1, value2, value3, valuef, valueStr)
  227. engineCallback(self.host, action, pluginId, value1, value2, value3, valuef, valueStr)
  228. @make_method('/ctrl/info', 'iiiihiisssssss')
  229. def carla_info(self, path, args):
  230. if DEBUG: print(path, args)
  231. self.fReceivedMsgs = True
  232. (
  233. pluginId, type_, category, hints, uniqueId, optsAvail, optsEnabled,
  234. name, filename, iconName, realName, label, maker, copyright,
  235. ) = args
  236. hints &= ~PLUGIN_HAS_CUSTOM_UI
  237. pinfo = {
  238. 'type': type_,
  239. 'category': category,
  240. 'hints': hints,
  241. 'optionsAvailable': optsAvail,
  242. 'optionsEnabled': optsEnabled,
  243. 'uniqueId': uniqueId,
  244. 'filename': filename,
  245. 'name': name,
  246. 'label': label,
  247. 'maker': maker,
  248. 'copyright': copyright,
  249. 'iconName': iconName
  250. }
  251. self.host._set_pluginInfoUpdate(pluginId, pinfo)
  252. self.host._set_pluginRealName(pluginId, realName)
  253. @make_method('/ctrl/ports', 'iiiiiiii')
  254. def carla_ports(self, path, args):
  255. if DEBUG: print(path, args)
  256. self.fReceivedMsgs = True
  257. pluginId, audioIns, audioOuts, midiIns, midiOuts, paramIns, paramOuts, paramTotal = args
  258. self.host._set_audioCountInfo(pluginId, {'ins': audioIns, 'outs': audioOuts})
  259. self.host._set_midiCountInfo(pluginId, {'ins': midiOuts, 'outs': midiOuts})
  260. self.host._set_parameterCountInfo(pluginId, paramTotal, {'ins': paramIns, 'outs': paramOuts})
  261. @make_method('/ctrl/paramInfo', 'iissss')
  262. def carla_paramInfo(self, path, args):
  263. if DEBUG: print(path, args)
  264. self.fReceivedMsgs = True
  265. pluginId, paramId, name, unit, comment, groupName = args
  266. paramInfo = {
  267. 'name': name,
  268. 'symbol': "",
  269. 'unit': unit,
  270. 'comment': comment,
  271. 'groupName': groupName,
  272. 'scalePointCount': 0,
  273. 'scalePoints': [],
  274. }
  275. self.host._set_parameterInfo(pluginId, paramId, paramInfo)
  276. @make_method('/ctrl/paramData', 'iiiiiifff')
  277. def carla_paramData(self, path, args):
  278. if DEBUG: print(path, args)
  279. self.fReceivedMsgs = True
  280. pluginId, paramId, type_, hints, midiChan, mappedCtrl, mappedMin, mappedMax, value = args
  281. hints &= ~(PARAMETER_USES_SCALEPOINTS | PARAMETER_USES_CUSTOM_TEXT)
  282. paramData = {
  283. 'type': type_,
  284. 'hints': hints,
  285. 'index': paramId,
  286. 'rindex': -1,
  287. 'midiChannel': midiChan,
  288. 'mappedControlIndex': mappedCtrl,
  289. 'mappedMinimum': mappedMin,
  290. 'mappedMaximum': mappedMax,
  291. }
  292. self.host._set_parameterData(pluginId, paramId, paramData)
  293. self.host._set_parameterValue(pluginId, paramId, value)
  294. @make_method('/ctrl/paramRanges', 'iiffffff')
  295. def carla_paramRanges(self, path, args):
  296. if DEBUG: print(path, args)
  297. self.fReceivedMsgs = True
  298. pluginId, paramId, def_, min_, max_, step, stepSmall, stepLarge = args
  299. paramRanges = {
  300. 'def': def_,
  301. 'min': min_,
  302. 'max': max_,
  303. 'step': step,
  304. 'stepSmall': stepSmall,
  305. 'stepLarge': stepLarge,
  306. }
  307. self.host._set_parameterRanges(pluginId, paramId, paramRanges)
  308. @make_method('/ctrl/count', 'iiiiii')
  309. def carla_count(self, path, args):
  310. if DEBUG: print(path, args)
  311. self.fReceivedMsgs = True
  312. pluginId, pcount, mpcount, cdcount, cp, cmp = args
  313. self.host._set_programCount(pluginId, pcount)
  314. self.host._set_midiProgramCount(pluginId, mpcount)
  315. self.host._set_customDataCount(pluginId, cdcount)
  316. self.host._set_pluginInfoUpdate(pluginId, { 'programCurrent': cp, 'midiProgramCurrent': cmp })
  317. @make_method('/ctrl/pcount', 'iii')
  318. def carla_pcount(self, path, args):
  319. if DEBUG: print(path, args)
  320. self.fReceivedMsgs = True
  321. pluginId, pcount, mpcount = args
  322. self.host._set_programCount(pluginId, pcount)
  323. self.host._set_midiProgramCount(pluginId, mpcount)
  324. @make_method('/ctrl/prog', 'iis')
  325. def carla_prog(self, path, args):
  326. if DEBUG: print(path, args)
  327. self.fReceivedMsgs = True
  328. pluginId, progId, progName = args
  329. self.host._set_programName(pluginId, progId, progName)
  330. @make_method('/ctrl/mprog', 'iiiis')
  331. def carla_mprog(self, path, args):
  332. if DEBUG: print(path, args)
  333. self.fReceivedMsgs = True
  334. pluginId, midiProgId, bank, program, name = args
  335. self.host._set_midiProgramData(pluginId, midiProgId, {'bank': bank, 'program': program, 'name': name})
  336. @make_method('/ctrl/cdata', 'iisss')
  337. def carla_cdata(self, path, args):
  338. if DEBUG: print(path, args)
  339. self.fReceivedMsgs = True
  340. pluginId, index, type_, key, value = args
  341. self.host._set_customData(pluginId, index, { 'type': type_, 'key': key, 'value': value })
  342. @make_method('/ctrl/iparams', 'ifffffff')
  343. def carla_iparams(self, path, args):
  344. if DEBUG: print(path, args)
  345. self.fReceivedMsgs = True
  346. pluginId, active, drywet, volume, balLeft, balRight, pan, ctrlChan = args
  347. self.host._set_internalValue(pluginId, PARAMETER_ACTIVE, active)
  348. self.host._set_internalValue(pluginId, PARAMETER_DRYWET, drywet)
  349. self.host._set_internalValue(pluginId, PARAMETER_VOLUME, volume)
  350. self.host._set_internalValue(pluginId, PARAMETER_BALANCE_LEFT, balLeft)
  351. self.host._set_internalValue(pluginId, PARAMETER_BALANCE_RIGHT, balRight)
  352. self.host._set_internalValue(pluginId, PARAMETER_PANNING, pan)
  353. self.host._set_internalValue(pluginId, PARAMETER_CTRL_CHANNEL, ctrlChan)
  354. @make_method('/ctrl/resp', 'is')
  355. def carla_resp(self, path, args):
  356. if DEBUG: print(path, args)
  357. self.fReceivedMsgs = True
  358. messageId, error = args
  359. self.host.responses[messageId] = error
  360. self.host.pendingMessages.remove(messageId)
  361. @make_method('/ctrl/exit', '')
  362. def carla_exit(self, path, args):
  363. if DEBUG: print(path, args)
  364. self.fReceivedMsgs = True
  365. #self.host.lo_target_tcp = None
  366. self.host.QuitCallback.emit()
  367. @make_method('/ctrl/exit-error', 's')
  368. def carla_exit_error(self, path, args):
  369. if DEBUG: print(path, args)
  370. self.fReceivedMsgs = True
  371. error, = args
  372. self.host.lo_target_tcp = None
  373. self.host.QuitCallback.emit()
  374. self.host.ErrorCallback.emit(error)
  375. @make_method(None, None)
  376. def fallback(self, path, args):
  377. print("ControlServerTCP::fallback(\"%s\") - unknown message, args =" % path, args)
  378. self.fReceivedMsgs = True
  379. # ---------------------------------------------------------------------------------------------------------------------
  380. class CarlaControlServerUDP(Server):
  381. def __init__(self, host):
  382. Server.__init__(self, proto=LO_UDP)
  383. if False:
  384. host = CarlaHostOSC()
  385. self.host = host
  386. def idle(self):
  387. self.fReceivedMsgs = False
  388. while self.recv(0) and self.fReceivedMsgs:
  389. pass
  390. def getFullURL(self):
  391. return "%sctrl" % self.get_url()
  392. @make_method('/ctrl/runtime', 'fiihiiif')
  393. def carla_runtime(self, path, args):
  394. self.fReceivedMsgs = True
  395. load, xruns, playing, frame, bar, beat, tick, bpm = args
  396. self.host._set_runtime_info(load, xruns)
  397. self.host._set_transport(bool(playing), frame, bar, beat, tick, bpm)
  398. @make_method('/ctrl/param', 'iif')
  399. def carla_param_fixme(self, path, args):
  400. self.fReceivedMsgs = True
  401. pluginId, paramId, paramValue = args
  402. self.host._set_parameterValue(pluginId, paramId, paramValue)
  403. @make_method('/ctrl/peaks', 'iffff')
  404. def carla_peaks(self, path, args):
  405. self.fReceivedMsgs = True
  406. pluginId, in1, in2, out1, out2 = args
  407. self.host._set_peaks(pluginId, in1, in2, out1, out2)
  408. @make_method(None, None)
  409. def fallback(self, path, args):
  410. print("ControlServerUDP::fallback(\"%s\") - unknown message, args =" % path, args)
  411. self.fReceivedMsgs = True
  412. # ---------------------------------------------------------------------------------------------------------------------
  413. # Main Window
  414. class HostWindowOSC(HostWindow):
  415. def __init__(self, host, oscAddr = None):
  416. self.fCustomOscAddress = oscAddr
  417. HostWindow.__init__(self, host, True)
  418. self.host = host
  419. if False:
  420. # kdevelop likes this :)
  421. host = CarlaHostOSC()
  422. self.host = host
  423. # ----------------------------------------------------------------------------------------------------
  424. # Connect actions to functions
  425. self.ui.act_file_connect.triggered.connect(self.slot_fileConnect)
  426. self.ui.act_file_refresh.triggered.connect(self.slot_fileRefresh)
  427. # ----------------------------------------------------------------------------------------------------
  428. # Final setup
  429. if oscAddr:
  430. QTimer.singleShot(0, self.connectOsc)
  431. def connectOsc(self, addrTCP = None, addrUDP = None):
  432. if self.fCustomOscAddress is not None:
  433. addrTCP = self.fCustomOscAddress.replace("osc.udp://","osc.tcp://")
  434. addrUDP = self.fCustomOscAddress.replace("osc.tcp://","osc.udp://")
  435. else:
  436. if addrTCP is not None:
  437. self.fOscAddressTCP = addrTCP
  438. if addrUDP is not None:
  439. self.fOscAddressUDP = addrUDP
  440. lo_target_tcp_name = addrTCP.rsplit("/", 1)[-1]
  441. lo_target_udp_name = addrUDP.rsplit("/", 1)[-1]
  442. err = None
  443. try:
  444. lo_target_tcp = Address(addrTCP)
  445. lo_server_tcp = CarlaControlServerTCP(self.host)
  446. lo_send(lo_target_tcp, "/register", lo_server_tcp.getFullURL())
  447. lo_target_udp = Address(addrUDP)
  448. lo_server_udp = CarlaControlServerUDP(self.host)
  449. lo_send(lo_target_udp, "/register", lo_server_udp.getFullURL())
  450. except AddressError as e:
  451. err = e
  452. except OSError as e:
  453. err = e
  454. except:
  455. err = Exception()
  456. if err is not None:
  457. fullError = self.tr("Failed to connect to the Carla instance.")
  458. if len(err.args) > 0:
  459. fullError += " %s\n%s\n" % (self.tr("Error was:"), err.args[0])
  460. fullError += "\n"
  461. fullError += self.tr("Make sure the remote Carla is running and the URL and Port are correct.") + "\n"
  462. fullError += self.tr("If it still does not work, check your current device and the remote's firewall.")
  463. CustomMessageBox(self,
  464. QMessageBox.Warning,
  465. self.tr("Error"),
  466. self.tr("Connection failed"),
  467. fullError,
  468. QMessageBox.Ok,
  469. QMessageBox.Ok)
  470. return
  471. self.host.lo_server_tcp = lo_server_tcp
  472. self.host.lo_target_tcp = lo_target_tcp
  473. self.host.lo_target_tcp_name = lo_target_tcp_name
  474. self.host.lo_server_udp = lo_server_udp
  475. self.host.lo_target_udp = lo_target_udp
  476. self.host.lo_target_udp_name = lo_target_udp_name
  477. self.ui.act_file_refresh.setEnabled(True)
  478. self.startTimers()
  479. def disconnectOsc(self):
  480. self.killTimers()
  481. self.unregister()
  482. self.removeAllPlugins()
  483. patchcanvas.clear()
  484. self.ui.act_file_refresh.setEnabled(False)
  485. # --------------------------------------------------------------------------------------------------------
  486. def unregister(self):
  487. if self.host.lo_server_tcp is not None:
  488. if self.host.lo_target_tcp is not None:
  489. try:
  490. lo_send(self.host.lo_target_tcp, "/unregister", self.host.lo_server_tcp.getFullURL())
  491. except:
  492. pass
  493. self.host.lo_target_tcp = None
  494. while self.host.lo_server_tcp.recv(0):
  495. pass
  496. #self.host.lo_server_tcp.free()
  497. self.host.lo_server_tcp = None
  498. if self.host.lo_server_udp is not None:
  499. if self.host.lo_target_udp is not None:
  500. try:
  501. lo_send(self.host.lo_target_udp, "/unregister", self.host.lo_server_udp.getFullURL())
  502. except:
  503. pass
  504. self.host.lo_target_udp = None
  505. while self.host.lo_server_udp.recv(0):
  506. pass
  507. #self.host.lo_server_udp.free()
  508. self.host.lo_server_udp = None
  509. self.host.lo_target_tcp_name = ""
  510. self.host.lo_target_udp_name = ""
  511. # --------------------------------------------------------------------------------------------------------
  512. # Timers
  513. def idleFast(self):
  514. HostWindow.idleFast(self)
  515. if self.host.lo_server_tcp is not None:
  516. self.host.lo_server_tcp.idle()
  517. else:
  518. self.disconnectOsc()
  519. if self.host.lo_server_udp is not None:
  520. self.host.lo_server_udp.idle()
  521. else:
  522. self.disconnectOsc()
  523. # --------------------------------------------------------------------------------------------------------
  524. def removeAllPlugins(self):
  525. self.host.fPluginsInfo = {}
  526. HostWindow.removeAllPlugins(self)
  527. # --------------------------------------------------------------------------------------------------------
  528. def loadSettings(self, firstTime):
  529. settings = HostWindow.loadSettings(self, firstTime)
  530. if self.fCustomOscAddress is not None:
  531. self.fOscAddressTCP = settings.value("RemoteAddressTCP", "osc.tcp://127.0.0.1:22752/Carla", str)
  532. self.fOscAddressUDP = settings.value("RemoteAddressUDP", "osc.udp://127.0.0.1:22752/Carla", str)
  533. def saveSettings(self):
  534. settings = HostWindow.saveSettings(self)
  535. if self.fOscAddressTCP:
  536. settings.setValue("RemoteAddressTCP", self.fOscAddressTCP)
  537. if self.fOscAddressUDP:
  538. settings.setValue("RemoteAddressUDP", self.fOscAddressUDP)
  539. # --------------------------------------------------------------------------------------------------------
  540. @pyqtSlot()
  541. def slot_fileConnect(self):
  542. dialog = ConnectDialog(self)
  543. if not dialog.exec_():
  544. return
  545. host, tcpPort, udpPort = dialog.getResult()
  546. self.disconnectOsc()
  547. self.connectOsc("osc.tcp://%s:%i/Carla" % (host, tcpPort),
  548. "osc.udp://%s:%i/Carla" % (host, udpPort))
  549. @pyqtSlot()
  550. def slot_fileRefresh(self):
  551. if None in (self.host.lo_server_tcp, self.host.lo_server_udp, self.host.lo_target_tcp, self.host.lo_target_udp):
  552. return
  553. lo_send(self.host.lo_target_udp, "/unregister", self.host.lo_server_udp.getFullURL())
  554. while self.host.lo_server_udp.recv(0):
  555. pass
  556. #self.host.lo_server_udp.free()
  557. lo_send(self.host.lo_target_tcp, "/unregister", self.host.lo_server_tcp.getFullURL())
  558. while self.host.lo_server_tcp.recv(0):
  559. pass
  560. #self.host.lo_server_tcp.free()
  561. self.removeAllPlugins()
  562. patchcanvas.clear()
  563. self.host.lo_server_tcp = CarlaControlServerTCP(self.host)
  564. self.host.lo_server_udp = CarlaControlServerUDP(self.host)
  565. try:
  566. lo_send(self.host.lo_target_tcp, "/register", self.host.lo_server_tcp.getFullURL())
  567. except:
  568. self.disconnectOsc()
  569. return
  570. try:
  571. lo_send(self.host.lo_target_udp, "/register", self.host.lo_server_udp.getFullURL())
  572. except:
  573. self.disconnectOsc()
  574. return
  575. # --------------------------------------------------------------------------------------------------------
  576. @pyqtSlot()
  577. def slot_handleSIGTERM(self):
  578. print("Got SIGTERM -> Closing now")
  579. self.host.pendingMessages = []
  580. self.close()
  581. @pyqtSlot()
  582. def slot_handleQuitCallback(self):
  583. self.disconnectOsc()
  584. HostWindow.slot_handleQuitCallback(self)
  585. # --------------------------------------------------------------------------------------------------------
  586. def closeEvent(self, event):
  587. self.killTimers()
  588. self.unregister()
  589. HostWindow.closeEvent(self, event)
  590. # ------------------------------------------------------------------------------------------------------------