|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
-
- # Carla plugin host
- # Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License as
- # published by the Free Software Foundation; either version 2 of
- # the License, or any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # For a full copy of the GNU General Public License see the GPL.txt file
-
- # ------------------------------------------------------------------------------------------------------------
- # Imports (Global)
-
- from PyQt4.QtGui import QLabel, QTabWidget
-
- # ------------------------------------------------------------------------------------------------------------
- # Imports (Custom Stuff)
-
- from carla_host import *
- from carla_patchbay import CarlaPatchbayW
- from carla_rack import CarlaRackW
-
- # ------------------------------------------------------------------------------------------------------------
- # Tab widget (rack + patchbay)
-
- class CarlaMultiW(QTabWidget):
- def __init__(self, parent):
- QTabWidget.__init__(self, parent)
-
- self.fRack = CarlaRackW(parent, False)
- self.fPatchbay = CarlaPatchbayW(parent, False)
- self.fParent = parent
-
- self.addTab(self.fRack, "Plugins")
- self.addTab(self.fPatchbay, "Patchbay")
-
- self.scene = self.fPatchbay.scene
-
- parent.ui.act_plugins_enable.triggered.connect(self.fRack.slot_pluginsEnable)
- parent.ui.act_plugins_disable.triggered.connect(self.fRack.slot_pluginsDisable)
- parent.ui.act_plugins_volume100.triggered.connect(self.fRack.slot_pluginsVolume100)
- parent.ui.act_plugins_mute.triggered.connect(self.fRack.slot_pluginsMute)
- parent.ui.act_plugins_wet100.triggered.connect(self.fRack.slot_pluginsWet100)
- parent.ui.act_plugins_bypass.triggered.connect(self.fRack.slot_pluginsBypass)
- parent.ui.act_plugins_center.triggered.connect(self.fRack.slot_pluginsCenter)
- parent.ui.act_plugins_panic.triggered.connect(self.fRack.slot_pluginsDisable)
-
- parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
- parent.ui.act_canvas_arrange.triggered.connect(self.fPatchbay.slot_canvasArrange)
- parent.ui.act_canvas_refresh.triggered.connect(self.fPatchbay.slot_canvasRefresh)
- parent.ui.act_canvas_zoom_fit.triggered.connect(self.fPatchbay.slot_canvasZoomFit)
- parent.ui.act_canvas_zoom_in.triggered.connect(self.fPatchbay.slot_canvasZoomIn)
- parent.ui.act_canvas_zoom_out.triggered.connect(self.fPatchbay.slot_canvasZoomOut)
- parent.ui.act_canvas_zoom_100.triggered.connect(self.fPatchbay.slot_canvasZoomReset)
- parent.ui.act_canvas_print.triggered.connect(self.fPatchbay.slot_canvasPrint)
- parent.ui.act_canvas_save_image.triggered.connect(self.fPatchbay.slot_canvasSaveImage)
-
- parent.ui.act_settings_configure.triggered.connect(self.fPatchbay.slot_configureCarla)
-
- parent.ParameterValueChangedCallback.connect(self.fRack.slot_handleParameterValueChangedCallback)
- parent.ParameterDefaultChangedCallback.connect(self.fRack.slot_handleParameterDefaultChangedCallback)
- parent.ParameterMidiChannelChangedCallback.connect(self.fRack.slot_handleParameterMidiChannelChangedCallback)
- parent.ParameterMidiCcChangedCallback.connect(self.fRack.slot_handleParameterMidiCcChangedCallback)
- parent.ProgramChangedCallback.connect(self.fRack.slot_handleProgramChangedCallback)
- parent.MidiProgramChangedCallback.connect(self.fRack.slot_handleMidiProgramChangedCallback)
- parent.UiStateChangedCallback.connect(self.fRack.slot_handleUiStateChangedCallback)
- parent.NoteOnCallback.connect(self.fRack.slot_handleNoteOnCallback)
- parent.NoteOffCallback.connect(self.fRack.slot_handleNoteOffCallback)
- parent.UpdateCallback.connect(self.fRack.slot_handleUpdateCallback)
- parent.ReloadInfoCallback.connect(self.fRack.slot_handleReloadInfoCallback)
- parent.ReloadParametersCallback.connect(self.fRack.slot_handleReloadParametersCallback)
- parent.ReloadProgramsCallback.connect(self.fRack.slot_handleReloadProgramsCallback)
- parent.ReloadAllCallback.connect(self.fRack.slot_handleReloadAllCallback)
-
- parent.PatchbayClientAddedCallback.connect(self.fPatchbay.slot_handlePatchbayClientAddedCallback)
- parent.PatchbayClientRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayClientRemovedCallback)
- parent.PatchbayClientRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayClientRenamedCallback)
- parent.PatchbayClientIconChangedCallback.connect(self.fPatchbay.slot_handlePatchbayClientIconChangedCallback)
- parent.PatchbayPortAddedCallback.connect(self.fPatchbay.slot_handlePatchbayPortAddedCallback)
- parent.PatchbayPortRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRemovedCallback)
- parent.PatchbayPortRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRenamedCallback)
- parent.PatchbayConnectionAddedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionAddedCallback)
- parent.PatchbayConnectionRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionRemovedCallback)
-
- # -----------------------------------------------------------------
-
- def getPluginCount(self):
- return self.fRack.getPluginCount()
-
- # -----------------------------------------------------------------
-
- def addPlugin(self, pluginId, isProjectLoading):
- self.fRack.addPlugin(pluginId, isProjectLoading)
-
- def removePlugin(self, pluginId):
- self.fRack.removePlugin(pluginId)
-
- def renamePlugin(self, pluginId, newName):
- self.fRack.renamePlugin(pluginId, newName)
-
- def disablePlugin(self, pluginId, errorMsg):
- self.fRack.disablePlugin(pluginId)
-
- def removeAllPlugins(self):
- self.fRack.removeAllPlugins()
-
- # -----------------------------------------------------------------
-
- def engineStarted(self):
- #self.fRack.engineStarted()
- #self.fPatchbay.engineStarted()
- self.fParent.engineChanged()
-
- def engineStopped(self):
- #self.fRack.engineStopped()
- self.fPatchbay.engineStopped()
- self.fParent.engineStopped()
-
- def engineChanged(self):
- self.fParent.engineChanged()
-
- # -----------------------------------------------------------------
-
- def idleFast(self):
- self.fRack.idleFast()
-
- def idleSlow(self):
- self.fRack.idleSlow()
-
- # -----------------------------------------------------------------
-
- def saveSettings(self, settings):
- #self.fRack.saveSettings(settings)
- self.fPatchbay.saveSettings(settings)
- #self.fParent.saveSettings(settings)
-
- # -----------------------------------------------------------------
-
- def fixCanvasPreviewSize(self):
- self.fPatchbay.resize(self.fRack.size())
- self.fPatchbay.slot_miniCanvasCheckSize()
-
- def resizeEvent(self, event):
- QTabWidget.resizeEvent(self, event)
-
- if self.currentIndex() == 0:
- self.fixCanvasPreviewSize()
-
- # ------------------------------------------------------------------------------------------------------------
- # Main Window
-
- class CarlaHostW(HostWindow):
- def __init__(self, parent=None):
- HostWindow.__init__(self, parent)
-
- # -------------------------------------------------------------
- # Set-up container
-
- self.fContainer = CarlaMultiW(self)
- self.setupContainer(True, self.fContainer.fPatchbay.themeData)
-
- # -------------------------------------------------------------
- # Set-up GUI stuff
-
- self.fInfoText = ""
- self.fInfoLabel = QLabel(self)
- self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
- self.fInfoLabel.setText("Engine stopped")
-
- if MACOS and False: # TODO: check if NOT using pro theme
- self.fInfoLabel.hide()
- self.setUnifiedTitleAndToolBarOnMac(True)
-
- # -------------------------------------------------------------
-
- self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
- self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
-
- QTimer.singleShot(0, self.slot_initWidgets)
-
- # -----------------------------------------------------------------
-
- def engineStopped(self):
- self.fInfoText = ""
- self.fInfoLabel.setText("Engine stopped")
-
- def engineChanged(self):
- self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (Carla.sampleRate, Carla.bufferSize)
- self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
-
- # -----------------------------------------------------------------
-
- def updateInfoLabelXandSize(self):
- tabBar = self.fContainer.tabBar()
- x = tabBar.width() + self.ui.tabUtils.width() + 20
- self.fInfoLabel.move(x, self.fInfoLabel.y())
- self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
-
- def updateInfoLabelY(self):
- tabBar = self.fContainer.tabBar()
- y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
-
- if not self.ui.toolBar.isVisible():
- y -= self.ui.toolBar.height()
-
- self.fInfoLabel.move(self.fInfoLabel.x(), y)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot()
- def slot_initWidgets(self):
- tabBar = self.fContainer.tabBar()
- x = tabBar.width() + self.ui.tabUtils.width() + 20
- y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
-
- self.fInfoLabel.move(x, y)
- self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
-
- # FIXME: Qt4 needs this so it properly creates & resizes the canvas
- self.fContainer.setCurrentIndex(1)
- self.fContainer.setCurrentIndex(0)
- self.fContainer.fixCanvasPreviewSize()
-
- @pyqtSlot()
- def slot_splitterMoved(self):
- self.updateInfoLabelXandSize()
-
- @pyqtSlot()
- def slot_toolbarShown(self):
- self.updateInfoLabelY()
-
- # -----------------------------------------------------------------
-
- def resizeEvent(self, event):
- HostWindow.resizeEvent(self, event)
- self.updateInfoLabelXandSize()
-
- def timerEvent(self, event):
- HostWindow.timerEvent(self, event)
-
- if event.timerId() == self.fIdleTimerFast:
- self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
-
- # ------------------------------------------------------------------------------------------------------------
- # Main
-
- if __name__ == '__main__':
- # -------------------------------------------------------------
- # App initialization
-
- app = CarlaApplication()
-
- # -------------------------------------------------------------
- # Set-up custom signal handling
-
- setUpSignals()
-
- # -------------------------------------------------------------
- # Read CLI args
-
- appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
- libPrefix = None
- projectFilename = None
-
- argv = app.arguments()
- argc = len(argv)
-
- for i in range(argc):
- if i == 0: continue
- argument = argv[i]
-
- if argument.startswith("--with-appname="):
- appName = os.path.basename(argument.replace("--with-appname=", ""))
-
- elif argument.startswith("--with-libprefix="):
- libPrefix = argument.replace("--with-libprefix=", "")
-
- elif os.path.exists(argument):
- projectFilename = argument
-
- if libPrefix is not None:
- app.addLibraryPath(os.path.join(libPrefix, "lib", "carla"))
-
- # -------------------------------------------------------------
- # Init host backend
-
- Carla.isControl = False
- Carla.isLocal = True
- Carla.isPlugin = False
-
- initHost(appName, libPrefix)
-
- # -------------------------------------------------------------
- # Create GUI
-
- Carla.gui = CarlaHostW()
-
- # set our gui as transient for all plugins UIs
- Carla.host.set_engine_option(ENGINE_OPTION_DEBUG, -1729, str(Carla.gui.winId()))
-
- # -------------------------------------------------------------
- # Load project file if set
-
- if projectFilename is not None:
- Carla.gui.loadProjectLater(projectFilename)
-
- # -------------------------------------------------------------
- # Show GUI
-
- Carla.gui.show()
-
- # -------------------------------------------------------------
- # App-Loop
-
- sys.exit(app.exec_())
|