Browse Source

Add option to run Carla without showing UI (requires project file)

Closes #188
tags/1.9.7
falkTX 9 years ago
parent
commit
d793de22d8
8 changed files with 203 additions and 148 deletions
  1. +0
    -11
      source/carla
  2. +0
    -11
      source/carla-patchbay
  3. +0
    -11
      source/carla-rack
  4. +9
    -3
      source/carla_app.py
  5. +1
    -6
      source/carla_database.py
  6. +161
    -92
      source/carla_host.py
  7. +1
    -6
      source/carla_settings.py
  8. +31
    -8
      source/carla_shared.py

+ 0
- 11
source/carla View File

@@ -51,17 +51,6 @@ if __name__ == '__main__':

gui = HostWindow(host, True)

# -------------------------------------------------------------
# Load project file if set

for arg in app.arguments():
if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix=") or arg == "--gdb":
continue

if os.path.exists(arg):
gui.loadProjectLater(arg)
break

# -------------------------------------------------------------
# Show GUI



+ 0
- 11
source/carla-patchbay View File

@@ -53,17 +53,6 @@ if __name__ == '__main__':

gui = HostWindow(host, True)

# -------------------------------------------------------------
# Load project file if set

for arg in app.arguments():
if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix=") or arg == "--gdb":
continue

if os.path.exists(arg):
gui.loadProjectLater(arg)
break

# -------------------------------------------------------------
# Show GUI



+ 0
- 11
source/carla-rack View File

@@ -53,17 +53,6 @@ if __name__ == '__main__':

gui = HostWindow(host, not(LADISH_APP_NAME or NSM_URL))

# -------------------------------------------------------------
# Load project file if set

for arg in app.arguments():
if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix=") or arg == "--gdb":
continue

if os.path.exists(arg):
gui.loadProjectLater(arg)
break

# -------------------------------------------------------------
# Show GUI



+ 9
- 3
source/carla_app.py View File

@@ -25,11 +25,11 @@ from carla_config import *
# Imports (Global)

if config_UseQt5:
from PyQt5.QtCore import Qt, QSettings
from PyQt5.QtCore import Qt, QCoreApplication, QSettings
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtWidgets import QApplication
else:
from PyQt4.QtCore import Qt, QSettings
from PyQt4.QtCore import Qt, QCoreApplication, QSettings
from PyQt4.QtGui import QApplication, QColor, QPalette

# ------------------------------------------------------------------------------------------------------------
@@ -80,6 +80,9 @@ class CarlaApplication(object):
# create app
self.createApp(appName)

if gCarla.nogui:
return

self.fApp.setStyle("carla" if stylesDir else "fusion")

# set palette
@@ -219,11 +222,14 @@ class CarlaApplication(object):
if MACOS:
QApplication.setAttribute(Qt.AA_DontShowIconsInMenus)

self.fApp = QApplication(sys.argv)
self.fApp = QCoreApplication(sys.argv) if gCarla.nogui else QApplication(sys.argv)
self.fApp.setApplicationName(appName)
self.fApp.setApplicationVersion(VERSION)
self.fApp.setOrganizationName("falkTX")

if gCarla.nogui:
return

if appName.lower() == "carla-control":
self.fApp.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
else:


+ 1
- 6
source/carla_database.py View File

@@ -1708,12 +1708,7 @@ if __name__ == '__main__':
from carla_app import CarlaApplication
from carla_host import initHost, loadHostSettings

libPrefix = None

for arg in sys.argv:
if arg.startswith("--with-libprefix="):
libPrefix = arg.replace("--with-libprefix=", "")
break
initName, libPrefix = handleInitialCommandLineArguments(__file__)

app = CarlaApplication("Carla2-Database", libPrefix)
host = initHost("Carla2-Database", libPrefix, False, False, False)


+ 161
- 92
source/carla_host.py View File

@@ -455,6 +455,13 @@ class HostWindow(QMainWindow):
if host.processModeForced and host.processMode == ENGINE_PROCESS_MODE_PATCHBAY and not host.isControl:
self.ui.tabWidget.setCurrentIndex(1)

# Load initial project file if set
if not (self.host.isControl or self.host.isPlugin):
projectFile = getInitialProjectFile(QApplication.instance())

if projectFile:
self.loadProjectLater(projectFile)

# For NSM we wait for the open message
if NSM_URL and host.nsmOK:
host.nsm_ready(-1)
@@ -596,7 +603,7 @@ class HostWindow(QMainWindow):

