-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinternalAnimationsHandler.py
More file actions
126 lines (102 loc) · 5.33 KB
/
internalAnimationsHandler.py
File metadata and controls
126 lines (102 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import shows
import sys
from dataBaseInterface import DataBaseInterface
from audioInfo import AudioEvent, AudioFileInfo
from audio_event_queue import SortedDLL
import shows
NUM_AUDIO_CHANNELS = 7
class InternalAninamtionsHandler:
'a class for handling audio messages to drive internal audio animations'
def __init__(self):
self.event_queue = SortedDLL() # create sorted dll to act as the audio event queue (with super duper special powers)
self.current_internal_track_per_channel = [0] * NUM_AUDIO_CHANNELS
self.next_audio_event = AudioEvent(-1, -1, "init", "init")
self.doing_animations = False
def set_do_animations(self, do):
self.doing_animations = do
def interpret_audio_msg(self, audio_msg):
print "day index: " + str(shows.bm_day_index)
if shows.bm_day_index >= 0: # preventing queing the static audio events prior to bm start (while just playing static animations)
channel_map = self.get_audio_file_info(audio_msg)
for channel in channel_map.keys():
if self.current_internal_track_per_channel[channel] > 0: # channel already had a track on it
old_audio = self.current_internal_track_per_channel[channel]
self.remove_audio_events_from_queue(old_audio)
audioInfo = channel_map[channel]
self.current_internal_track_per_channel[channel] = audioInfo
self.queue_audio_events(audioInfo)
if audioInfo is not None and self.doing_animations:
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "setting main animation param due to new audio track's info " + str(audioInfo.file_index)
shows.set_appropriate_layer_main_animation(audioInfo)
shows.update_playa_palette(audioInfo.getAudioDay(), audioInfo.getNumericalCategory())
# RJS I don't like how this hard coded... if the audio contorl message changes this needs to as well.
def get_audio_file_info(self, audio_msg):
# current msg format: a0;1;0;0,50,0,0
# print 'grabbing audio info from ' + str(audio_msg)
try:
info = audio_msg.split(";")
tracks = info[3].split(",")
except:
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "audio msg format is wrong or has changed", sys.exc_value
return {}
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "tracks: " + str(tracks)
output = {}
i = 0
if tracks[i] is not "" and tracks[i] != '':
while(i < len(tracks)):
if int(tracks[i]) > 0:
output[i] = (DataBaseInterface().grabAudioInfo(tracks[i]))
i += 1
return output
def progress_audio_queue(self):
# ensure not looking at events that have already passed
while True:
try:
next_audio_event_node = self.event_queue.peek()
old_event = self.next_audio_event
self.next_audio_event = next_audio_event_node.value
if shows.INTERNAL_ANIMATIONS_DEBUG and str(old_event) != str(self.next_audio_event):
print "next audio event " + str(self.next_audio_event)
except ValueError:
#if INTERNAL_ANIMATIONS_DEBUG:
#print "event_queue is empty", sys.exc_value
break
stale = self.next_audio_event.exec_time <= shows.timeMs() - 1000
if stale:
if shows.DEBUG:
print "it's " + str(shows.timeMs()) + " stale event " + str(self.next_audio_event) + " removing"
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "new audio event queue size: " + str(self.event_queue.size)
self.event_queue.remove(self.next_audio_event)
else:
break
return self.next_audio_event
def remove_audio_events_from_queue(self, audioInfo):
for event in audioInfo.events:
try:
self.event_queue.remove(event)
except ValueError:
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "event " + str(event) + " already has been removed from queue"
except AttributeError:
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "error removing event from queue"
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "new event queue size after removal: " + str(self.event_queue.size)
def queue_audio_events(self, audioInfo):
cur_time_ms = shows.timeMs()
if audioInfo is not None:
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "queueing events for audioInfo: " + str(audioInfo.file_index)
for event in audioInfo.events:
# print "event: " + str(event)
event.exec_time = int(event.time) + cur_time_ms
# print "NEW e TIME = " + str(event.exec_time) + "\nCURNT TIME = " + str(cur_time_ms)
node = self.event_queue.add(event)
elif shows.INTERNAL_ANIMATIONS_DEBUG:
print "seems like it was a database miss... this will happen while we don't have all the auido files"
if shows.INTERNAL_ANIMATIONS_DEBUG:
print "new event queue size: " + str(self.event_queue.size)