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.

1921 lines
78KB

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