0
|
1 from TLUtility import make_attributes_from_args, dict_scale, dict_max, \
|
|
2 DummyClass, last_less_than, first_greater_than
|
|
3 from time import time
|
|
4 from __future__ import division # "I'm sending you back to future!"
|
|
5
|
|
6 """
|
109
|
7 Changelog:
|
|
8 Fri May 16 15:17:34 PDT 2003
|
|
9 Project started (roughly).
|
|
10
|
|
11 Mon May 19 17:56:24 PDT 2003
|
|
12 Timeline is more or less working. Still bugs with skipping
|
|
13 FunctionFrames at random times.
|
|
14
|
|
15 Timeline idea
|
|
16 =============
|
|
17 time | 0 1 2 3 4 5 6
|
|
18 ---------+-----------------------------
|
|
19 frame | F F F
|
|
20 blenders | \ b / \- b ----/
|
|
21
|
|
22 Update: this is more or less what happened. However, there are
|
|
23 TimelineTracks as well. FunctionFrames go on their own track.
|
|
24 LevelFrames must have unique times, FunctionFrames do not.
|
|
25
|
|
26 Level propagation
|
|
27 =================
|
|
28 Cue1 is a CueNode. CueNodes consist of a timeline with any number
|
|
29 of LevelFrame nodes and LinearBlenders connecting all the frames.
|
|
30 At time 0, Cue1's timeline has LevelFrame1. At time 5, the timeline
|
|
31 has NodeFrame1. NodeFrame1 points to Node1, which has it's own sets
|
|
32 of levels. It could be a Cue, for all Cue1 cares. No matter what,
|
|
33 we always get down to LevelFrames holding the levels at the bottom,
|
|
34 then getting combined by Blenders.
|
|
35
|
|
36 /------\
|
|
37 | Cue1 |
|
|
38 |---------------\
|
|
39 | Timeline: |
|
|
40 | 0 ... 5 |
|
|
41 /--------- LF1 NF1 -------\
|
|
42 | | \ / | |
|
|
43 | | LinearBlender | |
|
|
44 | \---------------/ |
|
|
45 | points to
|
|
46 /---------------\ a port in Cue1,
|
|
47 | blueleft : 20 | which connects to a Node
|
|
48 | redwash : 12 |
|
|
49 | . |
|
|
50 | : |
|
|
51 | |
|
|
52 \---------------/
|
|
53
|
|
54 PS. blueleft and redwash are other nodes at the bottom of the tree.
|
|
55 The include their real channel number for the DimmerNode to process.
|
|
56
|
|
57 When Cue1 requests levels, the timeline looks at the current position.
|
|
58 If it is directly over a Frame (or Frames), that frame is handled.
|
|
59 If it is LevelFrame, those are the levels that it returns. If there is
|
|
60 a FunctionFrame, that function is activated. Thus, the order of Frames
|
|
61 at a specific time is very significant, since the FunctionFrame could
|
|
62 set the time to 5s in the future. If we are not currently over any
|
|
63 LevelFrames, we call upon a Blender to determine the value between.
|
|
64 Say that we are at 2.3s. We use the LinearBlender with 2.3/5.0s = 0.46%
|
|
65 and it determines that the levels are 1 - 0.46% = 0.54% of LF1 and
|
|
66 0.46% of NF1. NF1 asks Node9 for its levels and this process starts
|
|
67 all over.
|
|
68
|
|
69 Graph theory issues (node related issues, should be moved elsewhere)
|
|
70 ====================================================================
|
|
71 1. We need to determine dependencies for updating (topological order).
|
|
72 2. We need to do cyclicity tests.
|
|
73
|
|
74 Guess who wishes they had brought their theory book home?
|
|
75 I think we can do both with augmented DFS. An incremental version of both
|
|
76 would be very nice, though hopefully unnecessary.
|
|
77
|
0
|
78 """
|
|
79
|
109
|
80 class InvalidFrameOperation(Exception):
|
|
81 """You get these when you try to perform some operation on a frame
|
|
82 that doesn't make sense. The interface is advised to tell the user,
|
|
83 and indicate that a Blender or FunctionFramea should be disconnected
|
|
84 or fixed."""
|
|
85 pass
|
|
86
|
0
|
87 class MissingBlender(Exception):
|
|
88 """Raised when a TimedEvent is missing a blender."""
|
|
89 def __init__(self, timedevent):
|
|
90 make_attributes_from_args('timedevent')
|
|
91 Exception.__init__(self, "%r is missing a blender." % \
|
|
92 self.timedevent)
|
|
93
|
|
94 # these are chosen so we can multiply by -1 to reverse the direction,
|
|
95 # and multiply direction by the time difference to determine new times.
|
|
96 FORWARD = 1
|
|
97 BACKWARD = -1
|
|
98
|
109
|
99 class Frame:
|
|
100 """Frame is an event that happens at a specific time. There are two
|
|
101 types of frames: LevelFrames and FunctionFrames. LevelFrames provide
|
|
102 levels via their get_levels() function. FunctionFrames alter the
|
|
103 timeline (e.g. bouncing, looping, speed changes, etc.). They call
|
|
104 __call__'ed instead."""
|
|
105 def __init__(self, name):
|
|
106 self.name = name
|
|
107 self.timeline = DummyClass(use_warnings=0, raise_exceptions=0)
|
|
108 def set_timeline(self, timeline):
|
|
109 """Tell the Frame who the controlling Timeline is"""
|
|
110 self.timeline = timeline
|
|
111 def __mul__(self, percent):
|
|
112 """Generate a new Frame by multiplying the 'effect' of this frame by
|
|
113 a percent."""
|
|
114 raise InvalidFrameOperation, "Can't use multiply this Frame"
|
|
115 def __add__(self, otherframe):
|
|
116 """Combines this frame with another frame, generating a new one."""
|
|
117 raise InvalidFrameOperation, "Can't use add on this Frame"
|
|
118
|
|
119 class LevelFrame(Frame):
|
|
120 """LevelFrames provide levels. They can also be combined with other
|
|
121 LevelFrames."""
|
|
122 def __init__(self, name, levels):
|
|
123 Frame.__init__(self, name)
|
|
124 self.levels = levels
|
|
125 def __mul__(self, percent):
|
|
126 """Returns a new LevelFrame made by multiplying all levels by a
|
|
127 percentage. Percent is a float greater than 0.0"""
|
|
128 newlevels = dict_scale(self.get_levels(), percent)
|
|
129 return LevelFrame('(%s * %f)' % (self.name, percent), newlevels)
|
|
130 def __add__(self, otherframe):
|
|
131 """Combines this LevelFrame with another LevelFrame, generating a new
|
|
132 one. Values are max() together."""
|
|
133 theselevels, otherlevels = self.get_levels(), otherframe.get_levels()
|
|
134 return LevelFrame('(%s + %s)' % (self.name, otherframe.name),
|
|
135 dict_max(theselevels, otherlevels))
|
|
136 def get_levels(self):
|
|
137 """This function returns the levels held by this frame."""
|
|
138 return self.levels
|
|
139 def __repr__(self):
|
|
140 return "<%s %r %r>" % (str(self.__class__), self.name, self.levels)
|
|
141
|
|
142 class EmptyFrame(LevelFrame):
|
|
143 """An empty LevelFrame, for the purposes of extending the timeline."""
|
|
144 def __init__(self, name='Empty Frame'):
|
|
145 EmptyFrame.__init__(self, name, {})
|
|
146
|
|
147 class NodeFrame(LevelFrame):
|
|
148 """A LevelFrame that gets its levels from another Node. This must be
|
|
149 used from a Timeline that is enclosed in TimelineNode. Node is a string
|
|
150 describing the node requested."""
|
|
151 def __init__(self, name, node):
|
|
152 LevelFrame.__init__(self, name, {})
|
|
153 self.node = node
|
|
154 def get_levels(self):
|
|
155 """Ask the node that we point to for its levels"""
|
|
156 node = self.timeline.get_node(self.node)
|
|
157 self.levels = node.get_levels()
|
|
158 return self.levels
|
|
159
|
|
160 class FunctionFrame(Frame):
|
|
161 def __init__(self, name):
|
|
162 Frame.__init__(self, name)
|
|
163 def __call__(self, timeline, timedevent, node):
|
|
164 """Called when the FunctionFrame is activated. It is given a pointer
|
|
165 to it's master timeline, the TimedEvent containing it, and Node that
|
|
166 the timeline is contained in, if available."""
|
|
167 pass
|
|
168
|
|
169 # this is kinda broken
|
|
170 class BounceFunction(FunctionFrame):
|
|
171 def __call__(self, timeline, timedevent, node):
|
|
172 """Reverses the direction of play."""
|
|
173 timeline.reverse_direction()
|
|
174 print "boing! new dir:", timeline.direction
|
|
175
|
|
176 # this too
|
|
177 class LoopFunction(FunctionFrame):
|
|
178 def __call__(self, timeline, timedevent, node):
|
|
179 timeline.set_time(0)
|
|
180 print 'looped!'
|
|
181
|
|
182 class DoubleTimeFunction(FunctionFrame):
|
|
183 def __call__(self, timeline, timedevent, node):
|
|
184 timeline.set_rate(2 * timeline.rate)
|
|
185
|
|
186 class HalfTimeFunction(FunctionFrame):
|
|
187 def __call__(self, timeline, timedevent, node):
|
|
188 timeline.set_rate(0.5 * timeline.rate)
|
0
|
189
|
|
190 class TimedEvent:
|
|
191 """Container for a Frame which includes a time that it occurs at,
|
|
192 and which blender occurs after it."""
|
109
|
193 def __init__(self, time, frame, blender=None):
|
0
|
194 make_attributes_from_args('time', 'frame')
|
|
195 self.next_blender = blender
|
|
196 def __float__(self):
|
|
197 return self.time
|
|
198 def __cmp__(self, other):
|
|
199 if type(other) in (float, int):
|
|
200 return cmp(self.time, other)
|
|
201 else:
|
|
202 return cmp(self.time, other.time)
|
|
203 def __repr__(self):
|
109
|
204 return "<TimedEvent %s at %.2f, next blender=%s>" % \
|
|
205 (self.frame, self.time, self.next_blender)
|
|
206 def get_levels(self):
|
|
207 """Return the Frame's levels. Hopefully frame is a LevelFrame or
|
|
208 descendent."""
|
|
209 return self.frame.get_levels()
|
0
|
210
|
|
211 class Blender:
|
|
212 """Blenders are functions that merge the effects of two LevelFrames."""
|
|
213 def __init__(self):
|
|
214 pass
|
109
|
215 def __call__(self, startframe, endframe, blendtime):
|
0
|
216 """Return a LevelFrame combining two LevelFrames (startframe and
|
|
217 endframe). blendtime is how much of the blend should be performed
|
|
218 and will be expressed as a percentage divided by 100, i.e. a float
|
109
|
219 between 0.0 and 1.0.
|
0
|
220
|
|
221 Very important note: Blenders will *not* be asked for values
|
|
222 at end points (i.e. blendtime=0.0 and blendtime=1.0).
|
|
223 The LevelFrames will be allowed to specify the values at
|
|
224 those times. This is unfortunately for implemementation and
|
|
225 simplicity purposes. In other words, if we didn't do this,
|
|
226 we could have two blenders covering the same point in time and
|
|
227 not know which one to ask for the value. Thus, this saves us
|
|
228 a lot of messiness with minimal or no sacrifice."""
|
|
229 pass
|
|
230 def __str__(self):
|
|
231 """As a default, we'll just return the name of the class. Subclasses
|
|
232 can add parameters on if they want."""
|
|
233 return str(self.__class__)
|
|
234 def linear_blend(self, startframe, endframe, blendtime):
|
|
235 """Utility function to help you produce linear combinations of two
|
|
236 blends. blendtime is the percent/100 that the blend should
|
|
237 completed. In other words, 0.25 means it should be 0.75 * startframe +
|
|
238 0.25 * endframe. This function is included since many blenders are
|
|
239 just functions on the percentage and still combine start and end frames
|
|
240 in this way."""
|
109
|
241 return (startframe * (1.0 - blendtime)) + (endframe * blendtime)
|
0
|
242
|
|
243 class InstantEnd(Blender):
|
|
244 """Instant change from startframe to endframe at the end. In other words,
|
|
245 the value returned will be the startframe all the way until the very end
|
|
246 of the blend."""
|
109
|
247 def __call__(self, startframe, endframe, blendtime):
|
0
|
248 # "What!?" you say, "Why don't you care about blendtime?"
|
|
249 # This is because Blenders never be asked for blenders at the endpoints
|
|
250 # (after all, they wouldn't be blenders if they were). Please see
|
|
251 # 'Very important note' in Blender.__doc__
|
109
|
252 return startframe
|
0
|
253
|
|
254 class InstantStart(Blender):
|
|
255 """Instant change from startframe to endframe at the beginning. In other
|
|
256 words, the value returned will be the startframe at the very beginning
|
|
257 and then be endframe at all times afterwards."""
|
109
|
258 def __call__(self, startframe, endframe, blendtime):
|
0
|
259 # "What!?" you say, "Why don't you care about blendtime?"
|
|
260 # This is because Blenders never be asked for blenders at the endpoints
|
|
261 # (after all, they wouldn't be blenders if they were). Please see
|
|
262 # 'Very important note' in Blender.__doc__
|
109
|
263 return endframe
|
0
|
264
|
|
265 class LinearBlender(Blender):
|
|
266 """Linear fade from one frame to another"""
|
109
|
267 def __call__(self, startframe, endframe, blendtime):
|
0
|
268 return self.linear_blend(startframe, endframe, blendtime)
|
109
|
269 # return (startframe * (1.0 - blendtime)) + (endframe * blendtime)
|
0
|
270
|
|
271 class ExponentialBlender(Blender):
|
|
272 """Exponential fade fron one frame to another. You get to specify
|
|
273 the exponent. If my math is correct, exponent=1 means the same thing
|
|
274 as LinearBlender."""
|
|
275 def __init__(self, exponent):
|
|
276 self.exponent = exponent
|
109
|
277 def __call__(self, startframe, endframe, blendtime):
|
0
|
278 blendtime = blendtime ** self.exponent
|
|
279 return self.linear_blend(startframe, endframe, blendtime)
|
|
280
|
|
281 # 17:02:53 drewp: this makes a big difference for the SmoothBlender
|
|
282 # (-x*x*(x-1.5)*2) function
|
|
283 class SmoothBlender(Blender):
|
|
284 """Drew's "Smoove" Blender function. Hopefully he'll document and
|
|
285 parametrize it."""
|
109
|
286 def __call__(self, startframe, endframe, blendtime):
|
0
|
287 blendtime = (-1 * blendtime) * blendtime * (blendtime - 1.5) * 2
|
|
288 return self.linear_blend(startframe, endframe, blendtime)
|
|
289
|
|
290 class TimelineTrack:
|
|
291 """TimelineTrack is a single track in a Timeline. It consists of a
|
|
292 list of TimedEvents and a name. Length is automatically the location
|
|
293 of the last TimedEvent. To extend the Timeline past that, add an
|
109
|
294 EmptyTimedEvent."""
|
|
295 def __init__(self, name, *timedevents):
|
0
|
296 self.name = name
|
109
|
297 self.events = list(timedevents)
|
0
|
298 self.events.sort()
|
|
299 def __str__(self):
|
|
300 return "<TimelineTrack with events: %r>" % self.events
|
|
301 def has_events(self):
|
|
302 """Whether the TimelineTrack has anything in it. In general,
|
|
303 empty level Tracks should be avoided. However, empty function tracks
|
|
304 might be common."""
|
|
305 return len(self.events)
|
|
306 def length(self):
|
|
307 """Returns the length of this track in pseudosecond time units.
|
|
308 This is done by finding the position of the last TimedEvent."""
|
|
309 return float(self.events[-1])
|
|
310 def get(self, key, direction=FORWARD):
|
|
311 """Returns the event at a specific time key. If there is no event
|
|
312 at that time, a search will be performed in direction. Also note
|
|
313 that if there are multiple events at one time, only the first will
|
|
314 be returned. (Probably first in order of adding.) This is not
|
|
315 a problem at the present since this method is intended for LevelFrames,
|
|
316 which must exist at unique times."""
|
|
317 if direction == BACKWARD:
|
|
318 func = last_less_than
|
|
319 else:
|
|
320 func = first_greater_than
|
|
321
|
|
322 return func(self.events, key)
|
|
323 def get_range(self, i, j, direction=FORWARD):
|
|
324 """Returns all events between i and j, exclusively. If direction
|
|
325 is FORWARD, j will be included. If direction is BACKWARD, i will
|
|
326 be included. This is because this is used to find FunctionFrames
|
|
327 and we assume that any function frames at the start point (which
|
|
328 could be i or j) have been processed."""
|
|
329 if direction == FORWARD:
|
|
330 return [e for e in self.events if e > i and e <= j]
|
|
331 else:
|
|
332 return [e for e in self.events if e >= i and e < j]
|
|
333 def __getitem__(self, key):
|
|
334 """Returns the event at or after a specific time key.
|
|
335 For example: timeline[3] will get the first event at time 3.
|
|
336
|
|
337 If you want to get all events at time 3, you are in trouble, but
|
|
338 you could achieve it with something like:
|
|
339 timeline.get_range(2.99, 3.01, FORWARD)
|
|
340 This is hopefully a bogus problem, since you can't have multiple
|
|
341 LevelFrames at the same time."""
|
|
342 return self.get(key, direction=FORWARD)
|
|
343 def get_surrounding_frames(self, time):
|
|
344 """Returns frames before and after a specific time. This returns
|
|
345 a 2-tuple: (previousframe, nextframe). If you have chosen the exact
|
|
346 time of a frame, it will be both previousframe and nextframe."""
|
|
347 return self.get(time, direction=BACKWARD), \
|
|
348 self.get(time, direction=FORWARD)
|
|
349 def get_levels_at_time(self, time):
|
|
350 """Returns a LevelFrame with the levels of this track at that time."""
|
|
351 before, after = self.get_surrounding_frames(time)
|
|
352
|
109
|
353 if before == after:
|
|
354 return before.frame
|
0
|
355 else: # we have a blended value
|
|
356 diff = after.time - before.time
|
|
357 elapsed = time - before.time
|
|
358 percent = elapsed / diff
|
|
359 if not before.next_blender:
|
|
360 raise MissingBlender, before
|
109
|
361 return before.next_blender(before.frame, after.frame, percent)
|
0
|
362
|
|
363 class Timeline:
|
109
|
364 def __init__(self, tracks, functions, rate=1, direction=FORWARD):
|
0
|
365 """
|
109
|
366 Most of this is old:
|
0
|
367
|
|
368 You can have multiple FunctionFrames at the same time. Their
|
|
369 order is important though, since FunctionFrames will be applied
|
|
370 in the order seen in this list. blenders is a list of Blenders.
|
|
371 rate is the rate of playback. If set to 1, 1 unit inside the
|
|
372 Timeline will be 1 second. direction is the initial direction.
|
|
373 If you want to do have looping, place a LoopFunction at the end of
|
|
374 the Timeline. Timelines don't have a set length. Their length
|
|
375 is bounded by their last frame. You can put an EmptyFrame at
|
|
376 some time if you want to extend a Timeline."""
|
|
377
|
109
|
378 make_attributes_from_args('tracks', 'rate', 'direction')
|
|
379 # the function track is a special track
|
|
380 self.fn_track = TimelineTrack('functions', *functions)
|
|
381
|
0
|
382 self.current_time = 0
|
|
383 self.last_clock_time = None
|
|
384 self.stopped = 1
|
|
385 def length(self):
|
|
386 """Length of the timeline in pseudoseconds. This is determined by
|
|
387 finding the length of the longest track."""
|
|
388 track_lengths = [track.length() for track in self.tracks]
|
109
|
389 track_lengths.append(self.fn_track.length())
|
0
|
390 return max(track_lengths)
|
|
391 def play(self):
|
|
392 """Activates the timeline. Future calls to tick() will advance the
|
|
393 timeline in the appropriate direction."""
|
|
394 self.stopped = 0
|
|
395 def stop(self):
|
|
396 """The timeline will no longer continue in either direction, no
|
|
397 FunctionFrames will be activated."""
|
|
398 self.stopped = 1
|
|
399 self.last_clock_time = None
|
|
400 def reset(self):
|
|
401 """Resets the timeline to 0. Does not change the stoppedness of the
|
|
402 timeline."""
|
|
403 self.current_time = 0
|
|
404 def tick(self):
|
|
405 """Updates the current_time and runs any FunctionFrames that the cursor
|
|
406 passed over. This call is ignored if the timeline is stopped."""
|
|
407 if self.stopped:
|
|
408 return
|
|
409
|
|
410 last_time = self.current_time
|
|
411 last_clock = self.last_clock_time
|
|
412
|
|
413 # first, determine new time
|
|
414 clock_time = time()
|
|
415 if last_clock is None:
|
|
416 last_clock = clock_time
|
|
417 diff = clock_time - last_clock
|
|
418 new_time = (self.direction * self.rate * diff) + last_time
|
109
|
419 new_time = max(new_time, 0)
|
|
420 new_time = min(new_time, self.length())
|
0
|
421
|
|
422 # update the time
|
|
423 self.last_clock_time = clock_time
|
|
424 self.current_time = new_time
|
|
425
|
109
|
426 # now, find out if we missed any functions
|
|
427 if self.fn_track.has_events():
|
|
428 lower_time, higher_time = last_time, new_time
|
|
429 if lower_time > higher_time:
|
|
430 lower_time, higher_time = higher_time, lower_time
|
|
431
|
|
432 events_to_process = self.fn_track.get_range(lower_time,
|
|
433 higher_time, self.direction)
|
|
434
|
|
435 for event in events_to_process:
|
|
436 # they better be FunctionFrames
|
|
437 event.frame(self, event, None) # the None should be a Node,
|
|
438 # but that part is coming later
|
0
|
439 def reverse_direction(self):
|
|
440 """Reverses the direction of play for this node"""
|
|
441 self.direction = self.direction * -1
|
|
442 def set_direction(self, direction):
|
|
443 """Sets the direction of playback."""
|
|
444 self.direction = direction
|
|
445 def set_rate(self, new_rate):
|
|
446 """Sets the rate of playback"""
|
|
447 self.rate = new_rate
|
|
448 def set_time(self, new_time):
|
|
449 """Set the time to a new time."""
|
|
450 self.current_time = new_time
|
|
451 def get_levels(self):
|
|
452 """Return the current levels from this timeline. This is done by
|
|
453 adding all the non-functional tracks together."""
|
109
|
454 current_level_frame = LevelFrame('timeline sum', {})
|
|
455 for t in self.tracks:
|
|
456 current_level_frame += t.get_levels_at_time(self.current_time)
|
|
457
|
|
458 return current_level_frame.get_levels()
|
0
|
459
|
|
460 if __name__ == '__main__':
|
109
|
461 scene1 = LevelFrame('scene1', {'red' : 50, 'blue' : 25})
|
|
462 scene2 = LevelFrame('scene2', {'red' : 10, 'blue' : 5, 'green' : 70})
|
|
463 scene3 = LevelFrame('scene3', {'yellow' : 10, 'blue' : 80, 'purple' : 70})
|
0
|
464
|
109
|
465 T = TimedEvent
|
0
|
466
|
109
|
467 linear = LinearBlender()
|
0
|
468 quad = ExponentialBlender(2)
|
|
469 invquad = ExponentialBlender(0.5)
|
|
470 smoove = SmoothBlender()
|
|
471
|
109
|
472 track1 = TimelineTrack('lights',
|
|
473 T(0, scene1, blender=linear),
|
|
474 T(5, scene2, blender=quad),
|
|
475 T(10, scene3, blender=smoove),
|
|
476 T(15, scene2)) # last TimedEvent doesn't need a blender
|
0
|
477
|
109
|
478 if 1:
|
|
479 # bounce is semiworking
|
|
480 bouncer = BounceFunction('boing')
|
|
481 halver = HalfTimeFunction('1/2x')
|
|
482 doubler = DoubleTimeFunction('2x')
|
|
483 tl = Timeline([track1], [T(0, bouncer),
|
|
484 T(0, halver),
|
|
485 T(15, bouncer),
|
|
486 T(15, doubler)])
|
|
487 else:
|
|
488 looper = LoopFunction('loop1')
|
|
489 tl = Timeline([track1], [T(14, looper)])
|
0
|
490 tl.play()
|
|
491
|
|
492 import Tix
|
|
493 root = Tix.Tk()
|
|
494 colorscalesframe = Tix.Frame(root)
|
|
495 scalevars = {}
|
|
496 # wow, this works out so well, it's almost like I planned it!
|
|
497 # (actually, it's probably just Tk being as cool as it usually is)
|
|
498 # ps. if this code ever turns into mainstream code for flax, I'll be
|
|
499 # pissed (reason: we need to use classes, not this hacked crap!)
|
|
500 colors = 'red', 'blue', 'green', 'yellow', 'purple'
|
|
501 for color in colors:
|
|
502 sv = Tix.DoubleVar()
|
|
503 scalevars[color] = sv
|
109
|
504 scale = Tix.Scale(colorscalesframe, from_=100, to_=0, bg=color,
|
0
|
505 variable=sv)
|
|
506 scale.pack(side=Tix.LEFT)
|
|
507
|
|
508 def set_timeline_time(time):
|
|
509 tl.set_time(float(time))
|
|
510 # print 'set_timeline_time', time
|
|
511
|
|
512 def update_scales():
|
|
513 levels = tl.get_levels()
|
|
514 for color in colors:
|
|
515 scalevars[color].set(levels.get(color, 0))
|
|
516
|
|
517 colorscalesframe.pack()
|
109
|
518 time_scale = Tix.Scale(root, from_=0, to_=track1.length(),
|
0
|
519 orient=Tix.HORIZONTAL, res=0.01, command=set_timeline_time)
|
|
520 time_scale.pack(side=Tix.BOTTOM, fill=Tix.X, expand=1)
|
|
521
|
|
522 def play_tl():
|
|
523 tl.tick()
|
|
524 update_scales()
|
|
525 time_scale.set(tl.current_time)
|
|
526 # print 'time_scale.set', tl.current_time
|
|
527 root.after(10, play_tl)
|
|
528
|
|
529 controlwindow = Tix.Toplevel()
|
|
530 Tix.Button(controlwindow, text='Stop',
|
|
531 command=lambda: tl.stop()).pack(side=Tix.LEFT)
|
|
532 Tix.Button(controlwindow, text='Play',
|
|
533 command=lambda: tl.play()).pack(side=Tix.LEFT)
|
|
534 Tix.Button(controlwindow, text='Reset',
|
|
535 command=lambda: time_scale.set(0)).pack(side=Tix.LEFT)
|
|
536 Tix.Button(controlwindow, text='Flip directions',
|
|
537 command=lambda: tl.reverse_direction()).pack(side=Tix.LEFT)
|
|
538 Tix.Button(controlwindow, text='1/2x',
|
|
539 command=lambda: tl.set_rate(0.5 * tl.rate)).pack(side=Tix.LEFT)
|
|
540 Tix.Button(controlwindow, text='2x',
|
|
541 command=lambda: tl.set_rate(2 * tl.rate)).pack(side=Tix.LEFT)
|
|
542
|
|
543 root.after(100, play_tl)
|
|
544
|
|
545 # Timeline.set_time = trace(Timeline.set_time)
|
|
546
|
|
547 Tix.mainloop()
|