concertina_helper.note_generators
1from __future__ import annotations 2from collections.abc import Iterable 3 4from pyabc2 import Tune 5 6from .type_defs import Annotation, Pitch 7 8 9def notes_from_tune(tune: Tune) -> Iterable[Annotation]: 10 ''' 11 Given a pyabc2 `Tune`, 12 returns an iterable of the annotated pitches. 13 14 >>> tune = Tune(""" 15 ... X: 1 16 ... K: Cmaj 17 ... CEG|| 18 ... """) 19 >>> for note in notes_from_tune(tune): 20 ... print(note) 21 Annotation(pitch=Pitch(name='C4'), measure=1) 22 Annotation(pitch=Pitch(name='E4'), measure=1) 23 Annotation(pitch=Pitch(name='G4'), measure=1) 24 ''' 25 for i, measure in enumerate(tune.measures): 26 for note in measure: 27 yield Annotation( 28 measure=i + 1, 29 pitch=Pitch(note.to_pitch().name) 30 ) 31 32 33def notes_from_pitches(pitch_names: Iterable[str]) -> Iterable[Annotation]: 34 ''' 35 Given a sequence of scientific pitch names, 36 strips padding and returns an iterable of the annotated pitches. 37 38 >>> for note in notes_from_pitches(['C4', ' E4', 'G4 ']): 39 ... print(note) 40 Annotation(pitch=Pitch(name='C4'), measure=1) 41 Annotation(pitch=Pitch(name='E4'), measure=1) 42 Annotation(pitch=Pitch(name='G4'), measure=1) 43 ''' 44 for name in pitch_names: 45 yield Annotation( 46 measure=1, 47 pitch=Pitch(name.strip()) 48 )
def
notes_from_tune( tune: pyabc2.parse.Tune) -> collections.abc.Iterable[concertina_helper.type_defs.Annotation]:
10def notes_from_tune(tune: Tune) -> Iterable[Annotation]: 11 ''' 12 Given a pyabc2 `Tune`, 13 returns an iterable of the annotated pitches. 14 15 >>> tune = Tune(""" 16 ... X: 1 17 ... K: Cmaj 18 ... CEG|| 19 ... """) 20 >>> for note in notes_from_tune(tune): 21 ... print(note) 22 Annotation(pitch=Pitch(name='C4'), measure=1) 23 Annotation(pitch=Pitch(name='E4'), measure=1) 24 Annotation(pitch=Pitch(name='G4'), measure=1) 25 ''' 26 for i, measure in enumerate(tune.measures): 27 for note in measure: 28 yield Annotation( 29 measure=i + 1, 30 pitch=Pitch(note.to_pitch().name) 31 )
Given a pyabc2 Tune
,
returns an iterable of the annotated pitches.
>>> tune = Tune("""
... X: 1
... K: Cmaj
... CEG||
... """)
>>> for note in notes_from_tune(tune):
... print(note)
Annotation(pitch=Pitch(name='C4'), measure=1)
Annotation(pitch=Pitch(name='E4'), measure=1)
Annotation(pitch=Pitch(name='G4'), measure=1)
def
notes_from_pitches( pitch_names: collections.abc.Iterable[str]) -> collections.abc.Iterable[concertina_helper.type_defs.Annotation]:
34def notes_from_pitches(pitch_names: Iterable[str]) -> Iterable[Annotation]: 35 ''' 36 Given a sequence of scientific pitch names, 37 strips padding and returns an iterable of the annotated pitches. 38 39 >>> for note in notes_from_pitches(['C4', ' E4', 'G4 ']): 40 ... print(note) 41 Annotation(pitch=Pitch(name='C4'), measure=1) 42 Annotation(pitch=Pitch(name='E4'), measure=1) 43 Annotation(pitch=Pitch(name='G4'), measure=1) 44 ''' 45 for name in pitch_names: 46 yield Annotation( 47 measure=1, 48 pitch=Pitch(name.strip()) 49 )
Given a sequence of scientific pitch names, strips padding and returns an iterable of the annotated pitches.
>>> for note in notes_from_pitches(['C4', ' E4', 'G4 ']):
... print(note)
Annotation(pitch=Pitch(name='C4'), measure=1)
Annotation(pitch=Pitch(name='E4'), measure=1)
Annotation(pitch=Pitch(name='G4'), measure=1)