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.

carla_host.py 52KB

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