2 # -*- coding: utf-8 -*-
4 # This script is started pre-login
5 # It allows to pre-start jack, a2j and pulseaudio
11 from PyQt4
.QtCore
import QCoreApplication
, QProcess
, QSettings
12 from time
import sleep
14 # Cadence Global Settings
15 GlobalSettings
= QSettings("Cadence", "GlobalSettings")
17 HOME
= os
.getenv("HOME")
19 DEFAULT_LADSPA_PATH
= "/usr/lib/ladspa:/usr/local/lib/ladspa:/usr/lib32/ladspa:"+HOME
+"/.ladspa"
20 DEFAULT_DSSI_PATH
= "/usr/lib/dssi:/usr/local/lib/dssi:/usr/lib32/dssi:"+HOME
+"/.dssi"
21 DEFAULT_LV2_PATH
= "/usr/lib/lv2:/usr/local/lib/lv2:"+HOME
+"/.lv2"
22 DEFAULT_VST_PATH
= "/usr/lib/vst:/usr/local/lib/vst:/usr/lib32/vst:"+HOME
+"/.vst"
33 # Properly convert QString to str
34 def QStringStr(string
):
35 return str(unicode(string
).encode('utf-8'))
42 process
.start("ps", ["-e"])
43 process
.waitForFinished()
45 procs_dump
= QStringStr(process
.readAllStandardOutput()).split("\n")
47 for i
in range(len(procs_dump
)):
49 proc_test
= procs_dump
[i
].rsplit(":", 1)[-1].split(" ")
50 if (len(proc_test
) > 1):
51 procs
.append(proc_test
[1])
55 # Start JACK, A2J and Pulse, according to user settings
59 # Kill all audio processes first
60 procs_term
= ["a2j", "a2jmidid", "artsd", "jackd", "jackdmp", "knotify4", "lash", "ladishd", "ladiappd", "ladiconfd", "jmcore"]
61 procs_kill
= ["jackdbus", "pulseaudio"]
64 process
.start("killall", procs_term
)
65 process
.waitForFinished()
67 for x
in range(tries
):
68 procs_list
= getProcList()
69 for i
in range(len(procs_term
)):
70 if (procs_term
[i
] in procs_list
):
77 process
.start("killall", ["-KILL"] + procs_kill
)
78 process
.waitForFinished()
80 for x
in range(tries
):
81 procs_list
= getProcList()
82 for i
in range(len(procs_kill
)):
83 if (procs_kill
[i
] in procs_list
):
91 DBus
.bus
= dbus
.SessionBus()
93 DBus
.jack
= DBus
.bus
.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
95 DBus
.a2j
= dbus
.Interface(DBus
.bus
.get_object("org.gna.home.a2jmidid", "/"), "org.gna.home.a2jmidid.control")
99 # Load settings (JACK etc)
100 if (GlobalSettings
.value("JACK/AutoStart", True).toBool()):
101 if (GlobalSettings
.value("JACK/AutoLoadLadishStudio", False).toBool()):
103 ladish_control
= DBus
.bus
.get_object("org.ladish", "/org/ladish/Control")
109 ladish_conf
= DBus
.bus
.get_object("org.ladish.conf", "/org/ladish/conf")
114 studio_name
= dbus
.String(GlobalSettings
.value("JACK/LadishStudioName", "").toString())
115 studio_list_dump
= ladish_control
.GetStudioList()
117 for i
in range(len(studio_list_dump
)):
118 this_studio_name
= studio_list_dump
[i
][0]
119 if (this_studio_name
== studio_name
):
120 if (ladish_conf
and ladish_conf
.get('/org/ladish/daemon/notify')[0] == "true"):
121 ladish_conf
.set('/org/ladish/daemon/notify', "false")
124 ladish_control
.LoadStudio(this_studio_name
)
125 ladish_studio
= DBus
.bus
.get_object("org.ladish", "/org/ladish/Studio")
126 if (not bool(ladish_studio
.IsStarted())):
127 ladish_studio
.Start()
130 ladish_conf
.set('/org/ladish/daemon/notify', "true")
141 print "JACK is set to NOT auto-start on login"
144 if (bool(DBus
.jack
.IsStarted())):
145 if (GlobalSettings
.value("A2J/AutoStart", True).toBool() and DBus
.a2j
and not bool(DBus
.a2j
.is_started())):
146 a2j_hw_export
= GlobalSettings
.value("A2J/ExportHW", True).toBool()
147 DBus
.a2j
.set_hw_export(a2j_hw_export
)
150 if (GlobalSettings
.value("Pulse2JACK/AutoStart", True).toBool() and bool(DBus
.jack
.IsStarted())):
151 if (GlobalSettings
.value("Pulse2JACK/PlaybackModeOnly", False).toBool()):
152 os
.system("pulse2jack -p")
154 os
.system("pulse2jack")
156 print "JACK Started Successfully"
160 print "JACK Failed to Start"
164 if (not bool(DBus
.jack
.IsStarted())):
165 DBus
.jack
.StartServer()
167 def printLADSPA_PATH():
168 EXTRA_LADSPA_DIRS
= GlobalSettings
.value("AudioPlugins/EXTRA_LADSPA_PATH", "").toString().split(":")
169 LADSPA_PATH_str
= DEFAULT_LADSPA_PATH
171 for i
in range(len(EXTRA_LADSPA_DIRS
)):
172 if (EXTRA_LADSPA_DIRS
[i
]):
173 LADSPA_PATH_str
+= ":"+EXTRA_LADSPA_DIRS
[i
]
175 print LADSPA_PATH_str
177 def printDSSI_PATH():
178 EXTRA_DSSI_DIRS
= GlobalSettings
.value("AudioPlugins/EXTRA_DSSI_PATH", "").toString().split(":")
179 DSSI_PATH_str
= DEFAULT_DSSI_PATH
181 for i
in range(len(EXTRA_DSSI_DIRS
)):
182 if (EXTRA_DSSI_DIRS
[i
]):
183 DSSI_PATH_str
+= ":"+EXTRA_DSSI_DIRS
[i
]
188 EXTRA_LV2_DIRS
= GlobalSettings
.value("AudioPlugins/EXTRA_LV2_PATH", "").toString().split(":")
189 LV2_PATH_str
= DEFAULT_LV2_PATH
191 for i
in range(len(EXTRA_LV2_DIRS
)):
192 if (EXTRA_LV2_DIRS
[i
]):
193 LV2_PATH_str
+= ":"+EXTRA_LV2_DIRS
[i
]
198 EXTRA_VST_DIRS
= GlobalSettings
.value("AudioPlugins/EXTRA_VST_PATH", "").toString().split(":")
199 VST_PATH_str
= DEFAULT_VST_PATH
201 for i
in range(len(EXTRA_VST_DIRS
)):
202 if (EXTRA_VST_DIRS
[i
]):
203 VST_PATH_str
+= ":"+EXTRA_VST_DIRS
[i
]
207 def printArguments():
208 print "\t-s|--start \tStart session"
210 print "\t-h|--help \tShow this help message"
211 print "\t-v|--version\tShow version"
214 print "Invalid arguments"
215 print "Run '%s -h' for help" % (cmd
)
218 print "Usage: %s [cmd]" % (cmd
)
222 print "Cadence version %s" % (VERSION
)
223 print "Developed by falkTX and the rest of the KXStudio Team"
225 #--------------- main ------------------
226 if __name__
== '__main__':
229 app
= QCoreApplication(sys
.argv
)
230 app
.setApplicationName("Cadence")
231 app
.setApplicationVersion(VERSION
)
232 app
.setOrganizationName("falkTX")
237 if (app
.arguments().count() == 1):
239 elif (app
.arguments().count() == 2):
240 arg
= app
.arguments()[1]
241 if (arg
== "--printLADSPA_PATH"):
243 elif (arg
== "--printDSSI_PATH"):
245 elif (arg
== "--printLV2_PATH"):
247 elif (arg
== "--printVST_PATH"):
249 elif (arg
in ["-s", "--s", "-start", "--start"]):
250 sys
.exit(startSession())
251 elif (arg
in ["-h", "--h", "-help", "--help"]):
253 elif (arg
in ["-v", "--v", "-version", "--version"]):