def __call__(self): r'''Calls string quartet score template. Returns score. ''' # make first violin voice and staff first_violin_voice = scoretools.Voice(name='First Violin Voice') first_violin_staff = scoretools.Staff([first_violin_voice], name='First Violin Staff') clef = indicatortools.Clef('treble') attach(clef, first_violin_staff) violin = instrumenttools.Violin() attach(violin, first_violin_staff) # make second violin voice and staff second_violin_voice = scoretools.Voice(name='Second Violin Voice') second_violin_staff = scoretools.Staff([second_violin_voice], name='Second Violin Staff') clef = indicatortools.Clef('treble') attach(clef, second_violin_staff) violin = instrumenttools.Violin() attach(violin, second_violin_staff) # make viola voice and staff viola_voice = scoretools.Voice(name='Viola Voice') viola_staff = scoretools.Staff([viola_voice], name='Viola Staff') clef = indicatortools.Clef('alto') attach(clef, viola_staff) viola = instrumenttools.Viola() attach(viola, viola_staff) # make cello voice and staff cello_voice = scoretools.Voice(name='Cello Voice') cello_staff = scoretools.Staff([cello_voice], name='Cello Staff') clef = indicatortools.Clef('bass') attach(clef, cello_staff) cello = instrumenttools.Cello() attach(cello, cello_staff) # make string quartet staff group string_quartet_staff_group = scoretools.StaffGroup( [ first_violin_staff, second_violin_staff, viola_staff, cello_staff, ], name='String Quartet Staff Group', ) # make string quartet score string_quartet_score = scoretools.Score( [string_quartet_staff_group], name='String Quartet Score', ) # return string quartet score return string_quartet_score
def __illustrate__(self): r'''Illustrates pitch range. :: >>> show(pitch_range) # doctest: +SKIP Returns LilyPond file. ''' from abjad.tools import durationtools from abjad.tools import lilypondfiletools from abjad.tools import indicatortools from abjad.tools import markuptools from abjad.tools import pitchtools from abjad.tools import scoretools from abjad.tools import spannertools from abjad.tools.topleveltools import attach from abjad.tools.topleveltools import iterate from abjad.tools.topleveltools import override start_pitch_clef = pitchtools.suggest_clef_for_named_pitches( self.start_pitch) stop_pitch_clef = pitchtools.suggest_clef_for_named_pitches( self.stop_pitch) start_note = scoretools.Note(self.start_pitch, 1) stop_note = scoretools.Note(self.stop_pitch, 1) glissando = spannertools.Glissando() if start_pitch_clef == stop_pitch_clef: if start_pitch_clef == indicatortools.Clef('bass'): bass_staff = scoretools.Staff() attach(indicatortools.Clef('bass'), bass_staff) bass_staff.extend([start_note, stop_note]) attach(glissando, bass_staff.select_leaves()) score = scoretools.Score([bass_staff]) else: treble_staff = scoretools.Staff() attach(indicatortools.Clef('treble'), treble_staff) treble_staff.extend([start_note, stop_note]) attach(glissando, treble_staff.select_leaves()) score = scoretools.Score([treble_staff]) else: result = scoretools.make_empty_piano_score() score, treble_staff, bass_staff = result bass_staff.extend([start_note, stop_note]) treble_staff.extend(scoretools.Skip(1) * 2) attach(glissando, bass_staff.select_leaves()) attach(indicatortools.StaffChange(treble_staff), bass_staff[1]) for leaf in iterate(score).by_class(scoretools.Leaf): attach(durationtools.Multiplier(1, 4), leaf) override(score).bar_line.stencil = False override(score).span_bar.stencil = False override(score).glissando.thickness = 2 override(score).time_signature.stencil = False lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
def __call__(self): staves = [] for index in range(self.staff_count): number = index + 1 voice = scoretools.Voice(name='Voice {}'.format(number)) staff = scoretools.Staff([voice], name='Staff {}'.format(number)) clef = indicatortools.Clef('bass') attach(clef, staff) cello = instrumenttools.Cello( instrument_name='Cello {}'.format(number), short_instrument_name='Vc. {}'.format(number), ) attach(cello, staff) override(staff).stem.stemlet_length = 2 override(staff).beam.damping = '+inf.0' staves.append(staff) windungen_staff_group = scoretools.StaffGroup( staves, name='Windungen Staff Group', ) windungen_score = scoretools.Score( [windungen_staff_group], name='Windungen Score', ) return windungen_score
def make_empty_piano_score(): r'''Make empty piano score: :: >>> score, treble, bass = scoretools.make_empty_piano_score() .. doctest:: >>> print(format(score)) \new Score << \new PianoStaff << \context Staff = "treble" { \clef "treble" } \context Staff = "bass" { \clef "bass" } >> >> Returns score, treble staff, bass staff. ''' from abjad.tools import indicatortools from abjad.tools import scoretools # make treble staff treble_staff = scoretools.Staff([]) treble_staff.name = 'treble' clef = indicatortools.Clef('treble') attach(clef, treble_staff) # make bass staff bass_staff = scoretools.Staff([]) bass_staff.name = 'bass' clef = indicatortools.Clef('bass') attach(clef, bass_staff) # make piano staff and score staff_group = scoretools.StaffGroup([treble_staff, bass_staff]) staff_group.context_name = 'PianoStaff' score = scoretools.Score([]) score.append(staff_group) # return score, treble staff, bass staff return score, treble_staff, bass_staff
def __init__( self, clef='percussion', overrides=None, ): Spanner.__init__( self, overrides=overrides, ) clef = indicatortools.Clef(clef) self._clef = clef
def __call__(self): r'''Calls two-staff piano score template. Returns score. ''' # make RH voice and staff rh_voice = scoretools.Voice(name='RH Voice') rh_staff = scoretools.Staff( [rh_voice], name='RH Staff', ) clef = indicatortools.Clef('treble') attach(clef, rh_staff) # make LH voice and staff lh_voice = scoretools.Voice(name='LH Voice') lh_staff = scoretools.Staff( [lh_voice], name='LH Staff', ) clef = indicatortools.Clef('bass') attach(clef, lh_staff) # make piano staff staff_group = scoretools.StaffGroup( [rh_staff, lh_staff], context_name='PianoStaff', name='Piano Staff', ) piano = instrumenttools.Piano() attach(piano, staff_group) # make two-staf piano score two_staff_piano_score = scoretools.Score( [staff_group], name='Two-Staff Piano Score', ) # return two-staff piano score return two_staff_piano_score
def suggest_clef_for_named_pitches(pitches): '''Suggest clef for named `pitches`: :: >>> staff = Staff(scoretools.make_notes( ... list(range(-12, -6)), [(1, 4)])) >>> pitchtools.suggest_clef_for_named_pitches(staff) Clef(name='bass') Suggest clef based on minimal number of ledger lines. Returns clef. ''' from abjad.tools import indicatortools from abjad.tools import pitchtools pitches = pitchtools.list_named_pitches_in_expr(pitches) diatonic_pitch_numbers = [pitch.diatonic_pitch_number for pitch in pitches] max_diatonic_pitch_number = max(diatonic_pitch_numbers) min_diatonic_pitch_number = min(diatonic_pitch_numbers) lowest_treble_line_pitch = pitchtools.NamedPitch('e', 4) lowest_treble_line_diatonic_pitch_number = \ lowest_treble_line_pitch.diatonic_pitch_number candidate_steps_below_treble = \ lowest_treble_line_diatonic_pitch_number - min_diatonic_pitch_number highest_bass_line_pitch = pitchtools.NamedPitch('a', 3) highest_bass_line_diatonic_pitch_number = \ highest_bass_line_pitch.diatonic_pitch_number candidate_steps_above_bass = max_diatonic_pitch_number - highest_bass_line_diatonic_pitch_number if candidate_steps_above_bass < candidate_steps_below_treble: return indicatortools.Clef('bass') else: return indicatortools.Clef('treble')
def make_desordre_score(pitches): '''Makes Désordre score. ''' assert len(pitches) == 2 staff_group = scoretools.StaffGroup() staff_group.context_name = 'PianoStaff' # build the music for hand in pitches: staff = abjad.demos.desordre.make_desordre_staff(hand) staff_group.append(staff) # set clef and key signature to left hand staff clef = indicatortools.Clef('bass') attach(clef, staff_group[1]) key_signature = indicatortools.KeySignature('b', 'major') attach(key_signature, staff_group[1]) # wrap the piano staff in a score score = scoretools.Score([staff_group]) return score
def __illustrate__(self): r'''Illustrates pitch range inventory. :: >>> show(inventory) # doctest: +SKIP Returns LilyPond file. ''' from abjad.tools import durationtools from abjad.tools import lilypondfiletools from abjad.tools import indicatortools from abjad.tools import markuptools from abjad.tools import pitchtools from abjad.tools import scoretools from abjad.tools import spannertools from abjad.tools.topleveltools import attach from abjad.tools.topleveltools import iterate from abjad.tools.topleveltools import override start_note_clefs = [] stop_note_clefs = [] for pitch_range in self.items: start_note_clef = indicatortools.Clef.from_selection( pitch_range.start_pitch) start_note_clefs.append(start_note_clef) stop_note_clef = indicatortools.Clef.from_selection( pitch_range.stop_pitch) stop_note_clefs.append(stop_note_clef) if start_note_clefs == stop_note_clefs: clef = start_note_clefs[0] staff = scoretools.Staff() attach(clef, staff) score = scoretools.Score([staff]) for pitch_range in self.items: start_note = scoretools.Note(pitch_range.start_pitch, 1) stop_note = scoretools.Note(pitch_range.stop_pitch, 1) notes = [start_note, stop_note] glissando = spannertools.Glissando() staff.extend(notes) attach(glissando, notes) else: result = scoretools.make_empty_piano_score() score, treble_staff, bass_staff = result for pitch_range in self.items: start_note = scoretools.Note(pitch_range.start_pitch, 1) start_note_clef = indicatortools.Clef.from_selection( pitch_range.start_pitch) stop_note = scoretools.Note(pitch_range.stop_pitch, 1) stop_note_clef = indicatortools.Clef.from_selection( pitch_range.stop_pitch) notes = [start_note, stop_note] glissando = spannertools.Glissando() skips = 2 * scoretools.Skip(1) treble_clef = indicatortools.Clef('treble') bass_clef = indicatortools.Clef('bass') if start_note_clef == stop_note_clef == treble_clef: treble_staff.extend(notes) bass_staff.extend(skips) elif start_note_clef == stop_note_clef == bass_clef: bass_staff.extend(notes) treble_staff.extend(skips) else: assert start_note_clef == bass_clef assert stop_note_clef == treble_clef bass_staff.extend(notes) treble_staff.extend(skips) staff_change = indicatortools.StaffChange(treble_staff) attach(staff_change, stop_note) attach(glissando, notes) for leaf in iterate(score).by_class(scoretools.Leaf): multiplier = durationtools.Multiplier(1, 4) attach(multiplier, leaf) override(score).bar_line.stencil = False override(score).span_bar.stencil = False override(score).glissando.thickness = 2 override(score).time_signature.stencil = False lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.items.remove(lilypond_file['layout']) lilypond_file.items.remove(lilypond_file['paper']) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
def __call__(self): r'''Calls score template. .. container:: example **Example 1.** Call first template: :: >>> score_1 = template_1() :: >>> print(format(score_1)) \context Score = "Grouped Rhythmic Staves Score" << \context StaffGroup = "Grouped Rhythmic Staves Staff Group" << \context RhythmicStaff = "Staff 1" { \context Voice = "Voice 1" { } } \context RhythmicStaff = "Staff 2" { \context Voice = "Voice 2" { } } \context RhythmicStaff = "Staff 3" { \context Voice = "Voice 3" { } } \context RhythmicStaff = "Staff 4" { \context Voice = "Voice 4" { } } >> >> .. container:: example **Example 2.** Call second template: :: >>> score_2 = template_2() :: >>> print(format(score_2)) \context Score = "Grouped Rhythmic Staves Score" << \context StaffGroup = "Grouped Rhythmic Staves Staff Group" << \context RhythmicStaff = "Staff 1" << \context Voice = "Voice 1-1" { } \context Voice = "Voice 1-2" { } >> \context RhythmicStaff = "Staff 2" { \context Voice = "Voice 2" { } } \context RhythmicStaff = "Staff 3" << \context Voice = "Voice 3-1" { } \context Voice = "Voice 3-2" { } >> >> >> Returns score. ''' staves = [] if isinstance(self.staff_count, int): for index in range(self.staff_count): number = index + 1 name = 'Voice {}'.format(number) voice = scoretools.Voice(name=name) name = 'Staff {}'.format(number) staff = scoretools.Staff([voice], name=name) staff.context_name = 'RhythmicStaff' staves.append(staff) key = 'v{}'.format(number) self.context_name_abbreviations[key] = voice.name elif isinstance(self.staff_count, list): for staff_index, voice_count in enumerate(self.staff_count): staff_number = staff_index + 1 name = 'Staff {}'.format(staff_number) staff = scoretools.Staff(name=name) staff.context_name = 'RhythmicStaff' assert 1 <= voice_count for voice_index in range(voice_count): voice_number = voice_index + 1 if voice_count == 1: voice_identifier = str(staff_number) else: voice_identifier = '{}-{}'.format( staff_number, voice_number) staff.is_simultaneous = True name = 'Voice {}'.format(voice_identifier) voice = scoretools.Voice(name=name) staff.append(voice) key = 'v{}'.format(voice_identifier) self.context_name_abbreviations[key] = voice.name staves.append(staff) if self.with_clefs: for staff in staves: attach(indicatortools.Clef('percussion'), staff) grouped_rhythmic_staves_staff_group = scoretools.StaffGroup( staves, name='Grouped Rhythmic Staves Staff Group', ) grouped_rhythmic_staves_score = scoretools.Score( [grouped_rhythmic_staves_staff_group], name='Grouped Rhythmic Staves Score', ) return grouped_rhythmic_staves_score
def __call__(self): '''Calls score template. Returns LilyPond file. ''' # make bell voice and staff bell_voice = scoretools.Voice(name='Bell Voice') bell_staff = scoretools.Staff([bell_voice], name='Bell Staff') clef = indicatortools.Clef('treble') attach(clef, bell_staff) bells = instrumenttools.Instrument( instrument_name='Campana in La', short_instrument_name='Camp.', pitch_range='[C4, C6]', ) attach(bells, bell_staff) tempo = indicatortools.Tempo((1, 4), (112, 120)) attach(tempo, bell_staff) time_signature = indicatortools.TimeSignature((6, 4)) attach(time_signature, bell_staff) # make first violin voice and staff first_violin_voice = scoretools.Voice(name='First Violin Voice') first_violin_staff = scoretools.Staff( [first_violin_voice], name='First Violin Staff', ) clef = indicatortools.Clef('treble') attach(clef, first_violin_staff) violin = instrumenttools.Violin( instrument_name_markup=markuptools.Markup('Violin I'), short_instrument_name_markup=markuptools.Markup('Vl. I'), ) attach(violin, first_violin_staff) # make second violin voice and staff second_violin_voice = scoretools.Voice(name='Second Violin Voice') second_violin_staff = scoretools.Staff( [second_violin_voice], name='Second Violin Staff', ) clef = indicatortools.Clef('treble') attach(clef, second_violin_staff) violin = instrumenttools.Violin( instrument_name_markup=markuptools.Markup('Violin II'), short_instrument_name_markup=markuptools.Markup('Vl. II'), ) attach(violin, second_violin_staff) # make viola voice and staff viola_voice = scoretools.Voice(name='Viola Voice') viola_staff = scoretools.Staff([viola_voice], name='Viola Staff') clef = indicatortools.Clef('alto') attach(clef, viola_staff) viola = instrumenttools.Viola() attach(viola, viola_staff) # make cello voice and staff cello_voice = scoretools.Voice(name='Cello Voice') cello_staff = scoretools.Staff([cello_voice], name='Cello Staff') clef = indicatortools.Clef('bass') attach(clef, cello_staff) cello = instrumenttools.Cello() attach(cello, cello_staff) # make bass voice and staff bass_voice = scoretools.Voice(name='Bass Voice') bass_staff = scoretools.Staff([bass_voice], name='Bass Staff') clef = indicatortools.Clef('bass') attach(clef, bass_staff) contrabass = instrumenttools.Contrabass( short_instrument_name_markup=markuptools.Markup('Cb.'), ) attach(contrabass, bass_staff) # make strings staff group strings_staff_group = scoretools.StaffGroup( [ first_violin_staff, second_violin_staff, viola_staff, cello_staff, bass_staff, ], name='Strings Staff Group', ) # make score score = scoretools.Score([ bell_staff, strings_staff_group, ], name='Pärt Cantus Score') # return Pärt Cantus score return score
def _make_performer_staff_group( self, clef_name=None, instrument=None, number=None, ): if number is not None: name = '{} {}'.format( instrument.instrument_name.title(), number, ) else: name = instrument.instrument_name.title() pitch_range = instrument.pitch_range staff_group = scoretools.StaffGroup( context_name='StringPerformerStaffGroup', name='{} Staff Group'.format(name), ) tag_name = name.replace(' ', '') tag_string = "tag #'{}".format(tag_name) tag_command = indicatortools.LilyPondCommand( tag_string, 'before', ) attach(tag_command, staff_group) if self.split_hands: lh_voice = scoretools.Voice( context_name='FingeringVoice', name='{} Fingering Voice'.format(name), ) abbreviation = lh_voice.name.lower().replace(' ', '_') self.voice_name_abbreviations[abbreviation] = lh_voice.name lh_staff = scoretools.Staff( [lh_voice], context_name='FingeringStaff', name='{} Fingering Staff'.format(name), ) lh_staff.is_simultaneous = True attach(pitch_range, lh_staff) attach(indicatortools.Clef(clef_name), lh_staff) rh_voice = scoretools.Voice( context_name='BowingVoice', name='{} Bowing Voice'.format(name), ) abbreviation = rh_voice.name.lower().replace(' ', '_') self.voice_name_abbreviations[abbreviation] = rh_voice.name rh_staff = scoretools.Staff( [rh_voice], context_name='BowingStaff', name='{} Bowing Staff'.format(name), ) rh_staff.is_simultaneous = True staff_group.extend([rh_staff, lh_staff]) else: lh_voice = scoretools.Voice( context_name='FingeringVoice', name='{} Voice'.format(name), ) lh_staff = scoretools.Staff( [lh_voice], context_name='FingeringStaff', name='{} Staff'.format(name), ) lh_staff.is_simultaneous = True attach(pitch_range, lh_staff) attach(indicatortools.Clef(clef_name), lh_staff) staff_group.append(lh_staff) return staff_group, tag_name
def clef(self, string): r'''Handles LilyPond ``\clef`` command. ''' return indicatortools.Clef(string)
def notes_and_chords_are_on_expected_clefs( expr, percussion_clef_is_allowed=True, ): r'''Is true when notes and chords in `expr` are on expected clefs. :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> clef = Clef(name='treble') >>> attach(clef, staff) >>> violin = instrumenttools.Violin() >>> attach(violin, staff) :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs(staff) True Otherwise false: :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> clef = Clef(name='alto') >>> attach(clef, staff) >>> violin = instrumenttools.Violin() >>> attach(violin, staff) :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs(staff) False Allows percussion clef when `percussion_clef_is_allowed` is true: :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> clef = Clef(name='percussion') >>> attach(clef, staff) >>> violin = instrumenttools.Violin() >>> attach(violin, staff) .. doctest:: >>> print(format(staff)) \new Staff { \clef "percussion" \set Staff.instrumentName = \markup { Violin } \set Staff.shortInstrumentName = \markup { Vn. } c'8 d'8 e'8 f'8 } :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs( ... staff, percussion_clef_is_allowed=True) True Disallows percussion clef when `percussion_clef_is_allowed` is false: :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs( ... staff, percussion_clef_is_allowed=False) False Returns boolean. ''' from abjad.tools import instrumenttools for note_or_chord in iterate(expr).by_class( (scoretools.Note, scoretools.Chord)): instrument = note_or_chord._get_effective( instrumenttools.Instrument) if not instrument: return False clef = note_or_chord._get_effective(indicatortools.Clef) if not clef: return False if clef == indicatortools.Clef(name='percussion'): if percussion_clef_is_allowed: return True else: return False if clef not in instrument.allowable_clefs: return False else: return True
def notes_and_chords_are_on_expected_clefs( expr, percussion_clef_is_allowed=True, ): r'''Is true when notes and chords in `expr` are on expected clefs. .. todo:: Move to WellformednessManager. .. container:: example **Example 1.** Expected clef: :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> clef = Clef(name='treble') >>> attach(clef, staff) >>> violin = instrumenttools.Violin() >>> attach(violin, staff) >>> show(staff) # doctest: +SKIP :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs(staff) True .. container:: example **Example 2.** Unexpected clef: :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> clef = Clef(name='alto') >>> attach(clef, staff) >>> violin = instrumenttools.Violin() >>> attach(violin, staff) >>> show(staff) # doctest: +SKIP :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs(staff) False .. container:: example **Example 3.** Allows percussion clef: :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> clef = Clef(name='percussion') >>> attach(clef, staff) >>> violin = instrumenttools.Violin() >>> attach(violin, staff) >>> show(staff) # doctest: +SKIP .. doctest:: >>> print(format(staff)) \new Staff { \clef "percussion" \set Staff.instrumentName = \markup { Violin } \set Staff.shortInstrumentName = \markup { Vn. } c'8 d'8 e'8 f'8 } :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs( ... staff, percussion_clef_is_allowed=True) True .. container:: example **Example 4.** Forbids percussion clef: :: >>> instrumenttools.notes_and_chords_are_on_expected_clefs( ... staff, percussion_clef_is_allowed=False) False Returns true or false. ''' from abjad.tools import instrumenttools prototype = (scoretools.Note, scoretools.Chord) for note_or_chord in iterate(expr).by_class(prototype): instrument = note_or_chord._get_effective(instrumenttools.Instrument) if not instrument: return False clef = note_or_chord._get_effective(indicatortools.Clef) if not clef: return False if clef == indicatortools.Clef(name='percussion'): if percussion_clef_is_allowed: return True else: return False if clef not in instrument.allowable_clefs: return False else: return True