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.

2389 lines
96KB

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