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_instrument_staff_group( self, clef_name=None, count=None, instrument=None, ): instrument_name = instrument.instrument_name.title() instrument_staff_group = scoretools.StaffGroup( context_name='{}StaffGroup'.format(instrument_name), name='{} Staff Group'.format(instrument_name), ) tag_names = [] if count == 1: performer_staff_group, tag_name = \ self._make_performer_staff_group( clef_name=clef_name, instrument=instrument, number=None, ) instrument_staff_group.append(performer_staff_group) tag_names.append(tag_name) else: for i in range(1, count + 1): performer_staff_group, tag_name = \ self._make_performer_staff_group( clef_name=clef_name, instrument=instrument, number=i, ) instrument_staff_group.append(performer_staff_group) tag_names.append(tag_name) return instrument_staff_group, tag_names
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 __call__(self): '''Calls score template. :: >>> score = template() :: >>> print(format(score)) \context Score = "Grouped Staves Score" << \context StaffGroup = "Grouped Staves Staff Group" << \context Staff = "Staff 1" { \context Voice = "Voice 1" { } } \context Staff = "Staff 2" { \context Voice = "Voice 2" { } } \context Staff = "Staff 3" { \context Voice = "Voice 3" { } } \context Staff = "Staff 4" { \context Voice = "Voice 4" { } } >> >> Returns score. ''' 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)) staves.append(staff) self.context_name_abbreviations['v{}'.format(number)] = voice.name grouped_rhythmic_staves_staff_group = scoretools.StaffGroup( staves, name='Grouped Staves Staff Group', ) grouped_rhythmic_staves_score = scoretools.Score( [grouped_rhythmic_staves_staff_group], name='Grouped Staves Score', ) return grouped_rhythmic_staves_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 __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 save_composition(name: str, agent_name: str, composition: CompositionEnvironment, out_dir: str): score = Score() staff_group = scoretools.StaffGroup([], context_name='StaffGroup') for voice in composition.voices + composition.given_voices: staff = Staff([voice]) if voice.name == "cantus": attach(Clef("alto"), staff) attach(composition.composition_parameters.scale.key_signature, staff) staff_group.append(staff) tempo = Tempo(Duration(4, 4), 60) attach(tempo, staff_group[0]) score.append(staff_group) score.add_final_bar_line() lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.header_block.composer = markuptools.Markup(agent_name) lilypond_file.header_block.title = markuptools.Markup(name) lilypond_file.header_block.tagline = markuptools.Markup() midi_block = lilypondfiletools.Block(name="midi") context_block = lilypondfiletools.Block(name="context") channel_mapping = lilypondfiletools.Block(name="score") # channel_mapping.midiChannelMapping = "instrument" # context_block.items.append(channel_mapping) # midi_block.items.append(context_block) lilypond_file.score_block.items.append(midi_block) layout_block = lilypondfiletools.Block(name="layout") lilypond_file.score_block.items.append(layout_block) filename = name + ".ly" if not os.path.exists(out_dir): os.makedirs(out_dir) out_path = os.path.join(out_dir, filename) with open(out_path, mode="w") as f: f.write(format(lilypond_file))
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 __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 __call__(self): r'''Calls string orchestra template. Returns score. ''' ### TAGS ### tag_names = [] ### SCORE ### staff_group = scoretools.StaffGroup(name='Outer Staff Group', ) score = scoretools.Score( [staff_group], name='Score', ) ### VIOLINS ### if self.violin_count: clef_name = 'treble' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Violin() instrument_count = self.violin_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### VIOLAS ### if self.viola_count: clef_name = 'alto' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Viola() instrument_count = self.viola_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### CELLOS ### if self.cello_count: clef_name = 'bass' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Cello() instrument_count = self.cello_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### BASSES ### if self.contrabass_count: clef_name = 'bass_8' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Contrabass() instrument_count = self.contrabass_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### TIME SIGNATURE CONTEXT ### time_signature_context = scoretools.Context( name='TimeSignatureContext', context_name='TimeSignatureContext', ) instrument_tags = ' '.join(tag_names) tag_string = "tag #'({})".format(instrument_tags) tag_command = indicatortools.LilyPondCommand(tag_string, 'before') attach(tag_command, time_signature_context) score.insert(0, time_signature_context) 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 to_score(self): r'''Makes score from pitch arrays in inventory. :: >>> array_1 = pitchtools.PitchArray([ ... [1, (2, 1), ([-2, -1.5], 2)], ... [(7, 2), (6, 1), 1]]) :: >>> array_2 = pitchtools.PitchArray([ ... [1, 1, 1], ... [1, 1, 1]]) :: >>> arrays = [array_1, array_2] >>> inventory = pitchtools.PitchArrayInventory(arrays) :: >>> score = inventory.to_score() .. doctest:: >>> print(format(score)) \new Score << \new StaffGroup << \new Staff { { \time 4/8 r8 d'8 <bf bqf>4 } { \time 3/8 r8 r8 r8 } } \new Staff { { \time 4/8 g'4 fs'8 r8 } { \time 3/8 r8 r8 r8 } } >> >> :: >>> show(score) # doctest: +SKIP Create one staff per pitch-array row. Returns score. ''' from abjad.tools import scoretools score = scoretools.Score([]) staff_group = scoretools.StaffGroup([]) score.append(staff_group) number_staves = self[0].depth staves = scoretools.Staff([]) * number_staves staff_group.extend(staves) for pitch_array in self: measures = pitch_array.to_measures() for staff, measure in zip(staves, measures): staff.append(measure) return score
def __call__(self): pitch_pipes = instrumenttools.Percussion( instrument_name='pitch pipes', instrument_name_markup=markuptools.Markup.right_column( ['Pitch', 'Pipes'], direction=None, ), short_instrument_name='pp.', ) time_signature_context = scoretools.Context( context_name='TimeSignatureContext', name='Time Signature Context', ) self._attach_tag('time', time_signature_context) flute_staff = self._make_staff( 'Flute', 'treble', instrument=instrumenttools.Flute(), tag='flute', ) oboe_staff = self._make_staff( 'Oboe', 'treble', instrument=instrumenttools.Oboe(), tag='oboe', ) clarinet_staff = self._make_staff( 'Clarinet', 'treble', instrument=instrumenttools.BassClarinet( instrument_name_markup=markuptools.Markup.right_column( ['Bass', 'Clarinet'], direction=None, ), ), tag='clarinet', ) saxophone_staff = self._make_staff( 'Saxophone', 'treble', instrument=instrumenttools.BaritoneSaxophone( instrument_name_markup=markuptools.Markup.right_column( ['Baritone', 'Saxophone'], direction=None, ), ), tag='saxophone', ) wind_section_staff_group = scoretools.StaffGroup( [ flute_staff, oboe_staff, clarinet_staff, saxophone_staff, ], context_name='WindSectionStaffGroup', name='Wind Section Staff Group', ) guitar_staff = self._make_staff( 'Guitar', 'treble_8', instrument=instrumenttools.Guitar(), ) guitar_aux_staff = self._make_staff( 'Guitar Pitch Pipe', 'percussion', abbreviation='guitar_pp', context_name='Pitch Pipes', instrument=pitch_pipes, ) guitar_staff_group = scoretools.StaffGroup( [guitar_aux_staff, guitar_staff], name='Guitar Staff Group', context_name='GuitarStaffGroup', ) self._attach_tag('guitar', guitar_staff_group) piano_aux_staff = self._make_staff( 'Piano Pitch Pipe', 'percussion', abbreviation='piano_pp', context_name='Pitch Pipes', instrument=pitch_pipes, ) piano_rh_staff = self._make_staff( 'Piano Upper', 'treble', abbreviation='piano_rh', ) piano_lh_staff = self._make_staff( 'Piano Lower', 'bass', abbreviation='piano_lh', ) piano_pedals = self._make_voice( 'Piano Pedals', context_name='Dynamics', ) piano_staff = scoretools.StaffGroup( [piano_rh_staff, piano_lh_staff, piano_pedals], context_name='PianoStaff', name='Piano Staff', ) attach(instrumenttools.Piano(), piano_staff) piano_staff_group = scoretools.StaffGroup( [piano_aux_staff, piano_staff], context_name='PianoStaffGroup', name='Piano Staff Group', ) self._attach_tag('piano', piano_staff_group) percussion_staff = self._make_staff( 'Percussion', 'percussion', instrument=instrumenttools.Percussion(), ) percussion_aux_staff = self._make_staff( 'Percussion Pitch Pipe', 'percussion', abbreviation='percussion_pp', context_name='Pitch Pipes', instrument=pitch_pipes, ) percussion_staff_group = scoretools.StaffGroup( [percussion_aux_staff, percussion_staff], name='Percussion Staff Group', context_name='PercussionStaffGroup', ) self._attach_tag('percussion', percussion_staff_group) percussion_section_staff_group = scoretools.StaffGroup( [ guitar_staff_group, piano_staff_group, percussion_staff_group, ], context_name='PercussionSectionStaffGroup', name='Percussion Section Staff Group', ) violin_staff = self._make_staff( 'Violin', 'treble', instrument=instrumenttools.Violin(), tag='violin', ) viola_staff = self._make_staff( 'Viola', 'alto', instrument=instrumenttools.Viola(), tag='viola', ) cello_staff = self._make_staff( 'Cello', 'bass', instrument=instrumenttools.Cello(), tag='cello', ) contrabass_aux_staff = self._make_staff( 'Contrabass Pitch Pipe', 'percussion', abbreviation='bass_pp', context_name='Pitch Pipes', instrument=pitch_pipes, ) contrabass_staff = self._make_staff( 'Contrabass', 'bass_8', abbreviation='bass', instrument=instrumenttools.Contrabass(pitch_range='[E1, G4]', ), ) contrabass_staff_group = scoretools.StaffGroup( [contrabass_aux_staff, contrabass_staff], name='Contrabass Staff Group', context_name='ContrabassStaffGroup', ) self._attach_tag('contrabass', contrabass_staff_group) string_section_staff_group = scoretools.StaffGroup( [ violin_staff, viola_staff, cello_staff, contrabass_staff_group, ], context_name='StringSectionStaffGroup', name='String Section Staff Group', ) score = scoretools.Score( [ time_signature_context, wind_section_staff_group, percussion_section_staff_group, string_section_staff_group, ], name='Ersilia Score', ) return score