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.

carla 12KB

11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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.setText("Engine stopped")
  137. # -------------------------------------------------------------
  138. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  139. self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
  140. QTimer.singleShot(0, self.slot_initWidgets)
  141. # -----------------------------------------------------------------
  142. def engineStopped(self):
  143. self.fInfoText = ""
  144. self.fInfoLabel.setText("Engine stopped")
  145. def engineChanged(self):
  146. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (Carla.sampleRate, Carla.bufferSize)
  147. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  148. # -----------------------------------------------------------------
  149. def updateInfoLabelPos(self):
  150. tabBar = self.fContainer.tabBar()
  151. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() #+tabBar.height()/4
  152. if not self.ui.toolBar.isVisible():
  153. y -= self.ui.toolBar.height()
  154. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  155. def updateInfoLabelSize(self):
  156. tabBar = self.fContainer.tabBar()
  157. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
  158. # -----------------------------------------------------------------
  159. @pyqtSlot()
  160. def slot_initWidgets(self):
  161. tabBar = self.fContainer.tabBar()
  162. x = tabBar.width()+20
  163. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() #+ tabBar.height()/4
  164. self.fInfoLabel.move(x, y)
  165. self.fInfoLabel.resize(self.fContainer.width()-x, tabBar.height())
  166. # FIXME: Qt4 needs this so it properly creates & resizes the canvas
  167. self.fContainer.setCurrentIndex(1)
  168. self.fContainer.setCurrentIndex(0)
  169. self.fContainer.fixCanvasPreviewSize()
  170. @pyqtSlot()
  171. def slot_splitterMoved(self):
  172. self.updateInfoLabelSize()
  173. @pyqtSlot()
  174. def slot_toolbarShown(self):
  175. self.updateInfoLabelPos()
  176. # -----------------------------------------------------------------
  177. def resizeEvent(self, event):
  178. HostWindow.resizeEvent(self, event)
  179. self.updateInfoLabelSize()
  180. def timerEvent(self, event):
  181. HostWindow.timerEvent(self, event)
  182. if event.timerId() == self.fIdleTimerFast:
  183. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  184. # ------------------------------------------------------------------------------------------------------------
  185. # Main
  186. if __name__ == '__main__':
  187. # -------------------------------------------------------------
  188. # App initialization
  189. app = CarlaApplication()
  190. # -------------------------------------------------------------
  191. # Set-up custom signal handling
  192. setUpSignals()
  193. # -------------------------------------------------------------
  194. # Read CLI args
  195. appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  196. libPrefix = None
  197. projectFilename = None
  198. argv = app.arguments()
  199. argc = len(argv)
  200. for i in range(argc):
  201. if i == 0: continue
  202. argument = argv[i]
  203. if argument.startswith("--with-appname="):
  204. appName = os.path.basename(argument.replace("--with-appname=", ""))
  205. elif argument.startswith("--with-libprefix="):
  206. libPrefix = argument.replace("--with-libprefix=", "")
  207. elif os.path.exists(argument):
  208. projectFilename = argument
  209. if libPrefix is not None:
  210. app.addLibraryPath(os.path.join(libPrefix, "lib", "carla"))
  211. # -------------------------------------------------------------
  212. # Init host backend
  213. Carla.isControl = False
  214. Carla.isLocal = True
  215. Carla.isPlugin = False
  216. initHost(appName, libPrefix)
  217. # -------------------------------------------------------------
  218. # Create GUI
  219. Carla.gui = CarlaHostW()
  220. # -------------------------------------------------------------
  221. # Load project file if set
  222. if projectFilename is not None:
  223. Carla.gui.loadProjectLater(projectFilename)
  224. # -------------------------------------------------------------
  225. # Show GUI
  226. Carla.gui.show()
  227. # -------------------------------------------------------------
  228. # App-Loop
  229. sys.exit(app.exec_())