1
2
3
4 """
5 A barebones Python host for Csound
6
7 @author: Øyvind Brandtsegg
8 @contact: obrandts@gmail.com
9 @license: GPL
10 @requires: csnd
11 """
12
13 import csnd
14 import cs.csMessages
15 import cs.csModule
16 import time
17 import control.eventCaller
18 import control.theTime2
19 from constants import *
20
21
22
23
24
25
26 eventCaller = control.eventCaller.EventCaller()
27 """The event caller is the central module, communication with all other parts of the application."""
28
29 theTime = control.theTime2.TheTime2(eventCaller)
30 """theTime is the timed queue used for timed automation of method calls."""
31
32
33 csThread = cs.csModule.CsoundThreadRoutine(theTime)
34 """Instance of the Csound module, setting up and running Csound."""
35 csound = csThread.csound
36 """Pointer to the actual Csound instance."""
37 performanceThread = csound
38 """
39 (Would be) Pointer to the C++ thread running Csound.
40 The current implementation does not use the performancethread, but the ksmps loop based method of running Csound.
41 The pointer to the performance thread has been implemented to make it feasible to change between ksmps-loop and performancethread driven Csound.
42 """
43 csMessages = cs.csMessages.CsoundMessages(csound, performanceThread)
44 """Instance of csMessages, used for all message passing from python to csound."""
45
46
47 eventCaller.setPointers(csMessages, theTime)
48
49
50 csThread.csoundThread.start()
51
52 eventCaller.initValues()
53 print 'eventCaller starting threads'
54 eventCaller.startThreads()
55 theTime.runClock = True
56 """Set theTime clock to run mode."""
57
58 print '**************************************************************************'
59 print 'available commands:'
60 print ' perform(module)'
61 print ' setParameter(module, parameter, value)'
62 print ' i ... sends a score event to Csound (e.g. "i 1 0 1 -5 60 0.5 0.5")'
63 print ' other commands:'
64 print ' eventCaller.setTimeBpm(value)'
65 print ' eventCaller.recordAudio(START/STOP)'
66 print 'stop: stop the barebones system and exit the application'
67 print '**************************************************************************'
68
69
70
71 command = ''
72 while command != 'stop':
73 command = raw_input()
74 if command[:8] == 'perform(':
75 args = command[8:]
76 if 'START' in args:
77 module = args.split('START')[0][:-2]
78 eventCaller.perform(module, START)
79 elif 'STOP' in args:
80 module = args.split('STOP')[0][:-2]
81 eventCaller.perform(module, STOP)
82 else:
83 print 'perform must be called with START or STOP argument'
84 elif command[:13] == 'setParameter(':
85 args = command[13:]
86 module, parameter = args.split(',')[:2]
87 value = args.partition(parameter)[2]
88 while parameter[0] == ' ': parameter = parameter[1:]
89 while value[0] == ',' or value[0] == ' ': value = value[1:]
90 value = value[:-1]
91 eventCaller.setParameter(module, parameter, value)
92 elif command[0] == 'i':
93 csMessages.csoundInputMessage(command)
94 elif command != 'stop':
95
96 c = compile('r='+command, 'string', 'exec')
97 try:
98 exec(c)
99 except:
100 print command, 'is not a valid code object, skipping execution of', command
101 time.sleep(0)
102
103
104 eventCaller.stopThreads()
105 csThread.stop()
106