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.

2175 lines
89KB

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