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.

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