Mercurial > code > home > repos > light9
comparison flax/TheShow.py @ 0:45b12307c695
Initial revision
author | drewp |
---|---|
date | Wed, 03 Jul 2002 09:37:57 +0000 |
parents | |
children | 5670f66845ce |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:45b12307c695 |
---|---|
1 from Timeline import * | |
2 from Submaster import Submasters, sub_maxes | |
3 | |
4 class Show: | |
5 def __init__(self, timelines, submasters): | |
6 self.timelines = dict([(timeline.name, timeline) | |
7 for timeline in timelines]) | |
8 self.submasters = submasters | |
9 self.current_timeline = None | |
10 self.current_time = 0 | |
11 try: | |
12 self.current_timeline = timelines[0] | |
13 except ValueError: | |
14 pass | |
15 def calc_active_submaster(self): | |
16 "get levels from the current timeline at the current time" | |
17 if not (self.current_timeline or self.current_time): | |
18 return {} | |
19 tl = self.current_timeline | |
20 tl.set_time(self.current_time) | |
21 levels = tl.get_levels() | |
22 scaledsubs = [self.submasters.get_sub_by_name(sub) * level \ | |
23 for sub, level in levels.items()] | |
24 maxes = sub_maxes(*scaledsubs) | |
25 | |
26 return maxes | |
27 def set_timeline(self, name): | |
28 "select a timeline" | |
29 self.current_timeline = self.timelines.get(name) | |
30 self.set_time(0) | |
31 if not self.current_timeline: | |
32 print "Show: '%s' is not the same of a timeline." | |
33 def set_time(self, time): | |
34 "set time of current timeline" | |
35 self.current_time = time | |
36 self.current_timeline.set_time(time) | |
37 def get_timelines(self): | |
38 "Get names of all timelines" | |
39 return self.timelines.keys() | |
40 | |
41 # this is the default blender | |
42 linear = LinearBlender() | |
43 def T(time, level, **kw): | |
44 """This used to be a synonym for TimedEvent: | |
45 | |
46 T = TimedEvent | |
47 | |
48 It now acts in a similar way, except that it will fill in a default | |
49 blender if you don't. The default blender is a LinearBlender. It also | |
50 sets frame to MISSING so the track can fill it in.""" | |
51 if 'blender' not in kw: | |
52 global linear | |
53 kw['blender'] = linear | |
54 | |
55 return TimedEvent(time, level=level, frame=MISSING, **kw) | |
56 | |
57 quad = ExponentialBlender(2) | |
58 invquad = ExponentialBlender(0.5) | |
59 smoove = SmoothBlender() | |
60 | |
61 track1 = TimelineTrack('red track', | |
62 T(0, 0), | |
63 T(4, 0.5, blender=quad), | |
64 T(12, 0.7, blender=smoove), | |
65 T(15, level=0.0), default_frame='red') | |
66 track2 = TimelineTrack('green track', | |
67 T(0, 0.2, blender=invquad), | |
68 T(5, 1.0, blender=smoove), | |
69 T(10, 0.8), | |
70 T(15, 0.6), | |
71 T(20, 0.0), default_frame='green') | |
72 track3 = TimelineTrack('tableau demo', | |
73 T(0, 0.0), | |
74 T(2, 1.0, blender=InstantEnd()), | |
75 T(18, 1.0), | |
76 T(20, 0.0), default_frame='blue') | |
77 track4 = TimelineTrack('MJ fader', | |
78 T(0, 0.0), | |
79 T(5, 1.0), | |
80 T(10, 0.0), default_frame='red') | |
81 bump21 = TimelineTrack('bump at 21', | |
82 T(0, 0), | |
83 T(20.4, 0.05), | |
84 T(20.7, 1), | |
85 T(25, 0.4), | |
86 T(31, 0), | |
87 T(31.1, 1), | |
88 | |
89 default_frame='sill') | |
90 | |
91 # tl = Timeline('test', [track1, track2, track3, track4]) | |
92 tl = Timeline('test', [track4, bump21]) | |
93 | |
94 strobe1 = TimelineTrack('strobify', | |
95 T(0, 0, blender=Strobe(ontime=0.25, offtime=0.25)), | |
96 T(200, 1), default_frame='sill') | |
97 | |
98 strobe_tl = Timeline('strobe test', [strobe1]) | |
99 | |
100 show = Show([tl, strobe_tl], Submasters()) | |
101 | |
102 if __name__ == "__main__": | |
103 show.set_timeline('test') | |
104 show.set_time(4) | |
105 print show.get_levels().get_levels() | |
106 print | |
107 print show.get_levels() |