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.

2085 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. if newPath[-1] == os.sep:
  628. newPath = newPath[:-1]
  629. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  630. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  631. self.ui.b_disk_remove.setEnabled(True)
  632. @pyqtSlot()
  633. def slot_diskFolderRemove(self):
  634. index = self.ui.cb_disk.currentIndex()
  635. if index <= 0:
  636. return
  637. self.ui.cb_disk.removeItem(index)
  638. if self.ui.cb_disk.currentIndex() == 0:
  639. self.ui.b_disk_remove.setEnabled(False)
  640. @pyqtSlot(str)
  641. def slot_handleNSM_AnnounceCallback(self, smName):
  642. self.fSessionManagerName = smName
  643. self.ui.act_file_new.setEnabled(False)
  644. self.ui.act_file_open.setEnabled(False)
  645. self.ui.act_file_save_as.setEnabled(False)
  646. self.ui.act_engine_start.setEnabled(True)
  647. self.ui.act_engine_stop.setEnabled(False)
  648. @pyqtSlot(str)
  649. def slot_handleNSM_OpenCallback(self, data):
  650. projectPath, clientId = data.rsplit(":", 1)
  651. self.fClientName = clientId
  652. # restart engine
  653. if self.fEngineStarted:
  654. self.stopEngine()
  655. self.slot_engineStart()
  656. if self.fEngineStarted:
  657. self.loadProject(projectPath)
  658. Carla.host.nsm_reply_open()
  659. @pyqtSlot()
  660. def slot_handleNSM_SaveCallback(self):
  661. self.saveProject(self.fProjectFilename)
  662. Carla.host.nsm_reply_save()
  663. @pyqtSlot()
  664. def slot_toolbarShown(self):
  665. self.updateInfoLabelPos()
  666. @pyqtSlot()
  667. def slot_splitterMoved(self):
  668. self.updateInfoLabelSize()
  669. @pyqtSlot()
  670. def slot_canvasArrange(self):
  671. patchcanvas.arrange()
  672. @pyqtSlot()
  673. def slot_canvasRefresh(self):
  674. patchcanvas.clear()
  675. Carla.host.patchbay_refresh()
  676. QTimer.singleShot(1000 if self.fSavedSettings['Canvas/EyeCandy'] else 0, self.ui.miniCanvasPreview, SLOT("update()"))
  677. @pyqtSlot()
  678. def slot_canvasZoomFit(self):
  679. self.scene.zoom_fit()
  680. @pyqtSlot()
  681. def slot_canvasZoomIn(self):
  682. self.scene.zoom_in()
  683. @pyqtSlot()
  684. def slot_canvasZoomOut(self):
  685. self.scene.zoom_out()
  686. @pyqtSlot()
  687. def slot_canvasZoomReset(self):
  688. self.scene.zoom_reset()
  689. @pyqtSlot()
  690. def slot_canvasPrint(self):
  691. self.scene.clearSelection()
  692. self.fExportPrinter = QPrinter()
  693. dialog = QPrintDialog(self.fExportPrinter, self)
  694. if dialog.exec_():
  695. painter = QPainter(self.fExportPrinter)
  696. painter.setRenderHint(QPainter.Antialiasing)
  697. painter.setRenderHint(QPainter.TextAntialiasing)
  698. self.scene.render(painter)
  699. @pyqtSlot()
  700. def slot_canvasSaveImage(self):
  701. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  702. if newPath:
  703. self.scene.clearSelection()
  704. # FIXME - must be a better way...
  705. if newPath.endswith((".jpg", ".jpG", ".jPG", ".JPG", ".JPg", ".Jpg")):
  706. imgFormat = "JPG"
  707. elif newPath.endswith((".png", ".pnG", ".pNG", ".PNG", ".PNg", ".Png")):
  708. imgFormat = "PNG"
  709. else:
  710. # File-dialog may not auto-add the extension
  711. imgFormat = "PNG"
  712. newPath += ".png"
  713. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  714. painter = QPainter(self.fExportImage)
  715. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  716. painter.setRenderHint(QPainter.TextAntialiasing)
  717. self.scene.render(painter)
  718. self.fExportImage.save(newPath, imgFormat, 100)
  719. @pyqtSlot(QModelIndex)
  720. def slot_fileTreeDoubleClicked(self, modelIndex):
  721. filename = self.fDirModel.filePath(modelIndex)
  722. if not Carla.host.load_filename(filename):
  723. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  724. self.tr("Failed to load file"),
  725. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  726. @pyqtSlot(float)
  727. def slot_canvasScaleChanged(self, scale):
  728. self.ui.miniCanvasPreview.setViewScale(scale)
  729. @pyqtSlot(int, int, QPointF)
  730. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  731. self.ui.miniCanvasPreview.update()
  732. @pyqtSlot(int)
  733. def slot_horizontalScrollBarChanged(self, value):
  734. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  735. if maximum == 0:
  736. xp = 0
  737. else:
  738. xp = float(value) / maximum
  739. self.ui.miniCanvasPreview.setViewPosX(xp)
  740. @pyqtSlot(int)
  741. def slot_verticalScrollBarChanged(self, value):
  742. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  743. if maximum == 0:
  744. yp = 0
  745. else:
  746. yp = float(value) / maximum
  747. self.ui.miniCanvasPreview.setViewPosY(yp)
  748. @pyqtSlot()
  749. def slot_miniCanvasInit(self):
  750. settings = QSettings()
  751. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", DEFAULT_CANVAS_WIDTH / 3, type=int))
  752. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", DEFAULT_CANVAS_HEIGHT * 3 / 8, type=int))
  753. tabBar = self.ui.tabMain.tabBar()
  754. x = tabBar.width()+20
  755. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()+tabBar.height()/4
  756. self.fInfoLabel.move(x, y)
  757. self.fInfoLabel.resize(self.ui.tabMain.width()-x, tabBar.height())
  758. @pyqtSlot(float, float)
  759. def slot_miniCanvasMoved(self, xp, yp):
  760. self.ui.graphicsView.horizontalScrollBar().setValue(xp * DEFAULT_CANVAS_WIDTH)
  761. self.ui.graphicsView.verticalScrollBar().setValue(yp * DEFAULT_CANVAS_HEIGHT)
  762. @pyqtSlot()
  763. def slot_miniCanvasCheckAll(self):
  764. self.slot_miniCanvasCheckSize()
  765. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  766. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  767. @pyqtSlot()
  768. def slot_miniCanvasCheckSize(self):
  769. self.ui.miniCanvasPreview.setViewSize(float(self.ui.graphicsView.width()) / DEFAULT_CANVAS_WIDTH, float(self.ui.graphicsView.height()) / DEFAULT_CANVAS_HEIGHT)
  770. def startEngine(self):
  771. # ---------------------------------------------
  772. # Engine settings
  773. settings = QSettings()
  774. if LINUX:
  775. defaultMode = PROCESS_MODE_MULTIPLE_CLIENTS
  776. else:
  777. defaultMode = PROCESS_MODE_CONTINUOUS_RACK
  778. Carla.processMode = settings.value("Engine/ProcessMode", defaultMode, type=int)
  779. Carla.maxParameters = settings.value("Engine/MaxParameters", MAX_DEFAULT_PARAMETERS, type=int)
  780. transportMode = settings.value("Engine/TransportMode", TRANSPORT_MODE_JACK, type=int)
  781. forceStereo = settings.value("Engine/ForceStereo", False, type=bool)
  782. preferPluginBridges = settings.value("Engine/PreferPluginBridges", False, type=bool)
  783. preferUiBridges = settings.value("Engine/PreferUiBridges", True, type=bool)
  784. useDssiVstChunks = settings.value("Engine/UseDssiVstChunks", False, type=bool)
  785. oscUiTimeout = settings.value("Engine/OscUiTimeout", 40, type=int)
  786. preferredBufferSize = settings.value("Engine/PreferredBufferSize", 512, type=int)
  787. preferredSampleRate = settings.value("Engine/PreferredSampleRate", 44100, type=int)
  788. if Carla.processMode == PROCESS_MODE_CONTINUOUS_RACK:
  789. forceStereo = True
  790. elif Carla.processMode == PROCESS_MODE_MULTIPLE_CLIENTS and os.getenv("LADISH_APP_NAME"):
  791. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  792. Carla.processMode = PROCESS_MODE_SINGLE_CLIENT
  793. Carla.host.set_engine_option(OPTION_PROCESS_MODE, Carla.processMode, "")
  794. Carla.host.set_engine_option(OPTION_MAX_PARAMETERS, Carla.maxParameters, "")
  795. Carla.host.set_engine_option(OPTION_FORCE_STEREO, forceStereo, "")
  796. Carla.host.set_engine_option(OPTION_PREFER_PLUGIN_BRIDGES, preferPluginBridges, "")
  797. Carla.host.set_engine_option(OPTION_PREFER_UI_BRIDGES, preferUiBridges, "")
  798. Carla.host.set_engine_option(OPTION_USE_DSSI_VST_CHUNKS, useDssiVstChunks, "")
  799. Carla.host.set_engine_option(OPTION_OSC_UI_TIMEOUT, oscUiTimeout, "")
  800. Carla.host.set_engine_option(OPTION_PREFERRED_BUFFER_SIZE, preferredBufferSize, "")
  801. Carla.host.set_engine_option(OPTION_PREFERRED_SAMPLE_RATE, preferredSampleRate, "")
  802. # ---------------------------------------------
  803. # Start
  804. audioDriver = settings.value("Engine/AudioDriver", CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  805. if not Carla.host.engine_init(audioDriver, self.fClientName):
  806. if self.fFirstEngineInit:
  807. self.fFirstEngineInit = False
  808. return
  809. audioError = cString(Carla.host.get_last_error())
  810. if audioError:
  811. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  812. else:
  813. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  814. return
  815. self.fBufferSize = Carla.host.get_buffer_size()
  816. self.fSampleRate = Carla.host.get_sample_rate()
  817. self.fEngineStarted = True
  818. self.fFirstEngineInit = False
  819. self.fPluginCount = 0
  820. self.fPluginList = []
  821. if Carla.processMode == PROCESS_MODE_CONTINUOUS_RACK:
  822. maxCount = MAX_RACK_PLUGINS
  823. elif Carla.processMode == PROCESS_MODE_PATCHBAY:
  824. maxCount = MAX_PATCHBAY_PLUGINS
  825. else:
  826. maxCount = MAX_DEFAULT_PLUGINS
  827. if transportMode == TRANSPORT_MODE_JACK and audioDriver != "JACK":
  828. transportMode = TRANSPORT_MODE_INTERNAL
  829. for x in range(maxCount):
  830. self.fPluginList.append(None)
  831. Carla.host.set_engine_option(OPTION_TRANSPORT_MODE, transportMode, "")
  832. # Peaks and TimeInfo
  833. self.fIdleTimerFast = self.startTimer(self.fSavedSettings["Main/RefreshInterval"])
  834. # LEDs and edit dialog parameters
  835. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings["Main/RefreshInterval"]*2)
  836. def stopEngine(self):
  837. if self.fPluginCount > 0:
  838. 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"
  839. "Do you want to do this now?"),
  840. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  841. if ask != QMessageBox.Yes:
  842. return
  843. self.removeAllPlugins()
  844. self.fEngineStarted = False
  845. if Carla.host.is_engine_running() and not Carla.host.engine_close():
  846. print(cString(Carla.host.get_last_error()))
  847. self.fBufferSize = 0
  848. self.fSampleRate = 0.0
  849. self.fPluginCount = 0
  850. self.fPluginList = []
  851. self.killTimer(self.fIdleTimerFast)
  852. self.killTimer(self.fIdleTimerSlow)
  853. patchcanvas.clear()
  854. def setProperWindowTitle(self):
  855. title = "%s" % os.getenv("LADISH_APP_NAME", "Carla")
  856. if self.fProjectFilename:
  857. title += " - %s" % os.path.basename(self.fProjectFilename)
  858. if self.fSessionManagerName:
  859. title += " (%s)" % self.fSessionManagerName
  860. self.setWindowTitle(title)
  861. def loadProject(self, filename):
  862. self.fProjectFilename = filename
  863. self.setProperWindowTitle()
  864. self.fProjectLoading = True
  865. Carla.host.load_project(filename)
  866. self.fProjectLoading = False
  867. def loadProjectLater(self, filename):
  868. self.fProjectFilename = filename
  869. self.setProperWindowTitle()
  870. QTimer.singleShot(0, self, SLOT("slot_loadProjectLater()"))
  871. def saveProject(self, filename):
  872. self.fProjectFilename = filename
  873. self.setProperWindowTitle()
  874. Carla.host.save_project(filename)
  875. def addPlugin(self, btype, ptype, filename, name, label, extraStuff):
  876. if not self.fEngineStarted:
  877. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  878. return False
  879. if not Carla.host.add_plugin(btype, ptype, filename, name, label, extraStuff):
  880. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  881. return False
  882. return True
  883. def removeAllPlugins(self):
  884. while (self.ui.w_plugins.layout().takeAt(0)):
  885. pass
  886. self.ui.act_plugin_remove_all.setEnabled(False)
  887. for i in range(self.fPluginCount):
  888. pwidget = self.fPluginList[i]
  889. if pwidget is None:
  890. break
  891. self.fPluginList[i] = None
  892. pwidget.ui.edit_dialog.close()
  893. pwidget.close()
  894. pwidget.deleteLater()
  895. del pwidget
  896. self.fPluginCount = 0
  897. Carla.host.remove_all_plugins()
  898. @pyqtSlot()
  899. def slot_fileNew(self):
  900. self.removeAllPlugins()
  901. self.fProjectFilename = None
  902. self.fProjectLoading = False
  903. self.setProperWindowTitle()
  904. @pyqtSlot()
  905. def slot_fileOpen(self):
  906. fileFilter = self.tr("Carla Project File (*.carxp)")
  907. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings["Main/DefaultProjectFolder"], filter=fileFilter)
  908. if filenameTry:
  909. # FIXME - show dialog to user
  910. self.removeAllPlugins()
  911. self.loadProject(filenameTry)
  912. @pyqtSlot()
  913. def slot_fileSave(self, saveAs=False):
  914. if self.fProjectFilename and not saveAs:
  915. return self.saveProject(self.fProjectFilename)
  916. fileFilter = self.tr("Carla Project File (*.carxp)")
  917. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings["Main/DefaultProjectFolder"], filter=fileFilter)
  918. if filenameTry:
  919. if not filenameTry.endswith(".carxp"):
  920. filenameTry += ".carxp"
  921. self.saveProject(filenameTry)
  922. @pyqtSlot()
  923. def slot_fileSaveAs(self):
  924. self.slot_fileSave(True)
  925. @pyqtSlot()
  926. def slot_loadProjectLater(self):
  927. self.fProjectLoading = True
  928. Carla.host.load_project(self.fProjectFilename)
  929. self.fProjectLoading = False
  930. @pyqtSlot()
  931. def slot_engineStart(self):
  932. self.startEngine()
  933. check = Carla.host.is_engine_running()
  934. self.ui.act_engine_start.setEnabled(not check)
  935. self.ui.act_engine_stop.setEnabled(check)
  936. if self.fSessionManagerName != "Non Session Manager":
  937. self.ui.act_file_open.setEnabled(check)
  938. if check:
  939. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (self.fSampleRate, self.fBufferSize)
  940. self.refreshTransport(True)
  941. self.menuTransport(check)
  942. @pyqtSlot()
  943. def slot_engineStop(self):
  944. self.stopEngine()
  945. check = Carla.host.is_engine_running()
  946. self.ui.act_engine_start.setEnabled(not check)
  947. self.ui.act_engine_stop.setEnabled(check)
  948. if self.fSessionManagerName != "Non Session Manager":
  949. self.ui.act_file_open.setEnabled(check)
  950. if not check:
  951. self.fInfoText = ""
  952. self.fInfoLabel.setText("Engine stopped")
  953. self.menuTransport(check)
  954. @pyqtSlot()
  955. def slot_pluginAdd(self):
  956. dialog = PluginDatabaseW(self)
  957. if dialog.exec_():
  958. btype = dialog.fRetPlugin['build']
  959. ptype = dialog.fRetPlugin['type']
  960. filename = dialog.fRetPlugin['binary']
  961. label = dialog.fRetPlugin['label']
  962. extraStuff = self.getExtraStuff(dialog.fRetPlugin)
  963. self.addPlugin(btype, ptype, filename, None, label, extraStuff)
  964. @pyqtSlot()
  965. def slot_pluginRemoveAll(self):
  966. self.removeAllPlugins()
  967. def menuTransport(self, enabled):
  968. self.ui.act_transport_play.setEnabled(enabled)
  969. self.ui.act_transport_stop.setEnabled(enabled)
  970. self.ui.act_transport_backwards.setEnabled(enabled)
  971. self.ui.act_transport_forwards.setEnabled(enabled)
  972. self.ui.menu_Transport.setEnabled(enabled)
  973. def refreshTransport(self, forced = False):
  974. if not self.fEngineStarted:
  975. return
  976. if self.fSampleRate == 0.0:
  977. return
  978. timeInfo = Carla.host.get_transport_info()
  979. playing = timeInfo['playing']
  980. time = timeInfo['frame'] / self.fSampleRate
  981. secs = time % 60
  982. mins = (time / 60) % 60
  983. hrs = (time / 3600) % 60
  984. textTransport = "Transport %s, at %02i:%02i:%02i" % ("playing" if playing else "stopped", hrs, mins, secs)
  985. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, textTransport))
  986. if playing != self.fTransportWasPlaying or forced:
  987. self.fTransportWasPlaying = playing
  988. if playing:
  989. icon = getIcon("media-playback-pause")
  990. self.ui.act_transport_play.setChecked(True)
  991. self.ui.act_transport_play.setIcon(icon)
  992. self.ui.act_transport_play.setText(self.tr("&Pause"))
  993. else:
  994. icon = getIcon("media-playback-start")
  995. self.ui.act_transport_play.setChecked(False)
  996. self.ui.act_transport_play.setIcon(icon)
  997. self.ui.act_transport_play.setText(self.tr("&Play"))
  998. @pyqtSlot(bool)
  999. def slot_transportPlayPause(self, toggled):
  1000. if not self.fEngineStarted:
  1001. return
  1002. if toggled:
  1003. Carla.host.transport_play()
  1004. else:
  1005. Carla.host.transport_pause()
  1006. self.refreshTransport()
  1007. @pyqtSlot()
  1008. def slot_transportStop(self):
  1009. if not self.fEngineStarted:
  1010. return
  1011. Carla.host.transport_pause()
  1012. Carla.host.transport_relocate(0)
  1013. self.refreshTransport()
  1014. @pyqtSlot()
  1015. def slot_transportBackwards(self):
  1016. if not self.fEngineStarted:
  1017. return
  1018. newFrame = Carla.host.get_current_transport_frame() - 100000
  1019. if newFrame < 0:
  1020. newFrame = 0
  1021. Carla.host.transport_relocate(newFrame)
  1022. @pyqtSlot()
  1023. def slot_transportForwards(self):
  1024. if not self.fEngineStarted:
  1025. return
  1026. newFrame = Carla.host.get_current_transport_frame() + 100000
  1027. Carla.host.transport_relocate(newFrame)
  1028. @pyqtSlot()
  1029. def slot_aboutCarla(self):
  1030. CarlaAboutW(self).exec_()
  1031. @pyqtSlot()
  1032. def slot_configureCarla(self):
  1033. dialog = CarlaSettingsW(self)
  1034. if dialog.exec_():
  1035. self.loadSettings(False)
  1036. patchcanvas.clear()
  1037. pOptions = patchcanvas.options_t()
  1038. pOptions.theme_name = self.fSavedSettings["Canvas/Theme"]
  1039. pOptions.auto_hide_groups = self.fSavedSettings["Canvas/AutoHideGroups"]
  1040. pOptions.use_bezier_lines = self.fSavedSettings["Canvas/UseBezierLines"]
  1041. pOptions.antialiasing = self.fSavedSettings["Canvas/Antialiasing"]
  1042. pOptions.eyecandy = self.fSavedSettings["Canvas/EyeCandy"]
  1043. pFeatures = patchcanvas.features_t()
  1044. pFeatures.group_info = False
  1045. pFeatures.group_rename = False
  1046. pFeatures.port_info = False
  1047. pFeatures.port_rename = False
  1048. pFeatures.handle_group_pos = True
  1049. patchcanvas.setOptions(pOptions)
  1050. patchcanvas.setFeatures(pFeatures)
  1051. patchcanvas.init("Carla", self.scene, canvasCallback, False)
  1052. if self.fEngineStarted:
  1053. Carla.host.patchbay_refresh()
  1054. for pwidget in self.fPluginList:
  1055. if pwidget is None:
  1056. return
  1057. pwidget.setRefreshRate(self.fSavedSettings["Main/RefreshInterval"])
  1058. @pyqtSlot()
  1059. def slot_handleSIGUSR1(self):
  1060. print("Got SIGUSR1 -> Saving project now")
  1061. QTimer.singleShot(0, self, SLOT("slot_fileSave()"))
  1062. @pyqtSlot()
  1063. def slot_handleSIGTERM(self):
  1064. print("Got SIGTERM -> Closing now")
  1065. self.close()
  1066. @pyqtSlot(int, int, int, float, str)
  1067. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1068. self.ui.pte_log.appendPlainText(valueStr.replace("", "DEBUG: ").replace("", "ERROR: ").replace("", "").replace("\n", ""))
  1069. @pyqtSlot(int)
  1070. def slot_handlePluginAddedCallback(self, pluginId):
  1071. pwidget = PluginWidget(self, pluginId)
  1072. pwidget.setRefreshRate(self.fSavedSettings["Main/RefreshInterval"])
  1073. self.ui.w_plugins.layout().addWidget(pwidget)
  1074. self.fPluginCount += 1
  1075. self.fPluginList[pluginId] = pwidget
  1076. if not self.fProjectLoading:
  1077. pwidget.setActive(True, True, True)
  1078. if self.fPluginCount == 1:
  1079. self.ui.act_plugin_remove_all.setEnabled(True)
  1080. if self.fLastLoadedPluginId == -2:
  1081. self.fLastLoadedPluginId = pluginId
  1082. @pyqtSlot(int)
  1083. def slot_handlePluginRemovedCallback(self, pluginId):
  1084. if pluginId >= self.fPluginCount:
  1085. return
  1086. pwidget = self.fPluginList[pluginId]
  1087. if pwidget is None:
  1088. return
  1089. self.fPluginList[pluginId] = None
  1090. self.fPluginCount -= 1
  1091. self.ui.w_plugins.layout().removeWidget(pwidget)
  1092. pwidget.ui.edit_dialog.close()
  1093. pwidget.close()
  1094. pwidget.deleteLater()
  1095. del pwidget
  1096. # push all plugins 1 slot back
  1097. for i in range(pluginId, self.fPluginCount):
  1098. self.fPluginList[i] = self.fPluginList[i+1]
  1099. self.fPluginList[i].setId(i)
  1100. if self.fPluginCount == 0:
  1101. self.ui.act_plugin_remove_all.setEnabled(False)
  1102. @pyqtSlot(int, str)
  1103. def slot_handlePluginRenamedCallback(self, pluginId, newName):
  1104. if pluginId >= self.fPluginCount:
  1105. return
  1106. pwidget = self.fPluginList[pluginId]
  1107. if pwidget is None:
  1108. return
  1109. pwidget.ui.label_name.setText(newName)
  1110. @pyqtSlot(int, int, float)
  1111. def slot_handleParameterValueChangedCallback(self, pluginId, parameterId, value):
  1112. if pluginId >= self.fPluginCount:
  1113. return
  1114. pwidget = self.fPluginList[pluginId]
  1115. if pwidget is None:
  1116. return
  1117. pwidget.setParameterValue(parameterId, value)
  1118. @pyqtSlot(int, int, float)
  1119. def slot_handleParameterDefaultChangedCallback(self, pluginId, parameterId, value):
  1120. if pluginId >= self.fPluginCount:
  1121. return
  1122. pwidget = self.fPluginList[pluginId]
  1123. if pwidget is None:
  1124. return
  1125. pwidget.setParameterDefault(parameterId, value)
  1126. @pyqtSlot(int, int, int)
  1127. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, parameterId, channel):
  1128. if pluginId >= self.fPluginCount:
  1129. return
  1130. pwidget = self.fPluginList[pluginId]
  1131. if pwidget is None:
  1132. return
  1133. pwidget.setParameterMidiChannel(parameterId, channel)
  1134. @pyqtSlot(int, int, int)
  1135. def slot_handleParameterMidiCcChangedCallback(self, pluginId, parameterId, cc):
  1136. if pluginId >= self.fPluginCount:
  1137. return
  1138. pwidget = self.fPluginList[pluginId]
  1139. if pwidget is None:
  1140. return
  1141. pwidget.setParameterMidiControl(parameterId, cc)
  1142. @pyqtSlot(int, int)
  1143. def slot_handleProgramChangedCallback(self, pluginId, programId):
  1144. if pluginId >= self.fPluginCount:
  1145. return
  1146. pwidget = self.fPluginList[pluginId]
  1147. if pwidget is None:
  1148. return
  1149. pwidget.setProgram(programId)
  1150. @pyqtSlot(int, int)
  1151. def slot_handleMidiProgramChangedCallback(self, pluginId, midiProgramId):
  1152. if pluginId >= self.fPluginCount:
  1153. return
  1154. pwidget = self.fPluginList[pluginId]
  1155. if pwidget is None:
  1156. return
  1157. pwidget.setMidiProgram(midiProgramId)
  1158. @pyqtSlot(int, int, int, int)
  1159. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  1160. if pluginId >= self.fPluginCount:
  1161. return
  1162. pwidget = self.fPluginList[pluginId]
  1163. if pwidget is None:
  1164. return
  1165. pwidget.sendNoteOn(channel, note)
  1166. @pyqtSlot(int, int, int)
  1167. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1168. if pluginId >= self.fPluginCount:
  1169. return
  1170. pwidget = self.fPluginList[pluginId]
  1171. if pwidget is None:
  1172. return
  1173. pwidget.sendNoteOff(channel, note)
  1174. @pyqtSlot(int, int)
  1175. def slot_handleShowGuiCallback(self, pluginId, show):
  1176. if pluginId >= self.fPluginCount:
  1177. return
  1178. pwidget = self.fPluginList[pluginId]
  1179. if pwidget is None:
  1180. return
  1181. if show == 0:
  1182. pwidget.ui.b_gui.setChecked(False)
  1183. pwidget.ui.b_gui.setEnabled(True)
  1184. elif show == 1:
  1185. pwidget.ui.b_gui.setChecked(True)
  1186. pwidget.ui.b_gui.setEnabled(True)
  1187. elif show == -1:
  1188. pwidget.ui.b_gui.setChecked(False)
  1189. pwidget.ui.b_gui.setEnabled(False)
  1190. @pyqtSlot(int)
  1191. def slot_handleUpdateCallback(self, pluginId):
  1192. if pluginId >= self.fPluginCount:
  1193. return
  1194. pwidget = self.fPluginList[pluginId]
  1195. if pwidget is None:
  1196. return
  1197. pwidget.ui.edit_dialog.updateInfo()
  1198. @pyqtSlot(int)
  1199. def slot_handleReloadInfoCallback(self, pluginId):
  1200. if pluginId >= self.fPluginCount:
  1201. return
  1202. pwidget = self.fPluginList[pluginId]
  1203. if pwidget is None:
  1204. return
  1205. pwidget.ui.edit_dialog.reloadInfo()
  1206. @pyqtSlot(int)
  1207. def slot_handleReloadParametersCallback(self, pluginId):
  1208. if pluginId >= self.fPluginCount:
  1209. return
  1210. pwidget = self.fPluginList[pluginId]
  1211. if pwidget is None:
  1212. return
  1213. pwidget.ui.edit_dialog.reloadParameters()
  1214. @pyqtSlot(int)
  1215. def slot_handleReloadProgramsCallback(self, pluginId):
  1216. if pluginId >= self.fPluginCount:
  1217. return
  1218. pwidget = self.fPluginList[pluginId]
  1219. if pwidget is None:
  1220. return
  1221. pwidget.ui.edit_dialog.reloadPrograms()
  1222. @pyqtSlot(int)
  1223. def slot_handleReloadAllCallback(self, pluginId):
  1224. if pluginId >= self.fPluginCount:
  1225. return
  1226. pwidget = self.fPluginList[pluginId]
  1227. if pwidget is None:
  1228. return
  1229. pwidget.ui.edit_dialog.reloadAll()
  1230. @pyqtSlot(int, str)
  1231. def slot_handlePatchbayClientAddedCallback(self, clientId, clientName):
  1232. patchcanvas.addGroup(clientId, clientName)
  1233. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1234. @pyqtSlot(int)
  1235. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  1236. patchcanvas.removeGroup(clientId)
  1237. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1238. @pyqtSlot(int, str)
  1239. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  1240. patchcanvas.renameGroup(clientId, newClientName)
  1241. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1242. @pyqtSlot(int, int, int, str)
  1243. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  1244. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  1245. portMode = patchcanvas.PORT_MODE_INPUT
  1246. elif (portFlags & PATCHBAY_PORT_IS_OUTPUT):
  1247. portMode = patchcanvas.PORT_MODE_OUTPUT
  1248. else:
  1249. portMode = patchcanvas.PORT_MODE_NULL
  1250. if (portFlags & PATCHBAY_PORT_IS_AUDIO):
  1251. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1252. elif (portFlags & PATCHBAY_PORT_IS_MIDI):
  1253. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  1254. else:
  1255. portType = patchcanvas.PORT_TYPE_NULL
  1256. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  1257. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1258. @pyqtSlot(int)
  1259. def slot_handlePatchbayPortRemovedCallback(self, portId):
  1260. patchcanvas.removePort(portId)
  1261. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1262. @pyqtSlot(int, str)
  1263. def slot_handlePatchbayPortRenamedCallback(self, portId, newPortName):
  1264. patchcanvas.renamePort(portId, newPortName)
  1265. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1266. @pyqtSlot(int, int, int)
  1267. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  1268. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  1269. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1270. @pyqtSlot(int)
  1271. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId):
  1272. patchcanvas.disconnectPorts(connectionId)
  1273. QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  1274. @pyqtSlot(int)
  1275. def slot_handleBufferSizeChangedCallback(self, newBufferSize):
  1276. self.fBufferSize = newBufferSize
  1277. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (self.fSampleRate, self.fBufferSize)
  1278. @pyqtSlot(float)
  1279. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  1280. self.fSampleRate = newSampleRate
  1281. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (self.fSampleRate, self.fBufferSize)
  1282. @pyqtSlot(str)
  1283. def slot_handleErrorCallback(self, error):
  1284. QMessageBox.critical(self, self.tr("Error"), error)
  1285. @pyqtSlot()
  1286. def slot_handleQuitCallback(self):
  1287. CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1288. self.tr("Engine has been stopped or crashed.\nPlease restart Carla"),
  1289. self.tr("You may want to save your session now..."), QMessageBox.Ok, QMessageBox.Ok)
  1290. def getExtraStuff(self, plugin):
  1291. ptype = plugin['type']
  1292. if ptype == PLUGIN_LADSPA:
  1293. uniqueId = plugin['uniqueId']
  1294. for rdfItem in self.fLadspaRdfList:
  1295. if rdfItem.UniqueID == uniqueId:
  1296. return pointer(rdfItem)
  1297. elif ptype == PLUGIN_DSSI:
  1298. if (plugin['hints'] & PLUGIN_HAS_GUI):
  1299. gui = findDSSIGUI(plugin['binary'], plugin['name'], plugin['label'])
  1300. if gui:
  1301. return gui.encode("utf-8")
  1302. elif ptype in (PLUGIN_GIG, PLUGIN_SF2, PLUGIN_SFZ):
  1303. if plugin['name'].endswith(" (16 outputs)"):
  1304. # return a dummy non-null pointer
  1305. INTPOINTER = POINTER(c_int)
  1306. ptr = c_int(0x1)
  1307. addr = addressof(ptr)
  1308. return cast(addr, INTPOINTER)
  1309. return c_nullptr
  1310. def loadRDFs(self):
  1311. # Save RDF info for later
  1312. self.fLadspaRdfList = []
  1313. if not haveLRDF:
  1314. return
  1315. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1316. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1317. if os.path.exists(frLadspaFile):
  1318. frLadspa = open(frLadspaFile, 'r')
  1319. try:
  1320. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1321. except:
  1322. pass
  1323. frLadspa.close()
  1324. def saveSettings(self):
  1325. settings = QSettings()
  1326. settings.setValue("Geometry", self.saveGeometry())
  1327. settings.setValue("SplitterState", self.ui.splitter.saveState())
  1328. settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  1329. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1330. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1331. diskFolders = []
  1332. for i in range(self.ui.cb_disk.count()):
  1333. diskFolders.append(self.ui.cb_disk.itemData(i))
  1334. settings.setValue("DiskFolders", diskFolders)
  1335. def loadSettings(self, geometry):
  1336. settings = QSettings()
  1337. if geometry:
  1338. self.restoreGeometry(settings.value("Geometry", ""))
  1339. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1340. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1341. self.ui.toolBar.setVisible(showToolbar)
  1342. if settings.contains("SplitterState"):
  1343. self.ui.splitter.restoreState(settings.value("SplitterState", ""))
  1344. else:
  1345. self.ui.splitter.setSizes([99999, 210])
  1346. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  1347. self.ui.cb_disk.setItemData(0, HOME)
  1348. for i in range(len(diskFolders)):
  1349. if i == 0: continue
  1350. folder = diskFolders[i]
  1351. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1352. pal1 = app.palette().base().color()
  1353. pal2 = app.palette().button().color()
  1354. col1 = "stop:0 rgb(%i, %i, %i)" % (pal1.red(), pal1.green(), pal1.blue())
  1355. col2 = "stop:1 rgb(%i, %i, %i)" % (pal2.red(), pal2.green(), pal2.blue())
  1356. self.setStyleSheet("""
  1357. QWidget#w_plugins {
  1358. background-color: qlineargradient(spread:pad,
  1359. x1:0.0, y1:0.0,
  1360. x2:0.2, y2:1.0,
  1361. %s,
  1362. %s
  1363. );
  1364. }
  1365. """ % (col1, col2))
  1366. self.fSavedSettings = {
  1367. "Main/DefaultProjectFolder": settings.value("Main/DefaultProjectFolder", HOME, type=str),
  1368. "Main/RefreshInterval": settings.value("Main/RefreshInterval", 50, type=int),
  1369. "Canvas/Theme": settings.value("Canvas/Theme", patchcanvas.getDefaultThemeName(), type=str),
  1370. "Canvas/AutoHideGroups": settings.value("Canvas/AutoHideGroups", False, type=bool),
  1371. "Canvas/UseBezierLines": settings.value("Canvas/UseBezierLines", True, type=bool),
  1372. "Canvas/EyeCandy": settings.value("Canvas/EyeCandy", patchcanvas.EYECANDY_SMALL, type=int),
  1373. "Canvas/UseOpenGL": settings.value("Canvas/UseOpenGL", False, type=bool),
  1374. "Canvas/Antialiasing": settings.value("Canvas/Antialiasing", patchcanvas.ANTIALIASING_SMALL, type=int),
  1375. "Canvas/HighQualityAntialiasing": settings.value("Canvas/HighQualityAntialiasing", False, type=bool)
  1376. }
  1377. # ---------------------------------------------
  1378. # plugin checks
  1379. if settings.value("Engine/DisableChecks", False, type=bool):
  1380. os.environ["CARLA_DISCOVERY_NO_PROCESSING_CHECKS"] = "true"
  1381. elif os.getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS"):
  1382. os.environ.pop("CARLA_DISCOVERY_NO_PROCESSING_CHECKS")
  1383. # ---------------------------------------------
  1384. # plugin paths
  1385. Carla.LADSPA_PATH = toList(settings.value("Paths/LADSPA", Carla.LADSPA_PATH))
  1386. Carla.DSSI_PATH = toList(settings.value("Paths/DSSI", Carla.DSSI_PATH))
  1387. Carla.LV2_PATH = toList(settings.value("Paths/LV2", Carla.LV2_PATH))
  1388. Carla.VST_PATH = toList(settings.value("Paths/VST", Carla.VST_PATH))
  1389. Carla.GIG_PATH = toList(settings.value("Paths/GIG", Carla.GIG_PATH))
  1390. Carla.SF2_PATH = toList(settings.value("Paths/SF2", Carla.SF2_PATH))
  1391. Carla.SFZ_PATH = toList(settings.value("Paths/SFZ", Carla.SFZ_PATH))
  1392. os.environ["LADSPA_PATH"] = splitter.join(Carla.LADSPA_PATH)
  1393. os.environ["DSSI_PATH"] = splitter.join(Carla.DSSI_PATH)
  1394. os.environ["LV2_PATH"] = splitter.join(Carla.LV2_PATH)
  1395. os.environ["VST_PATH"] = splitter.join(Carla.VST_PATH)
  1396. os.environ["GIG_PATH"] = splitter.join(Carla.GIG_PATH)
  1397. os.environ["SF2_PATH"] = splitter.join(Carla.SF2_PATH)
  1398. os.environ["SFZ_PATH"] = splitter.join(Carla.SFZ_PATH)
  1399. def updateInfoLabelPos(self):
  1400. tabBar = self.ui.tabMain.tabBar()
  1401. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()+tabBar.height()/4
  1402. if not self.ui.toolBar.isVisible():
  1403. y -= self.ui.toolBar.height()
  1404. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  1405. def updateInfoLabelSize(self):
  1406. tabBar = self.ui.tabMain.tabBar()
  1407. self.fInfoLabel.resize(self.ui.tabMain.width()-tabBar.width()-20, self.fInfoLabel.height())
  1408. def dragEnterEvent(self, event):
  1409. if event.source() == self.ui.fileTreeView:
  1410. event.accept()
  1411. elif self.ui.tabMain.contentsRect().contains(event.pos()):
  1412. event.accept()
  1413. else:
  1414. QMainWindow.dragEnterEvent(self, event)
  1415. def dropEvent(self, event):
  1416. event.accept()
  1417. urls = event.mimeData().urls()
  1418. for url in urls:
  1419. filename = url.toLocalFile()
  1420. if not Carla.host.load_filename(filename):
  1421. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1422. self.tr("Failed to load file"),
  1423. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1424. def resizeEvent(self, event):
  1425. if self.ui.tabMain.currentIndex() == 0:
  1426. # Force update of 2nd tab
  1427. width = self.ui.tab_plugins.width()-4
  1428. height = self.ui.tab_plugins.height()-4
  1429. self.ui.miniCanvasPreview.setViewSize(float(width) / DEFAULT_CANVAS_WIDTH, float(height) / DEFAULT_CANVAS_HEIGHT)
  1430. else:
  1431. QTimer.singleShot(0, self, SLOT("slot_miniCanvasCheckSize()"))
  1432. self.updateInfoLabelSize()
  1433. QMainWindow.resizeEvent(self, event)
  1434. def timerEvent(self, event):
  1435. if event.timerId() == self.fIdleTimerFast:
  1436. if not self.fEngineStarted:
  1437. return
  1438. Carla.host.engine_idle()
  1439. for pwidget in self.fPluginList:
  1440. if pwidget is None:
  1441. break
  1442. pwidget.idleFast()
  1443. self.refreshTransport()
  1444. elif event.timerId() == self.fIdleTimerSlow:
  1445. if not self.fEngineStarted:
  1446. return
  1447. for pwidget in self.fPluginList:
  1448. if pwidget is None:
  1449. break
  1450. pwidget.idleSlow()
  1451. QMainWindow.timerEvent(self, event)
  1452. def closeEvent(self, event):
  1453. self.saveSettings()
  1454. if Carla.host.is_engine_running():
  1455. Carla.host.set_engine_about_to_close()
  1456. self.removeAllPlugins()
  1457. self.stopEngine()
  1458. QMainWindow.closeEvent(self, event)
  1459. # ------------------------------------------------------------------------------------------------
  1460. def canvasCallback(action, value1, value2, valueStr):
  1461. if action == patchcanvas.ACTION_GROUP_INFO:
  1462. pass
  1463. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1464. pass
  1465. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1466. groupId = value1
  1467. patchcanvas.splitGroup(groupId)
  1468. Carla.gui.ui.miniCanvasPreview.update()
  1469. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1470. groupId = value1
  1471. patchcanvas.joinGroup(groupId)
  1472. Carla.gui.ui.miniCanvasPreview.update()
  1473. elif action == patchcanvas.ACTION_PORT_INFO:
  1474. pass
  1475. elif action == patchcanvas.ACTION_PORT_RENAME:
  1476. pass
  1477. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1478. portIdA = value1
  1479. portIdB = value2
  1480. Carla.host.patchbay_connect(portIdA, portIdB)
  1481. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1482. connectionId = value1
  1483. Carla.host.patchbay_disconnect(connectionId)
  1484. def engineCallback(ptr, action, pluginId, value1, value2, value3, valueStr):
  1485. if pluginId < 0 or not Carla.gui:
  1486. return
  1487. if action == CALLBACK_DEBUG:
  1488. Carla.gui.emit(SIGNAL("DebugCallback(int, int, int, double, QString)"), pluginId, value1, value2, value3, cString(valueStr))
  1489. elif action == CALLBACK_PLUGIN_ADDED:
  1490. Carla.gui.emit(SIGNAL("PluginAddedCallback(int)"), pluginId)
  1491. elif action == CALLBACK_PLUGIN_REMOVED:
  1492. Carla.gui.emit(SIGNAL("PluginRemovedCallback(int)"), pluginId)
  1493. elif action == CALLBACK_PLUGIN_RENAMED:
  1494. Carla.gui.emit(SIGNAL("PluginRenamedCallback(int, QString)"), pluginId, valueStr)
  1495. elif action == CALLBACK_PARAMETER_VALUE_CHANGED:
  1496. Carla.gui.emit(SIGNAL("ParameterValueChangedCallback(int, int, double)"), pluginId, value1, value3)
  1497. elif action == CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1498. Carla.gui.emit(SIGNAL("ParameterDefaultChangedCallback(int, int, double)"), pluginId, value1, value3)
  1499. elif action == CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1500. Carla.gui.emit(SIGNAL("ParameterMidiChannelChangedCallback(int, int, int)"), pluginId, value1, value2)
  1501. elif action == CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1502. Carla.gui.emit(SIGNAL("ParameterMidiCcChangedCallback(int, int, int)"), pluginId, value1, value2)
  1503. elif action == CALLBACK_PROGRAM_CHANGED:
  1504. Carla.gui.emit(SIGNAL("ProgramChangedCallback(int, int)"), pluginId, value1)
  1505. elif action == CALLBACK_MIDI_PROGRAM_CHANGED:
  1506. Carla.gui.emit(SIGNAL("MidiProgramChangedCallback(int, int)"), pluginId, value1)
  1507. elif action == CALLBACK_NOTE_ON:
  1508. Carla.gui.emit(SIGNAL("NoteOnCallback(int, int, int, int)"), pluginId, value1, value2, value3)
  1509. elif action == CALLBACK_NOTE_OFF:
  1510. Carla.gui.emit(SIGNAL("NoteOffCallback(int, int, int)"), pluginId, value1, value2)
  1511. elif action == CALLBACK_SHOW_GUI:
  1512. Carla.gui.emit(SIGNAL("ShowGuiCallback(int, int)"), pluginId, value1)
  1513. elif action == CALLBACK_UPDATE:
  1514. Carla.gui.emit(SIGNAL("UpdateCallback(int)"), pluginId)
  1515. elif action == CALLBACK_RELOAD_INFO:
  1516. Carla.gui.emit(SIGNAL("ReloadInfoCallback(int)"), pluginId)
  1517. elif action == CALLBACK_RELOAD_PARAMETERS:
  1518. Carla.gui.emit(SIGNAL("ReloadParametersCallback(int)"), pluginId)
  1519. elif action == CALLBACK_RELOAD_PROGRAMS:
  1520. Carla.gui.emit(SIGNAL("ReloadProgramsCallback(int)"), pluginId)
  1521. elif action == CALLBACK_RELOAD_ALL:
  1522. Carla.gui.emit(SIGNAL("ReloadAllCallback(int)"), pluginId)
  1523. elif action == CALLBACK_PATCHBAY_CLIENT_ADDED:
  1524. Carla.gui.emit(SIGNAL("PatchbayClientAddedCallback(int, QString)"), value1, cString(valueStr))
  1525. elif action == CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1526. Carla.gui.emit(SIGNAL("PatchbayClientRemovedCallback(int)"), value1)
  1527. elif action == CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1528. Carla.gui.emit(SIGNAL("PatchbayClientRenamedCallback(int, QString)"), value1, cString(valueStr))
  1529. elif action == CALLBACK_PATCHBAY_PORT_ADDED:
  1530. Carla.gui.emit(SIGNAL("PatchbayPortAddedCallback(int, int, int, QString)"), value1, value2, int(value3), cString(valueStr))
  1531. elif action == CALLBACK_PATCHBAY_PORT_REMOVED:
  1532. Carla.gui.emit(SIGNAL("PatchbayPortRemovedCallback(int)"), value1)
  1533. elif action == CALLBACK_PATCHBAY_PORT_RENAMED:
  1534. Carla.gui.emit(SIGNAL("PatchbayPortRenamedCallback(int, QString)"), value1, cString(valueStr))
  1535. elif action == CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1536. Carla.gui.emit(SIGNAL("PatchbayConnectionAddedCallback(int, int, int)"), value1, value2, value3)
  1537. elif action == CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1538. Carla.gui.emit(SIGNAL("PatchbayConnectionRemovedCallback(int)"), value1)
  1539. elif action == CALLBACK_BUFFER_SIZE_CHANGED:
  1540. Carla.gui.emit(SIGNAL("BufferSizeChangedCallback(int)"), value1)
  1541. elif action == CALLBACK_SAMPLE_RATE_CHANGED:
  1542. Carla.gui.emit(SIGNAL("SampleRateChangedCallback(double)"), value3)
  1543. elif action == CALLBACK_NSM_ANNOUNCE:
  1544. Carla.gui.emit(SIGNAL("NSM_AnnounceCallback(QString)"), cString(valueStr))
  1545. elif action == CALLBACK_NSM_OPEN:
  1546. Carla.gui.emit(SIGNAL("NSM_OpenCallback(QString)"), cString(valueStr))
  1547. elif action == CALLBACK_NSM_SAVE:
  1548. Carla.gui.emit(SIGNAL("NSM_SaveCallback()"))
  1549. elif action == CALLBACK_ERROR:
  1550. Carla.gui.emit(SIGNAL("ErrorCallback(QString)"), cString(valueStr))
  1551. elif action == CALLBACK_QUIT:
  1552. Carla.gui.emit(SIGNAL("QuitCallback()"))
  1553. #--------------- main ------------------
  1554. if __name__ == '__main__':
  1555. # App initialization
  1556. app = QApplication(sys.argv)
  1557. app.setApplicationName("Carla")
  1558. app.setApplicationVersion(VERSION)
  1559. app.setOrganizationName("falkTX")
  1560. app.setWindowIcon(QIcon(":/scalable/carla.svg"))
  1561. for i in range(len(app.arguments())):
  1562. if i == 0: continue
  1563. argument = app.arguments()[i]
  1564. if argument.startswith("--with-appname="):
  1565. appName = os.path.basename(argument.replace("--with-appname=", ""))
  1566. elif argument.startswith("--with-libprefix="):
  1567. libPrefix = argument.replace("--with-libprefix=", "")
  1568. elif os.path.exists(argument):
  1569. projectFilename = argument
  1570. if libPrefix is not None:
  1571. libPath = os.path.join(libPrefix, "lib", "carla")
  1572. libName = os.path.join(libPath, carla_libname)
  1573. else:
  1574. libPath = carla_library_path.replace(carla_libname, "")
  1575. libName = carla_library_path
  1576. # Init backend
  1577. Carla.host = Host(libName)
  1578. Carla.host.set_engine_callback(engineCallback)
  1579. Carla.host.set_engine_option(OPTION_PROCESS_NAME, 0, "carla")
  1580. # Change dir to where DLL and resources are
  1581. os.chdir(libPath)
  1582. # Set bridge paths
  1583. if carla_bridge_native:
  1584. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_NATIVE, 0, carla_bridge_native)
  1585. if carla_bridge_posix32:
  1586. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_POSIX32, 0, carla_bridge_posix32)
  1587. if carla_bridge_posix64:
  1588. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_POSIX64, 0, carla_bridge_posix64)
  1589. if carla_bridge_win32:
  1590. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_WIN32, 0, carla_bridge_win32)
  1591. if carla_bridge_win64:
  1592. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_WIN64, 0, carla_bridge_win64)
  1593. if WINDOWS:
  1594. if carla_bridge_lv2_windows:
  1595. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_WINDOWS, 0, carla_bridge_lv2_windows)
  1596. if carla_bridge_vst_hwnd:
  1597. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_HWND, 0, carla_bridge_vst_hwnd)
  1598. elif MACOS:
  1599. if carla_bridge_lv2_cocoa:
  1600. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_COCOA, 0, carla_bridge_lv2_cocoa)
  1601. if carla_bridge_vst_cocoa:
  1602. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_COCOA, 0, carla_bridge_vst_cocoa)
  1603. else:
  1604. if carla_bridge_lv2_gtk2:
  1605. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_GTK2, 0, carla_bridge_lv2_gtk2)
  1606. if carla_bridge_lv2_gtk3:
  1607. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_GTK3, 0, carla_bridge_lv2_gtk3)
  1608. if carla_bridge_lv2_qt4:
  1609. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_QT4, 0, carla_bridge_lv2_qt4)
  1610. if carla_bridge_lv2_qt5:
  1611. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_QT5, 0, carla_bridge_lv2_qt5)
  1612. if carla_bridge_lv2_x11:
  1613. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_X11, 0, carla_bridge_lv2_x11)
  1614. if carla_bridge_vst_x11:
  1615. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_X11, 0, carla_bridge_vst_x11)
  1616. # Create GUI and start engine
  1617. Carla.gui = CarlaMainW()
  1618. # Set-up custom signal handling
  1619. setUpSignals()
  1620. # Show GUI
  1621. Carla.gui.show()
  1622. # Load project file if set
  1623. if projectFilename and not os.getenv("NSM_URL"):
  1624. Carla.gui.loadProjectLater(projectFilename)
  1625. # App-Loop
  1626. ret = app.exec_()
  1627. # Exit properly
  1628. sys.exit(ret)