1
2
3
4 """
5 Handles all communication between different parts of the barebones system.
6
7 @author: Øyvind Brandtsegg
8 @contact: obrandts@gmail.com
9 @license: GPL
10 @requires: Pyro
11 """
12
13 import time
14 import sys
15 import threading
16 import control.theTime
17 import comp.randMelody
18 import comp.serialMelody
19 from constants import *
20
22 """
23 The central control and communitation module
24
25 All events from the user interface(s) are sent here.
26 All events from the timed queue are processed here. EventCaller also communicates with the compositional logic,
27 and with Csound through cs.messages.
28 """
29
31 """
32 ## Class constructor.
33 #
34 # @param self: The object pointer.
35 """
36
37 self.csMessages = ''
38 """Pointer to csMessages instance."""
39
40 self.rMelody1 = comp.randMelody.RandMelody(self)
41 """Instance of the RandMelody composition class."""
42 self.rMelody2 = comp.randMelody.RandMelody(self)
43 """Instance of the RandMelody composition class."""
44
45 self.sMelody1 = comp.serialMelody.SerialMelody(self)
46 """Instance of the SerialMelody composition class."""
47
48 self.theTimeSeconds = control.theTime.TheTime(self, 60)
49 """Instance of a relaxed timed queue used for slow automation (seconds, minutes, hours)."""
50 self.theTime = self.theTimeSeconds
51 """Pointer to a precise timed queue, clock slaved to Csound control rate."""
52
53
54
55
56
58 """
59 Initialize the system.
60
61 This includes setting various initial values and instantiating csound instruments as needed for normal operation.
62
63 @param self: The object pointer.
64 """
65
66 scoreLength = 600000
67 self.csMessages.csoundInputMessage('i 98 0 %i'%scoreLength)
68 self.csMessages.csoundInputMessage('i 99 0 %i'%scoreLength)
69
70
71
72
73
84
86 """
87 Set a parameter for a composition module.
88
89 @param self: The object pointer.
90 @param module: The composition module to set a parameter value for.
91 @param parameter: The parameter name.
92 @param value: The value to set the parameter to.
93 """
94 print 'setParameter', module, parameter, value
95 func = 'self.%s.setParameter(%s, %s)'%(module, parameter, value)
96 c = compile(func, 'string', 'exec')
97 exec(c)
98
99
100
101
102
104 """
105 Parsing of events output from queue, called from theTime.
106
107 @param self: The object pointer.
108 @param event: The event to be parsed.
109 """
110
111 beat = event[0]
112 try:
113 event[1][0]()
114 except:
115 print '*** WARNING ***, timed event not recognized by eventCaller.parseEvent'
116 print '...or, maybe your composition module contains a bug preventing it from being run correctly: see below...'
117 print event
118 print 'exception', sys.exc_info()
119
120
121
123 """
124 Start or stop the timed queue clock
125
126 @param self: The object pointer.
127 @param state: The state (1 or 0) for the clock. Clock runs while state is 1, pause when state is 0.
128 """
129 self.theTime.startStopClock(state, offset)
130
131
132
133
134
136 """
137 Set tempo in bpm for the variable-tempo timed queue.
138
139 @param self: The object pointer.
140 @param bpm: The tempo in bpm.
141 """
142 print 'theTime tempo set to ', bpm
143 self.theTime.setBpm(bpm)
144
146 """
147 Start timed queue (sequencer) threads.
148
149 @param self: The object pointer.
150 """
151 self.theTimeSeconds.start()
152 self.theTimeSeconds.startStopClock(1)
153
155 """
156 Stop timed queue (sequencer) threads.
157
158 @param self: The object pointer.
159 """
160 self.theTimeSeconds.stop()
161
163 """
164 Set pointers to other modules in the system.
165
166 @param self: The object pointer.
167 @param csMessages: Pointer to the csMessages object.
168 @param theTime: Pointer to the theTime object
169 """
170 self.csMessages = csMessages
171 self.theTime = theTime
172
174 """
175 Make an audio recording of a realtime session.
176
177 @param self: The object pointer.
178 @param state: START to start recording, STOP to stop.
179 @param name: The file name to record audio to.
180 """
181 if name.find('.wav') < 0:
182 print 'filename must end with .wav, record aborted'
183 return
184 if state == START:
185 self.csMessages.csoundInputMessage('i 100 0 -1 "%s"'%name)
186 else:
187 self.csMessages.csoundInputMessage('i -100 0 1')
188 self.csMessages.csoundInputMessage('i 101 0 1')
189