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.

1219 lines
47KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2013 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 PyQt4.QtCore import qCritical, QModelIndex, QTimer
  20. from PyQt4.QtGui import QApplication, QFileSystemModel, QMainWindow, QPalette
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Imports (Custom)
  23. import ui_carla_host
  24. from carla_database import *
  25. from carla_settings import *
  26. from carla_style import *
  27. from carla_widgets import *
  28. # ------------------------------------------------------------------------------------------------------------
  29. # PatchCanvas defines
  30. CANVAS_ANTIALIASING_SMALL = 1
  31. CANVAS_EYECANDY_SMALL = 1
  32. # ------------------------------------------------------------------------------------------------------------
  33. # Session Management support
  34. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  35. NSM_URL = os.getenv("NSM_URL")
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Dummy widget
  38. class CarlaDummyW(object):
  39. def __init__(self, parent):
  40. object.__init__(self)
  41. # -----------------------------------------------------------------
  42. def getPluginCount(self):
  43. return 0
  44. # -----------------------------------------------------------------
  45. def addPlugin(self, pluginId, isProjectLoading):
  46. pass
  47. def removePlugin(self, pluginId):
  48. pass
  49. def renamePlugin(self, pluginId, newName):
  50. pass
  51. def disablePlugin(self, pluginId, errorMsg):
  52. pass
  53. def removeAllPlugins(self):
  54. pass
  55. # -----------------------------------------------------------------
  56. def engineStarted(self):
  57. pass
  58. def engineStopped(self):
  59. pass
  60. def engineChanged(self):
  61. pass
  62. # -----------------------------------------------------------------
  63. def idleFast(self):
  64. pass
  65. def idleSlow(self):
  66. pass
  67. # -----------------------------------------------------------------
  68. def projectLoaded(self):
  69. pass
  70. def saveSettings(self, settings):
  71. pass
  72. def showEditDialog(self, pluginId):
  73. pass
  74. # ------------------------------------------------------------------------------------------------------------
  75. # Host Window
  76. class HostWindow(QMainWindow):
  77. # signals
  78. DebugCallback = pyqtSignal(int, int, int, float, str)
  79. PluginAddedCallback = pyqtSignal(int, str)
  80. PluginRemovedCallback = pyqtSignal(int)
  81. PluginRenamedCallback = pyqtSignal(int, str)
  82. PluginUnavailableCallback = pyqtSignal(int, str)
  83. ParameterValueChangedCallback = pyqtSignal(int, int, float)
  84. ParameterDefaultChangedCallback = pyqtSignal(int, int, float)
  85. ParameterMidiCcChangedCallback = pyqtSignal(int, int, int)
  86. ParameterMidiChannelChangedCallback = pyqtSignal(int, int, int)
  87. ProgramChangedCallback = pyqtSignal(int, int)
  88. MidiProgramChangedCallback = pyqtSignal(int, int)
  89. UiStateChangedCallback = pyqtSignal(int, int)
  90. NoteOnCallback = pyqtSignal(int, int, int, int)
  91. NoteOffCallback = pyqtSignal(int, int, int)
  92. UpdateCallback = pyqtSignal(int)
  93. ReloadInfoCallback = pyqtSignal(int)
  94. ReloadParametersCallback = pyqtSignal(int)
  95. ReloadProgramsCallback = pyqtSignal(int)
  96. ReloadAllCallback = pyqtSignal(int)
  97. PatchbayClientAddedCallback = pyqtSignal(int, int, int, str)
  98. PatchbayClientRemovedCallback = pyqtSignal(int)
  99. PatchbayClientRenamedCallback = pyqtSignal(int, str)
  100. PatchbayClientDataChangedCallback = pyqtSignal(int, int, int)
  101. PatchbayPortAddedCallback = pyqtSignal(int, int, int, str)
  102. PatchbayPortRemovedCallback = pyqtSignal(int, int)
  103. PatchbayPortRenamedCallback = pyqtSignal(int, int, str)
  104. PatchbayConnectionAddedCallback = pyqtSignal(int, int, int)
  105. PatchbayConnectionRemovedCallback = pyqtSignal(int, int, int)
  106. EngineStartedCallback = pyqtSignal(int, int, str)
  107. EngineStoppedCallback = pyqtSignal()
  108. ProcessModeChangedCallback = pyqtSignal(int)
  109. TransportModeChangedCallback = pyqtSignal(int)
  110. BufferSizeChangedCallback = pyqtSignal(int)
  111. SampleRateChangedCallback = pyqtSignal(float)
  112. InfoCallback = pyqtSignal(str)
  113. ErrorCallback = pyqtSignal(str)
  114. QuitCallback = pyqtSignal()
  115. SIGTERM = pyqtSignal()
  116. SIGUSR1 = pyqtSignal()
  117. def __init__(self, parent):
  118. QMainWindow.__init__(self, parent)
  119. self.ui = ui_carla_host.Ui_CarlaHostW()
  120. self.ui.setupUi(self)
  121. if False:
  122. Carla.gui = self
  123. self.fContainer = CarlaDummyW(self)
  124. # -------------------------------------------------------------
  125. # Set callback, TODO put somewhere else
  126. if Carla.host is not None:
  127. Carla.host.set_engine_callback(engineCallback)
  128. # -------------------------------------------------------------
  129. # Internal stuff
  130. self.fIdleTimerFast = 0
  131. self.fIdleTimerSlow = 0
  132. self.fIsProjectLoading = False
  133. self.fProjectFilename = ""
  134. self.fLadspaRdfNeedsUpdate = True
  135. self.fLadspaRdfList = []
  136. self.fLastTransportFrame = 0
  137. self.fLastTransportState = False
  138. self.fTransportText = ""
  139. # when true, call engineChanged() asap
  140. self.fEngineChanged = False
  141. # first attempt of auto-start engine doesn't show an error
  142. self.fFirstEngineInit = True
  143. self.fSavedSettings = {}
  144. if LADISH_APP_NAME:
  145. self.fClientName = LADISH_APP_NAME
  146. self.fSessionManagerName = "LADISH"
  147. elif NSM_URL:
  148. self.fClientName = "Carla.tmp"
  149. self.fSessionManagerName = "Non Session Manager"
  150. else:
  151. self.fClientName = "Carla"
  152. self.fSessionManagerName = ""
  153. # -------------------------------------------------------------
  154. # Load Settings
  155. self.loadSettings(True)
  156. # -------------------------------------------------------------
  157. # Set up GUI (engine stopped)
  158. if Carla.isPlugin:
  159. self.ui.act_file_new.setEnabled(False)
  160. self.ui.act_file_open.setEnabled(False)
  161. self.ui.act_engine_start.setEnabled(False)
  162. self.ui.menu_Engine.setEnabled(False)
  163. else:
  164. self.ui.act_engine_start.setEnabled(True)
  165. self.ui.act_file_save.setEnabled(False)
  166. self.ui.act_file_save_as.setEnabled(False)
  167. self.ui.act_engine_stop.setEnabled(False)
  168. self.ui.act_plugin_remove_all.setEnabled(False)
  169. self.ui.menu_PluginMacros.setEnabled(False)
  170. self.ui.menu_Canvas.setEnabled(False)
  171. self.setTransportMenuEnabled(False)
  172. # -------------------------------------------------------------
  173. # Set up GUI (right panel)
  174. self.fDirModel = QFileSystemModel(self)
  175. self.fDirModel.setRootPath(HOME)
  176. if Carla.host is not None:
  177. self.fDirModel.setNameFilters(Carla.host.get_supported_file_extensions().split(";"))
  178. self.ui.fileTreeView.setModel(self.fDirModel)
  179. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  180. self.ui.fileTreeView.setColumnHidden(1, True)
  181. self.ui.fileTreeView.setColumnHidden(2, True)
  182. self.ui.fileTreeView.setColumnHidden(3, True)
  183. self.ui.fileTreeView.setHeaderHidden(True)
  184. self.setProperWindowTitle()
  185. # -------------------------------------------------------------
  186. # Connect actions to functions
  187. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  188. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  189. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  190. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  191. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  192. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  193. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  194. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  195. self.ui.act_plugin_remove_all.triggered.connect(self.slot_pluginRemoveAll)
  196. self.ui.act_transport_play.triggered.connect(self.slot_transportPlayPause)
  197. self.ui.act_transport_stop.triggered.connect(self.slot_transportStop)
  198. self.ui.act_transport_backwards.triggered.connect(self.slot_transportBackwards)
  199. self.ui.act_transport_forwards.triggered.connect(self.slot_transportForwards)
  200. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  201. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  202. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  203. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  204. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  205. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  206. self.DebugCallback.connect(self.slot_handleDebugCallback)
  207. self.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  208. self.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  209. self.PluginRenamedCallback.connect(self.slot_handlePluginRenamedCallback)
  210. self.PluginUnavailableCallback.connect(self.slot_handlePluginUnavailableCallback)
  211. # parameter (rack, patchbay)
  212. # program, midi-program, ui-state (rack, patchbay)
  213. # note on, off (rack, patchbay)
  214. # update, reload (rack, patchbay)
  215. # patchbay
  216. self.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  217. self.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  218. self.ProcessModeChangedCallback.connect(self.slot_handleProcessModeChangedCallback)
  219. self.TransportModeChangedCallback.connect(self.slot_handleTransportModeChangedCallback)
  220. self.BufferSizeChangedCallback.connect(self.slot_handleBufferSizeChangedCallback)
  221. self.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  222. self.InfoCallback.connect(self.slot_handleInfoCallback)
  223. self.ErrorCallback.connect(self.slot_handleErrorCallback)
  224. self.QuitCallback.connect(self.slot_handleQuitCallback)
  225. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  226. self.SIGTERM.connect(self.slot_handleSIGTERM)
  227. # -------------------------------------------------------------
  228. # Final setup
  229. QTimer.singleShot(0, self.slot_engineStart)
  230. #QTimer.singleShot(2000, self.slot_test)
  231. #@pyqtSlot()
  232. #def slot_test(self):
  233. #print("test started")
  234. #if not Carla.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, "/usr/bin/zita-rev1", "name of client", "label of client", None):
  235. #print(Carla.host.get_last_error())
  236. #print("test ended")
  237. # -----------------------------------------------------------------
  238. # Called by containers
  239. def openSettingsWindow(self, hasCanvas, hasCanvasGL):
  240. dialog = CarlaSettingsW(self, hasCanvas, hasCanvasGL)
  241. return dialog.exec_()
  242. def setupContainer(self, showMiniCanvas, canvasThemeData = []):
  243. if showMiniCanvas:
  244. canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData
  245. self.ui.miniCanvasPreview.setViewTheme(canvasBg, canvasBrush, canvasPen)
  246. self.ui.miniCanvasPreview.init(self.fContainer.scene, canvasWidth, canvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  247. else:
  248. self.ui.miniCanvasPreview.hide()
  249. self.ui.splitter.insertWidget(1, self.fContainer)
  250. def updateContainer(self, canvasThemeData):
  251. canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData
  252. self.ui.miniCanvasPreview.setViewTheme(canvasBg, canvasBrush, canvasPen)
  253. self.ui.miniCanvasPreview.init(self.fContainer.scene, canvasWidth, canvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  254. # -----------------------------------------------------------------
  255. # Internal stuff (files)
  256. def loadProjectNow(self):
  257. if not self.fProjectFilename:
  258. return qCritical("ERROR: loading project without filename set")
  259. self.fIsProjectLoading = True
  260. Carla.host.load_project(self.fProjectFilename)
  261. self.fIsProjectLoading = False
  262. self.fContainer.projectLoaded()
  263. @pyqtSlot()
  264. def slot_loadProjectNow(self):
  265. self.loadProjectNow()
  266. def loadProjectLater(self, filename):
  267. self.fProjectFilename = filename
  268. self.setProperWindowTitle()
  269. QTimer.singleShot(0, self.slot_loadProjectNow)
  270. def saveProjectNow(self):
  271. if not self.fProjectFilename:
  272. return qCritical("ERROR: saving project without filename set")
  273. Carla.host.save_project(self.fProjectFilename)
  274. # -----------------------------------------------------------------
  275. # Internal stuff (engine)
  276. def setEngineSettings(self, settings = None):
  277. if Carla.isPlugin:
  278. return "Plugin"
  279. if settings is None: settings = QSettings()
  280. # -------------------------------------------------------------
  281. # read settings
  282. # bool values
  283. try:
  284. forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  285. except:
  286. forceStereo = CARLA_DEFAULT_FORCE_STEREO
  287. try:
  288. preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  289. except:
  290. preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  291. try:
  292. preferUiBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  293. except:
  294. preferUiBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  295. try:
  296. uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  297. except:
  298. uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  299. # int values
  300. try:
  301. maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  302. except:
  303. maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  304. try:
  305. uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  306. except:
  307. uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  308. # enums
  309. try:
  310. processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  311. except:
  312. processMode = CARLA_DEFAULT_PROCESS_MODE
  313. try:
  314. transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  315. except:
  316. transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  317. # driver name
  318. try:
  319. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  320. except:
  321. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  322. # driver options
  323. try:
  324. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  325. except:
  326. audioDevice = ""
  327. try:
  328. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  329. except:
  330. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  331. try:
  332. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  333. except:
  334. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  335. try:
  336. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  337. except:
  338. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  339. # -------------------------------------------------------------
  340. # fix things if needed
  341. if processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  342. forceStereo = True
  343. elif processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  344. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  345. processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  346. if audioDriver != "JACK" and transportMode == ENGINE_TRANSPORT_MODE_JACK:
  347. transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  348. # -------------------------------------------------------------
  349. # apply to engine
  350. Carla.host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, forceStereo, "")
  351. Carla.host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, preferPluginBridges, "")
  352. Carla.host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, preferUiBridges, "")
  353. Carla.host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, uisAlwaysOnTop, "")
  354. Carla.host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, maxParameters, "")
  355. Carla.host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, uiBridgesTimeout, "")
  356. Carla.host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, processMode, "")
  357. Carla.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, transportMode, "")
  358. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  359. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  360. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  361. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  362. # save this for later
  363. Carla.maxParameters = maxParameters
  364. # return selected driver name
  365. return audioDriver
  366. def startEngine(self):
  367. audioDriver = self.setEngineSettings()
  368. if not Carla.host.engine_init(audioDriver, self.fClientName):
  369. if self.fFirstEngineInit:
  370. self.fFirstEngineInit = False
  371. return
  372. audioError = Carla.host.get_last_error()
  373. if audioError:
  374. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  375. else:
  376. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  377. return
  378. self.fFirstEngineInit = False
  379. def stopEngine(self):
  380. if self.fContainer.getPluginCount() > 0:
  381. ask = QMessageBox.question(self, self.tr("Warning"), self.tr("There are still some plugins loaded, you need to remove them to stop the engine.\n"
  382. "Do you want to do this now?"),
  383. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  384. if ask != QMessageBox.Yes:
  385. return
  386. self.ui.act_plugin_remove_all.setEnabled(False)
  387. self.fContainer.removeAllPlugins()
  388. if Carla.host.is_engine_running() and not Carla.host.engine_close():
  389. print(Carla.host.get_last_error())
  390. # -----------------------------------------------------------------
  391. # Internal stuff (plugins)
  392. def getExtraPtr(self, plugin):
  393. ptype = plugin['type']
  394. if ptype == PLUGIN_LADSPA:
  395. uniqueId = plugin['uniqueId']
  396. self.maybeLoadRDFs()
  397. for rdfItem in self.fLadspaRdfList:
  398. if rdfItem.UniqueID == uniqueId:
  399. return pointer(rdfItem)
  400. elif ptype in (PLUGIN_FILE_GIG, PLUGIN_FILE_SF2):
  401. if plugin['name'].lower().endswith(" (16 outputs)"):
  402. return c_char_p("true".encode("utf-8"))
  403. return None
  404. def maybeLoadRDFs(self):
  405. if not self.fLadspaRdfNeedsUpdate:
  406. return
  407. self.fLadspaRdfNeedsUpdate = False
  408. self.fLadspaRdfList = []
  409. if not haveLRDF:
  410. return
  411. settingsDir = os.path.join(HOME, ".config", "falkTX")
  412. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  413. if os.path.exists(frLadspaFile):
  414. frLadspa = open(frLadspaFile, 'r')
  415. try:
  416. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  417. except:
  418. pass
  419. frLadspa.close()
  420. def setLoadRDFsNeeded(self):
  421. self.fLadspaRdfNeedsUpdate = True
  422. # -----------------------------------------------------------------
  423. # Internal stuff (transport)
  424. def refreshTransport(self, forced = False):
  425. if Carla.sampleRate == 0.0 or not Carla.host.is_engine_running():
  426. return
  427. timeInfo = Carla.host.get_transport_info()
  428. playing = bool(timeInfo['playing'])
  429. frame = int(timeInfo['frame'])
  430. if playing != self.fLastTransportState or forced:
  431. if playing:
  432. icon = getIcon("media-playback-pause")
  433. self.ui.act_transport_play.setChecked(True)
  434. self.ui.act_transport_play.setIcon(icon)
  435. self.ui.act_transport_play.setText(self.tr("&Pause"))
  436. else:
  437. icon = getIcon("media-playback-start")
  438. self.ui.act_transport_play.setChecked(False)
  439. self.ui.act_transport_play.setIcon(icon)
  440. self.ui.act_transport_play.setText(self.tr("&Play"))
  441. self.fLastTransportState = playing
  442. if frame != self.fLastTransportFrame or forced:
  443. time = frame / Carla.sampleRate
  444. secs = time % 60
  445. mins = (time / 60) % 60
  446. hrs = (time / 3600) % 60
  447. self.fTextTransport = "Transport %s, at %02i:%02i:%02i" % ("playing" if playing else "stopped", hrs, mins, secs)
  448. self.fLastTransportFrame = frame
  449. def setTransportMenuEnabled(self, enabled):
  450. self.ui.act_transport_play.setEnabled(enabled)
  451. self.ui.act_transport_stop.setEnabled(enabled)
  452. self.ui.act_transport_backwards.setEnabled(enabled)
  453. self.ui.act_transport_forwards.setEnabled(enabled)
  454. self.ui.menu_Transport.setEnabled(enabled)
  455. # -----------------------------------------------------------------
  456. # Internal stuff (settings)
  457. def loadSettings(self, firstTime):
  458. settings = QSettings()
  459. if firstTime:
  460. self.restoreGeometry(settings.value("Geometry", ""))
  461. showToolbar = settings.value("ShowToolbar", True, type=bool)
  462. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  463. self.ui.toolBar.setVisible(showToolbar)
  464. if settings.contains("SplitterState"):
  465. self.ui.splitter.restoreState(settings.value("SplitterState", ""))
  466. else:
  467. self.ui.splitter.setSizes([210, 99999])
  468. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  469. self.ui.cb_disk.setItemData(0, HOME)
  470. for i in range(len(diskFolders)):
  471. if i == 0: continue
  472. folder = diskFolders[i]
  473. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  474. if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  475. self.setUnifiedTitleAndToolBarOnMac(True)
  476. # ---------------------------------------------
  477. # plugin checks
  478. if settings.value("Engine/DisableChecks", False, type=bool):
  479. os.environ["CARLA_DISCOVERY_NO_PROCESSING_CHECKS"] = "true"
  480. elif os.getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS"):
  481. os.environ.pop("CARLA_DISCOVERY_NO_PROCESSING_CHECKS")
  482. # ---------------------------------------------
  483. if not Carla.isPlugin:
  484. # engine
  485. self.setEngineSettings(settings)
  486. # plugin paths
  487. LADSPA_PATH = toList(settings.value("Paths/LADSPA", Carla.DEFAULT_LADSPA_PATH))
  488. DSSI_PATH = toList(settings.value("Paths/DSSI", Carla.DEFAULT_DSSI_PATH))
  489. LV2_PATH = toList(settings.value("Paths/LV2", Carla.DEFAULT_LV2_PATH))
  490. VST_PATH = toList(settings.value("Paths/VST", Carla.DEFAULT_VST_PATH))
  491. AU_PATH = toList(settings.value("Paths/AU", Carla.DEFAULT_AU_PATH))
  492. CSOUND_PATH = toList(settings.value("Paths/CSOUND", Carla.DEFAULT_CSOUND_PATH))
  493. GIG_PATH = toList(settings.value("Paths/GIG", Carla.DEFAULT_GIG_PATH))
  494. SF2_PATH = toList(settings.value("Paths/SF2", Carla.DEFAULT_SF2_PATH))
  495. SFZ_PATH = toList(settings.value("Paths/SFZ", Carla.DEFAULT_SFZ_PATH))
  496. os.environ["LADSPA_PATH"] = splitter.join(LADSPA_PATH)
  497. os.environ["DSSI_PATH"] = splitter.join(DSSI_PATH)
  498. os.environ["LV2_PATH"] = splitter.join(LV2_PATH)
  499. os.environ["VST_PATH"] = splitter.join(VST_PATH)
  500. os.environ["AU_PATH"] = splitter.join(AU_PATH)
  501. os.environ["CSOUND_PATH"] = splitter.join(CSOUND_PATH)
  502. os.environ["GIG_PATH"] = splitter.join(GIG_PATH)
  503. os.environ["SF2_PATH"] = splitter.join(SF2_PATH)
  504. os.environ["SFZ_PATH"] = splitter.join(SFZ_PATH)
  505. # ---------------------------------------------
  506. # TODO
  507. self.fSavedSettings = {
  508. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  509. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  510. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  511. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  512. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  513. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  514. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=int),
  515. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  516. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  517. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  518. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  519. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black")
  520. }
  521. # ---------------------------------------------
  522. if self.fIdleTimerFast != 0:
  523. self.killTimer(self.fIdleTimerFast)
  524. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  525. if self.fIdleTimerSlow != 0:
  526. self.killTimer(self.fIdleTimerSlow)
  527. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*2)
  528. def saveSettings(self):
  529. settings = QSettings()
  530. settings.setValue("Geometry", self.saveGeometry())
  531. settings.setValue("SplitterState", self.ui.splitter.saveState())
  532. settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  533. diskFolders = []
  534. for i in range(self.ui.cb_disk.count()):
  535. diskFolders.append(self.ui.cb_disk.itemData(i))
  536. settings.setValue("DiskFolders", diskFolders)
  537. self.fContainer.saveSettings(settings)
  538. # -----------------------------------------------------------------
  539. # Internal stuff (gui)
  540. def setProperWindowTitle(self):
  541. title = self.fClientName
  542. if self.fProjectFilename:
  543. title += " - %s" % os.path.basename(self.fProjectFilename)
  544. if self.fSessionManagerName:
  545. title += " (%s)" % self.fSessionManagerName
  546. self.setWindowTitle(title)
  547. # -----------------------------------------------------------------
  548. @pyqtSlot()
  549. def slot_fileNew(self):
  550. self.fContainer.removeAllPlugins()
  551. self.fProjectFilename = ""
  552. self.setProperWindowTitle()
  553. @pyqtSlot()
  554. def slot_fileOpen(self):
  555. fileFilter = self.tr("Carla Project File (*.carxp)")
  556. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  557. if not filenameTry:
  558. return
  559. filename = filenameTry if isinstance(filenameTry, str) else filenameTry[0]
  560. newFile = True
  561. if self.fContainer.getPluginCount() > 0:
  562. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  563. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  564. newFile = (ask == QMessageBox.Yes)
  565. if newFile:
  566. self.fContainer.removeAllPlugins()
  567. self.fProjectFilename = filename
  568. self.setProperWindowTitle()
  569. self.loadProjectNow()
  570. else:
  571. filenameOld = self.fProjectFilename
  572. self.fProjectFilename = filename
  573. self.loadProjectNow()
  574. self.fProjectFilename = filenameOld
  575. @pyqtSlot()
  576. def slot_fileSave(self, saveAs=False):
  577. if self.fProjectFilename and not saveAs:
  578. return self.saveProjectNow()
  579. fileFilter = self.tr("Carla Project File (*.carxp)")
  580. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  581. if not filenameTry:
  582. return
  583. filename = filenameTry if isinstance(filenameTry, str) else filenameTry[0]
  584. if not filename.endswith(".carxp"):
  585. filename += ".carxp"
  586. if self.fProjectFilename != filename:
  587. self.fProjectFilename = filename
  588. self.setProperWindowTitle()
  589. self.saveProjectNow()
  590. @pyqtSlot()
  591. def slot_fileSaveAs(self):
  592. self.slot_fileSave(True)
  593. # -----------------------------------------------------------------
  594. @pyqtSlot()
  595. def slot_engineStart(self, doStart = True):
  596. if doStart: self.startEngine()
  597. check = Carla.host.is_engine_running()
  598. self.ui.menu_PluginMacros.setEnabled(check)
  599. self.ui.menu_Canvas.setEnabled(check)
  600. if not Carla.isPlugin:
  601. self.ui.act_file_save.setEnabled(check)
  602. self.ui.act_engine_start.setEnabled(not check)
  603. self.ui.act_engine_stop.setEnabled(check)
  604. if self.fSessionManagerName != "Non Session Manager":
  605. self.ui.act_file_open.setEnabled(check)
  606. self.ui.act_file_save_as.setEnabled(check)
  607. self.setTransportMenuEnabled(check)
  608. if check:
  609. if not Carla.isPlugin:
  610. self.refreshTransport(True)
  611. self.fContainer.engineStarted()
  612. @pyqtSlot()
  613. def slot_engineStop(self, doStop = True):
  614. if doStop: self.stopEngine()
  615. # FIXME?
  616. if self.fContainer.getPluginCount() > 0:
  617. self.ui.act_plugin_remove_all.setEnabled(False)
  618. self.fContainer.removeAllPlugins()
  619. check = Carla.host.is_engine_running()
  620. self.ui.menu_PluginMacros.setEnabled(check)
  621. self.ui.menu_Canvas.setEnabled(check)
  622. if not Carla.isPlugin:
  623. self.ui.act_file_save.setEnabled(check)
  624. self.ui.act_engine_start.setEnabled(not check)
  625. self.ui.act_engine_stop.setEnabled(check)
  626. if self.fSessionManagerName != "Non Session Manager":
  627. self.ui.act_file_open.setEnabled(check)
  628. self.ui.act_file_save_as.setEnabled(check)
  629. self.setTransportMenuEnabled(check)
  630. if not check:
  631. self.fTextTransport = ""
  632. self.fContainer.engineStopped()
  633. # -----------------------------------------------------------------
  634. @pyqtSlot()
  635. def slot_pluginAdd(self):
  636. dialog = PluginDatabaseW(self)
  637. if not dialog.exec_():
  638. return
  639. if not Carla.host.is_engine_running():
  640. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  641. return
  642. btype = dialog.fRetPlugin['build']
  643. ptype = dialog.fRetPlugin['type']
  644. filename = dialog.fRetPlugin['filename']
  645. label = dialog.fRetPlugin['label']
  646. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  647. if not Carla.host.add_plugin(btype, ptype, filename, None, label, extraPtr):
  648. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), charPtrToString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  649. return
  650. @pyqtSlot()
  651. def slot_pluginRemoveAll(self):
  652. self.ui.act_plugin_remove_all.setEnabled(False)
  653. self.fContainer.removeAllPlugins()
  654. Carla.host.remove_all_plugins()
  655. # -----------------------------------------------------------------
  656. @pyqtSlot(bool)
  657. def slot_transportPlayPause(self, toggled):
  658. if not Carla.host.is_engine_running():
  659. return
  660. if toggled:
  661. Carla.host.transport_play()
  662. else:
  663. Carla.host.transport_pause()
  664. self.refreshTransport()
  665. @pyqtSlot()
  666. def slot_transportStop(self):
  667. if not Carla.host.is_engine_running():
  668. return
  669. Carla.host.transport_pause()
  670. Carla.host.transport_relocate(0)
  671. self.refreshTransport()
  672. @pyqtSlot()
  673. def slot_transportBackwards(self):
  674. if not Carla.host.is_engine_running():
  675. return
  676. newFrame = Carla.host.get_current_transport_frame() - 100000
  677. if newFrame < 0:
  678. newFrame = 0
  679. Carla.host.transport_relocate(newFrame)
  680. @pyqtSlot()
  681. def slot_transportForwards(self):
  682. if not Carla.host.is_engine_running():
  683. return
  684. newFrame = Carla.host.get_current_transport_frame() + 100000
  685. Carla.host.transport_relocate(newFrame)
  686. # -----------------------------------------------------------------
  687. @pyqtSlot()
  688. def slot_aboutCarla(self):
  689. CarlaAboutW(self).exec_()
  690. @pyqtSlot()
  691. def slot_aboutQt(self):
  692. QApplication.instance().aboutQt()
  693. # -----------------------------------------------------------------
  694. @pyqtSlot(int)
  695. def slot_diskFolderChanged(self, index):
  696. if index < 0:
  697. return
  698. elif index == 0:
  699. filename = HOME
  700. self.ui.b_disk_remove.setEnabled(False)
  701. else:
  702. filename = self.ui.cb_disk.itemData(index)
  703. self.ui.b_disk_remove.setEnabled(True)
  704. self.fDirModel.setRootPath(filename)
  705. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  706. @pyqtSlot()
  707. def slot_diskFolderAdd(self):
  708. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  709. if newPath:
  710. if newPath[-1] == os.sep:
  711. newPath = newPath[:-1]
  712. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  713. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  714. self.ui.b_disk_remove.setEnabled(True)
  715. @pyqtSlot()
  716. def slot_diskFolderRemove(self):
  717. index = self.ui.cb_disk.currentIndex()
  718. if index <= 0:
  719. return
  720. self.ui.cb_disk.removeItem(index)
  721. if self.ui.cb_disk.currentIndex() == 0:
  722. self.ui.b_disk_remove.setEnabled(False)
  723. @pyqtSlot(QModelIndex)
  724. def slot_fileTreeDoubleClicked(self, modelIndex):
  725. filename = self.fDirModel.filePath(modelIndex)
  726. if not Carla.host.load_file(filename):
  727. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  728. self.tr("Failed to load file"),
  729. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  730. # -----------------------------------------------------------------
  731. @pyqtSlot(int, int, int, float, str)
  732. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  733. print("DEBUG:", pluginId, value1, value2, value3, valueStr)
  734. #self.ui.pte_log.appendPlainText(valueStr.replace("", "DEBUG: ").replace("", "ERROR: ").replace("", "").replace("\n", ""))
  735. # -----------------------------------------------------------------
  736. @pyqtSlot(int, str)
  737. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  738. self.fContainer.addPlugin(pluginId, self.fIsProjectLoading)
  739. if self.fContainer.getPluginCount() == 1:
  740. self.ui.act_plugin_remove_all.setEnabled(True)
  741. @pyqtSlot(int)
  742. def slot_handlePluginRemovedCallback(self, pluginId):
  743. self.fContainer.removePlugin(pluginId)
  744. if self.fContainer.getPluginCount() == 0:
  745. self.ui.act_plugin_remove_all.setEnabled(False)
  746. @pyqtSlot(int, str)
  747. def slot_handlePluginRenamedCallback(self, pluginId, newName):
  748. self.fContainer.renamePlugin(pluginId, newName)
  749. @pyqtSlot(int, str)
  750. def slot_handlePluginUnavailableCallback(self, pluginId, errorMsg):
  751. self.fContainer.disablePlugin(pluginId, errorMsg)
  752. # -----------------------------------------------------------------
  753. @pyqtSlot(str)
  754. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  755. Carla.processMode = processMode
  756. Carla.transportMode = transportMode
  757. Carla.bufferSize = Carla.host.get_buffer_size()
  758. Carla.sampleRate = Carla.host.get_sample_rate()
  759. self.slot_engineStart(False)
  760. if self.fIdleTimerFast == 0:
  761. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  762. if self.fIdleTimerSlow == 0:
  763. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*2)
  764. @pyqtSlot()
  765. def slot_handleEngineStoppedCallback(self):
  766. if self.fIdleTimerFast != 0:
  767. self.killTimer(self.fIdleTimerFast)
  768. self.fIdleTimerFast = 0
  769. if self.fIdleTimerSlow != 0:
  770. self.killTimer(self.fIdleTimerSlow)
  771. self.fIdleTimerSlow = 0
  772. self.slot_engineStop(False)
  773. Carla.bufferSize = 0
  774. Carla.sampleRate = 0.0
  775. # -----------------------------------------------------------------
  776. @pyqtSlot(int)
  777. def slot_handleProcessModeChangedCallback(self, newProcessMode):
  778. self.fEngineChanged = True
  779. @pyqtSlot(int)
  780. def slot_handleTransportModeChangedCallback(self, newTransportMode):
  781. self.fEngineChanged = True
  782. # -----------------------------------------------------------------
  783. @pyqtSlot(int)
  784. def slot_handleBufferSizeChangedCallback(self, newBufferSize):
  785. self.fEngineChanged = True
  786. @pyqtSlot(float)
  787. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  788. self.fEngineChanged = True
  789. # -----------------------------------------------------------------
  790. @pyqtSlot(str)
  791. def slot_handleInfoCallback(self, info):
  792. pass
  793. @pyqtSlot(str)
  794. def slot_handleErrorCallback(self, error):
  795. pass
  796. @pyqtSlot()
  797. def slot_handleQuitCallback(self):
  798. pass
  799. # -----------------------------------------------------------------
  800. @pyqtSlot()
  801. def slot_handleSIGUSR1(self):
  802. print("Got SIGUSR1 -> Saving project now")
  803. QTimer.singleShot(0, self.slot_fileSave)
  804. @pyqtSlot()
  805. def slot_handleSIGTERM(self):
  806. print("Got SIGTERM -> Closing now")
  807. self.close()
  808. # -----------------------------------------------------------------
  809. def timerEvent(self, event):
  810. if event.timerId() == self.fIdleTimerFast:
  811. #if not Carla.isPlugin:
  812. Carla.host.engine_idle()
  813. self.refreshTransport()
  814. self.fContainer.idleFast()
  815. elif event.timerId() == self.fIdleTimerSlow:
  816. if self.fEngineChanged:
  817. self.fContainer.engineChanged()
  818. self.fEngineChanged = False
  819. self.fContainer.idleSlow()
  820. QMainWindow.timerEvent(self, event)
  821. def closeEvent(self, event):
  822. if self.fIdleTimerFast != 0:
  823. self.killTimer(self.fIdleTimerFast)
  824. self.fIdleTimerFast = 0
  825. if self.fIdleTimerSlow != 0:
  826. self.killTimer(self.fIdleTimerSlow)
  827. self.fIdleTimerSlow = 0
  828. self.saveSettings()
  829. if Carla.host.is_engine_running():
  830. Carla.host.set_engine_about_to_close()
  831. self.ui.act_plugin_remove_all.setEnabled(False)
  832. self.fContainer.removeAllPlugins()
  833. self.stopEngine()
  834. QMainWindow.closeEvent(self, event)
  835. # ------------------------------------------------------------------------------------------------------------
  836. # Engine callback
  837. def engineCallback(ptr, action, pluginId, value1, value2, value3, valueStr):
  838. if action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  839. Carla.processMode = value1
  840. if Carla.gui is not None:
  841. Carla.gui.ProcessModeChangedCallback.emit(value1)
  842. return
  843. if action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  844. Carla.transportMode = value1
  845. if Carla.gui is not None:
  846. Carla.gui.TransportModeChangedCallback.emit(value1)
  847. return
  848. if action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  849. Carla.bufferSize = value1
  850. if Carla.gui is not None:
  851. Carla.gui.BufferSizeChangedCallback.emit(value1)
  852. return
  853. if action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  854. Carla.sampleRate = value1
  855. if Carla.gui is not None:
  856. Carla.gui.SampleRateChangedCallback.emit(value3)
  857. return
  858. if Carla.gui is None:
  859. print("WARNING: Got engine callback but UI is not ready : ", pluginId, value1, value2, value3, valueStr)
  860. return
  861. valueStr = charPtrToString(valueStr)
  862. if action == ENGINE_CALLBACK_DEBUG:
  863. Carla.gui.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  864. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  865. Carla.gui.PluginAddedCallback.emit(pluginId, valueStr)
  866. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  867. Carla.gui.PluginRemovedCallback.emit(pluginId)
  868. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  869. Carla.gui.PluginRenamedCallback.emit(pluginId, valueStr)
  870. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  871. Carla.gui.PluginUnavailableCallback.emit(pluginId, valueStr)
  872. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  873. Carla.gui.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  874. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  875. Carla.gui.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  876. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  877. Carla.gui.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  878. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  879. Carla.gui.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  880. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  881. Carla.gui.ProgramChangedCallback.emit(pluginId, value1)
  882. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  883. Carla.gui.MidiProgramChangedCallback.emit(pluginId, value1)
  884. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  885. Carla.gui.UiStateChangedCallback.emit(pluginId, value1)
  886. elif action == ENGINE_CALLBACK_NOTE_ON:
  887. Carla.gui.NoteOnCallback.emit(pluginId, value1, value2, int(value3))
  888. elif action == ENGINE_CALLBACK_NOTE_OFF:
  889. Carla.gui.NoteOffCallback.emit(pluginId, value1, value2)
  890. elif action == ENGINE_CALLBACK_UPDATE:
  891. Carla.gui.UpdateCallback.emit(pluginId)
  892. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  893. Carla.gui.ReloadInfoCallback.emit(pluginId)
  894. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  895. Carla.gui.ReloadParametersCallback.emit(pluginId)
  896. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  897. Carla.gui.ReloadProgramsCallback.emit(pluginId)
  898. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  899. Carla.gui.ReloadAllCallback.emit(pluginId)
  900. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  901. Carla.gui.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  902. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  903. Carla.gui.PatchbayClientRemovedCallback.emit(pluginId)
  904. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  905. Carla.gui.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  906. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  907. Carla.gui.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  908. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  909. Carla.gui.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  910. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  911. Carla.gui.PatchbayPortRemovedCallback.emit(pluginId, value1)
  912. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  913. Carla.gui.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  914. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  915. Carla.gui.PatchbayConnectionAddedCallback.emit(pluginId, value1, value2)
  916. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  917. Carla.gui.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  918. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  919. Carla.gui.EngineStartedCallback.emit(value1, value2, valueStr)
  920. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  921. Carla.gui.EngineStoppedCallback.emit()
  922. elif action == ENGINE_CALLBACK_INFO:
  923. Carla.gui.InfoCallback.emit(valueStr)
  924. elif action == ENGINE_CALLBACK_ERROR:
  925. Carla.gui.ErrorCallback.emit(valueStr)
  926. elif action == ENGINE_CALLBACK_QUIT:
  927. Carla.gui.QuitCallback.emit()