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.

2081 lines
84KB

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