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.

1628 lines
67KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla plugin host
  4. # Copyright (C) 2011-2013 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 GPL.txt file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt4.QtCore import Qt, QPointF, QSize
  20. from PyQt4.QtGui import QApplication, QDialogButtonBox, QMainWindow, QResizeEvent
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Imports (Custom Stuff)
  23. import patchcanvas
  24. import ui_carla
  25. import ui_carla_settings
  26. from carla_backend import * # FIXME, remove later
  27. from carla_shared import *
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Try Import OpenGL
  30. try:
  31. from PyQt4.QtOpenGL import QGLWidget
  32. hasGL = True
  33. except:
  34. hasGL = False
  35. # ------------------------------------------------------------------------------------------------------------
  36. # Static Variables
  37. DEFAULT_CANVAS_WIDTH = 3100
  38. DEFAULT_CANVAS_HEIGHT = 2400
  39. # Tab indexes
  40. TAB_INDEX_MAIN = 0
  41. TAB_INDEX_CANVAS = 1
  42. TAB_INDEX_CARLA_ENGINE = 2
  43. TAB_INDEX_CARLA_PATHS = 3
  44. TAB_INDEX_NONE = 4
  45. # Single and Multiple client mode is only for JACK,
  46. # but we still want to match QComboBox index to defines,
  47. # so add +2 pos padding if driverName != "JACK".
  48. PROCESS_MODE_NON_JACK_PADDING = 2
  49. # Carla defaults
  50. CARLA_DEFAULT_PROCESS_HIGH_PRECISION = False
  51. CARLA_DEFAULT_MAX_PARAMETERS = 200
  52. CARLA_DEFAULT_FORCE_STEREO = False
  53. CARLA_DEFAULT_USE_DSSI_VST_CHUNKS = False
  54. CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES = False
  55. CARLA_DEFAULT_PREFER_UI_BRIDGES = True
  56. CARLA_DEFAULT_OSC_UI_TIMEOUT = 4000
  57. CARLA_DEFAULT_DISABLE_CHECKS = False
  58. # PatchCanvas defines
  59. CANVAS_ANTIALIASING_SMALL = 1
  60. CANVAS_EYECANDY_SMALL = 1
  61. # ------------------------------------------------------------------------------------------------------------
  62. # Settings Dialog
  63. class CarlaSettingsW(QDialog):
  64. def __init__(self, parent):
  65. QDialog.__init__(self, parent)
  66. self.ui = ui_carla_settings.Ui_CarlaSettingsW()
  67. self.ui.setupUi(self)
  68. # TODO
  69. self.ui.lw_page.hideRow(TAB_INDEX_CANVAS)
  70. # -------------------------------------------------------------
  71. # Load settings
  72. self.loadSettings()
  73. # -------------------------------------------------------------
  74. # Set-up GUI
  75. driverCount = Carla.host.get_engine_driver_count()
  76. for i in range(driverCount):
  77. driverName = cString(Carla.host.get_engine_driver_name(i))
  78. self.ui.cb_engine_audio_driver.addItem(driverName)
  79. #if not hasOpenGL:
  80. #self.cb_canvas_use_opengl.setChecked(False)
  81. #self.cb_canvas_use_opengl.setEnabled(False)
  82. # -------------------------------------------------------------
  83. # Set-up connections
  84. self.connect(self, SIGNAL("accepted()"), SLOT("slot_saveSettings()"))
  85. self.connect(self.ui.buttonBox.button(QDialogButtonBox.Reset), SIGNAL("clicked()"), SLOT("slot_resetSettings()"))
  86. self.connect(self.ui.b_main_def_folder_open, SIGNAL("clicked()"), SLOT("slot_getAndSetProjectPath()"))
  87. self.connect(self.ui.cb_engine_audio_driver, SIGNAL("currentIndexChanged(int)"), SLOT("slot_engineAudioDriverChanged()"))
  88. self.connect(self.ui.b_paths_add, SIGNAL("clicked()"), SLOT("slot_addPluginPath()"))
  89. self.connect(self.ui.b_paths_remove, SIGNAL("clicked()"), SLOT("slot_removePluginPath()"))
  90. self.connect(self.ui.b_paths_change, SIGNAL("clicked()"), SLOT("slot_changePluginPath()"))
  91. self.connect(self.ui.tw_paths, SIGNAL("currentChanged(int)"), SLOT("slot_pluginPathTabChanged(int)"))
  92. self.connect(self.ui.lw_ladspa, SIGNAL("currentRowChanged(int)"), SLOT("slot_pluginPathRowChanged(int)"))
  93. self.connect(self.ui.lw_dssi, SIGNAL("currentRowChanged(int)"), SLOT("slot_pluginPathRowChanged(int)"))
  94. self.connect(self.ui.lw_lv2, SIGNAL("currentRowChanged(int)"), SLOT("slot_pluginPathRowChanged(int)"))
  95. self.connect(self.ui.lw_vst, SIGNAL("currentRowChanged(int)"), SLOT("slot_pluginPathRowChanged(int)"))
  96. self.connect(self.ui.lw_sf2, SIGNAL("currentRowChanged(int)"), SLOT("slot_pluginPathRowChanged(int)"))
  97. # -------------------------------------------------------------
  98. # Post-connect setup
  99. self.ui.lw_ladspa.setCurrentRow(0)
  100. self.ui.lw_dssi.setCurrentRow(0)
  101. self.ui.lw_lv2.setCurrentRow(0)
  102. self.ui.lw_vst.setCurrentRow(0)
  103. self.ui.lw_gig.setCurrentRow(0)
  104. self.ui.lw_sf2.setCurrentRow(0)
  105. self.ui.lw_sfz.setCurrentRow(0)
  106. #QTimer.singleShot(0, self, )
  107. #self.slot_pluginPathTabChanged(self.tw_paths.currentIndex())
  108. self.ui.lw_page.setCurrentCell(0, 0)
  109. def loadSettings(self):
  110. settings = QSettings()
  111. # ---------------------------------------
  112. self.ui.le_main_def_folder.setText(settings.value("Main/DefaultProjectFolder", HOME, type=str))
  113. self.ui.sb_gui_refresh.setValue(settings.value("Main/RefreshInterval", 50, type=int))
  114. # ---------------------------------------
  115. self.ui.cb_canvas_hide_groups.setChecked(settings.value("Canvas/AutoHideGroups", False, type=bool))
  116. self.ui.cb_canvas_bezier_lines.setChecked(settings.value("Canvas/UseBezierLines", True, type=bool))
  117. self.ui.cb_canvas_eyecandy.setCheckState(settings.value("Canvas/EyeCandy", CANVAS_EYECANDY_SMALL, type=int))
  118. self.ui.cb_canvas_use_opengl.setChecked(settings.value("Canvas/UseOpenGL", False, type=bool))
  119. self.ui.cb_canvas_render_aa.setCheckState(settings.value("Canvas/Antialiasing", CANVAS_ANTIALIASING_SMALL, type=int))
  120. self.ui.cb_canvas_render_hq_aa.setChecked(settings.value("Canvas/HighQualityAntialiasing", False, type=bool))
  121. #themeName = settings.value("Canvas/Theme", getDefaultThemeName(), type=str)
  122. #for i in range(Theme.THEME_MAX):
  123. #thisThemeName = getThemeName(i)
  124. #self.ui.cb_canvas_theme.addItem(thisThemeName)
  125. #if thisThemeName == themeName:
  126. #self.ui.cb_canvas_theme.setCurrentIndex(i)
  127. # --------------------------------------------
  128. audioDriver = settings.value("Engine/AudioDriver", "JACK", type=str)
  129. for i in range(self.ui.cb_engine_audio_driver.count()):
  130. if self.ui.cb_engine_audio_driver.itemText(i) == audioDriver:
  131. self.ui.cb_engine_audio_driver.setCurrentIndex(i)
  132. break
  133. else:
  134. self.ui.cb_engine_audio_driver.setCurrentIndex(-1)
  135. if audioDriver == "JACK":
  136. processModeIndex = settings.value("Engine/ProcessMode", PROCESS_MODE_MULTIPLE_CLIENTS, type=int)
  137. self.ui.cb_engine_process_mode_jack.setCurrentIndex(processModeIndex)
  138. self.ui.sw_engine_process_mode.setCurrentIndex(0)
  139. else:
  140. processModeIndex = settings.value("Engine/ProcessMode", PROCESS_MODE_CONTINUOUS_RACK, type=int)
  141. processModeIndex -= PROCESS_MODE_NON_JACK_PADDING
  142. self.ui.cb_engine_process_mode_other.setCurrentIndex(processModeIndex)
  143. self.ui.sw_engine_process_mode.setCurrentIndex(1)
  144. self.ui.sb_engine_max_params.setValue(settings.value("Engine/MaxParameters", CARLA_DEFAULT_MAX_PARAMETERS, type=int))
  145. self.ui.ch_engine_prefer_ui_bridges.setChecked(settings.value("Engine/PreferUiBridges", CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool))
  146. self.ui.sb_engine_oscgui_timeout.setValue(settings.value("Engine/OscUiTimeout", CARLA_DEFAULT_OSC_UI_TIMEOUT, type=int))
  147. self.ui.ch_engine_disable_checks.setChecked(settings.value("Engine/DisableChecks", CARLA_DEFAULT_DISABLE_CHECKS, type=bool))
  148. self.ui.ch_engine_dssi_chunks.setChecked(settings.value("Engine/UseDssiVstChunks", CARLA_DEFAULT_USE_DSSI_VST_CHUNKS, type=bool))
  149. self.ui.ch_engine_prefer_plugin_bridges.setChecked(settings.value("Engine/PreferPluginBridges", CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool))
  150. self.ui.ch_engine_force_stereo.setChecked(settings.value("Engine/ForceStereo", CARLA_DEFAULT_FORCE_STEREO, type=bool))
  151. # --------------------------------------------
  152. ladspas = toList(settings.value("Paths/LADSPA", Carla.LADSPA_PATH))
  153. dssis = toList(settings.value("Paths/DSSI", Carla.DSSI_PATH))
  154. lv2s = toList(settings.value("Paths/LV2", Carla.LV2_PATH))
  155. vsts = toList(settings.value("Paths/VST", Carla.VST_PATH))
  156. gigs = toList(settings.value("Paths/GIG", Carla.GIG_PATH))
  157. sf2s = toList(settings.value("Paths/SF2", Carla.SF2_PATH))
  158. sfzs = toList(settings.value("Paths/SFZ", Carla.SFZ_PATH))
  159. ladspas.sort()
  160. dssis.sort()
  161. lv2s.sort()
  162. vsts.sort()
  163. gigs.sort()
  164. sf2s.sort()
  165. sfzs.sort()
  166. for ladspa in ladspas:
  167. self.ui.lw_ladspa.addItem(ladspa)
  168. for dssi in dssis:
  169. self.ui.lw_dssi.addItem(dssi)
  170. for lv2 in lv2s:
  171. self.ui.lw_lv2.addItem(lv2)
  172. for vst in vsts:
  173. self.ui.lw_vst.addItem(vst)
  174. for gig in gigs:
  175. self.ui.lw_gig.addItem(gig)
  176. for sf2 in sf2s:
  177. self.ui.lw_sf2.addItem(sf2)
  178. for sfz in sfzs:
  179. self.ui.lw_sfz.addItem(sfz)
  180. @pyqtSlot()
  181. def slot_saveSettings(self):
  182. settings = QSettings()
  183. # ---------------------------------------
  184. settings.setValue("Main/RefreshInterval", self.ui.sb_gui_refresh.value())
  185. settings.setValue("Main/DefaultProjectFolder", self.ui.le_main_def_folder.text())
  186. # ---------------------------------------
  187. #settings.setValue("Canvas/Theme", self.ui.cb_canvas_theme.currentText())
  188. #settings.setValue("Canvas/AutoHideGroups", self.ui.cb_canvas_hide_groups.isChecked())
  189. #settings.setValue("Canvas/UseBezierLines", self.ui.cb_canvas_bezier_lines.isChecked())
  190. #settings.setValue("Canvas/UseOpenGL", self.ui.cb_canvas_use_opengl.isChecked())
  191. #settings.setValue("Canvas/HighQualityAntialiasing", self.ui.cb_canvas_render_hq_aa.isChecked())
  192. ## 0, 1, 2 match their enum variants
  193. #settings.setValue("Canvas/EyeCandy", self.ui.cb_canvas_eyecandy.checkState())
  194. #settings.setValue("Canvas/Antialiasing", self.ui.cb_canvas_render_aa.checkState())
  195. # --------------------------------------------
  196. audioDriver = self.ui.cb_engine_audio_driver.currentText()
  197. settings.setValue("Engine/AudioDriver", audioDriver)
  198. if audioDriver == "JACK":
  199. settings.setValue("Engine/ProcessMode", self.ui.cb_engine_process_mode_jack.currentIndex())
  200. else:
  201. settings.setValue("Engine/ProcessMode", self.ui.cb_engine_process_mode_other.currentIndex()+PROCESS_MODE_NON_JACK_PADDING)
  202. settings.setValue("Engine/MaxParameters", self.ui.sb_engine_max_params.value())
  203. settings.setValue("Engine/PreferUiBridges", self.ui.ch_engine_prefer_ui_bridges.isChecked())
  204. settings.setValue("Engine/OscUiTimeout", self.ui.sb_engine_oscgui_timeout.value())
  205. settings.setValue("Engine/DisableChecks", self.ui.ch_engine_disable_checks.isChecked())
  206. settings.setValue("Engine/UseDssiVstChunks", self.ui.ch_engine_dssi_chunks.isChecked())
  207. settings.setValue("Engine/PreferPluginBridges", self.ui.ch_engine_prefer_plugin_bridges.isChecked())
  208. settings.setValue("Engine/ForceStereo", self.ui.ch_engine_force_stereo.isChecked())
  209. # --------------------------------------------
  210. # FIXME - find a cleaner way to do this, *.items() ?
  211. ladspas = []
  212. dssis = []
  213. lv2s = []
  214. vsts = []
  215. gigs = []
  216. sf2s = []
  217. sfzs = []
  218. for i in range(self.ui.lw_ladspa.count()):
  219. ladspas.append(self.ui.lw_ladspa.item(i).text())
  220. for i in range(self.ui.lw_dssi.count()):
  221. dssis.append(self.ui.lw_dssi.item(i).text())
  222. for i in range(self.ui.lw_lv2.count()):
  223. lv2s.append(self.ui.lw_lv2.item(i).text())
  224. for i in range(self.ui.lw_vst.count()):
  225. vsts.append(self.ui.lw_vst.item(i).text())
  226. for i in range(self.ui.lw_gig.count()):
  227. gigs.append(self.ui.lw_gig.item(i).text())
  228. for i in range(self.ui.lw_sf2.count()):
  229. sf2s.append(self.ui.lw_sf2.item(i).text())
  230. for i in range(self.ui.lw_sfz.count()):
  231. sfzs.append(self.ui.lw_sfz.item(i).text())
  232. settings.setValue("Paths/LADSPA", ladspas)
  233. settings.setValue("Paths/DSSI", dssis)
  234. settings.setValue("Paths/LV2", lv2s)
  235. settings.setValue("Paths/VST", vsts)
  236. settings.setValue("Paths/GIG", gigs)
  237. settings.setValue("Paths/SF2", sf2s)
  238. settings.setValue("Paths/SFZ", sfzs)
  239. @pyqtSlot()
  240. def slot_resetSettings(self):
  241. if self.ui.lw_page.currentRow() == TAB_INDEX_MAIN:
  242. self.ui.le_main_def_folder.setText(HOME)
  243. self.ui.sb_gui_refresh.setValue(50)
  244. elif self.ui.lw_page.currentRow() == TAB_INDEX_CANVAS:
  245. self.ui.cb_canvas_theme.setCurrentIndex(0)
  246. self.ui.cb_canvas_hide_groups.setChecked(False)
  247. self.ui.cb_canvas_bezier_lines.setChecked(True)
  248. self.ui.cb_canvas_eyecandy.setCheckState(Qt.PartiallyChecked)
  249. self.ui.cb_canvas_use_opengl.setChecked(False)
  250. self.ui.cb_canvas_render_aa.setCheckState(Qt.PartiallyChecked)
  251. self.ui.cb_canvas_render_hq_aa.setChecked(False)
  252. elif self.ui.lw_page.currentRow() == TAB_INDEX_CARLA_ENGINE:
  253. self.ui.cb_engine_audio_driver.setCurrentIndex(0)
  254. self.ui.sb_engine_max_params.setValue(CARLA_DEFAULT_MAX_PARAMETERS)
  255. self.ui.ch_engine_prefer_ui_bridges.setChecked(CARLA_DEFAULT_PREFER_UI_BRIDGES)
  256. self.ui.sb_engine_oscgui_timeout.setValue(CARLA_DEFAULT_OSC_UI_TIMEOUT)
  257. self.ui.ch_engine_disable_checks.setChecked(CARLA_DEFAULT_DISABLE_CHECKS)
  258. self.ui.ch_engine_dssi_chunks.setChecked(CARLA_DEFAULT_USE_DSSI_VST_CHUNKS)
  259. self.ui.ch_engine_prefer_plugin_bridges.setChecked(CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES)
  260. self.ui.ch_engine_force_stereo.setChecked(CARLA_DEFAULT_FORCE_STEREO)
  261. if self.ui.cb_engine_audio_driver.currentText() == "JACK":
  262. self.ui.cb_engine_process_mode_jack.setCurrentIndex(PROCESS_MODE_MULTIPLE_CLIENTS)
  263. self.ui.sw_engine_process_mode.setCurrentIndex(0)
  264. else:
  265. self.ui.cb_engine_process_mode_other.setCurrentIndex(PROCESS_MODE_CONTINUOUS_RACK-PROCESS_MODE_NON_JACK_PADDING)
  266. self.ui.sw_engine_process_mode.setCurrentIndex(1)
  267. elif self.ui.lw_page.currentRow() == TAB_INDEX_CARLA_PATHS:
  268. if self.ui.tw_paths.currentIndex() == 0:
  269. Carla.LADSPA_PATH.sort()
  270. self.ui.lw_ladspa.clear()
  271. for ladspa in Carla.LADSPA_PATH:
  272. self.ui.lw_ladspa.addItem(ladspa)
  273. elif self.ui.tw_paths.currentIndex() == 1:
  274. Carla.DSSI_PATH.sort()
  275. self.ui.lw_dssi.clear()
  276. for dssi in Carla.DSSI_PATH:
  277. self.ui.lw_dssi.addItem(dssi)
  278. elif self.ui.tw_paths.currentIndex() == 2:
  279. Carla.LV2_PATH.sort()
  280. self.ui.lw_lv2.clear()
  281. for lv2 in Carla.LV2_PATH:
  282. self.ui.lw_lv2.addItem(lv2)
  283. elif self.ui.tw_paths.currentIndex() == 3:
  284. Carla.VST_PATH.sort()
  285. self.ui.lw_vst.clear()
  286. for vst in Carla.VST_PATH:
  287. self.ui.lw_vst.addItem(vst)
  288. elif self.ui.tw_paths.currentIndex() == 4:
  289. Carla.GIG_PATH.sort()
  290. self.ui.lw_gig.clear()
  291. for gig in Carla.GIG_PATH:
  292. self.ui.lw_gig.addItem(gig)
  293. elif self.ui.tw_paths.currentIndex() == 5:
  294. Carla.SF2_PATH.sort()
  295. self.ui.lw_sf2.clear()
  296. for sf2 in Carla.SF2_PATH:
  297. self.ui.lw_sf2.addItem(sf2)
  298. elif self.ui.tw_paths.currentIndex() == 6:
  299. Carla.SFZ_PATH.sort()
  300. self.ui.lw_sfz.clear()
  301. for sfz in Carla.SFZ_PATH:
  302. self.ui.lw_sfz.addItem(sfz)
  303. @pyqtSlot()
  304. def slot_getAndSetProjectPath(self):
  305. pass #getAndSetPath(self, self.le_main_def_folder.text(), self.le_main_def_folder)
  306. @pyqtSlot()
  307. def slot_engineAudioDriverChanged(self):
  308. if self.ui.cb_engine_audio_driver.currentText() == "JACK":
  309. self.ui.sw_engine_process_mode.setCurrentIndex(0)
  310. else:
  311. self.ui.sw_engine_process_mode.setCurrentIndex(1)
  312. @pyqtSlot()
  313. def slot_addPluginPath(self):
  314. newPath = QFileDialog.getExistingDirectory(self, self.tr("Add Path"), "", QFileDialog.ShowDirsOnly)
  315. if newPath:
  316. if self.ui.tw_paths.currentIndex() == 0:
  317. self.ui.lw_ladspa.addItem(newPath)
  318. elif self.ui.tw_paths.currentIndex() == 1:
  319. self.ui.lw_dssi.addItem(newPath)
  320. elif self.ui.tw_paths.currentIndex() == 2:
  321. self.ui.lw_lv2.addItem(newPath)
  322. elif self.ui.tw_paths.currentIndex() == 3:
  323. self.ui.lw_vst.addItem(newPath)
  324. elif self.ui.tw_paths.currentIndex() == 4:
  325. self.ui.lw_gig.addItem(newPath)
  326. elif self.ui.tw_paths.currentIndex() == 5:
  327. self.ui.lw_sf2.addItem(newPath)
  328. elif self.ui.tw_paths.currentIndex() == 6:
  329. self.ui.lw_sfz.addItem(newPath)
  330. @pyqtSlot()
  331. def slot_removePluginPath(self):
  332. if self.ui.tw_paths.currentIndex() == 0:
  333. self.ui.lw_ladspa.takeItem(self.ui.lw_ladspa.currentRow())
  334. elif self.ui.tw_paths.currentIndex() == 1:
  335. self.ui.lw_dssi.takeItem(self.ui.lw_dssi.currentRow())
  336. elif self.ui.tw_paths.currentIndex() == 2:
  337. self.ui.lw_lv2.takeItem(self.ui.lw_lv2.currentRow())
  338. elif self.ui.tw_paths.currentIndex() == 3:
  339. self.ui.lw_vst.takeItem(self.ui.lw_vst.currentRow())
  340. elif self.ui.tw_paths.currentIndex() == 4:
  341. self.ui.lw_gig.takeItem(self.ui.lw_gig.currentRow())
  342. elif self.ui.tw_paths.currentIndex() == 5:
  343. self.ui.lw_sf2.takeItem(self.ui.lw_sf2.currentRow())
  344. elif self.ui.tw_paths.currentIndex() == 6:
  345. self.ui.lw_sfz.takeItem(self.ui.lw_sfz.currentRow())
  346. @pyqtSlot()
  347. def slot_changePluginPath(self):
  348. if self.ui.tw_paths.currentIndex() == 0:
  349. currentPath = self.ui.lw_ladspa.currentItem().text()
  350. elif self.ui.tw_paths.currentIndex() == 1:
  351. currentPath = self.ui.lw_dssi.currentItem().text()
  352. elif self.ui.tw_paths.currentIndex() == 2:
  353. currentPath = self.ui.lw_lv2.currentItem().text()
  354. elif self.ui.tw_paths.currentIndex() == 3:
  355. currentPath = self.ui.lw_vst.currentItem().text()
  356. elif self.ui.tw_paths.currentIndex() == 4:
  357. currentPath = self.ui.lw_gig.currentItem().text()
  358. elif self.ui.tw_paths.currentIndex() == 5:
  359. currentPath = self.ui.lw_sf2.currentItem().text()
  360. elif self.ui.tw_paths.currentIndex() == 6:
  361. currentPath = self.ui.lw_sfz.currentItem().text()
  362. else:
  363. currentPath = ""
  364. newPath = QFileDialog.getExistingDirectory(self, self.tr("Add Path"), currentPath, QFileDialog.ShowDirsOnly)
  365. if newPath:
  366. if self.ui.tw_paths.currentIndex() == 0:
  367. self.ui.lw_ladspa.currentItem().setText(newPath)
  368. elif self.ui.tw_paths.currentIndex() == 1:
  369. self.ui.lw_dssi.currentItem().setText(newPath)
  370. elif self.ui.tw_paths.currentIndex() == 2:
  371. self.ui.lw_lv2.currentItem().setText(newPath)
  372. elif self.ui.tw_paths.currentIndex() == 3:
  373. self.ui.lw_vst.currentItem().setText(newPath)
  374. elif self.ui.tw_paths.currentIndex() == 4:
  375. self.ui.lw_gig.currentItem().setText(newPath)
  376. elif self.ui.tw_paths.currentIndex() == 5:
  377. self.ui.lw_sf2.currentItem().setText(newPath)
  378. elif self.ui.tw_paths.currentIndex() == 6:
  379. self.ui.lw_sfz.currentItem().setText(newPath)
  380. @pyqtSlot(int)
  381. def slot_pluginPathTabChanged(self, index):
  382. if index == 0:
  383. row = self.ui.lw_ladspa.currentRow()
  384. elif index == 1:
  385. row = self.ui.lw_dssi.currentRow()
  386. elif index == 2:
  387. row = self.ui.lw_lv2.currentRow()
  388. elif index == 3:
  389. row = self.ui.lw_vst.currentRow()
  390. elif index == 4:
  391. row = self.ui.lw_gig.currentRow()
  392. elif index == 5:
  393. row = self.ui.lw_sf2.currentRow()
  394. elif index == 6:
  395. row = self.ui.lw_sfz.currentRow()
  396. else:
  397. row = -1
  398. check = bool(row >= 0)
  399. self.ui.b_paths_remove.setEnabled(check)
  400. self.ui.b_paths_change.setEnabled(check)
  401. @pyqtSlot(int)
  402. def slot_pluginPathRowChanged(self, row):
  403. check = bool(row >= 0)
  404. self.ui.b_paths_remove.setEnabled(check)
  405. self.ui.b_paths_change.setEnabled(check)
  406. def done(self, r):
  407. QDialog.done(self, r)
  408. self.close()
  409. # ------------------------------------------------------------------------------------------------------------
  410. # Main Window
  411. class CarlaMainW(QMainWindow):
  412. def __init__(self, parent=None):
  413. QMainWindow.__init__(self, parent)
  414. self.ui = ui_carla.Ui_CarlaMainW()
  415. self.ui.setupUi(self)
  416. # -------------------------------------------------------------
  417. # Load Settings
  418. self.loadSettings(True)
  419. self.loadRDFs()
  420. self.setStyleSheet("""
  421. QWidget#w_plugins {
  422. background-color: qlineargradient(spread:pad,
  423. x1:0.0, y1:0.0,
  424. x2:0.2, y2:1.0,
  425. stop:0 rgb( 7, 7, 7),
  426. stop:1 rgb(28, 28, 28)
  427. );
  428. }
  429. """)
  430. # -------------------------------------------------------------
  431. # Internal stuff
  432. self.fEngineStarted = False
  433. self.fFirstEngineInit = False
  434. self.fProjectFilename = None
  435. self.fProjectLoading = False
  436. self.fPluginCount = 0
  437. self.fPluginList = []
  438. self.fIdleTimerFast = 0
  439. self.fIdleTimerSlow = 0
  440. #self._nsmAnnounce2str = ""
  441. #self._nsmOpen1str = ""
  442. #self._nsmOpen2str = ""
  443. #self.nsm_server = None
  444. #self.nsm_url = None
  445. # -------------------------------------------------------------
  446. # Set-up GUI stuff
  447. self.ui.act_engine_start.setEnabled(False)
  448. self.ui.act_engine_stop.setEnabled(False)
  449. self.ui.act_plugin_remove_all.setEnabled(False)
  450. # FIXME: Qt4 needs this so it properly create & resize the canvas
  451. self.ui.tabWidget.setCurrentIndex(1)
  452. self.ui.tabWidget.setCurrentIndex(0)
  453. # -------------------------------------------------------------
  454. # Set-up Canvas
  455. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  456. self.ui.graphicsView.setScene(self.scene)
  457. #self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, bool(self.fSavedSettings["Canvas/Antialiasing"] == patchcanvas.ANTIALIASING_FULL))
  458. #if self.fSavedSettings["Canvas/UseOpenGL"] and hasGL:
  459. #self.ui.graphicsView.setViewport(QGLWidget(self.ui.graphicsView))
  460. #self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings["Canvas/HighQualityAntialiasing"])
  461. pOptions = patchcanvas.options_t()
  462. pOptions.theme_name = self.fSavedSettings["Canvas/Theme"]
  463. pOptions.auto_hide_groups = self.fSavedSettings["Canvas/AutoHideGroups"]
  464. pOptions.use_bezier_lines = self.fSavedSettings["Canvas/UseBezierLines"]
  465. pOptions.antialiasing = self.fSavedSettings["Canvas/Antialiasing"]
  466. pOptions.eyecandy = self.fSavedSettings["Canvas/EyeCandy"]
  467. pFeatures = patchcanvas.features_t()
  468. pFeatures.group_info = False
  469. pFeatures.group_rename = False
  470. pFeatures.port_info = False
  471. pFeatures.port_rename = False
  472. pFeatures.handle_group_pos = True
  473. patchcanvas.setOptions(pOptions)
  474. patchcanvas.setFeatures(pFeatures)
  475. patchcanvas.init("Carla", self.scene, canvasCallback, True)
  476. patchcanvas.setCanvasSize(0, 0, DEFAULT_CANVAS_WIDTH, DEFAULT_CANVAS_HEIGHT)
  477. patchcanvas.setInitialPos(DEFAULT_CANVAS_WIDTH / 2, DEFAULT_CANVAS_HEIGHT / 2)
  478. self.ui.graphicsView.setSceneRect(0, 0, DEFAULT_CANVAS_WIDTH, DEFAULT_CANVAS_HEIGHT)
  479. # -------------------------------------------------------------
  480. # Set-up Canvas Preview
  481. self.ui.miniCanvasPreview.setRealParent(self)
  482. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  483. self.ui.miniCanvasPreview.init(self.scene, DEFAULT_CANVAS_WIDTH, DEFAULT_CANVAS_HEIGHT)
  484. QTimer.singleShot(100, self, SLOT("slot_miniCanvasInit()"))
  485. #self.m_fakeEdit = PluginEdit(self, -1)
  486. #self.m_curEdit = self.m_fakeEdit
  487. #self.w_edit.layout().addWidget(self.m_curEdit)
  488. #self.w_edit.layout().addStretch()
  489. # -------------------------------------------------------------
  490. # Connect actions to functions
  491. self.connect(self.ui.act_file_new, SIGNAL("triggered()"), SLOT("slot_fileNew()"))
  492. self.connect(self.ui.act_file_open, SIGNAL("triggered()"), SLOT("slot_fileOpen()"))
  493. self.connect(self.ui.act_file_save, SIGNAL("triggered()"), SLOT("slot_fileSave()"))
  494. self.connect(self.ui.act_file_save_as, SIGNAL("triggered()"), SLOT("slot_fileSaveAs()"))
  495. self.connect(self.ui.act_engine_start, SIGNAL("triggered()"), SLOT("slot_engineStart()"))
  496. self.connect(self.ui.act_engine_stop, SIGNAL("triggered()"), SLOT("slot_engineStop()"))
  497. self.connect(self.ui.act_plugin_add, SIGNAL("triggered()"), SLOT("slot_pluginAdd()"))
  498. self.connect(self.ui.act_plugin_remove_all, SIGNAL("triggered()"), SLOT("slot_pluginRemoveAll()"))
  499. self.connect(self.ui.act_settings_configure, SIGNAL("triggered()"), SLOT("slot_configureCarla()"))
  500. self.connect(self.ui.act_help_about, SIGNAL("triggered()"), SLOT("slot_aboutCarla()"))
  501. self.connect(self.ui.act_help_about_qt, SIGNAL("triggered()"), app, SLOT("aboutQt()"))
  502. self.connect(self.ui.ch_transport, SIGNAL("currentIndexChanged(int)"), SLOT("slot_transportModeChanged(int)"))
  503. self.connect(self.ui.b_transport_play, SIGNAL("clicked(bool)"), SLOT("slot_transportPlayPause(bool)"))
  504. self.connect(self.ui.b_transport_stop, SIGNAL("clicked()"), SLOT("slot_transportStop()"))
  505. self.connect(self.ui.miniCanvasPreview, SIGNAL("miniCanvasMoved(double, double)"), SLOT("slot_miniCanvasMoved(double, double)"))
  506. self.connect(self.ui.graphicsView.horizontalScrollBar(), SIGNAL("valueChanged(int)"), SLOT("slot_horizontalScrollBarChanged(int)"))
  507. self.connect(self.ui.graphicsView.verticalScrollBar(), SIGNAL("valueChanged(int)"), SLOT("slot_verticalScrollBarChanged(int)"))
  508. self.connect(self.scene, SIGNAL("sceneGroupMoved(int, int, QPointF)"), SLOT("slot_canvasItemMoved(int, int, QPointF)"))
  509. self.connect(self.scene, SIGNAL("scaleChanged(double)"), SLOT("slot_canvasScaleChanged(double)"))
  510. self.connect(self, SIGNAL("SIGUSR1()"), SLOT("slot_handleSIGUSR1()"))
  511. self.connect(self, SIGNAL("SIGTERM()"), SLOT("slot_handleSIGTERM()"))
  512. self.connect(self, SIGNAL("DebugCallback(int, int, int, double, QString)"), SLOT("slot_handleDebugCallback(int, int, int, double, QString)"))
  513. self.connect(self, SIGNAL("PluginAddedCallback(int)"), SLOT("slot_handlePluginAddedCallback(int)"))
  514. self.connect(self, SIGNAL("PluginRemovedCallback(int)"), SLOT("slot_handlePluginRemovedCallback(int)"))
  515. self.connect(self, SIGNAL("ParameterValueChangedCallback(int, int, double)"), SLOT("slot_handleParameterValueChangedCallback(int, int, double)"))
  516. self.connect(self, SIGNAL("ParameterDefaultChangedCallback(int, int, double)"), SLOT("slot_handleParameterDefaultChangedCallback(int, int, double)"))
  517. self.connect(self, SIGNAL("ParameterMidiChannelChangedCallback(int, int, int)"), SLOT("slot_handleParameterMidiChannelChangedCallback(int, int, int)"))
  518. self.connect(self, SIGNAL("ParameterMidiCcChangedCallback(int, int, int)"), SLOT("slot_handleParameterMidiCcChangedCallback(int, int, int)"))
  519. self.connect(self, SIGNAL("ProgramChangedCallback(int, int)"), SLOT("slot_handleProgramChangedCallback(int, int)"))
  520. self.connect(self, SIGNAL("MidiProgramChangedCallback(int, int)"), SLOT("slot_handleMidiProgramChangedCallback(int, int)"))
  521. self.connect(self, SIGNAL("NoteOnCallback(int, int, int, int)"), SLOT("slot_handleNoteOnCallback(int, int, int, int)"))
  522. self.connect(self, SIGNAL("NoteOffCallback(int, int, int)"), SLOT("slot_handleNoteOffCallback(int, int, int)"))
  523. self.connect(self, SIGNAL("ShowGuiCallback(int, int)"), SLOT("slot_handleShowGuiCallback(int, int)"))
  524. self.connect(self, SIGNAL("UpdateCallback(int)"), SLOT("slot_handleUpdateCallback(int)"))
  525. self.connect(self, SIGNAL("ReloadInfoCallback(int)"), SLOT("slot_handleReloadInfoCallback(int)"))
  526. self.connect(self, SIGNAL("ReloadParametersCallback(int)"), SLOT("slot_handleReloadParametersCallback(int)"))
  527. self.connect(self, SIGNAL("ReloadProgramsCallback(int)"), SLOT("slot_handleReloadProgramsCallback(int)"))
  528. self.connect(self, SIGNAL("ReloadAllCallback(int)"), SLOT("slot_handleReloadAllCallback(int)"))
  529. self.connect(self, SIGNAL("PatchbayClientAddedCallback(int, QString)"), SLOT("slot_handlePatchbayClientAddedCallback(int, QString)"))
  530. self.connect(self, SIGNAL("PatchbayClientRemovedCallback(int)"), SLOT("slot_handlePatchbayClientRemovedCallback(int)"))
  531. self.connect(self, SIGNAL("PatchbayClientRenamedCallback(int, QString)"), SLOT("slot_handlePatchbayClientRenamedCallback(int, QString)"))
  532. self.connect(self, SIGNAL("PatchbayPortAddedCallback(int, int, int, QString)"), SLOT("slot_handlePatchbayPortAddedCallback(int, int, int, QString)"))
  533. self.connect(self, SIGNAL("PatchbayPortRemovedCallback(int)"), SLOT("slot_handlePatchbayPortRemovedCallback(int)"))
  534. self.connect(self, SIGNAL("PatchbayPortRenamedCallback(int, QString)"), SLOT("slot_handlePatchbayPortRenamedCallback(int, QString)"))
  535. self.connect(self, SIGNAL("PatchbayConnectionAddedCallback(int, int, int)"), SLOT("slot_handlePatchbayConnectionAddedCallback(int, int, int)"))
  536. self.connect(self, SIGNAL("PatchbayConnectionRemovedCallback(int)"), SLOT("slot_handlePatchbayConnectionRemovedCallback(int)"))
  537. #self.connect(self, SIGNAL("NSM_AnnounceCallback()"), SLOT("slot_handleNSM_AnnounceCallback()"))
  538. #self.connect(self, SIGNAL("NSM_Open1Callback()"), SLOT("slot_handleNSM_Open1Callback()"))
  539. #self.connect(self, SIGNAL("NSM_Open2Callback()"), SLOT("slot_handleNSM_Open2Callback()"))
  540. #self.connect(self, SIGNAL("NSM_SaveCallback()"), SLOT("slot_handleNSM_SaveCallback()"))
  541. self.connect(self, SIGNAL("ErrorCallback(QString)"), SLOT("slot_handleErrorCallback(QString)"))
  542. self.connect(self, SIGNAL("QuitCallback()"), SLOT("slot_handleQuitCallback()"))
  543. #NSM_URL = os.getenv("NSM_URL")
  544. #if NSM_URL:
  545. #Carla.host.nsm_announce(NSM_URL, os.getpid())
  546. #else:
  547. QTimer.singleShot(0, self, SLOT("slot_engineStart()"))
  548. @pyqtSlot(float)
  549. def slot_canvasScaleChanged(self, scale):
  550. self.ui.miniCanvasPreview.setViewScale(scale)
  551. @pyqtSlot(int, int, QPointF)
  552. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  553. self.ui.miniCanvasPreview.update()
  554. @pyqtSlot(int)
  555. def slot_horizontalScrollBarChanged(self, value):
  556. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  557. if maximum == 0:
  558. xp = 0
  559. else:
  560. xp = float(value) / maximum
  561. self.ui.miniCanvasPreview.setViewPosX(xp)
  562. @pyqtSlot(int)
  563. def slot_verticalScrollBarChanged(self, value):
  564. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  565. if maximum == 0:
  566. yp = 0
  567. else:
  568. yp = float(value) / maximum
  569. self.ui.miniCanvasPreview.setViewPosY(yp)
  570. @pyqtSlot()
  571. def slot_miniCanvasInit(self):
  572. settings = QSettings()
  573. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", DEFAULT_CANVAS_WIDTH / 3, type=int))
  574. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", DEFAULT_CANVAS_HEIGHT * 3 / 8, type=int))
  575. @pyqtSlot(float, float)
  576. def slot_miniCanvasMoved(self, xp, yp):
  577. self.ui.graphicsView.horizontalScrollBar().setValue(xp * DEFAULT_CANVAS_WIDTH)
  578. self.ui.graphicsView.verticalScrollBar().setValue(yp * DEFAULT_CANVAS_HEIGHT)
  579. @pyqtSlot()
  580. def slot_miniCanvasCheckAll(self):
  581. self.slot_miniCanvasCheckSize()
  582. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  583. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  584. @pyqtSlot()
  585. def slot_miniCanvasCheckSize(self):
  586. self.ui.miniCanvasPreview.setViewSize(float(self.ui.graphicsView.width()) / DEFAULT_CANVAS_WIDTH, float(self.ui.graphicsView.height()) / DEFAULT_CANVAS_HEIGHT)
  587. def startEngine(self, clientName = "Carla"):
  588. # ---------------------------------------------
  589. # Engine settings
  590. settings = QSettings()
  591. Carla.processMode = settings.value("Engine/ProcessMode", PROCESS_MODE_MULTIPLE_CLIENTS, type=int)
  592. Carla.maxParameters = settings.value("Engine/MaxParameters", MAX_DEFAULT_PARAMETERS, type=int)
  593. transportMode = settings.value("Engine/TransportMode", TRANSPORT_MODE_JACK, type=int)
  594. forceStereo = settings.value("Engine/ForceStereo", False, type=bool)
  595. preferPluginBridges = settings.value("Engine/PreferPluginBridges", False, type=bool)
  596. preferUiBridges = settings.value("Engine/PreferUiBridges", True, type=bool)
  597. useDssiVstChunks = settings.value("Engine/UseDssiVstChunks", False, type=bool)
  598. oscUiTimeout = settings.value("Engine/OscUiTimeout", 40, type=int)
  599. preferredBufferSize = settings.value("Engine/PreferredBufferSize", 512, type=int)
  600. preferredSampleRate = settings.value("Engine/PreferredSampleRate", 44100, type=int)
  601. if Carla.processMode == PROCESS_MODE_CONTINUOUS_RACK:
  602. forceStereo = True
  603. elif Carla.processMode == PROCESS_MODE_MULTIPLE_CLIENTS and os.getenv("LADISH_APP_NAME"):
  604. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  605. Carla.processMode = PROCESS_MODE_SINGLE_CLIENT
  606. Carla.host.set_engine_option(OPTION_PROCESS_MODE, Carla.processMode, "")
  607. Carla.host.set_engine_option(OPTION_MAX_PARAMETERS, Carla.maxParameters, "")
  608. Carla.host.set_engine_option(OPTION_FORCE_STEREO, forceStereo, "")
  609. Carla.host.set_engine_option(OPTION_PREFER_PLUGIN_BRIDGES, preferPluginBridges, "")
  610. Carla.host.set_engine_option(OPTION_PREFER_UI_BRIDGES, preferUiBridges, "")
  611. Carla.host.set_engine_option(OPTION_USE_DSSI_VST_CHUNKS, useDssiVstChunks, "")
  612. Carla.host.set_engine_option(OPTION_OSC_UI_TIMEOUT, oscUiTimeout, "")
  613. Carla.host.set_engine_option(OPTION_PREFERRED_BUFFER_SIZE, preferredBufferSize, "")
  614. Carla.host.set_engine_option(OPTION_PREFERRED_SAMPLE_RATE, preferredSampleRate, "")
  615. # ---------------------------------------------
  616. # Start
  617. audioDriver = settings.value("Engine/AudioDriver", "JACK", type=str)
  618. if not Carla.host.engine_init(audioDriver, clientName):
  619. if self.fFirstEngineInit:
  620. self.fFirstEngineInit = False
  621. return
  622. audioError = cString(Carla.host.get_last_error())
  623. if audioError:
  624. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  625. else:
  626. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  627. return
  628. self.fEngineStarted = True
  629. self.fFirstEngineInit = False
  630. self.fPluginCount = 0
  631. self.fPluginList = []
  632. if Carla.processMode == PROCESS_MODE_CONTINUOUS_RACK:
  633. maxCount = MAX_RACK_PLUGINS
  634. elif Carla.processMode == PROCESS_MODE_PATCHBAY:
  635. maxCount = MAX_PATCHBAY_PLUGINS
  636. else:
  637. maxCount = MAX_DEFAULT_PLUGINS
  638. self.ui.ch_transport.blockSignals(True)
  639. self.ui.ch_transport.addItem(self.tr("Internal"))
  640. if audioDriver == "JACK":
  641. self.ui.ch_transport.addItem(self.tr("JACK"))
  642. elif transportMode == TRANSPORT_MODE_JACK:
  643. transportMode = TRANSPORT_MODE_INTERNAL
  644. self.ui.ch_transport.setCurrentIndex(transportMode)
  645. self.ui.ch_transport.blockSignals(False)
  646. for x in range(maxCount):
  647. self.fPluginList.append(None)
  648. Carla.host.set_engine_option(OPTION_TRANSPORT_MODE, transportMode, "")
  649. # Peaks
  650. self.fIdleTimerFast = self.startTimer(self.fSavedSettings["Main/RefreshInterval"])
  651. # LEDs and edit dialog parameters
  652. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings["Main/RefreshInterval"]*2)
  653. def stopEngine(self):
  654. if self.fPluginCount > 0:
  655. 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"
  656. "Do you want to do this now?"),
  657. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  658. if ask != QMessageBox.Yes:
  659. return
  660. self.removeAllPlugins()
  661. if Carla.host.is_engine_running() and not Carla.host.engine_close():
  662. print(cString(Carla.host.get_last_error()))
  663. self.fEngineStarted = False
  664. self.fPluginCount = 0
  665. self.fPluginList = []
  666. self.killTimer(self.fIdleTimerFast)
  667. self.killTimer(self.fIdleTimerSlow)
  668. settings = QSettings()
  669. settings.setValue("Engine/TransportMode", self.ui.ch_transport.currentIndex())
  670. self.ui.ch_transport.blockSignals(True)
  671. self.ui.ch_transport.clear()
  672. self.ui.ch_transport.blockSignals(False)
  673. patchcanvas.clear()
  674. def loadProject(self, filename):
  675. self.fProjectFilename = filename
  676. self.setWindowTitle("Carla - %s" % os.path.basename(filename))
  677. self.fProjectLoading = True
  678. Carla.host.load_project(filename)
  679. self.fProjectLoading = False
  680. def loadProjectLater(self, filename):
  681. self.fProjectFilename = filename
  682. self.setWindowTitle("Carla - %s" % os.path.basename(filename))
  683. QTimer.singleShot(0, self, SLOT("slot_loadProjectLater()"))
  684. def saveProject(self, filename):
  685. self.fProjectFilename = filename
  686. self.setWindowTitle("Carla - %s" % os.path.basename(filename))
  687. Carla.host.save_project(filename)
  688. def addPlugin(self, btype, ptype, filename, name, label, extraStuff):
  689. if not self.fEngineStarted:
  690. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  691. return False
  692. if not Carla.host.add_plugin(btype, ptype, filename, name, label, extraStuff):
  693. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  694. return False
  695. return True
  696. def removeAllPlugins(self):
  697. while (self.ui.w_plugins.layout().takeAt(0)):
  698. pass
  699. self.ui.act_plugin_remove_all.setEnabled(False)
  700. for i in range(self.fPluginCount):
  701. pwidget = self.fPluginList[i]
  702. if pwidget is None:
  703. break
  704. self.fPluginList[i] = None
  705. pwidget.ui.edit_dialog.close()
  706. pwidget.close()
  707. pwidget.deleteLater()
  708. del pwidget
  709. self.fPluginCount = 0
  710. Carla.host.remove_all_plugins()
  711. @pyqtSlot()
  712. def slot_fileNew(self):
  713. self.removeAllPlugins()
  714. self.fProjectFilename = None
  715. self.fProjectLoading = False
  716. self.setWindowTitle("Carla")
  717. @pyqtSlot()
  718. def slot_fileOpen(self):
  719. fileFilter = self.tr("Carla Project File (*.carxp)")
  720. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings["Main/DefaultProjectFolder"], filter=fileFilter)
  721. if filenameTry:
  722. # FIXME - show dialog to user
  723. self.removeAllPlugins()
  724. self.loadProject(filenameTry)
  725. @pyqtSlot()
  726. def slot_fileSave(self, saveAs=False):
  727. if self.fProjectFilename and not saveAs:
  728. return self.saveProject(self.fProjectFilename)
  729. fileFilter = self.tr("Carla Project File (*.carxp)")
  730. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings["Main/DefaultProjectFolder"], filter=fileFilter)
  731. if filenameTry:
  732. if not filenameTry.endswith(".carxp"):
  733. filenameTry += ".carxp"
  734. self.saveProject(filenameTry)
  735. @pyqtSlot()
  736. def slot_fileSaveAs(self):
  737. self.slot_fileSave(True)
  738. @pyqtSlot()
  739. def slot_loadProjectLater(self):
  740. self.fProjectLoading = True
  741. Carla.host.load_project(self.fProjectFilename)
  742. self.fProjectLoading = False
  743. @pyqtSlot()
  744. def slot_engineStart(self):
  745. self.startEngine()
  746. check = Carla.host.is_engine_running()
  747. self.ui.act_file_open.setEnabled(check)
  748. self.ui.act_engine_start.setEnabled(not check)
  749. self.ui.act_engine_stop.setEnabled(check)
  750. self.ui.act_engine_configure.setEnabled(not check)
  751. self.ui.frame_transport.setEnabled(check)
  752. @pyqtSlot()
  753. def slot_engineStop(self):
  754. self.stopEngine()
  755. check = Carla.host.is_engine_running()
  756. self.ui.act_file_open.setEnabled(check)
  757. self.ui.act_engine_start.setEnabled(not check)
  758. self.ui.act_engine_stop.setEnabled(check)
  759. self.ui.frame_transport.setEnabled(check)
  760. @pyqtSlot()
  761. def slot_pluginAdd(self):
  762. dialog = PluginDatabaseW(self)
  763. if dialog.exec_():
  764. btype = dialog.fRetPlugin['build']
  765. ptype = dialog.fRetPlugin['type']
  766. filename = dialog.fRetPlugin['binary']
  767. label = dialog.fRetPlugin['label']
  768. extraStuff = self.getExtraStuff(dialog.fRetPlugin)
  769. self.addPlugin(btype, ptype, filename, None, label, extraStuff)
  770. @pyqtSlot()
  771. def slot_pluginRemoveAll(self):
  772. self.removeAllPlugins()
  773. self.connect(self.ui.ch_transport, SIGNAL("currentIndexChanged(int)"), SLOT("(int)"))
  774. self.connect(self.ui.b_transport_play, SIGNAL("clicked(bool)"), SLOT("(bool)"))
  775. self.connect(self.ui.b_transport_stop, SIGNAL("clicked()"), SLOT("()"))
  776. @pyqtSlot(int)
  777. def slot_transportModeChanged(self, newMode):
  778. Carla.host.set_engine_option(OPTION_TRANSPORT_MODE, newMode, "")
  779. @pyqtSlot(bool)
  780. def slot_transportPlayPause(self, toggled):
  781. if toggled:
  782. Carla.host.transport_play()
  783. else:
  784. Carla.host.transport_pause()
  785. @pyqtSlot()
  786. def slot_transportStop(self):
  787. Carla.host.transport_pause()
  788. Carla.host.transport_relocate(0)
  789. @pyqtSlot()
  790. def slot_aboutCarla(self):
  791. CarlaAboutW(self).exec_()
  792. @pyqtSlot()
  793. def slot_configureCarla(self):
  794. dialog = CarlaSettingsW(self)
  795. if dialog.exec_():
  796. self.loadSettings(False)
  797. for pwidget in self.fPluginList:
  798. if pwidget is None:
  799. return
  800. pwidget.setRefreshRate(self.fSavedSettings["Main/RefreshInterval"])
  801. @pyqtSlot()
  802. def slot_handleSIGUSR1(self):
  803. print("Got SIGUSR1 -> Saving project now")
  804. QTimer.singleShot(0, self, SLOT("slot_fileSave()"))
  805. @pyqtSlot()
  806. def slot_handleSIGTERM(self):
  807. print("Got SIGTERM -> Closing now")
  808. self.close()
  809. @pyqtSlot(int, int, int, float, str)
  810. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  811. print("DEBUG :: %i, %i, %i, %f, \"%s\")" % (pluginId, value1, value2, value3, valueStr))
  812. @pyqtSlot(int)
  813. def slot_handlePluginAddedCallback(self, pluginId):
  814. pwidget = PluginWidget(self, pluginId)
  815. pwidget.setRefreshRate(self.fSavedSettings["Main/RefreshInterval"])
  816. self.ui.w_plugins.layout().addWidget(pwidget)
  817. self.fPluginCount += 1
  818. self.fPluginList[pluginId] = pwidget
  819. if not self.fProjectLoading:
  820. pwidget.setActive(True, True, True)
  821. if self.fPluginCount == 1:
  822. self.ui.act_plugin_remove_all.setEnabled(True)
  823. @pyqtSlot(int)
  824. def slot_handlePluginRemovedCallback(self, pluginId):
  825. if pluginId >= self.fPluginCount:
  826. return
  827. pwidget = self.fPluginList[pluginId]
  828. if pwidget is None:
  829. return
  830. self.fPluginList[pluginId] = None
  831. self.fPluginCount -= 1
  832. self.ui.w_plugins.layout().removeWidget(pwidget)
  833. pwidget.ui.edit_dialog.close()
  834. pwidget.close()
  835. pwidget.deleteLater()
  836. del pwidget
  837. # push all plugins 1 slot back
  838. for i in range(pluginId, self.fPluginCount):
  839. self.fPluginList[i] = self.fPluginList[i+1]
  840. self.fPluginList[i].setId(i)
  841. if self.fPluginCount == 0:
  842. self.ui.act_plugin_remove_all.setEnabled(False)
  843. @pyqtSlot(int, int, float)
  844. def slot_handleParameterValueChangedCallback(self, pluginId, parameterId, value):
  845. if pluginId >= self.fPluginCount:
  846. return
  847. pwidget = self.fPluginList[pluginId]
  848. if pwidget is None:
  849. return
  850. pwidget.setParameterValue(parameterId, value)
  851. @pyqtSlot(int, int, float)
  852. def slot_handleParameterDefaultChangedCallback(self, pluginId, parameterId, value):
  853. if pluginId >= self.fPluginCount:
  854. return
  855. pwidget = self.fPluginList[pluginId]
  856. if pwidget is None:
  857. return
  858. pwidget.setParameterDefault(parameterId, value)
  859. @pyqtSlot(int, int, int)
  860. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, parameterId, channel):
  861. if pluginId >= self.fPluginCount:
  862. return
  863. pwidget = self.fPluginList[pluginId]
  864. if pwidget is None:
  865. return
  866. pwidget.setParameterMidiChannel(parameterId, channel)
  867. @pyqtSlot(int, int, int)
  868. def slot_handleParameterMidiCcChangedCallback(self, pluginId, parameterId, cc):
  869. if pluginId >= self.fPluginCount:
  870. return
  871. pwidget = self.fPluginList[pluginId]
  872. if pwidget is None:
  873. return
  874. pwidget.setParameterMidiControl(parameterId, cc)
  875. @pyqtSlot(int, int)
  876. def slot_handleProgramChangedCallback(self, pluginId, programId):
  877. if pluginId >= self.fPluginCount:
  878. return
  879. pwidget = self.fPluginList[pluginId]
  880. if pwidget is None:
  881. return
  882. pwidget.setProgram(programId)
  883. @pyqtSlot(int, int)
  884. def slot_handleMidiProgramChangedCallback(self, pluginId, midiProgramId):
  885. if pluginId >= self.fPluginCount:
  886. return
  887. pwidget = self.fPluginList[pluginId]
  888. if pwidget is None:
  889. return
  890. pwidget.setMidiProgram(midiProgramId)
  891. @pyqtSlot(int, int, int, int)
  892. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  893. if pluginId >= self.fPluginCount:
  894. return
  895. pwidget = self.fPluginList[pluginId]
  896. if pwidget is None:
  897. return
  898. pwidget.sendNoteOn(channel, note)
  899. @pyqtSlot(int, int, int)
  900. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  901. if pluginId >= self.fPluginCount:
  902. return
  903. pwidget = self.fPluginList[pluginId]
  904. if pwidget is None:
  905. return
  906. pwidget.sendNoteOff(channel, note)
  907. @pyqtSlot(int, int)
  908. def slot_handleShowGuiCallback(self, pluginId, show):
  909. if pluginId >= self.fPluginCount:
  910. return
  911. pwidget = self.fPluginList[pluginId]
  912. if pwidget is None:
  913. return
  914. if show == 0:
  915. pwidget.ui.b_gui.setChecked(False)
  916. pwidget.ui.b_gui.setEnabled(True)
  917. elif show == 1:
  918. pwidget.ui.b_gui.setChecked(True)
  919. pwidget.ui.b_gui.setEnabled(True)
  920. elif show == -1:
  921. pwidget.ui.b_gui.setChecked(False)
  922. pwidget.ui.b_gui.setEnabled(False)
  923. @pyqtSlot(int)
  924. def slot_handleUpdateCallback(self, pluginId):
  925. if pluginId >= self.fPluginCount:
  926. return
  927. pwidget = self.fPluginList[pluginId]
  928. if pwidget is None:
  929. return
  930. pwidget.ui.edit_dialog.do_update()
  931. @pyqtSlot(int)
  932. def slot_handleReloadInfoCallback(self, pluginId):
  933. if pluginId >= self.fPluginCount:
  934. return
  935. pwidget = self.fPluginList[pluginId]
  936. if pwidget is None:
  937. return
  938. pwidget.ui.edit_dialog.reloadInfo()
  939. @pyqtSlot(int)
  940. def slot_handleReloadParametersCallback(self, pluginId):
  941. if pluginId >= self.fPluginCount:
  942. return
  943. pwidget = self.fPluginList[pluginId]
  944. if pwidget is None:
  945. return
  946. pwidget.ui.edit_dialog.reloadParameters()
  947. @pyqtSlot(int)
  948. def slot_handleReloadProgramsCallback(self, pluginId):
  949. if pluginId >= self.fPluginCount:
  950. return
  951. pwidget = self.fPluginList[pluginId]
  952. if pwidget is None:
  953. return
  954. pwidget.ui.edit_dialog.reloadPrograms()
  955. @pyqtSlot(int)
  956. def slot_handleReloadAllCallback(self, pluginId):
  957. if pluginId >= self.fPluginCount:
  958. return
  959. pwidget = self.fPluginList[pluginId]
  960. if pwidget is None:
  961. return
  962. pwidget.ui.edit_dialog.reloadAll()
  963. @pyqtSlot(int, str)
  964. def slot_handlePatchbayClientAddedCallback(self, clientId, clientName):
  965. patchcanvas.addGroup(clientId, clientName)
  966. @pyqtSlot(int)
  967. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  968. patchcanvas.removeGroup(clientId)
  969. @pyqtSlot(int, str)
  970. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  971. patchcanvas.renameGroup(clientId, newClientName)
  972. @pyqtSlot(int, int, int, str)
  973. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  974. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  975. portMode = patchcanvas.PORT_MODE_INPUT
  976. elif (portFlags & PATCHBAY_PORT_IS_OUTPUT):
  977. portMode = patchcanvas.PORT_MODE_OUTPUT
  978. else:
  979. portMode = patchcanvas.PORT_MODE_NULL
  980. if (portFlags & PATCHBAY_PORT_IS_AUDIO):
  981. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  982. elif (portFlags & PATCHBAY_PORT_IS_MIDI):
  983. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  984. else:
  985. portType = patchcanvas.PORT_TYPE_NULL
  986. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  987. @pyqtSlot(int)
  988. def slot_handlePatchbayPortRemovedCallback(self, portId):
  989. patchcanvas.removePort(portId)
  990. @pyqtSlot(int, str)
  991. def slot_handlePatchbayPortRenamedCallback(self, portId, newPortName):
  992. patchcanvas.renamePort(portId, newPortName)
  993. @pyqtSlot(int, int, int)
  994. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  995. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  996. @pyqtSlot(int)
  997. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId):
  998. patchcanvas.disconnectPorts(connectionId)
  999. @pyqtSlot(str)
  1000. def slot_handleErrorCallback(self, error):
  1001. QMessageBox.critical(self, self.tr("Error"), error)
  1002. @pyqtSlot()
  1003. def slot_handleQuitCallback(self):
  1004. CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1005. self.tr("Engine has been stopped or crashed.\nPlease restart Carla"),
  1006. self.tr("You may want to save your session now..."), QMessageBox.Ok, QMessageBox.Ok)
  1007. def getExtraStuff(self, plugin):
  1008. ptype = plugin['type']
  1009. if ptype == PLUGIN_LADSPA:
  1010. uniqueId = plugin['uniqueId']
  1011. for rdfItem in self.fLadspaRdfList:
  1012. if rdfItem.UniqueID == uniqueId:
  1013. return pointer(rdfItem)
  1014. elif ptype == PLUGIN_DSSI:
  1015. if (plugin['hints'] & PLUGIN_HAS_GUI):
  1016. gui = findDSSIGUI(plugin['binary'], plugin['name'], plugin['label'])
  1017. if gui:
  1018. return gui.encode("utf-8")
  1019. elif ptype == PLUGIN_SF2:
  1020. if plugin['name'].endswith(" (16 outputs)"):
  1021. # return a dummy non-null pointer
  1022. INTPOINTER = POINTER(c_int)
  1023. ptr = c_int(0x1)
  1024. addr = addressof(ptr)
  1025. return cast(addr, INTPOINTER)
  1026. return c_nullptr
  1027. def loadRDFs(self):
  1028. # Save RDF info for later
  1029. self.fLadspaRdfList = []
  1030. if not haveLRDF:
  1031. return
  1032. settingsDir = os.path.join(HOME, ".config", "Cadence")
  1033. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1034. if os.path.exists(frLadspaFile):
  1035. frLadspa = open(frLadspaFile, 'r')
  1036. try:
  1037. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1038. except:
  1039. pass
  1040. frLadspa.close()
  1041. def saveSettings(self):
  1042. settings = QSettings()
  1043. settings.setValue("Geometry", self.saveGeometry())
  1044. settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  1045. settings.setValue("ShowTransport", self.ui.frame_transport.isVisible())
  1046. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1047. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1048. def loadSettings(self, geometry):
  1049. settings = QSettings()
  1050. if geometry:
  1051. self.restoreGeometry(settings.value("Geometry", ""))
  1052. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1053. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1054. self.ui.toolBar.setVisible(showToolbar)
  1055. showTransport = settings.value("ShowTransport", True, type=bool)
  1056. self.ui.act_settings_show_transport.setChecked(showTransport)
  1057. self.ui.frame_transport.setVisible(showTransport)
  1058. self.fSavedSettings = {
  1059. "Main/DefaultProjectFolder": settings.value("Main/DefaultProjectFolder", HOME, type=str),
  1060. "Main/RefreshInterval": settings.value("Main/RefreshInterval", 50, type=int),
  1061. "Canvas/Theme": settings.value("Canvas/Theme", patchcanvas.getDefaultThemeName(), type=str),
  1062. "Canvas/AutoHideGroups": settings.value("Canvas/AutoHideGroups", False, type=bool),
  1063. "Canvas/UseBezierLines": settings.value("Canvas/UseBezierLines", True, type=bool),
  1064. "Canvas/EyeCandy": settings.value("Canvas/EyeCandy", patchcanvas.EYECANDY_SMALL, type=int),
  1065. "Canvas/UseOpenGL": settings.value("Canvas/UseOpenGL", False, type=bool),
  1066. "Canvas/Antialiasing": settings.value("Canvas/Antialiasing", patchcanvas.ANTIALIASING_SMALL, type=int),
  1067. "Canvas/HighQualityAntialiasing": settings.value("Canvas/HighQualityAntialiasing", False, type=bool)
  1068. }
  1069. # ---------------------------------------------
  1070. # plugin checks
  1071. if settings.value("Engine/DisableChecks", False, type=bool):
  1072. os.environ["CARLA_DISCOVERY_NO_PROCESSING_CHECKS"] = "true"
  1073. elif os.getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS"):
  1074. os.environ.pop("CARLA_DISCOVERY_NO_PROCESSING_CHECKS")
  1075. # ---------------------------------------------
  1076. # plugin paths
  1077. Carla.LADSPA_PATH = toList(settings.value("Paths/LADSPA", Carla.LADSPA_PATH))
  1078. Carla.DSSI_PATH = toList(settings.value("Paths/DSSI", Carla.DSSI_PATH))
  1079. Carla.LV2_PATH = toList(settings.value("Paths/LV2", Carla.LV2_PATH))
  1080. Carla.VST_PATH = toList(settings.value("Paths/VST", Carla.VST_PATH))
  1081. Carla.GIG_PATH = toList(settings.value("Paths/GIG", Carla.GIG_PATH))
  1082. Carla.SF2_PATH = toList(settings.value("Paths/SF2", Carla.SF2_PATH))
  1083. Carla.SFZ_PATH = toList(settings.value("Paths/SFZ", Carla.SFZ_PATH))
  1084. os.environ["LADSPA_PATH"] = splitter.join(Carla.LADSPA_PATH)
  1085. os.environ["DSSI_PATH"] = splitter.join(Carla.DSSI_PATH)
  1086. os.environ["LV2_PATH"] = splitter.join(Carla.LV2_PATH)
  1087. os.environ["VST_PATH"] = splitter.join(Carla.VST_PATH)
  1088. os.environ["GIG_PATH"] = splitter.join(Carla.GIG_PATH)
  1089. os.environ["SF2_PATH"] = splitter.join(Carla.SF2_PATH)
  1090. os.environ["SFZ_PATH"] = splitter.join(Carla.SFZ_PATH)
  1091. def resizeEvent(self, event):
  1092. if self.ui.tabWidget.currentIndex() == 0:
  1093. # Force update of 2nd tab
  1094. width = self.ui.tab_plugins.width()-4
  1095. height = self.ui.tab_plugins.height()-4
  1096. self.ui.miniCanvasPreview.setViewSize(float(width) / DEFAULT_CANVAS_WIDTH, float(height) / DEFAULT_CANVAS_HEIGHT)
  1097. else:
  1098. QTimer.singleShot(0, self, SLOT("slot_miniCanvasCheckSize()"))
  1099. QMainWindow.resizeEvent(self, event)
  1100. def timerEvent(self, event):
  1101. if event.timerId() == self.fIdleTimerFast:
  1102. Carla.host.engine_idle()
  1103. for pwidget in self.fPluginList:
  1104. if pwidget is None:
  1105. break
  1106. pwidget.idleFast()
  1107. elif event.timerId() == self.fIdleTimerSlow:
  1108. for pwidget in self.fPluginList:
  1109. if pwidget is None:
  1110. break
  1111. pwidget.idleSlow()
  1112. QMainWindow.timerEvent(self, event)
  1113. def closeEvent(self, event):
  1114. #if self.nsm_server:
  1115. #self.nsm_server.stop()
  1116. self.saveSettings()
  1117. if Carla.host.is_engine_running():
  1118. Carla.host.set_engine_about_to_close()
  1119. self.removeAllPlugins()
  1120. self.stopEngine()
  1121. QMainWindow.closeEvent(self, event)
  1122. # ------------------------------------------------------------------------------------------------
  1123. def canvasCallback(action, value1, value2, valueStr):
  1124. if action == patchcanvas.ACTION_GROUP_INFO:
  1125. pass
  1126. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1127. pass
  1128. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1129. groupId = value1
  1130. patchcanvas.splitGroup(groupId)
  1131. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1132. groupId = value1
  1133. patchcanvas.joinGroup(groupId)
  1134. elif action == patchcanvas.ACTION_PORT_INFO:
  1135. pass
  1136. elif action == patchcanvas.ACTION_PORT_RENAME:
  1137. pass
  1138. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1139. portIdA = value1
  1140. portIdB = value2
  1141. Carla.host.patchbay_connect(portIdA, portIdB)
  1142. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1143. connectionId = value1
  1144. Carla.host.patchbay_disconnect(connectionId)
  1145. def engineCallback(ptr, action, pluginId, value1, value2, value3, valueStr):
  1146. if pluginId < 0 or not Carla.gui:
  1147. return
  1148. if action == CALLBACK_DEBUG:
  1149. Carla.gui.emit(SIGNAL("DebugCallback(int, int, int, double, QString)"), pluginId, value1, value2, value3, cString(valueStr))
  1150. elif action == CALLBACK_PLUGIN_ADDED:
  1151. Carla.gui.emit(SIGNAL("PluginAddedCallback(int)"), pluginId)
  1152. elif action == CALLBACK_PLUGIN_REMOVED:
  1153. Carla.gui.emit(SIGNAL("PluginRemovedCallback(int)"), pluginId)
  1154. elif action == CALLBACK_PARAMETER_VALUE_CHANGED:
  1155. Carla.gui.emit(SIGNAL("ParameterValueChangedCallback(int, int, double)"), pluginId, value1, value3)
  1156. elif action == CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1157. Carla.gui.emit(SIGNAL("ParameterDefaultChangedCallback(int, int, double)"), pluginId, value1, value3)
  1158. elif action == CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1159. Carla.gui.emit(SIGNAL("ParameterMidiChannelChangedCallback(int, int, int)"), pluginId, value1, value2)
  1160. elif action == CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1161. Carla.gui.emit(SIGNAL("ParameterMidiCcChangedCallback(int, int, int)"), pluginId, value1, value2)
  1162. elif action == CALLBACK_PROGRAM_CHANGED:
  1163. Carla.gui.emit(SIGNAL("ProgramChangedCallback(int, int)"), pluginId, value1)
  1164. elif action == CALLBACK_MIDI_PROGRAM_CHANGED:
  1165. Carla.gui.emit(SIGNAL("MidiProgramChangedCallback(int, int)"), pluginId, value1)
  1166. elif action == CALLBACK_NOTE_ON:
  1167. Carla.gui.emit(SIGNAL("NoteOnCallback(int, int, int, int)"), pluginId, value1, value2, value3)
  1168. elif action == CALLBACK_NOTE_OFF:
  1169. Carla.gui.emit(SIGNAL("NoteOffCallback(int, int, int)"), pluginId, value1, value2)
  1170. elif action == CALLBACK_SHOW_GUI:
  1171. Carla.gui.emit(SIGNAL("ShowGuiCallback(int, int)"), pluginId, value1)
  1172. elif action == CALLBACK_UPDATE:
  1173. Carla.gui.emit(SIGNAL("UpdateCallback(int)"), pluginId)
  1174. elif action == CALLBACK_RELOAD_INFO:
  1175. Carla.gui.emit(SIGNAL("ReloadInfoCallback(int)"), pluginId)
  1176. elif action == CALLBACK_RELOAD_PARAMETERS:
  1177. Carla.gui.emit(SIGNAL("ReloadParametersCallback(int)"), pluginId)
  1178. elif action == CALLBACK_RELOAD_PROGRAMS:
  1179. Carla.gui.emit(SIGNAL("ReloadProgramsCallback(int)"), pluginId)
  1180. elif action == CALLBACK_RELOAD_ALL:
  1181. Carla.gui.emit(SIGNAL("ReloadAllCallback(int)"), pluginId)
  1182. elif action == CALLBACK_PATCHBAY_CLIENT_ADDED:
  1183. Carla.gui.emit(SIGNAL("PatchbayClientAddedCallback(int, QString)"), value1, cString(valueStr))
  1184. elif action == CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1185. Carla.gui.emit(SIGNAL("PatchbayClientRemovedCallback(int)"), value1)
  1186. elif action == CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1187. Carla.gui.emit(SIGNAL("PatchbayClientRenamedCallback(int, QString)"), value1, cString(valueStr))
  1188. elif action == CALLBACK_PATCHBAY_PORT_ADDED:
  1189. Carla.gui.emit(SIGNAL("PatchbayPortAddedCallback(int, int, int, QString)"), value1, value2, value3, cString(valueStr))
  1190. elif action == CALLBACK_PATCHBAY_PORT_REMOVED:
  1191. Carla.gui.emit(SIGNAL("PatchbayPortRemovedCallback(int)"), value1)
  1192. elif action == CALLBACK_PATCHBAY_PORT_RENAMED:
  1193. Carla.gui.emit(SIGNAL("PatchbayPortRenamedCallback(int, QString)"), value1, cString(valueStr))
  1194. elif action == CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1195. Carla.gui.emit(SIGNAL("PatchbayConnectionAddedCallback(int, int, int)"), value1, value2, value3)
  1196. elif action == CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1197. Carla.gui.emit(SIGNAL("PatchbayConnectionRemovedCallback(int)"), value1)
  1198. #elif action == CALLBACK_NSM_ANNOUNCE:
  1199. #Carla.gui._nsmAnnounce2str = cString(Carla.host.get_last_error())
  1200. #Carla.gui.emit(SIGNAL("NSM_AnnounceCallback()"))
  1201. #elif action == CALLBACK_NSM_OPEN1:
  1202. #Carla.gui._nsmOpen1str = cString(valueStr)
  1203. #Carla.gui.emit(SIGNAL("NSM_Open1Callback()"))
  1204. #elif action == CALLBACK_NSM_OPEN2:
  1205. #Carla.gui._nsmOpen2str = cString(valueStr)
  1206. #Carla.gui.emit(SIGNAL("NSM_Open2Callback()"))
  1207. #elif action == CALLBACK_NSM_SAVE:
  1208. #Carla.gui.emit(SIGNAL("NSM_SaveCallback()"))
  1209. elif action == CALLBACK_ERROR:
  1210. Carla.gui.emit(SIGNAL("ErrorCallback(QString)"), valueStr)
  1211. elif action == CALLBACK_QUIT:
  1212. Carla.gui.emit(SIGNAL("QuitCallback()"))
  1213. #--------------- main ------------------
  1214. if __name__ == '__main__':
  1215. # App initialization
  1216. app = QApplication(sys.argv)
  1217. app.setApplicationName("Carla")
  1218. app.setApplicationVersion(VERSION)
  1219. app.setOrganizationName("Cadence")
  1220. app.setWindowIcon(QIcon(":/scalable/carla.svg"))
  1221. libPrefix = None
  1222. projectFilename = None
  1223. for i in range(len(app.arguments())):
  1224. if i == 0: continue
  1225. argument = app.arguments()[i]
  1226. if argument.startswith("--with-libprefix="):
  1227. libPrefix = argument.replace("--with-libprefix=", "")
  1228. elif os.path.exists(argument):
  1229. projectFilename = argument
  1230. # Init backend
  1231. Carla.host = Host(libPrefix)
  1232. Carla.host.set_engine_callback(engineCallback)
  1233. Carla.host.set_engine_option(OPTION_PROCESS_NAME, 0, "carla")
  1234. # Set bridge paths
  1235. if carla_bridge_native:
  1236. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_NATIVE, 0, carla_bridge_native)
  1237. if carla_bridge_posix32:
  1238. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_POSIX32, 0, carla_bridge_posix32)
  1239. if carla_bridge_posix64:
  1240. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_POSIX64, 0, carla_bridge_posix64)
  1241. if carla_bridge_win32:
  1242. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_WIN32, 0, carla_bridge_win32)
  1243. if carla_bridge_win64:
  1244. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_WIN64, 0, carla_bridge_win64)
  1245. if WINDOWS:
  1246. if carla_bridge_lv2_windows:
  1247. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_WINDOWS, 0, carla_bridge_lv2_windows)
  1248. if carla_bridge_vst_hwnd:
  1249. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_HWND, 0, carla_bridge_vst_hwnd)
  1250. elif MACOS:
  1251. if carla_bridge_lv2_cocoa:
  1252. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_COCOA, 0, carla_bridge_lv2_cocoa)
  1253. if carla_bridge_vst_cocoa:
  1254. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_COCOA, 0, carla_bridge_vst_cocoa)
  1255. else:
  1256. if carla_bridge_lv2_gtk2:
  1257. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_GTK2, 0, carla_bridge_lv2_gtk2)
  1258. if carla_bridge_lv2_gtk3:
  1259. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_GTK3, 0, carla_bridge_lv2_gtk3)
  1260. if carla_bridge_lv2_qt4:
  1261. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_QT4, 0, carla_bridge_lv2_qt4)
  1262. if carla_bridge_lv2_qt5:
  1263. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_QT5, 0, carla_bridge_lv2_qt5)
  1264. if carla_bridge_lv2_x11:
  1265. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_X11, 0, carla_bridge_lv2_x11)
  1266. if carla_bridge_vst_x11:
  1267. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_X11, 0, carla_bridge_vst_x11)
  1268. # Create GUI and start engine
  1269. Carla.gui = CarlaMainW()
  1270. # Set-up custom signal handling
  1271. setUpSignals()
  1272. # Show GUI
  1273. Carla.gui.show()
  1274. # Load project file if set
  1275. if projectFilename:
  1276. Carla.gui.loadProjectLater(projectFilename)
  1277. # App-Loop
  1278. ret = app.exec_()
  1279. # Exit properly
  1280. sys.exit(ret)