diff options
author | Ben Connors <benconnors@outlook.com> | 2022-11-30 18:11:08 -0500 |
---|---|---|
committer | Ben Connors <benconnors@outlook.com> | 2022-11-30 18:11:08 -0500 |
commit | 585716f212459e4192d6040bae5e2bfc93238e54 (patch) | |
tree | 1b3e63982ee2997176b2586836fd0491acd3f695 | |
parent | e857679ee6affccb25f9689ced4db2c7fc5cf521 (diff) |
- Assume missing audio files have length 1s
- Add check to interface to find missing audio files
-rw-r--r-- | blc2/functions/audio.py | 9 | ||||
-rw-r--r-- | interface/interface.py | 37 |
2 files changed, 45 insertions, 1 deletions
diff --git a/blc2/functions/audio.py b/blc2/functions/audio.py index 5881e18..cf0e27c 100644 --- a/blc2/functions/audio.py +++ b/blc2/functions/audio.py @@ -36,7 +36,13 @@ class Audio(Function): self._fade_in = fade_in if filename is not None: - self._actual_duration = self.w.get_audio_length(filename) + probed = self.w.get_audio_length(filename) + if probed == 0: + ## Missing audio file + ## FIXME: Throw an error here? + self._actual_duration = 1000 + else: + self._actual_duration = probed self._duration = max(0, self._actual_duration - self._fade_out) self._audio_scope = frozenset(((filename,),)) else: @@ -128,6 +134,7 @@ class Audio(Function): """Set the current audio filename, updating the duration.""" if value is not None: self._set_duration(self.w.get_audio_length(value), update=False) + print("UPDATED AUDIO LENGTH", self.duration) self._audio_scope = frozenset((value,)) else: self._set_duration(0, update=False) diff --git a/interface/interface.py b/interface/interface.py index 0586f16..d500344 100644 --- a/interface/interface.py +++ b/interface/interface.py @@ -1,6 +1,7 @@ import curses import os import datetime as dt +import itertools import threading import traceback as tb @@ -101,8 +102,40 @@ class Interface: if not self.output.ok: self.pager.display_many(("WARNING: Output is not OK!",), True) + self.verify_audio() + self.input.main(self._resize) + def verify_audio(self): + def gather_audio(func): + if func.type == AUDIO: + return (func,) + elif func.type in (CHASER, JOIN): + return tuple(itertools.chain(*(gather_audio(i) for i in func.steps))) + elif func.type == CHASERSTEP and func.function is not None: + return gather_audio(func.function) + + return () + + f = None + bad = [] + with self.w_lock: + funcs = set() + if f is None: + for func in self.w.functions.values(): + funcs.update(gather_audio(func)) + else: + funcs = gather_audio(f) + + for f in sorted(funcs, key=lambda i: i.id): + if not os.path.isfile(f.filename): + bad.append("- %3d \"%s\"" % (f.id, f.filename)) + + if bad: + self.pager.display_many(["MISSING AUDIO FILES:"] + bad) + else: + self.pager.display_many(("No missing audio files!",)) + def handle_show(self, f): with self.w_lock: if f is None or f.type == SCENE: @@ -798,6 +831,7 @@ class Interface: ("pager page", self.page), ("pager clear", self.page_clear), + ("verify audio", self.verify_audio), ("quit", self.base_quit), ), { None: "This is the base edit mode for editing functions.", @@ -863,6 +897,7 @@ class Interface: ("pager page", self.page), ("pager clear", self.page_clear), + ("verify audio", self.verify_audio), ("quit", self.handle_exit), ), { None: "This mode is for editing chasers. All functions (excepting select) which take a number as an argument may be called without to act on the currently selected step.", @@ -923,6 +958,7 @@ class Interface: ("pager page", self.page), ("pager clear", self.page_clear), + ("verify audio", self.verify_audio), ("quit", self.audio_exit), ), { None: "This mode is for editing audio primitives for single audio files.", @@ -980,6 +1016,7 @@ class Interface: ("pager page", self.page), ("pager clear", self.page_clear), + ("verify audio", self.verify_audio), ("quit", self.handle_exit), )) |