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.

296 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.PatchbayIconChangedCallback.connect(self.fPatchbay.slot_handlePatchbayIconChangedCallback)
  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. self.fPatchbay.renamePlugin(pluginId, newName)
  91. def disablePlugin(self, pluginId, errorMsg):
  92. pass
  93. def removeAllPlugins(self):
  94. self.fRack.removeAllPlugins()
  95. # -----------------------------------------------------------------
  96. def engineStarted(self):
  97. #self.fRack.engineStarted()
  98. #self.fPatchbay.engineStarted()
  99. self.fParent.engineChanged()
  100. def engineStopped(self):
  101. #self.fRack.engineStopped()
  102. self.fPatchbay.engineStopped()
  103. self.fParent.engineStopped()
  104. def engineChanged(self):
  105. self.fParent.engineChanged()
  106. # -----------------------------------------------------------------
  107. def idleFast(self):
  108. self.fRack.idleFast()
  109. def idleSlow(self):
  110. self.fRack.idleSlow()
  111. # -----------------------------------------------------------------
  112. def saveSettings(self, settings):
  113. pass
  114. #self.fRack.saveSettings(settings)
  115. #self.fPatchbay.saveSettings(settings)
  116. # ------------------------------------------------------------------------------------------------------------
  117. # Main Window
  118. class CarlaHostW(HostWindow):
  119. def __init__(self, parent=None):
  120. HostWindow.__init__(self, parent)
  121. # -------------------------------------------------------------
  122. # Set-up container
  123. self.fContainer = CarlaMultiW(self)
  124. self.setupContainer(True)
  125. # -------------------------------------------------------------
  126. # Set-up GUI stuff
  127. self.fInfoText = ""
  128. self.fInfoLabel = QLabel(self)
  129. self.fInfoLabel.setText("Engine stopped")
  130. # -------------------------------------------------------------
  131. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  132. self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
  133. QTimer.singleShot(0, self.slot_infoLabelInit)
  134. # -----------------------------------------------------------------
  135. def engineStopped(self):
  136. self.fInfoText = ""
  137. self.fInfoLabel.setText("Engine stopped")
  138. def engineChanged(self):
  139. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (Carla.sampleRate, Carla.bufferSize)
  140. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  141. # -----------------------------------------------------------------
  142. def updateInfoLabelPos(self):
  143. tabBar = self.fContainer.tabBar()
  144. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() #+tabBar.height()/4
  145. if not self.ui.toolBar.isVisible():
  146. y -= self.ui.toolBar.height()
  147. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  148. def updateInfoLabelSize(self):
  149. tabBar = self.fContainer.tabBar()
  150. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
  151. # -----------------------------------------------------------------
  152. @pyqtSlot()
  153. def slot_splitterMoved(self):
  154. self.updateInfoLabelSize()
  155. @pyqtSlot()
  156. def slot_toolbarShown(self):
  157. self.updateInfoLabelPos()
  158. @pyqtSlot()
  159. def slot_infoLabelInit(self):
  160. tabBar = self.fContainer.tabBar()
  161. x = tabBar.width()+20
  162. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() #+ tabBar.height()/4
  163. self.fInfoLabel.move(x, y)
  164. self.fInfoLabel.resize(self.fContainer.width()-x, tabBar.height())
  165. # -----------------------------------------------------------------
  166. def resizeEvent(self, event):
  167. self.updateInfoLabelSize()
  168. HostWindow.resizeEvent(self, event)
  169. def timerEvent(self, event):
  170. HostWindow.timerEvent(self, event)
  171. if event.timerId() == self.fIdleTimerFast:
  172. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  173. # ------------------------------------------------------------------------------------------------------------
  174. # Main
  175. if __name__ == '__main__':
  176. # -------------------------------------------------------------
  177. # App initialization
  178. app = CarlaApplication()
  179. # -------------------------------------------------------------
  180. # Set-up custom signal handling
  181. setUpSignals()
  182. # -------------------------------------------------------------
  183. # Read CLI args
  184. appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  185. libPrefix = None
  186. projectFilename = None
  187. argv = app.arguments()
  188. argc = len(argv)
  189. for i in range(argc):
  190. if i == 0: continue
  191. argument = argv[i]
  192. if argument.startswith("--with-appname="):
  193. appName = os.path.basename(argument.replace("--with-appname=", ""))
  194. elif argument.startswith("--with-libprefix="):
  195. libPrefix = argument.replace("--with-libprefix=", "")
  196. elif os.path.exists(argument):
  197. projectFilename = argument
  198. # -------------------------------------------------------------
  199. # Init host backend
  200. Carla.isControl = False
  201. Carla.isLocal = True
  202. Carla.isPlugin = False
  203. initHost(appName, libPrefix)
  204. # -------------------------------------------------------------
  205. # Create GUI
  206. Carla.gui = CarlaHostW()
  207. # -------------------------------------------------------------
  208. # Load project file if set
  209. if projectFilename is not None:
  210. Carla.gui.loadProjectLater(projectFilename)
  211. # -------------------------------------------------------------
  212. # Show GUI
  213. Carla.gui.show()
  214. # -------------------------------------------------------------
  215. # App-Loop
  216. sys.exit(app.exec_())