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.

796 lines
29KB

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