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.

2299 lines
93KB

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