@pyqtSlot()
def slot_engineStart(self):
audioDriver = self.setEngineSettings()
audioDriver = setEngineSettings(self.host)
firstInit = self.fFirstEngineInit

self.fFirstEngineInit = False
@@ -1199,96 +1206,6 @@ class HostWindow(QMainWindow):
# --------------------------------------------------------------------------------------------------------
# Settings

def setEngineSettings(self):
# ----------------------------------------------------------------------------------------------------
# do nothing if control

if self.host.isControl:
return "Control"

# ----------------------------------------------------------------------------------------------------

settings = QSettings("falkTX", "Carla2")

# ----------------------------------------------------------------------------------------------------
# main settings

setHostSettings(self.host)

# ----------------------------------------------------------------------------------------------------
# plugin paths

LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
VST3_PATH = toList(settings.value(CARLA_KEY_PATHS_VST3, CARLA_DEFAULT_VST3_PATH))
GIG_PATH = toList(settings.value(CARLA_KEY_PATHS_GIG, CARLA_DEFAULT_GIG_PATH))
SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))

self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST3, splitter.join(VST3_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_GIG, splitter.join(GIG_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))

# ----------------------------------------------------------------------------------------------------
# don't continue if plugin

if self.host.isPlugin:
return "Plugin"

# ----------------------------------------------------------------------------------------------------
# driver and device settings

# driver name
try:
audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
except:
audioDriver = CARLA_DEFAULT_AUDIO_DRIVER

# driver options
try:
audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
except:
audioDevice = ""

try:
audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
except:
audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS

try:
audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
except:
audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE

try:
audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
except:
audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE

self.host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
self.host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
self.host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
self.host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")

# ----------------------------------------------------------------------------------------------------
# fix things if needed

if audioDriver != "JACK" and self.host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
self.host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")

# ----------------------------------------------------------------------------------------------------
# return selected driver name

return audioDriver

def saveSettings(self):
settings = QSettings()

@@ -1385,7 +1302,7 @@ class HostWindow(QMainWindow):

self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] == patchcanvas.EYECANDY_FULL else 0

self.setEngineSettings()
setEngineSettings(self.host)
self.restartTimersIfNeeded()

# --------------------------------------------------------------------------------------------------------
@@ -2286,6 +2203,12 @@ def loadHostSettings(host):
print("LADISH detected but using multiple clients (not allowed), forcing single client now")
host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT

# --------------------------------------------------------------------------------------------------------
# run headless host now if nogui option enabled

if gCarla.nogui:
runHostWithoutUI(host)

# ------------------------------------------------------------------------------------------------------------
# Set host settings

@@ -2311,3 +2234,149 @@ def setHostSettings(host):
host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, "")

# ------------------------------------------------------------------------------------------------------------
# Set Engine settings according to carla preferences. Returns selected audio driver.

def setEngineSettings(host):
# kdevelop likes this :)
if False: host = CarlaHostNull()

# --------------------------------------------------------------------------------------------------------
# do nothing if control

if host.isControl:
return "Control"

# --------------------------------------------------------------------------------------------------------

settings = QSettings("falkTX", "Carla2")

# --------------------------------------------------------------------------------------------------------
# main settings

setHostSettings(host)

# --------------------------------------------------------------------------------------------------------
# plugin paths

LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
VST3_PATH = toList(settings.value(CARLA_KEY_PATHS_VST3, CARLA_DEFAULT_VST3_PATH))
GIG_PATH = toList(settings.value(CARLA_KEY_PATHS_GIG, CARLA_DEFAULT_GIG_PATH))
SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))

host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST3, splitter.join(VST3_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_GIG, splitter.join(GIG_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))

# --------------------------------------------------------------------------------------------------------
# don't continue if plugin

if host.isPlugin:
return "Plugin"

# --------------------------------------------------------------------------------------------------------
# driver and device settings

# driver name
try:
audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
except:
audioDriver = CARLA_DEFAULT_AUDIO_DRIVER

# driver options
try:
audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
except:
audioDevice = ""

try:
audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
except:
audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS

try:
audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
except:
audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE

try:
audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
except:
audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE

host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")

# --------------------------------------------------------------------------------------------------------
# fix things if needed

if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")

# --------------------------------------------------------------------------------------------------------
# return selected driver name

return audioDriver

# ------------------------------------------------------------------------------------------------------------
# Run Carla without showing UI

