From f1ce4888af99705b52797f003f231dfbb472736d Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Tue, 7 Nov 2023 08:36:53 -0800 Subject: [PATCH] Get timed ranges --- tests/test_cue.py | 8 ++++++++ wavinfo/wave_cues_reader.py | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/test_cue.py b/tests/test_cue.py index 54cbd06..4271769 100644 --- a/tests/test_cue.py +++ b/tests/test_cue.py @@ -28,6 +28,14 @@ class TestCue(TestCase): self.assertEqual("Marker 1", label) self.assertIsNone(note) + def test_range(self): + file = "tests/test_files/cue_chunks/izotoperx_cues_test.wav" + w1 = wavinfo.WavInfoReader(file) + self.assertIsNotNone(w1.cues) + assert w1.cues is not None + + self.assertEqual(w1.cues.range(3), 10000) + def test_encoding_fallback(self): """ Added this after I noticed that iZotope RX seems to just encode "notes" diff --git a/wavinfo/wave_cues_reader.py b/wavinfo/wave_cues_reader.py index 08a9476..7d578c0 100644 --- a/wavinfo/wave_cues_reader.py +++ b/wavinfo/wave_cues_reader.py @@ -221,18 +221,31 @@ class WavCuesReader: for cue in self.cues: yield (cue.name, cue.sample_offset) - def label_and_note(self, cue_ident: int) -> Tuple[Optional[str], Optional[str]]: + def label_and_note(self, cue_ident: int) -> Tuple[Optional[str], + Optional[str]]: """ Get the label and note (extended comment) for a cue. - :param cue_ident: the cue's name, it's unique identifying number + :param cue_ident: the cue's name, its unique identifying number :returns: a tuple of the the cue's label (if present) and note (if present) """ - label = next((l.text for l in self.labels if l.name == cue_ident), None) - note = next((n.text for n in self.notes if n.name == cue_ident), None) + label = next((l.text for l in self.labels + if l.name == cue_ident), None) + note = next((n.text for n in self.notes + if n.name == cue_ident), None) return (label, note) + def range(self, cue_ident: int) -> Optional[int]: + """ + Get the length of the time range for a cue, if it has one. + + :param cue_ident: the cue's name, its unique identifying number + :returns: the length of the marker's range, or `None` + """ + return next((r.length for r in self.ranges + if r.name == cue_ident), None) + def to_dict(self) -> Dict[str, Any]: return dict(cues=[c.__dict__ for c in self.cues], labels=[l.__dict__ for l in self.labels],