summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Connors <benconnors@outlook.com>2019-12-01 22:09:48 -0500
committerBen Connors <benconnors@outlook.com>2019-12-01 22:09:48 -0500
commit827f7f135bd49313de3e64f6804e57760d983eb8 (patch)
tree5435f7004724afa6129283689e71b6d57cdb6433
parent5dc21ef69f6d72bdfb796a7a75dcd185d4cb997f (diff)
Add audio fades in renderer; render bugfix
- Now audio fades work - Can't advance past end of chaser
-rw-r--r--interface/render.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/interface/render.py b/interface/render.py
index a15b473..4507c33 100644
--- a/interface/render.py
+++ b/interface/render.py
@@ -5,6 +5,7 @@ import mpv
from blc2.workspace import Workspace
from blc2.topology import Fixture
+from blc2.constants import ONESHOT
class Renderer:
def hold(self, values):
@@ -61,7 +62,7 @@ class Renderer:
sleep = 1/60
next_ap = []
- ap = []
+ ap = {}
running_ap = set()
t = 0
start = time.monotonic()
@@ -90,22 +91,34 @@ class Renderer:
if _last[c] < v:
_last[c] = v
- for guid, filename, *_ in ac:
+ for guid, filename, start_t, fin, fstart, fout in ac:
if guid in running_ap:
- continue
- running_ap.add(guid)
- nap = mpv.MPV()
- nap.pause = True
- nap.play(filename)
- next_ap.append(nap)
- ap.append(nap)
+ mul = 100
+ if t < fin:
+ mul = max(0, int(100*(t/fin)))
+ elif t > fstart+fout:
+ mul = -1
+ elif t > fstart:
+ mul = max(0, int(100*(1 - (t-fstart)/fout)))
+
+ if mul == -1:
+ ap[guid].pause = True
+ else:
+ ap[guid].volume = mul
+ else:
+ running_ap.add(guid)
+ nap = mpv.MPV()
+ nap.pause = True
+ nap.play(filename)
+ next_ap.append(nap)
+ ap[guid] = nap
self._last = _last
self._update()
if not self._running:
## We're done, clean up
- for a in ap:
+ for a in ap.values():
a.pause = True
del a
self._last = {c: 0 for c in self._channels}
@@ -130,7 +143,15 @@ class Renderer:
a, p = a
f = self._functions[a]
t = int(1000*self._current)
- d = f.advance(t, self._data[a], n=p)
+ if f.advance_mode == ONESHOT and self._data[a].steps and self._data[a].steps[-1].index+1 == len(f.steps):
+ continue
+ try:
+ d2 = f.advance(t, self._data[a], n=p)
+ except ValueError:
+ ## Done
+ pass
+ else:
+ d = d2
_, _, self._data[a] = f.render(t, d)
def __init__(self, w: Workspace, w_lock: threading.RLock, output, callback=None):