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.

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