From 8aad9ae9b936cc3206056a162c28cf3c7c14629e Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Mon, 6 Nov 2023 23:09:06 -0800 Subject: [PATCH] Cues reader implementation --- wavinfo/wave_cues_reader.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/wavinfo/wave_cues_reader.py b/wavinfo/wave_cues_reader.py index 5283e0b..fd2a753 100644 --- a/wavinfo/wave_cues_reader.py +++ b/wavinfo/wave_cues_reader.py @@ -12,7 +12,7 @@ import encodings from .riff_parser import ChunkDescriptor from struct import unpack, calcsize -from typing import Optional, NamedTuple, List, Dict, Any +from typing import Optional, Tuple, NamedTuple, List, Dict, Any, Generator #: Country Codes used in the RIFF standard to resolve locale. These codes #: appear in CSET and LTXT metadata. @@ -212,6 +212,25 @@ class WavCuesReader: return WavCuesReader(cues=cue_list, labels=label_list, ranges=range_list, notes=note_list) + def each_cue(self) -> Generator[Tuple[int, int], None, None]: + """ + Iterate through each cue. + :yields: the cue's ``name`` and ``sample_offset`` + """ + for cue in self.cues: + yield (cue.name, cue.sample_offset) + + 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 + :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) + return (label, note) + 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], @@ -220,7 +239,3 @@ class WavCuesReader: - - - -