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 self.sMelody2 = comp.serialMelody.SerialMelody(self)
48 """Instance of the SerialMelody composition class."""
49
50 self.theTimeSeconds = control.theTime.TheTime(self, 60)
51 """Instance of a relaxed timed queue used for slow automation (seconds, minutes, hours)."""
52 self.theTime = self.theTimeSeconds
53 """Pointer to a precise timed queue, clock slaved to Csound control rate."""
54
55
56
57
58
60 """
61 Initialize the system.
62
63 This includes setting various initial values and instantiating csound instruments as needed for normal operation.
64
65 @param self: The object pointer.
66 """
67
68 scoreLength = 600000
69 self.csMessages.csoundInputMessage('i 98 0 %i'%scoreLength)
70 self.csMessages.csoundInputMessage('i 99 0 %i'%scoreLength)
71
72
73
74
75
77 """
78 Wrapper for (any) composition module's perform method.
79
80 @param self: The object pointer.
81 @param module: The composition module to perform.
82 """
83 func = 'self.%s.perform(%i)'%(module, state)
84 c = compile(func, 'string', 'exec')
85 exec(c)
86
88 """
89 Set a parameter for a composition module.
90
91 @param self: The object pointer.
92 @param module: The composition module to set a parameter value for.
93 @param parameter: The parameter name.
94 @param value: The value to set the parameter to.
95 """
96 print 'setParameter', module, parameter, value
97 func = 'self.%s.setParameter(%s, %s)'%(module, parameter, value)
98 c = compile(func, 'string', 'exec')
99 exec(c)
100
101
102
103
104
106 """
107 Parsing of events output from queue, called from theTime.
108
109 @param self: The object pointer.
110 @param event: The event to be parsed.
111 """
112
113 beat = event[0]
114 try:
115 event[1][0]()
116 except:
117 print '*** WARNING ***, timed event not recognized by eventCaller.parseEvent'
118 print '...or, maybe your composition module contains a bug preventing it from being run correctly: see below...'
119 print event
120 print 'exception', sys.exc_info()
121
122
123
125 """
126 Start or stop the timed queue clock
127
128 @param self: The object pointer.
129 @param state: The state (1 or 0) for the clock. Clock runs while state is 1, pause when state is 0.
130 """
131 self.theTime.startStopClock(state, offset)
132
133
134
135
136
138 """
139 Set tempo in bpm for the variable-tempo timed queue.
140
141 @param self: The object pointer.
142 @param bpm: The tempo in bpm.
143 """
144 print 'theTime tempo set to ', bpm
145 self.theTime.setBpm(bpm)
146
148 """
149 Start timed queue (sequencer) threads.
150
151 @param self: The object pointer.
152 """
153 self.theTimeSeconds.start()
154 self.theTimeSeconds.startStopClock(1)
155
157 """
158 Stop timed queue (sequencer) threads.
159
160 @param self: The object pointer.
161 """
162 self.theTimeSeconds.stop()
163
165 """
166 Set pointers to other modules in the system.
167
168 @param self: The object pointer.
169 @param csMessages: Pointer to the csMessages object.
170 @param theTime: Pointer to the theTime object
171 """
172 self.csMessages = csMessages
173 self.theTime = theTime
174
176 """
177 Make an audio recording of a realtime session.
178
179 @param self: The object pointer.
180 @param state: START to start recording, STOP to stop.
181 @param name: The file name to record audio to.
182 """
183 if name.find('.wav') < 0:
184 print 'filename must end with .wav, record aborted'
185 return
186 if state == START:
187 self.csMessages.csoundInputMessage('i 100 0 -1 "%s"'%name)
188 else:
189 self.csMessages.csoundInputMessage('i -100 0 1')
190 self.csMessages.csoundInputMessage('i 101 0 1')
191