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.

1336 lines
51KB

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