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.

320 lines
12KB

  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. #try:
  20. #from PyQt5.QtWidgets import QLabel, QTabWidget
  21. #except:
  22. from PyQt4.QtGui import QLabel, QTabWidget
  23. # ------------------------------------------------------------------------------------------------------------
  24. # Imports (Custom Stuff)
  25. from carla_host import *
  26. from carla_patchbay import CarlaPatchbayW
  27. from carla_rack import CarlaRackW
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Tab widget (rack + patchbay)
  30. class CarlaMultiW(QTabWidget):
  31. def __init__(self, parent):
  32. QTabWidget.__init__(self, parent)
  33. self.fRack = CarlaRackW(parent, False)
  34. self.fPatchbay = CarlaPatchbayW(parent, False)
  35. self.fParent = parent
  36. self.addTab(self.fRack, "Plugins")
  37. self.addTab(self.fPatchbay, "Patchbay")
  38. self.scene = self.fPatchbay.scene
  39. parent.ui.act_plugins_enable.triggered.connect(self.fRack.slot_pluginsEnable)
  40. parent.ui.act_plugins_disable.triggered.connect(self.fRack.slot_pluginsDisable)
  41. parent.ui.act_plugins_volume100.triggered.connect(self.fRack.slot_pluginsVolume100)
  42. parent.ui.act_plugins_mute.triggered.connect(self.fRack.slot_pluginsMute)
  43. parent.ui.act_plugins_wet100.triggered.connect(self.fRack.slot_pluginsWet100)
  44. parent.ui.act_plugins_bypass.triggered.connect(self.fRack.slot_pluginsBypass)
  45. parent.ui.act_plugins_center.triggered.connect(self.fRack.slot_pluginsCenter)
  46. parent.ui.act_plugins_panic.triggered.connect(self.fRack.slot_pluginsDisable)
  47. parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  48. parent.ui.act_canvas_arrange.triggered.connect(self.fPatchbay.slot_canvasArrange)
  49. parent.ui.act_canvas_refresh.triggered.connect(self.fPatchbay.slot_canvasRefresh)
  50. parent.ui.act_canvas_zoom_fit.triggered.connect(self.fPatchbay.slot_canvasZoomFit)
  51. parent.ui.act_canvas_zoom_in.triggered.connect(self.fPatchbay.slot_canvasZoomIn)
  52. parent.ui.act_canvas_zoom_out.triggered.connect(self.fPatchbay.slot_canvasZoomOut)
  53. parent.ui.act_canvas_zoom_100.triggered.connect(self.fPatchbay.slot_canvasZoomReset)
  54. parent.ui.act_canvas_print.triggered.connect(self.fPatchbay.slot_canvasPrint)
  55. parent.ui.act_canvas_save_image.triggered.connect(self.fPatchbay.slot_canvasSaveImage)
  56. parent.ui.act_settings_configure.triggered.connect(self.fPatchbay.slot_configureCarla)
  57. parent.ParameterValueChangedCallback.connect(self.fRack.slot_handleParameterValueChangedCallback)
  58. parent.ParameterDefaultChangedCallback.connect(self.fRack.slot_handleParameterDefaultChangedCallback)
  59. parent.ParameterMidiChannelChangedCallback.connect(self.fRack.slot_handleParameterMidiChannelChangedCallback)
  60. parent.ParameterMidiCcChangedCallback.connect(self.fRack.slot_handleParameterMidiCcChangedCallback)
  61. parent.ProgramChangedCallback.connect(self.fRack.slot_handleProgramChangedCallback)
  62. parent.MidiProgramChangedCallback.connect(self.fRack.slot_handleMidiProgramChangedCallback)
  63. parent.UiStateChangedCallback.connect(self.fRack.slot_handleUiStateChangedCallback)
  64. parent.NoteOnCallback.connect(self.fRack.slot_handleNoteOnCallback)
  65. parent.NoteOffCallback.connect(self.fRack.slot_handleNoteOffCallback)
  66. parent.UpdateCallback.connect(self.fRack.slot_handleUpdateCallback)
  67. parent.ReloadInfoCallback.connect(self.fRack.slot_handleReloadInfoCallback)
  68. parent.ReloadParametersCallback.connect(self.fRack.slot_handleReloadParametersCallback)
  69. parent.ReloadProgramsCallback.connect(self.fRack.slot_handleReloadProgramsCallback)
  70. parent.ReloadAllCallback.connect(self.fRack.slot_handleReloadAllCallback)
  71. parent.PatchbayClientAddedCallback.connect(self.fPatchbay.slot_handlePatchbayClientAddedCallback)
  72. parent.PatchbayClientRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayClientRemovedCallback)
  73. parent.PatchbayClientRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayClientRenamedCallback)
  74. parent.PatchbayClientIconChangedCallback.connect(self.fPatchbay.slot_handlePatchbayClientIconChangedCallback)
  75. parent.PatchbayPortAddedCallback.connect(self.fPatchbay.slot_handlePatchbayPortAddedCallback)
  76. parent.PatchbayPortRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRemovedCallback)
  77. parent.PatchbayPortRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRenamedCallback)
  78. parent.PatchbayConnectionAddedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionAddedCallback)
  79. parent.PatchbayConnectionRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionRemovedCallback)
  80. # -----------------------------------------------------------------
  81. def getPluginCount(self):
  82. return self.fRack.getPluginCount()
  83. # -----------------------------------------------------------------
  84. def addPlugin(self, pluginId, isProjectLoading):
  85. self.fRack.addPlugin(pluginId, isProjectLoading)
  86. def removePlugin(self, pluginId):
  87. self.fRack.removePlugin(pluginId)
  88. def renamePlugin(self, pluginId, newName):
  89. self.fRack.renamePlugin(pluginId, newName)
  90. def disablePlugin(self, pluginId, errorMsg):
  91. self.fRack.disablePlugin(pluginId)
  92. def removeAllPlugins(self):
  93. self.fRack.removeAllPlugins()
  94. # -----------------------------------------------------------------
  95. def engineStarted(self):
  96. #self.fRack.engineStarted()
  97. #self.fPatchbay.engineStarted()
  98. self.fParent.engineChanged()
  99. def engineStopped(self):
  100. #self.fRack.engineStopped()
  101. self.fPatchbay.engineStopped()
  102. self.fParent.engineStopped()
  103. def engineChanged(self):
  104. self.fParent.engineChanged()
  105. # -----------------------------------------------------------------
  106. def idleFast(self):
  107. self.fRack.idleFast()
  108. def idleSlow(self):
  109. self.fRack.idleSlow()
  110. # -----------------------------------------------------------------
  111. def saveSettings(self, settings):
  112. #self.fRack.saveSettings(settings)
  113. self.fPatchbay.saveSettings(settings)
  114. #self.fParent.saveSettings(settings)
  115. # -----------------------------------------------------------------
  116. def fixCanvasPreviewSize(self):
  117. self.fPatchbay.resize(self.fRack.size())
  118. self.fPatchbay.slot_miniCanvasCheckSize()
  119. def resizeEvent(self, event):
  120. QTabWidget.resizeEvent(self, event)
  121. if self.currentIndex() == 0:
  122. self.fixCanvasPreviewSize()
  123. # ------------------------------------------------------------------------------------------------------------
  124. # Main Window
  125. class CarlaHostW(HostWindow):
  126. def __init__(self, parent=None):
  127. HostWindow.__init__(self, parent)
  128. # -------------------------------------------------------------
  129. # Set-up container
  130. self.fContainer = CarlaMultiW(self)
  131. self.setupContainer(True, self.fContainer.fPatchbay.themeData)
  132. # -------------------------------------------------------------
  133. # Set-up GUI stuff
  134. self.fInfoText = ""
  135. self.fInfoLabel = QLabel(self)
  136. self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
  137. self.fInfoLabel.setText("Engine stopped")
  138. # -------------------------------------------------------------
  139. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  140. self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
  141. QTimer.singleShot(0, self.slot_initWidgets)
  142. # -----------------------------------------------------------------
  143. def engineStopped(self):
  144. self.fInfoText = ""
  145. self.fInfoLabel.setText("Engine stopped")
  146. def engineChanged(self):
  147. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (Carla.sampleRate, Carla.bufferSize)
  148. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  149. # -----------------------------------------------------------------
  150. def updateInfoLabelXandSize(self):
  151. tabBar = self.fContainer.tabBar()
  152. x = tabBar.width() + self.ui.tabUtils.width() + 20
  153. self.fInfoLabel.move(x, self.fInfoLabel.y())
  154. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
  155. def updateInfoLabelY(self):
  156. tabBar = self.fContainer.tabBar()
  157. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  158. if not self.ui.toolBar.isVisible():
  159. y -= self.ui.toolBar.height()
  160. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  161. # -----------------------------------------------------------------
  162. @pyqtSlot()
  163. def slot_initWidgets(self):
  164. tabBar = self.fContainer.tabBar()
  165. x = tabBar.width() + self.ui.tabUtils.width() + 20
  166. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  167. self.fInfoLabel.move(x, y)
  168. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
  169. # FIXME: Qt4 needs this so it properly creates & resizes the canvas
  170. self.fContainer.setCurrentIndex(1)
  171. self.fContainer.setCurrentIndex(0)
  172. self.fContainer.fixCanvasPreviewSize()
  173. @pyqtSlot()
  174. def slot_splitterMoved(self):
  175. self.updateInfoLabelXandSize()
  176. @pyqtSlot()
  177. def slot_toolbarShown(self):
  178. self.updateInfoLabelY()
  179. # -----------------------------------------------------------------
  180. def resizeEvent(self, event):
  181. HostWindow.resizeEvent(self, event)
  182. self.updateInfoLabelXandSize()
  183. def timerEvent(self, event):
  184. HostWindow.timerEvent(self, event)
  185. if event.timerId() == self.fIdleTimerFast:
  186. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  187. # ------------------------------------------------------------------------------------------------------------
  188. # Main
  189. if __name__ == '__main__':
  190. # -------------------------------------------------------------
  191. # App initialization
  192. app = CarlaApplication()
  193. # -------------------------------------------------------------
  194. # Set-up custom signal handling
  195. setUpSignals()
  196. # -------------------------------------------------------------
  197. # Read CLI args
  198. appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  199. libPrefix = None
  200. projectFilename = None
  201. argv = app.arguments()
  202. argc = len(argv)
  203. for i in range(argc):
  204. if i == 0: continue
  205. argument = argv[i]
  206. if argument.startswith("--with-appname="):
  207. appName = os.path.basename(argument.replace("--with-appname=", ""))
  208. elif argument.startswith("--with-libprefix="):
  209. libPrefix = argument.replace("--with-libprefix=", "")
  210. elif os.path.exists(argument):
  211. projectFilename = argument
  212. if libPrefix is not None:
  213. app.addLibraryPath(os.path.join(libPrefix, "lib", "carla"))
  214. # -------------------------------------------------------------
  215. # Init host backend
  216. Carla.isControl = False
  217. Carla.isLocal = True
  218. Carla.isPlugin = False
  219. initHost(appName, libPrefix)
  220. # -------------------------------------------------------------
  221. # Create GUI
  222. Carla.gui = CarlaHostW()
  223. # -------------------------------------------------------------
  224. # Load project file if set
  225. if projectFilename is not None:
  226. Carla.gui.loadProjectLater(projectFilename)
  227. # -------------------------------------------------------------
  228. # Show GUI
  229. Carla.gui.show()
  230. # -------------------------------------------------------------
  231. # App-Loop
  232. sys.exit(app.exec_())