def runHostWithoutUI(host):
# kdevelop likes this :)
if False: host = CarlaHostNull()

# --------------------------------------------------------------------------------------------------------
# Some initial checks

if not gCarla.nogui:
return

projectFile = getInitialProjectFile(QCoreApplication.instance(), True)

if not projectFile:
print("Carla no-gui mode can only be used together with a project file.")
sys.exit(1)

# --------------------------------------------------------------------------------------------------------
# Additional imports

from time import sleep

# --------------------------------------------------------------------------------------------------------
# Init engine

audioDriver = setEngineSettings(host)
if not host.engine_init(audioDriver, "Carla-nogui"):
print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
sys.exit(1)

if not host.load_project(projectFile):
print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
host.engine_close()
sys.exit(1)

# --------------------------------------------------------------------------------------------------------
# Idle

while host.is_engine_running() and not gCarla.term:
host.engine_idle()
sleep(0.5)

# --------------------------------------------------------------------------------------------------------
# Stop

host.engine_close()
sys.exit(0)

# ------------------------------------------------------------------------------------------------------------

+ 1
- 6
source/carla_settings.py View File

@@ -851,12 +851,7 @@ if __name__ == '__main__':
from carla_app import CarlaApplication
from carla_host import initHost, loadHostSettings

libPrefix = None

for arg in sys.argv:
if arg.startswith("--with-libprefix="):
libPrefix = arg.replace("--with-libprefix=", "")
break
initName, libPrefix = handleInitialCommandLineArguments(__file__)

app = CarlaApplication("Carla2-Settings", libPrefix)
host = initHost("Carla2-Settings", libPrefix, False, False, False)


+ 31
- 8
source/carla_shared.py View File

@@ -477,12 +477,16 @@ del DEFAULT_SFZ_PATH

class CarlaObject(object):
__slots__ = [
'gui', # Host Window
'utils' # Utils object
'gui', # Host Window
'nogui', # Skip UI
'term', # Terminated by OS signal
'utils' # Utils object
]

gCarla = CarlaObject()
gCarla.gui = None
gCarla.nogui = False
gCarla.term = False
gCarla.utils = None

# ------------------------------------------------------------------------------------------------------------
@@ -544,7 +548,7 @@ def handleInitialCommandLineArguments(file):
initName = os.path.basename(file) if ("__file__" in dir() and os.path.dirname(file) in PATH) else sys.argv[0]
libPrefix = None

for arg in sys.argv:
for arg in sys.argv[1:]:
if arg.startswith("--with-appname="):
initName = os.path.basename(arg.replace("--with-initname=", ""))

@@ -554,6 +558,9 @@ def handleInitialCommandLineArguments(file):
elif arg == "--gdb":
pass

elif arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
gCarla.nogui = True

elif arg in ("-h", "--h", "-help", "--help"):
print("Usage: %s [OPTION]... [FILE|URL]" % initName)
print("")
@@ -562,6 +569,7 @@ def handleInitialCommandLineArguments(file):
print(" and OPTION can be one or more of the following:")
print("")
print(" --gdb \t Run Carla inside gdb.")
print(" -n,--no-gui \t Run Carla headless, don't show UI.")
print("")
print(" -h,--help \t Print this help text and exit.")
print(" -v,--version\t Print version information and exit.")
@@ -583,6 +591,20 @@ def handleInitialCommandLineArguments(file):

return (initName, libPrefix)

# ------------------------------------------------------------------------------------------------------------
# Get initial project file (as passed in the command-line parameters)

def getInitialProjectFile(app, skipExistCheck = False):
for arg in app.arguments()[1:]:
if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix=") or arg == "--gdb":
continue
if arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
continue
if skipExistCheck or os.path.exists(arg):
return arg

return None

# ------------------------------------------------------------------------------------------------------------
# Get paths (binaries, resources)

@@ -628,13 +650,14 @@ def getPaths(libPrefix = None):
# TODO move to carla_host.py or something

def signalHandler(sig, frame):
if gCarla.gui is None:
return

if sig in (SIGINT, SIGTERM):
gCarla.gui.SIGTERM.emit()
gCarla.term = True
if gCarla.gui is not None:
gCarla.gui.SIGTERM.emit()

elif haveSIGUSR1 and sig == SIGUSR1:
gCarla.gui.SIGUSR1.emit()
if gCarla.gui is not None:
gCarla.gui.SIGUSR1.emit()

def setUpSignals():
signal(SIGINT, signalHandler)


Loading…
Cancel
Save