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.

1243 lines
48KB

  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. Carla.host.set_file_callback(fileCallback)
  129. # -------------------------------------------------------------
  130. # Internal stuff
  131. self.fIdleTimerFast = 0
  132. self.fIdleTimerSlow = 0
  133. self.fIsProjectLoading = False
  134. self.fProjectFilename = ""
  135. self.fLadspaRdfNeedsUpdate = True
  136. self.fLadspaRdfList = []
  137. self.fLastTransportFrame = 0
  138. self.fLastTransportState = False
  139. self.fTransportText = ""
  140. # when true, call engineChanged() asap
  141. self.fEngineChanged = False
  142. # first attempt of auto-start engine doesn't show an error
  143. self.fFirstEngineInit = True
  144. self.fSavedSettings = {}
  145. if LADISH_APP_NAME:
  146. self.fClientName = LADISH_APP_NAME
  147. self.fSessionManagerName = "LADISH"
  148. elif NSM_URL:
  149. self.fClientName = "Carla.tmp"
  150. self.fSessionManagerName = "Non Session Manager"
  151. else:
  152. self.fClientName = "Carla"
  153. self.fSessionManagerName = ""
  154. # -------------------------------------------------------------
  155. # Load Settings
  156. self.loadSettings(True)
  157. # -------------------------------------------------------------
  158. # Set up GUI (engine stopped)
  159. if Carla.isPlugin:
  160. self.ui.act_file_new.setEnabled(False)
  161. self.ui.act_file_open.setEnabled(False)
  162. self.ui.act_engine_start.setEnabled(False)
  163. self.ui.menu_Engine.setEnabled(False)
  164. else:
  165. self.ui.act_engine_start.setEnabled(True)
  166. self.ui.act_file_save.setEnabled(False)
  167. self.ui.act_file_save_as.setEnabled(False)
  168. self.ui.act_engine_stop.setEnabled(False)
  169. self.ui.act_plugin_remove_all.setEnabled(False)
  170. self.ui.menu_PluginMacros.setEnabled(False)
  171. self.ui.menu_Canvas.setEnabled(False)
  172. self.setTransportMenuEnabled(False)
  173. # -------------------------------------------------------------
  174. # Set up GUI (right panel)
  175. self.fDirModel = QFileSystemModel(self)
  176. self.fDirModel.setRootPath(HOME)
  177. if Carla.host is not None:
  178. self.fDirModel.setNameFilters(Carla.host.get_supported_file_extensions().split(";"))
  179. self.ui.fileTreeView.setModel(self.fDirModel)
  180. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  181. self.ui.fileTreeView.setColumnHidden(1, True)
  182. self.ui.fileTreeView.setColumnHidden(2, True)
  183. self.ui.fileTreeView.setColumnHidden(3, True)
  184. self.ui.fileTreeView.setHeaderHidden(True)
  185. self.setProperWindowTitle()
  186. # -------------------------------------------------------------
  187. # Connect actions to functions
  188. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  189. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  190. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  191. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  192. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  193. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  194. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  195. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  196. self.ui.act_plugin_remove_all.triggered.connect(self.slot_pluginRemoveAll)
  197. self.ui.act_transport_play.triggered.connect(self.slot_transportPlayPause)
  198. self.ui.act_transport_stop.triggered.connect(self.slot_transportStop)
  199. self.ui.act_transport_backwards.triggered.connect(self.slot_transportBackwards)
  200. self.ui.act_transport_forwards.triggered.connect(self.slot_transportForwards)
  201. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  202. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  203. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  204. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  205. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  206. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  207. self.DebugCallback.connect(self.slot_handleDebugCallback)
  208. self.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  209. self.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  210. self.PluginRenamedCallback.connect(self.slot_handlePluginRenamedCallback)
  211. self.PluginUnavailableCallback.connect(self.slot_handlePluginUnavailableCallback)
  212. # parameter (rack, patchbay)
  213. # program, midi-program, ui-state (rack, patchbay)
  214. # note on, off (rack, patchbay)
  215. # update, reload (rack, patchbay)
  216. # patchbay
  217. self.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  218. self.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  219. self.ProcessModeChangedCallback.connect(self.slot_handleProcessModeChangedCallback)
  220. self.TransportModeChangedCallback.connect(self.slot_handleTransportModeChangedCallback)
  221. self.BufferSizeChangedCallback.connect(self.slot_handleBufferSizeChangedCallback)
  222. self.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  223. self.InfoCallback.connect(self.slot_handleInfoCallback)
  224. self.ErrorCallback.connect(self.slot_handleErrorCallback)
  225. self.QuitCallback.connect(self.slot_handleQuitCallback)
  226. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  227. self.SIGTERM.connect(self.slot_handleSIGTERM)
  228. # -------------------------------------------------------------
  229. # Final setup
  230. QTimer.singleShot(0, self.slot_engineStart)
  231. #QTimer.singleShot(2000, self.slot_test)
  232. #@pyqtSlot()
  233. #def slot_test(self):
  234. #print("test started")
  235. #if not Carla.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, "/usr/bin/zita-rev1", "name of client", "label of client", None):
  236. #print(Carla.host.get_last_error())
  237. #print("test ended")
  238. # -----------------------------------------------------------------
  239. # Called by containers
  240. def openSettingsWindow(self, hasCanvas, hasCanvasGL):
  241. dialog = CarlaSettingsW(self, hasCanvas, hasCanvasGL)
  242. return dialog.exec_()
  243. def setupContainer(self, showMiniCanvas, canvasThemeData = []):
  244. if showMiniCanvas:
  245. canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData
  246. self.ui.miniCanvasPreview.setViewTheme(canvasBg, canvasBrush, canvasPen)
  247. self.ui.miniCanvasPreview.init(self.fContainer.scene, canvasWidth, canvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  248. else:
  249. self.ui.miniCanvasPreview.hide()
  250. self.ui.splitter.insertWidget(1, self.fContainer)
  251. def updateContainer(self, canvasThemeData):
  252. canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData
  253. self.ui.miniCanvasPreview.setViewTheme(canvasBg, canvasBrush, canvasPen)
  254. self.ui.miniCanvasPreview.init(self.fContainer.scene, canvasWidth, canvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  255. # -----------------------------------------------------------------
  256. # Internal stuff (files)
  257. def loadProjectNow(self):
  258. if not self.fProjectFilename:
  259. return qCritical("ERROR: loading project without filename set")
  260. self.fIsProjectLoading = True
  261. Carla.host.load_project(self.fProjectFilename)
  262. self.fIsProjectLoading = False
  263. self.fContainer.projectLoaded()
  264. @pyqtSlot()
  265. def slot_loadProjectNow(self):
  266. self.loadProjectNow()
  267. def loadProjectLater(self, filename):
  268. self.fProjectFilename = filename
  269. self.setProperWindowTitle()
  270. QTimer.singleShot(0, self.slot_loadProjectNow)
  271. def saveProjectNow(self):
  272. if not self.fProjectFilename:
  273. return qCritical("ERROR: saving project without filename set")
  274. Carla.host.save_project(self.fProjectFilename)
  275. # -----------------------------------------------------------------
  276. # Internal stuff (engine)
  277. def setEngineSettings(self, settings = None):
  278. if Carla.isPlugin:
  279. return "Plugin"
  280. if settings is None: settings = QSettings()
  281. # -------------------------------------------------------------
  282. # read settings
  283. # bool values
  284. try:
  285. forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  286. except:
  287. forceStereo = CARLA_DEFAULT_FORCE_STEREO
  288. try:
  289. preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  290. except:
  291. preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  292. try:
  293. preferUiBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  294. except:
  295. preferUiBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  296. try:
  297. uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  298. except:
  299. uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  300. # int values
  301. try:
  302. maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  303. except:
  304. maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  305. try:
  306. uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  307. except:
  308. uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  309. # enums
  310. try:
  311. processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  312. except:
  313. processMode = CARLA_DEFAULT_PROCESS_MODE
  314. try:
  315. transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  316. except:
  317. transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  318. # driver name
  319. try:
  320. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  321. except:
  322. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  323. # driver options
  324. try:
  325. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  326. except:
  327. audioDevice = ""
  328. try:
  329. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  330. except:
  331. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  332. try:
  333. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  334. except:
  335. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  336. try:
  337. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  338. except:
  339. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  340. # -------------------------------------------------------------
  341. # fix things if needed
  342. if processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  343. forceStereo = True
  344. elif processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  345. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  346. processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  347. if audioDriver != "JACK" and transportMode == ENGINE_TRANSPORT_MODE_JACK:
  348. transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  349. # -------------------------------------------------------------
  350. # apply to engine
  351. Carla.host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, forceStereo, "")
  352. Carla.host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, uisAlwaysOnTop, "")
  353. if not Carla.isPlugin:
  354. Carla.host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, preferPluginBridges, "")
  355. Carla.host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, preferUiBridges, "")
  356. Carla.host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, maxParameters, "")
  357. Carla.host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, uiBridgesTimeout, "")
  358. Carla.host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, processMode, "")
  359. Carla.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, transportMode, "")
  360. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  361. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  362. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  363. Carla.host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  364. # save this for later
  365. Carla.maxParameters = maxParameters
  366. # return selected driver name
  367. return audioDriver
  368. def startEngine(self):
  369. audioDriver = self.setEngineSettings()
  370. if not Carla.host.engine_init(audioDriver, self.fClientName):
  371. if self.fFirstEngineInit:
  372. self.fFirstEngineInit = False
  373. return
  374. audioError = Carla.host.get_last_error()
  375. if audioError:
  376. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  377. else:
  378. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  379. return
  380. self.fFirstEngineInit = False
  381. def stopEngine(self):
  382. if self.fContainer.getPluginCount() > 0:
  383. 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"
  384. "Do you want to do this now?"),
  385. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  386. if ask != QMessageBox.Yes:
  387. return
  388. self.ui.act_plugin_remove_all.setEnabled(False)
  389. self.fContainer.removeAllPlugins()
  390. if Carla.host.is_engine_running() and not Carla.host.engine_close():
  391. print(Carla.host.get_last_error())
  392. # -----------------------------------------------------------------
  393. # Internal stuff (plugins)
  394. def getExtraPtr(self, plugin):
  395. ptype = plugin['type']
  396. if ptype == PLUGIN_LADSPA:
  397. uniqueId = plugin['uniqueId']
  398. self.maybeLoadRDFs()
  399. for rdfItem in self.fLadspaRdfList:
  400. if rdfItem.UniqueID == uniqueId:
  401. return pointer(rdfItem)
  402. elif ptype in (PLUGIN_FILE_GIG, PLUGIN_FILE_SF2):
  403. if plugin['name'].lower().endswith(" (16 outputs)"):
  404. return c_char_p("true".encode("utf-8"))
  405. return None
  406. def maybeLoadRDFs(self):
  407. if not self.fLadspaRdfNeedsUpdate:
  408. return
  409. self.fLadspaRdfNeedsUpdate = False
  410. self.fLadspaRdfList = []
  411. if not haveLRDF:
  412. return
  413. settingsDir = os.path.join(HOME, ".config", "falkTX")
  414. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  415. if os.path.exists(frLadspaFile):
  416. frLadspa = open(frLadspaFile, 'r')
  417. try:
  418. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  419. except:
  420. pass
  421. frLadspa.close()
  422. def setLoadRDFsNeeded(self):
  423. self.fLadspaRdfNeedsUpdate = True
  424. # -----------------------------------------------------------------
  425. # Internal stuff (transport)
  426. def refreshTransport(self, forced = False):
  427. if Carla.sampleRate == 0.0 or not Carla.host.is_engine_running():
  428. return
  429. timeInfo = Carla.host.get_transport_info()
  430. playing = bool(timeInfo['playing'])
  431. frame = int(timeInfo['frame'])
  432. if playing != self.fLastTransportState or forced:
  433. if playing:
  434. icon = getIcon("media-playback-pause")
  435. self.ui.act_transport_play.setChecked(True)
  436. self.ui.act_transport_play.setIcon(icon)
  437. self.ui.act_transport_play.setText(self.tr("&Pause"))
  438. else:
  439. icon = getIcon("media-playback-start")
  440. self.ui.act_transport_play.setChecked(False)
  441. self.ui.act_transport_play.setIcon(icon)
  442. self.ui.act_transport_play.setText(self.tr("&Play"))
  443. self.fLastTransportState = playing
  444. if frame != self.fLastTransportFrame or forced:
  445. time = frame / Carla.sampleRate
  446. secs = time % 60
  447. mins = (time / 60) % 60
  448. hrs = (time / 3600) % 60
  449. self.fTextTransport = "Transport %s, at %02i:%02i:%02i" % ("playing" if playing else "stopped", hrs, mins, secs)
  450. self.fLastTransportFrame = frame
  451. def setTransportMenuEnabled(self, enabled):
  452. self.ui.act_transport_play.setEnabled(enabled)
  453. self.ui.act_transport_stop.setEnabled(enabled)
  454. self.ui.act_transport_backwards.setEnabled(enabled)
  455. self.ui.act_transport_forwards.setEnabled(enabled)
  456. self.ui.menu_Transport.setEnabled(enabled)
  457. # -----------------------------------------------------------------
  458. # Internal stuff (settings)
  459. def loadSettings(self, firstTime):
  460. settings = QSettings()
  461. if firstTime:
  462. self.restoreGeometry(settings.value("Geometry", ""))
  463. showToolbar = settings.value("ShowToolbar", True, type=bool)
  464. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  465. self.ui.toolBar.setVisible(showToolbar)
  466. if settings.contains("SplitterState"):
  467. self.ui.splitter.restoreState(settings.value("SplitterState", ""))
  468. else:
  469. self.ui.splitter.setSizes([210, 99999])
  470. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  471. self.ui.cb_disk.setItemData(0, HOME)
  472. for i in range(len(diskFolders)):
  473. if i == 0: continue
  474. folder = diskFolders[i]
  475. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  476. if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  477. self.setUnifiedTitleAndToolBarOnMac(True)
  478. # ---------------------------------------------
  479. # plugin checks
  480. if settings.value("Engine/DisableChecks", False, type=bool):
  481. os.environ["CARLA_DISCOVERY_NO_PROCESSING_CHECKS"] = "true"
  482. elif os.getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS"):
  483. os.environ.pop("CARLA_DISCOVERY_NO_PROCESSING_CHECKS")
  484. # ---------------------------------------------
  485. if not Carla.isPlugin:
  486. # engine
  487. self.setEngineSettings(settings)
  488. # plugin paths
  489. LADSPA_PATH = toList(settings.value("Paths/LADSPA", Carla.DEFAULT_LADSPA_PATH))
  490. DSSI_PATH = toList(settings.value("Paths/DSSI", Carla.DEFAULT_DSSI_PATH))
  491. LV2_PATH = toList(settings.value("Paths/LV2", Carla.DEFAULT_LV2_PATH))
  492. VST_PATH = toList(settings.value("Paths/VST", Carla.DEFAULT_VST_PATH))
  493. AU_PATH = toList(settings.value("Paths/AU", Carla.DEFAULT_AU_PATH))
  494. CSOUND_PATH = toList(settings.value("Paths/CSOUND", Carla.DEFAULT_CSOUND_PATH))
  495. GIG_PATH = toList(settings.value("Paths/GIG", Carla.DEFAULT_GIG_PATH))
  496. SF2_PATH = toList(settings.value("Paths/SF2", Carla.DEFAULT_SF2_PATH))
  497. SFZ_PATH = toList(settings.value("Paths/SFZ", Carla.DEFAULT_SFZ_PATH))
  498. os.environ["LADSPA_PATH"] = splitter.join(LADSPA_PATH)
  499. os.environ["DSSI_PATH"] = splitter.join(DSSI_PATH)
  500. os.environ["LV2_PATH"] = splitter.join(LV2_PATH)
  501. os.environ["VST_PATH"] = splitter.join(VST_PATH)
  502. os.environ["AU_PATH"] = splitter.join(AU_PATH)
  503. os.environ["CSOUND_PATH"] = splitter.join(CSOUND_PATH)
  504. os.environ["GIG_PATH"] = splitter.join(GIG_PATH)
  505. os.environ["SF2_PATH"] = splitter.join(SF2_PATH)
  506. os.environ["SFZ_PATH"] = splitter.join(SFZ_PATH)
  507. # ---------------------------------------------
  508. # TODO
  509. self.fSavedSettings = {
  510. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  511. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  512. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  513. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  514. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  515. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  516. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=int),
  517. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  518. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  519. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  520. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  521. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black")
  522. }
  523. # ---------------------------------------------
  524. if self.fIdleTimerFast != 0:
  525. self.killTimer(self.fIdleTimerFast)
  526. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  527. if self.fIdleTimerSlow != 0:
  528. self.killTimer(self.fIdleTimerSlow)
  529. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*2)
  530. def saveSettings(self):
  531. settings = QSettings()
  532. settings.setValue("Geometry", self.saveGeometry())
  533. settings.setValue("SplitterState", self.ui.splitter.saveState())
  534. settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  535. diskFolders = []
  536. for i in range(self.ui.cb_disk.count()):
  537. diskFolders.append(self.ui.cb_disk.itemData(i))
  538. settings.setValue("DiskFolders", diskFolders)
  539. self.fContainer.saveSettings(settings)
  540. # -----------------------------------------------------------------
  541. # Internal stuff (gui)
  542. def killTimers(self):
  543. if self.fIdleTimerFast != 0:
  544. self.killTimer(self.fIdleTimerFast)
  545. self.fIdleTimerFast = 0
  546. if self.fIdleTimerSlow != 0:
  547. self.killTimer(self.fIdleTimerSlow)
  548. self.fIdleTimerSlow = 0
  549. def setProperWindowTitle(self):
  550. title = self.fClientName
  551. if self.fProjectFilename:
  552. title += " - %s" % os.path.basename(self.fProjectFilename)
  553. if self.fSessionManagerName:
  554. title += " (%s)" % self.fSessionManagerName
  555. self.setWindowTitle(title)
  556. # -----------------------------------------------------------------
  557. @pyqtSlot()
  558. def slot_fileNew(self):
  559. self.fContainer.removeAllPlugins()
  560. self.fProjectFilename = ""
  561. self.setProperWindowTitle()
  562. @pyqtSlot()
  563. def slot_fileOpen(self):
  564. fileFilter = self.tr("Carla Project File (*.carxp)")
  565. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  566. if not filenameTry:
  567. return
  568. filename = filenameTry if isinstance(filenameTry, str) else filenameTry[0]
  569. newFile = True
  570. if self.fContainer.getPluginCount() > 0:
  571. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  572. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  573. newFile = (ask == QMessageBox.Yes)
  574. if newFile:
  575. self.fContainer.removeAllPlugins()
  576. self.fProjectFilename = filename
  577. self.setProperWindowTitle()
  578. self.loadProjectNow()
  579. else:
  580. filenameOld = self.fProjectFilename
  581. self.fProjectFilename = filename
  582. self.loadProjectNow()
  583. self.fProjectFilename = filenameOld
  584. @pyqtSlot()
  585. def slot_fileSave(self, saveAs=False):
  586. if self.fProjectFilename and not saveAs:
  587. return self.saveProjectNow()
  588. fileFilter = self.tr("Carla Project File (*.carxp)")
  589. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  590. if not filenameTry:
  591. return
  592. filename = filenameTry if isinstance(filenameTry, str) else filenameTry[0]
  593. if not filename.endswith(".carxp"):
  594. filename += ".carxp"
  595. if self.fProjectFilename != filename:
  596. self.fProjectFilename = filename
  597. self.setProperWindowTitle()
  598. self.saveProjectNow()
  599. @pyqtSlot()
  600. def slot_fileSaveAs(self):
  601. self.slot_fileSave(True)
  602. # -----------------------------------------------------------------
  603. @pyqtSlot()
  604. def slot_engineStart(self, doStart = True):
  605. if doStart: self.startEngine()
  606. check = Carla.host.is_engine_running()
  607. self.ui.menu_PluginMacros.setEnabled(check)
  608. self.ui.menu_Canvas.setEnabled(check)
  609. if not Carla.isPlugin:
  610. self.ui.act_file_save.setEnabled(check)
  611. self.ui.act_engine_start.setEnabled(not check)
  612. self.ui.act_engine_stop.setEnabled(check)
  613. if self.fSessionManagerName != "Non Session Manager":
  614. self.ui.act_file_open.setEnabled(check)
  615. self.ui.act_file_save_as.setEnabled(check)
  616. self.setTransportMenuEnabled(check)
  617. if check:
  618. if not Carla.isPlugin:
  619. self.refreshTransport(True)
  620. self.fContainer.engineStarted()
  621. @pyqtSlot()
  622. def slot_engineStop(self, doStop = True):
  623. if doStop: self.stopEngine()
  624. # FIXME?
  625. if self.fContainer.getPluginCount() > 0:
  626. self.ui.act_plugin_remove_all.setEnabled(False)
  627. self.fContainer.removeAllPlugins()
  628. check = Carla.host.is_engine_running()
  629. self.ui.menu_PluginMacros.setEnabled(check)
  630. self.ui.menu_Canvas.setEnabled(check)
  631. if not Carla.isPlugin:
  632. self.ui.act_file_save.setEnabled(check)
  633. self.ui.act_engine_start.setEnabled(not check)
  634. self.ui.act_engine_stop.setEnabled(check)
  635. if self.fSessionManagerName != "Non Session Manager":
  636. self.ui.act_file_open.setEnabled(check)
  637. self.ui.act_file_save_as.setEnabled(check)
  638. self.setTransportMenuEnabled(check)
  639. if not check:
  640. self.fTextTransport = ""
  641. self.fContainer.engineStopped()
  642. # -----------------------------------------------------------------
  643. @pyqtSlot()
  644. def slot_pluginAdd(self):
  645. dialog = PluginDatabaseW(self)
  646. if not dialog.exec_():
  647. return
  648. if not Carla.host.is_engine_running():
  649. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  650. return
  651. btype = dialog.fRetPlugin['build']
  652. ptype = dialog.fRetPlugin['type']
  653. filename = dialog.fRetPlugin['filename']
  654. label = dialog.fRetPlugin['label']
  655. uniqueId = dialog.fRetPlugin['uniqueId']
  656. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  657. if not Carla.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr):
  658. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), charPtrToString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  659. return
  660. @pyqtSlot()
  661. def slot_pluginRemoveAll(self):
  662. self.ui.act_plugin_remove_all.setEnabled(False)
  663. self.fContainer.removeAllPlugins()
  664. Carla.host.remove_all_plugins()
  665. # -----------------------------------------------------------------
  666. @pyqtSlot(bool)
  667. def slot_transportPlayPause(self, toggled):
  668. if not Carla.host.is_engine_running():
  669. return
  670. if toggled:
  671. Carla.host.transport_play()
  672. else:
  673. Carla.host.transport_pause()
  674. self.refreshTransport()
  675. @pyqtSlot()
  676. def slot_transportStop(self):
  677. if not Carla.host.is_engine_running():
  678. return
  679. Carla.host.transport_pause()
  680. Carla.host.transport_relocate(0)
  681. self.refreshTransport()
  682. @pyqtSlot()
  683. def slot_transportBackwards(self):
  684. if not Carla.host.is_engine_running():
  685. return
  686. newFrame = Carla.host.get_current_transport_frame() - 100000
  687. if newFrame < 0:
  688. newFrame = 0
  689. Carla.host.transport_relocate(newFrame)
  690. @pyqtSlot()
  691. def slot_transportForwards(self):
  692. if not Carla.host.is_engine_running():
  693. return
  694. newFrame = Carla.host.get_current_transport_frame() + 100000
  695. Carla.host.transport_relocate(newFrame)
  696. # -----------------------------------------------------------------
  697. @pyqtSlot()
  698. def slot_aboutCarla(self):
  699. CarlaAboutW(self).exec_()
  700. @pyqtSlot()
  701. def slot_aboutQt(self):
  702. QApplication.instance().aboutQt()
  703. # -----------------------------------------------------------------
  704. @pyqtSlot(int)
  705. def slot_diskFolderChanged(self, index):
  706. if index < 0:
  707. return
  708. elif index == 0:
  709. filename = HOME
  710. self.ui.b_disk_remove.setEnabled(False)
  711. else:
  712. filename = self.ui.cb_disk.itemData(index)
  713. self.ui.b_disk_remove.setEnabled(True)
  714. self.fDirModel.setRootPath(filename)
  715. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  716. @pyqtSlot()
  717. def slot_diskFolderAdd(self):
  718. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  719. if newPath:
  720. if newPath[-1] == os.sep:
  721. newPath = newPath[:-1]
  722. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  723. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  724. self.ui.b_disk_remove.setEnabled(True)
  725. @pyqtSlot()
  726. def slot_diskFolderRemove(self):
  727. index = self.ui.cb_disk.currentIndex()
  728. if index <= 0:
  729. return
  730. self.ui.cb_disk.removeItem(index)
  731. if self.ui.cb_disk.currentIndex() == 0:
  732. self.ui.b_disk_remove.setEnabled(False)
  733. @pyqtSlot(QModelIndex)
  734. def slot_fileTreeDoubleClicked(self, modelIndex):
  735. filename = self.fDirModel.filePath(modelIndex)
  736. if not Carla.host.load_file(filename):
  737. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  738. self.tr("Failed to load file"),
  739. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  740. # -----------------------------------------------------------------
  741. @pyqtSlot(int, int, int, float, str)
  742. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  743. print("DEBUG:", pluginId, value1, value2, value3, valueStr)
  744. #self.ui.pte_log.appendPlainText(valueStr.replace("", "DEBUG: ").replace("", "ERROR: ").replace("", "").replace("\n", ""))
  745. # -----------------------------------------------------------------
  746. @pyqtSlot(int, str)
  747. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  748. self.fContainer.addPlugin(pluginId, self.fIsProjectLoading)
  749. if self.fContainer.getPluginCount() == 1:
  750. self.ui.act_plugin_remove_all.setEnabled(True)
  751. @pyqtSlot(int)
  752. def slot_handlePluginRemovedCallback(self, pluginId):
  753. self.fContainer.removePlugin(pluginId)
  754. if self.fContainer.getPluginCount() == 0:
  755. self.ui.act_plugin_remove_all.setEnabled(False)
  756. @pyqtSlot(int, str)
  757. def slot_handlePluginRenamedCallback(self, pluginId, newName):
  758. self.fContainer.renamePlugin(pluginId, newName)
  759. @pyqtSlot(int, str)
  760. def slot_handlePluginUnavailableCallback(self, pluginId, errorMsg):
  761. self.fContainer.disablePlugin(pluginId, errorMsg)
  762. # -----------------------------------------------------------------
  763. @pyqtSlot(str)
  764. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  765. Carla.processMode = processMode
  766. Carla.transportMode = transportMode
  767. Carla.bufferSize = Carla.host.get_buffer_size()
  768. Carla.sampleRate = Carla.host.get_sample_rate()
  769. self.slot_engineStart(False)
  770. if self.fIdleTimerFast == 0:
  771. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  772. if self.fIdleTimerSlow == 0:
  773. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*2)
  774. @pyqtSlot()
  775. def slot_handleEngineStoppedCallback(self):
  776. self.killTimers()
  777. self.slot_engineStop(False)
  778. Carla.bufferSize = 0
  779. Carla.sampleRate = 0.0
  780. # -----------------------------------------------------------------
  781. @pyqtSlot(int)
  782. def slot_handleProcessModeChangedCallback(self, newProcessMode):
  783. self.fEngineChanged = True
  784. @pyqtSlot(int)
  785. def slot_handleTransportModeChangedCallback(self, newTransportMode):
  786. self.fEngineChanged = True
  787. # -----------------------------------------------------------------
  788. @pyqtSlot(int)
  789. def slot_handleBufferSizeChangedCallback(self, newBufferSize):
  790. self.fEngineChanged = True
  791. @pyqtSlot(float)
  792. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  793. self.fEngineChanged = True
  794. # -----------------------------------------------------------------
  795. @pyqtSlot(str)
  796. def slot_handleInfoCallback(self, info):
  797. QMessageBox.information(self, "Information", info)
  798. @pyqtSlot(str)
  799. def slot_handleErrorCallback(self, error):
  800. QMessageBox.critical(self, "Error", error)
  801. @pyqtSlot()
  802. def slot_handleQuitCallback(self):
  803. pass
  804. # -----------------------------------------------------------------
  805. @pyqtSlot()
  806. def slot_handleSIGUSR1(self):
  807. print("Got SIGUSR1 -> Saving project now")
  808. QTimer.singleShot(0, self.slot_fileSave)
  809. @pyqtSlot()
  810. def slot_handleSIGTERM(self):
  811. print("Got SIGTERM -> Closing now")
  812. self.close()
  813. # -----------------------------------------------------------------
  814. def timerEvent(self, event):
  815. if event.timerId() == self.fIdleTimerFast:
  816. #if not Carla.isPlugin:
  817. Carla.host.engine_idle()
  818. self.refreshTransport()
  819. self.fContainer.idleFast()
  820. elif event.timerId() == self.fIdleTimerSlow:
  821. if self.fEngineChanged:
  822. self.fContainer.engineChanged()
  823. self.fEngineChanged = False
  824. self.fContainer.idleSlow()
  825. QMainWindow.timerEvent(self, event)
  826. def closeEvent(self, event):
  827. self.killTimers()
  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.killTimers()
  922. Carla.gui.EngineStoppedCallback.emit()
  923. elif action == ENGINE_CALLBACK_INFO:
  924. Carla.gui.InfoCallback.emit(valueStr)
  925. elif action == ENGINE_CALLBACK_ERROR:
  926. Carla.gui.ErrorCallback.emit(valueStr)
  927. elif action == ENGINE_CALLBACK_QUIT:
  928. Carla.gui.QuitCallback.emit()
  929. # ------------------------------------------------------------------------------------------------------------
  930. # File callback
  931. def fileCallback(ptr, action, isDir, title, filter):
  932. if Carla.gui is None:
  933. return None
  934. ret = ""
  935. if action == FILE_CALLBACK_DEBUG:
  936. pass
  937. elif action == FILE_CALLBACK_OPEN:
  938. ret = QFileDialog.getOpenFileName(Carla.gui, charPtrToString(title), "", charPtrToString(filter) ) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  939. elif action == FILE_CALLBACK_SAVE:
  940. ret = QFileDialog.getSaveFileName(Carla.gui, charPtrToString(title), "", charPtrToString(filter), QFileDialog.ShowDirsOnly if isDir else 0x0)
  941. if not ret:
  942. return None
  943. Carla.gui._fileRet = c_char_p(ret.encode("utf-8"))
  944. retval = cast(byref(Carla.gui._fileRet), POINTER(c_uintptr))
  945. return retval.contents.value