forked from natelewis/pi-led-matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffect_playlist.py
51 lines (46 loc) · 1.45 KB
/
effect_playlist.py
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
import os
import time
import random
import inspect
import importlib
import multiprocessing
from src.led_matrix import Matrix, pixel_height, pixel_width, playlist_delay, playlist
def import_effect(name):
effect_dir = os.path.realpath(
os.path.abspath(
os.path.join(
os.path.split(inspect.getfile(inspect.currentframe()))[0],
'effects/' + name
)
)
)
return importlib.import_module('effects.' + name +'.effect'), effect_dir
# preload all the effects
effects = []
for e_data in playlist:
effect_module, e_dir = import_effect(e_data['effect'])
effects.append({
'name': e_data['effect'],
'argv': e_data['argv'],
'module': effect_module,
'dir': e_dir,
})
def run_effect(index):
effect_obj = effects[index]
print("Starting " + effect_obj['name'])
# import effect # pylint: disable=import-outside-toplevel
matrix = Matrix()
effect_obj['module'].run(matrix, {
'pixel_height': pixel_height,
'pixel_width': pixel_width,
'effect_dir': effect_obj['dir'],
'argv': effect_obj['argv'],
})
if __name__ == '__main__':
print("Starting playlist: CTRL-c to stop")
multiprocessing.set_start_method('spawn')
while True:
effect_index = random.randrange(len(effects))
p = multiprocessing.Process(target=run_effect, name="run_effect", args=(effect_index,))
p.start()
p.join()