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.

1346 lines
52KB

  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. #QTimer.singleShot(2000, self.slot_test)
  258. #@pyqtSlot()
  259. #def slot_test(self):
  260. #print("test started")
  261. #if not gCarla.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, "/usr/bin/zita-rev1", "name of client", "label of client", None):
  262. #print(gCarla.host.get_last_error())
  263. #print("test ended")
  264. # -----------------------------------------------------------------
  265. # Called by containers
  266. def openSettingsWindow(self, hasCanvas, hasCanvasGL):
  267. hasEngine = bool(self.fSessionManagerName != "Non Session Manager")
  268. dialog = CarlaSettingsW(self, hasCanvas, hasCanvasGL, hasEngine)
  269. return dialog.exec_()
  270. def setupContainer(self, showCanvas, canvasThemeData = []):
  271. if showCanvas:
  272. canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData
  273. self.ui.miniCanvasPreview.setViewTheme(canvasBg, canvasBrush, canvasPen)
  274. self.ui.miniCanvasPreview.init(self.fContainer.scene, canvasWidth, canvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  275. else:
  276. self.ui.act_canvas_arrange.setVisible(False)
  277. self.ui.act_canvas_print.setVisible(False)
  278. self.ui.act_canvas_refresh.setVisible(False)
  279. self.ui.act_canvas_save_image.setVisible(False)
  280. self.ui.act_canvas_zoom_100.setVisible(False)
  281. self.ui.act_canvas_zoom_fit.setVisible(False)
  282. self.ui.act_canvas_zoom_in.setVisible(False)
  283. self.ui.act_canvas_zoom_out.setVisible(False)
  284. self.ui.act_settings_show_meters.setVisible(False)
  285. self.ui.act_settings_show_keyboard.setVisible(False)
  286. self.ui.menu_Canvas.setEnabled(False)
  287. self.ui.menu_Canvas.setVisible(False)
  288. self.ui.menu_Canvas_Zoom.setEnabled(False)
  289. self.ui.menu_Canvas_Zoom.setVisible(False)
  290. self.ui.miniCanvasPreview.hide()
  291. self.ui.splitter.insertWidget(1, self.fContainer)
  292. def updateContainer(self, canvasThemeData):
  293. canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData
  294. self.ui.miniCanvasPreview.setViewTheme(canvasBg, canvasBrush, canvasPen)
  295. self.ui.miniCanvasPreview.init(self.fContainer.scene, canvasWidth, canvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  296. # -----------------------------------------------------------------
  297. # Internal stuff (files)
  298. def loadProjectNow(self):
  299. if not self.fProjectFilename:
  300. return qCritical("ERROR: loading project without filename set")
  301. self.fContainer.projectLoadingStarted()
  302. self.fIsProjectLoading = True
  303. if gCarla.host is not None:
  304. gCarla.host.load_project(self.fProjectFilename)
  305. self.fIsProjectLoading = False
  306. self.fContainer.projectLoadingFinished()
  307. @pyqtSlot()
  308. def slot_loadProjectNow(self):
  309. self.loadProjectNow()
  310. def loadProjectLater(self, filename):
  311. self.fProjectFilename = filename
  312. self.setProperWindowTitle()
  313. QTimer.singleShot(0, self.slot_loadProjectNow)
  314. def saveProjectNow(self):
  315. if not self.fProjectFilename:
  316. return qCritical("ERROR: saving project without filename set")
  317. gCarla.host.save_project(self.fProjectFilename)
  318. # -----------------------------------------------------------------
  319. # Internal stuff (engine)
  320. def setEngineSettings(self, settings = None):
  321. if gCarla.isPlugin:
  322. return "Plugin"
  323. if self.fSessionManagerName == "Non Session Manager":
  324. return "JACK"
  325. if settings is None: settings = QSettings()
  326. # -------------------------------------------------------------
  327. # read settings
  328. # bool values
  329. try:
  330. forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  331. except:
  332. forceStereo = CARLA_DEFAULT_FORCE_STEREO
  333. try:
  334. preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  335. except:
  336. preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  337. try:
  338. preferUiBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  339. except:
  340. preferUiBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  341. try:
  342. uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  343. except:
  344. uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  345. # int values
  346. try:
  347. maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  348. except:
  349. maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  350. try:
  351. uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  352. except:
  353. uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  354. # enums
  355. try:
  356. processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  357. except:
  358. processMode = CARLA_DEFAULT_PROCESS_MODE
  359. try:
  360. transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  361. except:
  362. transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  363. # driver name
  364. try:
  365. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  366. except:
  367. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  368. # driver options
  369. try:
  370. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  371. except:
  372. audioDevice = ""
  373. try:
  374. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  375. except:
  376. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  377. try:
  378. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  379. except:
  380. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  381. try:
  382. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  383. except:
  384. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  385. if gCarla.processModeForced:
  386. processMode = gCarla.processMode
  387. # -------------------------------------------------------------
  388. # fix things if needed
  389. if processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  390. forceStereo = True
  391. elif processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  392. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  393. processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  394. if audioDriver != "JACK" and transportMode == ENGINE_TRANSPORT_MODE_JACK:
  395. transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  396. if gCarla.host is None:
  397. return audioDriver
  398. # -------------------------------------------------------------
  399. # apply to engine
  400. gCarla.host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, forceStereo, "")
  401. gCarla.host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, uisAlwaysOnTop, "")
  402. if not gCarla.isPlugin:
  403. gCarla.host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, preferPluginBridges, "")
  404. gCarla.host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, preferUiBridges, "")
  405. gCarla.host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, maxParameters, "")
  406. gCarla.host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, uiBridgesTimeout, "")
  407. gCarla.host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, processMode, "")
  408. gCarla.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, transportMode, "")
  409. gCarla.host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  410. gCarla.host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  411. gCarla.host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  412. gCarla.host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  413. # save this for later
  414. gCarla.maxParameters = maxParameters
  415. # return selected driver name
  416. return audioDriver
  417. def startEngine(self):
  418. audioDriver = self.setEngineSettings()
  419. if gCarla.host is not None and not gCarla.host.engine_init(audioDriver, self.fClientName):
  420. if self.fFirstEngineInit:
  421. self.fFirstEngineInit = False
  422. return
  423. audioError = gCarla.host.get_last_error()
  424. if audioError:
  425. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  426. else:
  427. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  428. return
  429. self.fFirstEngineInit = False
  430. def stopEngine(self):
  431. if self.fContainer.getPluginCount() > 0:
  432. 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"
  433. "Do you want to do this now?"),
  434. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  435. if ask != QMessageBox.Yes:
  436. return
  437. self.ui.act_plugin_remove_all.setEnabled(False)
  438. self.fContainer.removeAllPlugins()
  439. if gCarla.host.is_engine_running() and not gCarla.host.engine_close():
  440. print(gCarla.host.get_last_error())
  441. # -----------------------------------------------------------------
  442. # Internal stuff (plugins)
  443. def getExtraPtr(self, plugin):
  444. ptype = plugin['type']
  445. if ptype == PLUGIN_LADSPA:
  446. uniqueId = plugin['uniqueId']
  447. self.maybeLoadRDFs()
  448. for rdfItem in self.fLadspaRdfList:
  449. if rdfItem.UniqueID == uniqueId:
  450. return pointer(rdfItem)
  451. elif ptype in (PLUGIN_FILE_GIG, PLUGIN_FILE_SF2):
  452. if plugin['name'].lower().endswith(" (16 outputs)"):
  453. return c_char_p("true".encode("utf-8"))
  454. return None
  455. def maybeLoadRDFs(self):
  456. if not self.fLadspaRdfNeedsUpdate:
  457. return
  458. self.fLadspaRdfNeedsUpdate = False
  459. self.fLadspaRdfList = []
  460. if not haveLRDF:
  461. return
  462. settingsDir = os.path.join(HOME, ".config", "falkTX")
  463. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  464. if os.path.exists(frLadspaFile):
  465. frLadspa = open(frLadspaFile, 'r')
  466. try:
  467. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  468. except:
  469. pass
  470. frLadspa.close()
  471. def setLoadRDFsNeeded(self):
  472. self.fLadspaRdfNeedsUpdate = True
  473. # -----------------------------------------------------------------
  474. # Internal stuff (transport)
  475. def refreshTransport(self, forced = False):
  476. if gCarla.sampleRate == 0.0 or not gCarla.host.is_engine_running():
  477. return
  478. timeInfo = gCarla.host.get_transport_info()
  479. playing = bool(timeInfo['playing'])
  480. frame = int(timeInfo['frame'])
  481. if playing != self.fLastTransportState or forced:
  482. if playing:
  483. icon = getIcon("media-playback-pause")
  484. self.ui.act_transport_play.setChecked(True)
  485. self.ui.act_transport_play.setIcon(icon)
  486. self.ui.act_transport_play.setText(self.tr("&Pause"))
  487. else:
  488. icon = getIcon("media-playback-start")
  489. self.ui.act_transport_play.setChecked(False)
  490. self.ui.act_transport_play.setIcon(icon)
  491. self.ui.act_transport_play.setText(self.tr("&Play"))
  492. self.fLastTransportState = playing
  493. if frame != self.fLastTransportFrame or forced:
  494. time = frame / gCarla.sampleRate
  495. secs = time % 60
  496. mins = (time / 60) % 60
  497. hrs = (time / 3600) % 60
  498. self.fTextTransport = "Transport %s, at %02i:%02i:%02i" % ("playing" if playing else "stopped", hrs, mins, secs)
  499. self.fLastTransportFrame = frame
  500. def setTransportMenuEnabled(self, enabled):
  501. self.ui.act_transport_play.setEnabled(enabled)
  502. self.ui.act_transport_stop.setEnabled(enabled)
  503. self.ui.act_transport_backwards.setEnabled(enabled)
  504. self.ui.act_transport_forwards.setEnabled(enabled)
  505. self.ui.menu_Transport.setEnabled(enabled)
  506. # -----------------------------------------------------------------
  507. # Internal stuff (settings)
  508. def loadSettings(self, firstTime):
  509. settings = QSettings()
  510. if firstTime:
  511. self.restoreGeometry(settings.value("Geometry", ""))
  512. showToolbar = settings.value("ShowToolbar", True, type=bool)
  513. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  514. self.ui.toolBar.setVisible(showToolbar)
  515. if settings.contains("SplitterState"):
  516. self.ui.splitter.restoreState(settings.value("SplitterState", ""))
  517. else:
  518. self.ui.splitter.setSizes([210, 99999])
  519. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  520. self.ui.cb_disk.setItemData(0, HOME)
  521. for i in range(len(diskFolders)):
  522. if i == 0: continue
  523. folder = diskFolders[i]
  524. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  525. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  526. # self.setUnifiedTitleAndToolBarOnMac(True)
  527. # ---------------------------------------------
  528. if not gCarla.isPlugin:
  529. # engine
  530. self.setEngineSettings(settings)
  531. # plugin paths
  532. LADSPA_PATH = toList(settings.value("Paths/LADSPA", gCarla.DEFAULT_LADSPA_PATH))
  533. DSSI_PATH = toList(settings.value("Paths/DSSI", gCarla.DEFAULT_DSSI_PATH))
  534. LV2_PATH = toList(settings.value("Paths/LV2", gCarla.DEFAULT_LV2_PATH))
  535. VST_PATH = toList(settings.value("Paths/VST", gCarla.DEFAULT_VST_PATH))
  536. AU_PATH = toList(settings.value("Paths/AU", gCarla.DEFAULT_AU_PATH))
  537. CSOUND_PATH = toList(settings.value("Paths/CSOUND", gCarla.DEFAULT_CSOUND_PATH))
  538. GIG_PATH = toList(settings.value("Paths/GIG", gCarla.DEFAULT_GIG_PATH))
  539. SF2_PATH = toList(settings.value("Paths/SF2", gCarla.DEFAULT_SF2_PATH))
  540. SFZ_PATH = toList(settings.value("Paths/SFZ", gCarla.DEFAULT_SFZ_PATH))
  541. os.environ["LADSPA_PATH"] = splitter.join(LADSPA_PATH)
  542. os.environ["DSSI_PATH"] = splitter.join(DSSI_PATH)
  543. os.environ["LV2_PATH"] = splitter.join(LV2_PATH)
  544. os.environ["VST_PATH"] = splitter.join(VST_PATH)
  545. os.environ["AU_PATH"] = splitter.join(AU_PATH)
  546. os.environ["CSOUND_PATH"] = splitter.join(CSOUND_PATH)
  547. os.environ["GIG_PATH"] = splitter.join(GIG_PATH)
  548. os.environ["SF2_PATH"] = splitter.join(SF2_PATH)
  549. os.environ["SFZ_PATH"] = splitter.join(SFZ_PATH)
  550. # ---------------------------------------------
  551. # TODO
  552. self.fSavedSettings = {
  553. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  554. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  555. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  556. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  557. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  558. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  559. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=int),
  560. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  561. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  562. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  563. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  564. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black")
  565. }
  566. # ---------------------------------------------
  567. if self.fIdleTimerFast != 0:
  568. self.killTimer(self.fIdleTimerFast)
  569. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  570. if self.fIdleTimerSlow != 0:
  571. self.killTimer(self.fIdleTimerSlow)
  572. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  573. def saveSettings(self):
  574. settings = QSettings()
  575. settings.setValue("Geometry", self.saveGeometry())
  576. settings.setValue("SplitterState", self.ui.splitter.saveState())
  577. settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  578. diskFolders = []
  579. for i in range(self.ui.cb_disk.count()):
  580. diskFolders.append(self.ui.cb_disk.itemData(i))
  581. settings.setValue("DiskFolders", diskFolders)
  582. self.fContainer.saveSettings(settings)
  583. # -----------------------------------------------------------------
  584. # Internal stuff (gui)
  585. def killTimers(self):
  586. if self.fIdleTimerFast != 0:
  587. self.killTimer(self.fIdleTimerFast)
  588. self.fIdleTimerFast = 0
  589. if self.fIdleTimerSlow != 0:
  590. self.killTimer(self.fIdleTimerSlow)
  591. self.fIdleTimerSlow = 0
  592. def setProperWindowTitle(self):
  593. title = self.fClientName
  594. if self.fProjectFilename:
  595. title += " - %s" % os.path.basename(self.fProjectFilename)
  596. if self.fSessionManagerName:
  597. title += " (%s)" % self.fSessionManagerName
  598. self.setWindowTitle(title)
  599. # -----------------------------------------------------------------
  600. @pyqtSlot()
  601. def slot_fileNew(self):
  602. self.fContainer.removeAllPlugins()
  603. self.fProjectFilename = ""
  604. self.setProperWindowTitle()
  605. @pyqtSlot()
  606. def slot_fileOpen(self):
  607. fileFilter = self.tr("Carla Project File (*.carxp)")
  608. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  609. if not filenameTry:
  610. return
  611. filename = filenameTry if isinstance(filenameTry, str) else filenameTry[0]
  612. newFile = True
  613. if self.fContainer.getPluginCount() > 0:
  614. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  615. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  616. newFile = (ask == QMessageBox.Yes)
  617. if newFile:
  618. self.fContainer.removeAllPlugins()
  619. self.fProjectFilename = filename
  620. self.setProperWindowTitle()
  621. self.loadProjectNow()
  622. else:
  623. filenameOld = self.fProjectFilename
  624. self.fProjectFilename = filename
  625. self.loadProjectNow()
  626. self.fProjectFilename = filenameOld
  627. @pyqtSlot()
  628. def slot_fileSave(self, saveAs=False):
  629. if self.fProjectFilename and not saveAs:
  630. return self.saveProjectNow()
  631. fileFilter = self.tr("Carla Project File (*.carxp)")
  632. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  633. if not filenameTry:
  634. return
  635. filename = filenameTry if isinstance(filenameTry, str) else filenameTry[0]
  636. if not filename.endswith(".carxp"):
  637. filename += ".carxp"
  638. if self.fProjectFilename != filename:
  639. self.fProjectFilename = filename
  640. self.setProperWindowTitle()
  641. self.saveProjectNow()
  642. @pyqtSlot()
  643. def slot_fileSaveAs(self):
  644. self.slot_fileSave(True)
  645. # -----------------------------------------------------------------
  646. @pyqtSlot()
  647. def slot_engineStart(self, doStart = True):
  648. if doStart: self.startEngine()
  649. check = gCarla.host is not None and gCarla.host.is_engine_running()
  650. self.ui.menu_PluginMacros.setEnabled(check)
  651. self.ui.menu_Canvas.setEnabled(check)
  652. if not gCarla.isPlugin:
  653. self.ui.act_engine_start.setEnabled(not check)
  654. self.ui.act_engine_stop.setEnabled(check)
  655. if not self.fSessionManagerName:
  656. self.ui.act_file_open.setEnabled(check)
  657. self.ui.act_file_save.setEnabled(check)
  658. self.ui.act_file_save_as.setEnabled(check)
  659. self.setTransportMenuEnabled(check)
  660. if check:
  661. if not gCarla.isPlugin:
  662. self.refreshTransport(True)
  663. self.fContainer.engineStarted()
  664. @pyqtSlot()
  665. def slot_engineStop(self, doStop = True):
  666. if doStop: self.stopEngine()
  667. # FIXME?
  668. if self.fContainer.getPluginCount() > 0:
  669. self.ui.act_plugin_remove_all.setEnabled(False)
  670. self.fContainer.removeAllPlugins()
  671. check = gCarla.host.is_engine_running()
  672. self.ui.menu_PluginMacros.setEnabled(check)
  673. self.ui.menu_Canvas.setEnabled(check)
  674. if not gCarla.isPlugin:
  675. self.ui.act_engine_start.setEnabled(not check)
  676. self.ui.act_engine_stop.setEnabled(check)
  677. if not self.fSessionManagerName:
  678. self.ui.act_file_open.setEnabled(check)
  679. self.ui.act_file_save.setEnabled(check)
  680. self.ui.act_file_save_as.setEnabled(check)
  681. self.setTransportMenuEnabled(check)
  682. if not check:
  683. self.fTextTransport = ""
  684. self.fContainer.engineStopped()
  685. # -----------------------------------------------------------------
  686. @pyqtSlot()
  687. def slot_pluginAdd(self, pluginToReplace = -1):
  688. dialog = PluginDatabaseW(self)
  689. if not dialog.exec_():
  690. return
  691. if gCarla.host is not None and not gCarla.host.is_engine_running():
  692. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  693. return
  694. btype = dialog.fRetPlugin['build']
  695. ptype = dialog.fRetPlugin['type']
  696. filename = dialog.fRetPlugin['filename']
  697. label = dialog.fRetPlugin['label']
  698. uniqueId = dialog.fRetPlugin['uniqueId']
  699. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  700. if pluginToReplace >= 0:
  701. if not gCarla.host.replace_plugin(pluginToReplace):
  702. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), gCarla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  703. return
  704. ok = gCarla.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr)
  705. if pluginToReplace >= 0:
  706. gCarla.host.replace_plugin(self.fContainer.getPluginCount())
  707. if not ok:
  708. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), gCarla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  709. @pyqtSlot()
  710. def slot_pluginRemoveAll(self):
  711. self.ui.act_plugin_remove_all.setEnabled(False)
  712. count = self.fContainer.getPluginCount()
  713. if count == 0:
  714. return
  715. self.fContainer.projectLoadingStarted()
  716. app = QApplication.instance()
  717. for i in range(count):
  718. app.processEvents()
  719. gCarla.host.remove_plugin(count-i-1)
  720. self.fContainer.projectLoadingFinished()
  721. #self.fContainer.removeAllPlugins()
  722. #gCarla.host.remove_all_plugins()
  723. # -----------------------------------------------------------------
  724. @pyqtSlot(bool)
  725. def slot_transportPlayPause(self, toggled):
  726. if not gCarla.host.is_engine_running():
  727. return
  728. if toggled:
  729. gCarla.host.transport_play()
  730. else:
  731. gCarla.host.transport_pause()
  732. self.refreshTransport()
  733. @pyqtSlot()
  734. def slot_transportStop(self):
  735. if not gCarla.host.is_engine_running():
  736. return
  737. gCarla.host.transport_pause()
  738. gCarla.host.transport_relocate(0)
  739. self.refreshTransport()
  740. @pyqtSlot()
  741. def slot_transportBackwards(self):
  742. if not gCarla.host.is_engine_running():
  743. return
  744. newFrame = gCarla.host.get_current_transport_frame() - 100000
  745. if newFrame < 0:
  746. newFrame = 0
  747. gCarla.host.transport_relocate(newFrame)
  748. @pyqtSlot()
  749. def slot_transportForwards(self):
  750. if not gCarla.host.is_engine_running():
  751. return
  752. newFrame = gCarla.host.get_current_transport_frame() + 100000
  753. gCarla.host.transport_relocate(newFrame)
  754. # -----------------------------------------------------------------
  755. @pyqtSlot()
  756. def slot_aboutCarla(self):
  757. CarlaAboutW(self).exec_()
  758. @pyqtSlot()
  759. def slot_aboutQt(self):
  760. QApplication.instance().aboutQt()
  761. # -----------------------------------------------------------------
  762. @pyqtSlot(int)
  763. def slot_diskFolderChanged(self, index):
  764. if index < 0:
  765. return
  766. elif index == 0:
  767. filename = HOME
  768. self.ui.b_disk_remove.setEnabled(False)
  769. else:
  770. filename = self.ui.cb_disk.itemData(index)
  771. self.ui.b_disk_remove.setEnabled(True)
  772. self.fDirModel.setRootPath(filename)
  773. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  774. @pyqtSlot()
  775. def slot_diskFolderAdd(self):
  776. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  777. if newPath:
  778. if newPath[-1] == os.sep:
  779. newPath = newPath[:-1]
  780. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  781. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  782. self.ui.b_disk_remove.setEnabled(True)
  783. @pyqtSlot()
  784. def slot_diskFolderRemove(self):
  785. index = self.ui.cb_disk.currentIndex()
  786. if index <= 0:
  787. return
  788. self.ui.cb_disk.removeItem(index)
  789. if self.ui.cb_disk.currentIndex() == 0:
  790. self.ui.b_disk_remove.setEnabled(False)
  791. @pyqtSlot(QModelIndex)
  792. def slot_fileTreeDoubleClicked(self, modelIndex):
  793. filename = self.fDirModel.filePath(modelIndex)
  794. if not gCarla.host.load_file(filename):
  795. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  796. self.tr("Failed to load file"),
  797. gCarla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  798. # -----------------------------------------------------------------
  799. @pyqtSlot(int, int, int, float, str)
  800. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  801. print("DEBUG:", pluginId, value1, value2, value3, valueStr)
  802. #self.ui.pte_log.appendPlainText(valueStr.replace("", "DEBUG: ").replace("", "ERROR: ").replace("", "").replace("\n", ""))
  803. # -----------------------------------------------------------------
  804. @pyqtSlot(int, str)
  805. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  806. self.fContainer.addPlugin(pluginId, self.fIsProjectLoading)
  807. if self.fContainer.getPluginCount() == 1:
  808. self.ui.act_plugin_remove_all.setEnabled(True)
  809. @pyqtSlot(int)
  810. def slot_handlePluginRemovedCallback(self, pluginId):
  811. self.fContainer.removePlugin(pluginId)
  812. if self.fContainer.getPluginCount() == 0:
  813. self.ui.act_plugin_remove_all.setEnabled(False)
  814. @pyqtSlot(int, str)
  815. def slot_handlePluginRenamedCallback(self, pluginId, newName):
  816. self.fContainer.renamePlugin(pluginId, newName)
  817. @pyqtSlot(int, str)
  818. def slot_handlePluginUnavailableCallback(self, pluginId, errorMsg):
  819. self.fContainer.disablePlugin(pluginId, errorMsg)
  820. # -----------------------------------------------------------------
  821. @pyqtSlot(str)
  822. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  823. gCarla.processMode = processMode
  824. gCarla.transportMode = transportMode
  825. gCarla.bufferSize = gCarla.host.get_buffer_size()
  826. gCarla.sampleRate = gCarla.host.get_sample_rate()
  827. self.slot_engineStart(False)
  828. if self.fIdleTimerFast == 0:
  829. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  830. if self.fIdleTimerSlow == 0:
  831. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  832. @pyqtSlot()
  833. def slot_handleEngineStoppedCallback(self):
  834. self.killTimers()
  835. self.slot_engineStop(False)
  836. gCarla.bufferSize = 0
  837. gCarla.sampleRate = 0.0
  838. # -----------------------------------------------------------------
  839. @pyqtSlot(int)
  840. def slot_handleProcessModeChangedCallback(self, newProcessMode):
  841. self.fEngineChanged = True
  842. @pyqtSlot(int)
  843. def slot_handleTransportModeChangedCallback(self, newTransportMode):
  844. self.fEngineChanged = True
  845. # -----------------------------------------------------------------
  846. @pyqtSlot(int)
  847. def slot_handleBufferSizeChangedCallback(self, newBufferSize):
  848. self.fEngineChanged = True
  849. @pyqtSlot(float)
  850. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  851. self.fEngineChanged = True
  852. # -----------------------------------------------------------------
  853. @pyqtSlot(str)
  854. def slot_handleInfoCallback(self, info):
  855. QMessageBox.information(self, "Information", info)
  856. @pyqtSlot(str)
  857. def slot_handleErrorCallback(self, error):
  858. QMessageBox.critical(self, "Error", error)
  859. @pyqtSlot()
  860. def slot_handleQuitCallback(self):
  861. pass
  862. # -----------------------------------------------------------------
  863. @pyqtSlot()
  864. def slot_handleSIGUSR1(self):
  865. print("Got SIGUSR1 -> Saving project now")
  866. QTimer.singleShot(0, self.slot_fileSave)
  867. @pyqtSlot()
  868. def slot_handleSIGTERM(self):
  869. print("Got SIGTERM -> Closing now")
  870. self.close()
  871. # -----------------------------------------------------------------
  872. def showEvent(self, event):
  873. QMainWindow.showEvent(self, event)
  874. # set our gui as parent for all plugins UIs
  875. if gCarla.host is not None:
  876. gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "%x" % self.winId())
  877. def timerEvent(self, event):
  878. if event.timerId() == self.fIdleTimerFast:
  879. #if not gCarla.isPlugin:
  880. gCarla.host.engine_idle()
  881. self.refreshTransport()
  882. self.fContainer.idleFast()
  883. elif event.timerId() == self.fIdleTimerSlow:
  884. if self.fEngineChanged:
  885. self.fContainer.engineChanged()
  886. self.fEngineChanged = False
  887. self.fContainer.idleSlow()
  888. QMainWindow.timerEvent(self, event)
  889. def closeEvent(self, event):
  890. self.killTimers()
  891. self.saveSettings()
  892. if gCarla.host is None or gCarla.isPlugin:
  893. pass
  894. elif gCarla.host.is_engine_running():
  895. gCarla.host.set_engine_about_to_close()
  896. count = self.fContainer.getPluginCount()
  897. if count > 0:
  898. # simulate project loading, to disable container
  899. self.ui.act_plugin_remove_all.setEnabled(False)
  900. self.fContainer.projectLoadingStarted()
  901. app = QApplication.instance()
  902. for i in range(count):
  903. app.processEvents()
  904. gCarla.host.remove_plugin(count-i-1)
  905. app.processEvents()
  906. #self.fContainer.removeAllPlugins()
  907. #gCarla.host.remove_all_plugins()
  908. self.stopEngine()
  909. QMainWindow.closeEvent(self, event)
  910. # ------------------------------------------------------------------------------------------------------------
  911. # Engine callback
  912. def engineCallback(ptr, action, pluginId, value1, value2, value3, valueStr):
  913. if action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  914. gCarla.processMode = value1
  915. if gCarla.gui is not None:
  916. gCarla.gui.ProcessModeChangedCallback.emit(value1)
  917. return
  918. if action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  919. gCarla.transportMode = value1
  920. if gCarla.gui is not None:
  921. gCarla.gui.TransportModeChangedCallback.emit(value1)
  922. return
  923. if action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  924. gCarla.bufferSize = value1
  925. if gCarla.gui is not None:
  926. gCarla.gui.BufferSizeChangedCallback.emit(value1)
  927. return
  928. if action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  929. gCarla.sampleRate = value1
  930. if gCarla.gui is not None:
  931. gCarla.gui.SampleRateChangedCallback.emit(value3)
  932. return
  933. if gCarla.gui is None:
  934. print("WARNING: Got engine callback but UI is not ready : ", pluginId, value1, value2, value3, valueStr)
  935. return
  936. valueStr = charPtrToString(valueStr)
  937. if action == ENGINE_CALLBACK_DEBUG:
  938. gCarla.gui.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  939. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  940. gCarla.gui.PluginAddedCallback.emit(pluginId, valueStr)
  941. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  942. gCarla.gui.PluginRemovedCallback.emit(pluginId)
  943. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  944. gCarla.gui.PluginRenamedCallback.emit(pluginId, valueStr)
  945. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  946. gCarla.gui.PluginUnavailableCallback.emit(pluginId, valueStr)
  947. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  948. gCarla.gui.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  949. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  950. gCarla.gui.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  951. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  952. gCarla.gui.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  953. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  954. gCarla.gui.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  955. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  956. gCarla.gui.ProgramChangedCallback.emit(pluginId, value1)
  957. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  958. gCarla.gui.MidiProgramChangedCallback.emit(pluginId, value1)
  959. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  960. gCarla.gui.UiStateChangedCallback.emit(pluginId, value1)
  961. elif action == ENGINE_CALLBACK_NOTE_ON:
  962. gCarla.gui.NoteOnCallback.emit(pluginId, value1, value2, int(value3))
  963. elif action == ENGINE_CALLBACK_NOTE_OFF:
  964. gCarla.gui.NoteOffCallback.emit(pluginId, value1, value2)
  965. elif action == ENGINE_CALLBACK_UPDATE:
  966. gCarla.gui.UpdateCallback.emit(pluginId)
  967. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  968. gCarla.gui.ReloadInfoCallback.emit(pluginId)
  969. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  970. gCarla.gui.ReloadParametersCallback.emit(pluginId)
  971. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  972. gCarla.gui.ReloadProgramsCallback.emit(pluginId)
  973. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  974. gCarla.gui.ReloadAllCallback.emit(pluginId)
  975. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  976. gCarla.gui.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  977. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  978. gCarla.gui.PatchbayClientRemovedCallback.emit(pluginId)
  979. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  980. gCarla.gui.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  981. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  982. gCarla.gui.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  983. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  984. gCarla.gui.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  985. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  986. gCarla.gui.PatchbayPortRemovedCallback.emit(pluginId, value1)
  987. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  988. gCarla.gui.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  989. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  990. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  991. gCarla.gui.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  992. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  993. gCarla.gui.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  994. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  995. gCarla.gui.EngineStartedCallback.emit(value1, value2, valueStr)
  996. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  997. gCarla.gui.killTimers()
  998. gCarla.gui.EngineStoppedCallback.emit()
  999. elif action == ENGINE_CALLBACK_IDLE:
  1000. QApplication.instance().processEvents()
  1001. elif action == ENGINE_CALLBACK_INFO:
  1002. gCarla.gui.InfoCallback.emit(valueStr)
  1003. elif action == ENGINE_CALLBACK_ERROR:
  1004. gCarla.gui.ErrorCallback.emit(valueStr)
  1005. elif action == ENGINE_CALLBACK_QUIT:
  1006. gCarla.gui.QuitCallback.emit()
  1007. # ------------------------------------------------------------------------------------------------------------
  1008. # File callback
  1009. def fileCallback(ptr, action, isDir, title, filter):
  1010. if gCarla.gui is None:
  1011. return None
  1012. ret = ""
  1013. if action == FILE_CALLBACK_DEBUG:
  1014. pass
  1015. elif action == FILE_CALLBACK_OPEN:
  1016. ret = QFileDialog.getOpenFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter) ) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1017. elif action == FILE_CALLBACK_SAVE:
  1018. ret = QFileDialog.getSaveFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter), QFileDialog.ShowDirsOnly if isDir else 0x0)
  1019. if not ret:
  1020. return None
  1021. gCarla.gui._fileRet = c_char_p(ret.encode("utf-8"))
  1022. retval = cast(byref(gCarla.gui._fileRet), POINTER(c_uintptr))
  1023. return retval.contents.value