Restore JACK parameters during studio load. Closes #2
[ladish.git] / ladish_control
blobd6d22dc9dd8ee8f1d1d40209b4923536aab5b017
1 #!/usr/bin/env python
3 # LADI Session Handler (ladish)
5 # Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
7 #*************************************************************************
8 # This file contains code of the commandline control app
9 #*************************************************************************
11 # LADI Session Handler is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # LADI Session Handler is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 # or write to the Free Software Foundation, Inc.,
24 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 control_interface_name = 'org.ladish.Control'
27 service_name = 'org.ladish'
28 dbus_object_path = "/org/ladish/Control"
30 import sys
31 import os
32 import time
33 from traceback import print_exc
35 import dbus
37 def bool_convert(str_value):
38 if str_value.lower() == "false":
39 return False
41 if str_value.lower() == "off":
42 return False
44 if str_value.lower() == "no":
45 return False
47 if str_value == "0":
48 return False
50 if str_value.lower() == "(null)":
51 return False
53 return bool(str_value)
55 def dbus_type_to_python_type(dbus_value):
56 if type(dbus_value) == dbus.Boolean:
57 return bool(dbus_value)
58 if type(dbus_value) == dbus.Int32 or type(dbus_value) == dbus.UInt32:
59 return int(dbus_value)
60 return dbus_value
62 def dbus_type_to_type_string(dbus_value):
63 if type(dbus_value) == dbus.Boolean:
64 return "bool"
65 if type(dbus_value) == dbus.Int32:
66 return "sint"
67 if type(dbus_value) == dbus.UInt32:
68 return "uint"
69 if type(dbus_value) == dbus.Byte:
70 return "char"
71 if type(dbus_value) == dbus.String:
72 return "str"
74 return None # throw exception here?
76 def dbus_typesig_to_type_string(type_char):
77 type_char = str(type_char)
78 if type_char == 'i':
79 return "sint"
80 if type_char == 'u':
81 return "uint"
82 if type_char == 'y':
83 return "char"
84 if type_char == 's':
85 return "str"
86 if type_char == 'b':
87 return "bool"
89 print 'shit'
90 return None # throw exception here?
92 def main():
93 if len(sys.argv) == 1:
94 print "Usage: %s [command] [command] ..." % os.path.basename(sys.argv[0])
95 print "Commands:"
96 print " exit - exit ladish dbus service"
97 print " studios - list studios"
98 print " apps - list apps"
99 print " load <studioname> - load studio"
100 sys.exit(0)
102 bus = dbus.SessionBus()
103 lash = None
105 # check arguments
106 index = 1
107 while index < len(sys.argv):
108 arg = sys.argv[index]
109 index += 1
110 try:
111 if not lash:
112 lash = bus.get_object(service_name, dbus_object_path)
113 control_iface = dbus.Interface(lash, control_interface_name)
115 if arg == "exit":
116 print "--- exit"
117 control_iface.Exit()
118 time.sleep(1)
119 # we have deactivated the object and we need to get new connection if there are more commands
120 lash = None
121 control_iface = None
122 elif arg == 'studios':
123 print "--- studio list"
124 for studio in control_iface.GetStudioList():
125 name = studio[0]
126 mtime = studio[1]['Modification Time']
127 print '"%s" last modified on %s' % (name, time.ctime(mtime))
128 elif arg == 'apps':
129 print "--- app list"
130 for app in control_iface.GetApplicationList():
131 print app
132 elif arg == 'load':
133 if index >= len(sys.argv):
134 print "load studio command requires studio name argument"
135 sys.exit()
137 arg = sys.argv[index]
138 index += 1
140 open_options = {}
141 #open_options["option1"] = "asd"
142 #open_options["option2"] = True
144 control_iface.LoadStudio(arg, open_options)
145 else:
146 print "Unknown command '%s'" % arg
147 except dbus.DBusException, e:
148 print "DBus exception: %s" % str(e)
150 if __name__ == '__main__':
151 main()