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.

1320 lines
51KB

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