def test_double_barlines_before_time_signatures_05(): staff = abjad.Staff(r"R1 " r"\time 3/4 c'2. " r"\time 4/4 d'1 " r"e'1 " r"\time 6/4 f'2. g'2. " r"\time 2/4 a'2") abjad.attach(abjad.BarLine('.|:'), staff[0]) abjad.attach(abjad.BarLine(':|.'), staff[1]) abjad.attach(abjad.BarLine('|'), staff[3]) abjad.attach(abjad.BarLine('!'), staff[5]) auxjad.mutate(staff[:]).double_barlines_before_time_signatures() assert format(staff) == abjad.String.normalize(r""" \new Staff { R1 \bar ".|:" \time 3/4 c'2. \bar ":|." \time 4/4 d'1 e'1 \bar "||" \time 6/4 f'2. g'2. \bar "!" \time 2/4 a'2 } """)
def apply_final_bar_lines(score): """ Applies final bar lines to score. """ last_leaf = abjad.inspect(score).leaf(-1) bar_line = abjad.BarLine("|.") abjad.attach(bar_line, last_leaf)
def add_final_bar_line( self, abbreviation='|.', to_each_voice=False, ): r""" Add final bar line to end of score. >>> staff = abjad.Staff("c'4 d'4 e'4 f'4") >>> score = abjad.Score([staff]) >>> abjad.show(score) # doctest: +SKIP .. docs:: >>> abjad.f(score) \new Score << \new Staff { c'4 d'4 e'4 f'4 } >> >>> bar_line = score.add_final_bar_line() >>> abjad.show(score) # doctest: +SKIP .. docs:: >>> abjad.f(score) \new Score << \new Staff { c'4 d'4 e'4 f'4 \bar "|." %! SCORE_1 } >> Set ``to_each_voice`` to true to make part extraction easier. Returns bar line. """ import abjad bar_line = abjad.BarLine(abbreviation) if not to_each_voice: last_leaf = abjad.inspect(self).leaf(-1) abjad.attach(bar_line, last_leaf, tag='SCORE_1') else: for voice in abjad.iterate(self).components(abjad.Voice): last_leaf = abjad.inspect(voice).leaf(-1) abjad.attach(bar_line, last_leaf, tag='SCORE_1') return bar_line
def apply_final_bar_lines(score): """ Applies final bar lines to score. """ for voice in abjad.iterate(score).components(abjad.Voice): bar_line = abjad.BarLine('|.') leaf = abjad.inspect(voice).leaf(-1) abjad.attach(bar_line, leaf)
def make_mozart_score(): """ Makes Mozart score. """ score_template = abjad.TwoStaffPianoScoreTemplate() score = score_template() # select the measures to use choices = abjad.demos.mozart.choose_mozart_measures() # create and populate the volta containers treble_volta = abjad.Container() bass_volta = abjad.Container() for choice in choices[:7]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) treble_volta.append(treble) bass_volta.append(bass) # abjad.attach indicators to the volta containers command = abjad.LilyPondLiteral(r"\repeat volta 2", "before") abjad.attach(command, treble_volta) command = abjad.LilyPondLiteral(r"\repeat volta 2", "before") abjad.attach(command, bass_volta) # append the volta containers to our staves score["RH_Voice"].append(treble_volta) score["LH_Voice"].append(bass_volta) # create and populate the alternative ending containers treble_alternative = abjad.Container() bass_alternative = abjad.Container() for choice in choices[7:9]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) treble_alternative.append(treble) bass_alternative.append(bass) # abjad.attach indicators to the alternative containers command = abjad.LilyPondLiteral(r"\alternative", "before") abjad.attach(command, treble_alternative) command = abjad.LilyPondLiteral(r"\alternative", "before") abjad.attach(command, bass_alternative) # append the alternative containers to our staves score["RH_Voice"].append(treble_alternative) score["LH_Voice"].append(bass_alternative) # create the remaining measures for choice in choices[9:]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) score["RH_Voice"].append(treble) score["LH_Voice"].append(bass) # abjad.attach indicators time_signature = abjad.TimeSignature((3, 8)) leaf = abjad.inspect(score["RH_Staff"]).leaf(0) abjad.attach(time_signature, leaf) bar_line = abjad.BarLine("|.") leaf = abjad.inspect(score["RH_Staff"]).leaf(-1) abjad.attach(bar_line, leaf) # remove the default piano instrument and add a custom one: abjad.detach(abjad.Instrument, score["Piano_Staff"]) klavier = abjad.Piano(name="Katzenklavier", short_name="kk.") leaf = abjad.inspect(score["Piano_Staff"]).leaf(0) abjad.attach(klavier, leaf) return score
def _attach_double_barlines(staff, double_barlines_positions: tuple) -> None: for bar, has_double_bar_line in zip(staff, double_barlines_positions): if has_double_bar_line: try: abjad.attach( abjad.BarLine(".", format_slot="absolute_before"), bar[0]) # don't attach if there is already another bar line (perhaps from repeats) except abjad.PersistentIndicatorError: pass
def test_Score_add_double_bar_lines_before_time_signatures_08(): staff = abjad.Staff(r"R1 " r"\time 3/4 c'2. " r"\time 4/4 d'1 " r"e'1 " r"\time 6/4 f'2. g'2. " r"\time 2/4 a'2") abjad.attach(abjad.BarLine('.|:'), staff[0]) abjad.attach(abjad.BarLine(':|.'), staff[1]) abjad.attach(abjad.BarLine('|'), staff[3]) abjad.attach(abjad.BarLine('!'), staff[5]) score = auxjad.Score([staff]) score.add_double_bar_lines_before_time_signatures() assert abjad.lilypond(score) == abjad.String.normalize(r""" \new Score << \new Staff { R1 \bar ".|:" \time 3/4 c'2. \bar ":|." \time 4/4 d'1 e'1 \bar "||" \time 6/4 f'2. g'2. \bar "!" \time 2/4 a'2 } >> """)
def _double_bar_line_adder(container: abjad.Container) -> None: r"""Goes through a container and adds double bar lines before each and every time signature change.""" leaves = abjad.select(container).leaves() for i, leaf in enumerate(leaves[1:], 1): time_signature = abjad.get.indicator(leaf, abjad.TimeSignature) if time_signature is not None: bar_line = abjad.get.indicator(leaves[i - 1], abjad.BarLine) if bar_line is not None and bar_line.abbreviation in ('|', ''): abjad.detach(abjad.BarLine, leaves[i - 1]) bar_line = None if bar_line is None: abjad.attach(abjad.BarLine("||"), leaves[i - 1], context='Voice', )
def _prepare_voice(voice: abjad.Voice, instrument_id: str): # Preparation that applies to all voices first_leaf = abjad.get.leaf(voice, 0) abjad.attach( abjad.LilyPondLiteral( "\\set Staff.instrumentName = \\markup { \\teeny {" + instruments. INSTRUMENT_ID_TO_LONG_INSTRUMENT_NAME[instrument_id] + " } }"), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\set Staff.shortInstrumentName = \\markup { \\teeny { " + instruments. INSTRUMENT_ID_TO_SHORT_INSTRUMENT_NAME[instrument_id] + " } }"), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\override Staff.TimeSignature.style = #'single-digit"), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\set Score.proportionalNotationDuration = #(ly:make-moment 1/8)" ), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\override Score.SpacingSpanner.strict-note-spacing = ##t"), first_leaf, ) abjad.attach(abjad.LilyPondLiteral("\\hide Staff.BarLine"), first_leaf) last_leaf = abjad.get.leaf(voice, -1) abjad.attach(abjad.BarLine("|.", format_slot="absolute_after"), last_leaf) abjad.attach( abjad.LilyPondLiteral(r"\undo \hide Staff.BarLine", format_slot="absolute_after"), last_leaf, )
def make_desordre_cell(pitches): """ Makes a Désordre cell. """ notes = [abjad.Note(pitch, (1, 8)) for pitch in pitches] notes = abjad.Selection(notes) beam = abjad.Beam() abjad.attach(beam, notes) slur = abjad.Slur() abjad.attach(slur, notes) clef = abjad.Dynamic('f') abjad.attach(clef, notes[0]) dynamic = abjad.Dynamic('p') abjad.attach(dynamic, notes[1]) # make the lower voice lower_voice = abjad.Voice(notes) lower_voice.name = 'RH Lower Voice' command = abjad.LilyPondLiteral(r'\voiceTwo') abjad.attach(command, lower_voice) n = int(math.ceil(len(pitches) / 2.)) chord = abjad.Chord([pitches[0], pitches[0] + 12], (n, 8)) articulation = abjad.Articulation('>') abjad.attach(articulation, chord) # make the upper voice upper_voice = abjad.Voice([chord]) upper_voice.name = 'RH Upper Voice' command = abjad.LilyPondLiteral(r'\voiceOne') abjad.attach(command, upper_voice) # combine them together container = abjad.Container([lower_voice, upper_voice]) container.is_simultaneous = True # make all 1/8 beats breakable leaves = abjad.select(lower_voice).leaves() for leaf in leaves[:-1]: bar_line = abjad.BarLine('') abjad.attach(bar_line, leaf) return container
def __call__( self, complex_event_to_convert: events.abc.ComplexEvent, container_to_process: abjad.Container, ): for staff_group in container_to_process: for staff in staff_group: first_leaf = abjad.get.leaf(staff, 0) abjad.attach( abjad.LilyPondLiteral( "\\set Score.proportionalNotationDuration = #(ly:make-moment" " 1/8)"), first_leaf, ) last_leaf = abjad.get.leaf(staff, -1) abjad.attach(abjad.LilyPondLiteral("\\hide Staff.BarLine"), first_leaf) abjad.attach( abjad.LilyPondLiteral("\\omit Staff.TimeSignature"), first_leaf) # abjad.attach( # abjad.LilyPondLiteral('\\remove "Bar_engraver"'), first_leaf # ) # abjad.attach( # abjad.LilyPondLiteral('\\hide Score.BarLine'), first_leaf # ) # abjad.attach( # abjad.LilyPondLiteral('\\hide StaffGroup.BarLine'), first_leaf # ) try: abjad.attach( abjad.BarLine("|.", format_slot="absolute_after"), last_leaf) except Exception: pass abjad.attach( abjad.LilyPondLiteral(r"\undo \hide Staff.BarLine", format_slot="absolute_after"), last_leaf, )
def test_double_barlines_before_time_signatures_04(): staff = abjad.Staff( r"\time 3/4 c'2. \time 4/4 d'1 e'1 \time 6/4 f'2. g'2.") abjad.attach(abjad.BarLine('||'), staff[2]) auxjad.mutate(staff[:]).double_barlines_before_time_signatures() assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 3/4 c'2. \bar "||" \time 4/4 d'1 e'1 \bar "||" \time 6/4 f'2. g'2. } """)
def test_LilyPondParser__indicators__BarLine_01(): maker = abjad.NoteMaker() target = abjad.Staff(maker(["e'", "d'", "c'"], [(1, 4), (1, 4), (1, 2)])) bar_line = abjad.BarLine("|.") abjad.attach(bar_line, target[-1]) assert format(target) == abjad.String.normalize(r""" \new Staff { e'4 d'4 c'2 \bar "|." } """) parser = abjad.parser.LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result items = abjad.inspect(result[2]).indicators() assert 1 == len(items) and isinstance(items[0], abjad.BarLine)
def _add_segments_to_voice(voice, label, segments, names, do_not_page_break=False): pairs = zip(segments, names) leaves = [] for i, pair in enumerate(pairs): segment, name = pair notes = [abjad.Note(_.number, (1, 8)) for _ in segment] abjad.horizontal_bracket(notes) name = rf'\markup "{name}"' abjad.override(notes[0]).HorizontalBracketText.text = name voice.extend(notes) skip = abjad.Skip("s8") voice.append(skip) number = i + 1 markup = abjad.Markup(rf"\markup {number}") bundle = abjad.bundle(markup, r"- \tweak staff-padding 2") abjad.attach(bundle, notes[0], direction=abjad.UP) if i == 0: string = rf'\markup \bold \with-color #red "{label}"' markup = abjad.Markup(string) bundle = abjad.bundle(markup, r"- \tweak staff-padding 6") abjad.attach(bundle, notes[0], direction=abjad.UP) if i == len(segments) - 1: literal = abjad.LilyPondLiteral(r"\break", site="after") abjad.attach(literal, voice[-1]) leaves.extend(notes) leaves.append(skip) for i, leaf in enumerate(leaves): if i % 30 == 29: literal = abjad.LilyPondLiteral(r"\break", site="after") abjad.attach(literal, leaf) if not do_not_page_break: literal = abjad.LilyPondLiteral(r"\pageBreak") abjad.attach(literal, leaves[0]) bar_line = abjad.BarLine("||") abjad.attach(bar_line, leaves[-1]) literal = abjad.LilyPondLiteral( r"\once \override Score.BarLine.transparent = ##f", site="after" ) abjad.attach(literal, leaves[-1])
def make_desordre_cell(pitches): """ Makes a Désordre cell. """ notes = [abjad.Note(pitch, (1, 8)) for pitch in pitches] notes = abjad.Selection(notes) abjad.beam(notes) abjad.slur(notes) abjad.attach(abjad.Dynamic("f"), notes[0]) abjad.attach(abjad.Dynamic("p"), notes[1]) # make the lower voice lower_voice = abjad.Voice(notes) lower_voice.name = "RH_Lower_Voice" command = abjad.LilyPondLiteral(r"\voiceTwo") abjad.attach(command, lower_voice) n = int(math.ceil(len(pitches) / 2.0)) chord = abjad.Chord([pitches[0], pitches[0] + 12], (n, 8)) abjad.attach(abjad.Articulation(">"), chord) # make the upper voice upper_voice = abjad.Voice([chord]) upper_voice.name = "RH_Upper_Voice" command = abjad.LilyPondLiteral(r"\voiceOne") abjad.attach(command, upper_voice) # combine them together voices = [lower_voice, upper_voice] container = abjad.Container(voices, simultaneous=True) # make all 1/8 beats breakable leaves = abjad.select(lower_voice).leaves() for leaf in leaves[:-1]: bar_line = abjad.BarLine("") abjad.attach(bar_line, leaf) return container
def _annotate_stages(self): r""" Adds stage number markup and barlines to score. """ if not self.show_stage_annotations: return print('Annotating stages...') context = self._score[0] for stage_index in range(self.number_of_stages): start_measure_index, stop_measure_index = \ self._stage_index_to_measure_indices(stage_index) rehearsal_mark = abjad.indicatortools.RehearsalMark( number=stage_index + 1 ) start_measure = context[0][start_measure_index] stop_measure = context[0][stop_measure_index] abjad.attach(rehearsal_mark, start_measure[0]) bar_line = abjad.BarLine('|') abjad.attach(bar_line, stop_measure) scheme = abjad.schemetools.Scheme('format-mark-box-alphabet') abjad.setting(self._score).markFormatter = scheme
def _add_attachments(self): print("Adding attachments ...") if self.colophon is not None: last_voice = abjad.select(self.score_template).components( abjad.Voice)[-1] # colophon_leaf = abjad.select(last_voice).leaves()[-2] # abjad.attach(self.colophon, colophon_leaf) if self.abbreviations is not None: abbreviations = [] abb = self.abbreviations mark_abbreviations = [ abjad.Markup(fr"\markup {{ \hcenter-in #12 {_} }}", literal=True) for _ in abb ] for x in mark_abbreviations: abbreviations.append(abjad.MarginMarkup(markup=x)) else: abbreviations = [_ for _ in range(len(self.instruments))] if self.names is not None: names = [] nm = self.names mark_names = [ abjad.Markup(fr"\markup {{ \hcenter-in #14 {_} }}", literal=True) for _ in nm ] for x in mark_names: names.append(abjad.StartMarkup(markup=x)) else: names = [_ for _ in range(len(self.instruments))] metro = abjad.MetronomeMark(self.tempo[0], self.tempo[1]) # metro = abjad.MetronomeMark(custom_markup=metro.make_tempo_equation_markup())#remove if broken if self.tempo is not None: for staff in abjad.iterate( self.score_template["Global Context"]).components( abjad.Staff): leaf1 = abjad.select(staff).leaves()[0] abjad.attach(metro, leaf1) markup2 = abjad.RehearsalMark(markup=abjad.Markup( fr"\markup \bold {{ {self.rehearsal_mark} }}", literal=True)) if self.rehearsal_mark is not None: for staff in abjad.iterate( self.score_template["Global Context"]).components( abjad.Staff): leaf1 = abjad.select(staff).leaves()[0] abjad.attach(markup2, leaf1) bar_line = abjad.BarLine(self.barline) if self.barline is not None: for voice in abjad.iterate( self.score_template["Staff Group"]).components( abjad.Staff # was Voice ): if self.barline == "|.": last_leaf = abjad.select(voice).leaves()[-1] abjad.attach(bar_line, last_leaf) else: last_leaf = abjad.select(voice).leaves()[-3] abjad.attach(bar_line, last_leaf) if self.clef_handlers is None: self.clef_handlers = [ None for _ in abjad.select( self.score_template["Staff Group"]).components(abjad.Staff) ] for abbrev, name, inst, handler, voice in zip( abbreviations, names, self.instruments, self.clef_handlers, abjad.select(self.score_template["Staff Group"]).components( abjad.Staff), # was Voice ): first_leaf = abjad.select(voice).leaves()[0] if self.name_staves is True: if not isinstance(abbrev, int): abjad.attach( abbrev, first_leaf, tag=abjad.Tag("applying staff names and clefs"), ) if not isinstance(name, int): abjad.attach( name, first_leaf, tag=abjad.Tag("applying staff names and clefs"), ) abjad.attach(inst, first_leaf, tag=abjad.Tag("applying staff names and clefs")) # abjad.iterpitches.transpose_from_sounding_pitch(voice) if handler is not None: handler(voice)
lh_voice_2.extend(lh_2) time_signature = abjad.TimeSignature((2, 4)) note = abjad.select(rh_voice).note(0) abjad.attach(time_signature, note) time_signature = abjad.TimeSignature((3, 4)) note = abjad.select(rh_voice).note(4) abjad.attach(time_signature, note) time_signature = abjad.TimeSignature((2, 4)) note = abjad.select(rh_voice).note(9) abjad.attach(time_signature, note) clef = abjad.Clef("bass") note = abjad.select(lh_voice_2).note(0) abjad.attach(clef, note) bar_line = abjad.BarLine("|.") note = abjad.select(lh_voice_2).note(-1) abjad.attach(bar_line, note) note = abjad.select(rh_voice).note(-2) abjad.override(note).hairpin.to_barline = False # Doesn't do a damned thing. abjad.persist.as_midi(score, "fragment") # Does produce a MIDI file, squirreled away in ~/.abjad/output/{tempfilename}.mid. # This can be configured with arguments to the Player creator. The Player seems to # use Lilypond exclusively for output. abjad.play(score)
def add_final_bar_line(self, bar_line: Union[str, abjad.BarLine] = "|.", *, to_each_voice: bool = False, ) -> None: r"""Adds a final bar line to all components of |abjad.Score|. Note that Auxjad adds this function as an extension method to |abjad.Score| (see usage below). Basic usage: >>> staff = abjad.Staff(r"c'4 d'4 e'4 f'4") >>> score = abjad.Score([staff]) >>> abjad.show(score) .. docs:: \new Score << \new Staff { c'4 d'4 e'4 f'4 } >> .. figure:: ../_images/Score-fdO5TP6ff9.png >>> score.add_final_bar_line() >>> abjad.show(score) .. docs:: \new Score << \new Staff { c'4 d'4 e'4 f'4 \bar "|." } >> .. figure:: ../_images/Score-SHok9MqNVh.png Multiple staves: Works with multiple staves: >>> staff_1 = abjad.Staff(r"c''1 d''1 e''1 f''1") >>> staff_2 = abjad.Staff(r"c'1 d'1 e'1 f'1") >>> score = abjad.Score([staff_1, staff_2]) >>> score.add_final_bar_line() >>> abjad.show(score) .. docs:: \new Score << \new Staff { c''1 d''1 e''1 f''1 \bar "|." } \new Staff { c'1 d'1 e'1 f'1 \bar "|." } >> .. figure:: ../_images/Score-oCR5QGUz6W.png Each stave will receive their own final bar line, which can be useful when part extracting: >>> abjad.show(staff_1) .. docs:: \new Staff { c''1 d''1 e''1 f''1 \bar "|." } .. figure:: ../_images/Score-tTXh7GOAop.png >>> abjad.show(staff_2) .. docs:: \new Staff { c'1 d'1 e'1 f'1 \bar "|." } .. figure:: ../_images/Score-MRWgOyiqt3.png ``to_each_voice`` When multiple voices are present in a staff, the final bar line is added to the last voice only: >>> voice_1 = abjad.Voice(r"c''1 d''1 e''1 f''1") >>> voice_2 = abjad.Voice(r"c'2 d'2 e'2 f'2 g'2 a'2 b'2 c''2") >>> staff = abjad.Staff([voice_1, voice_2], simultaneous=True) >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceOne'), voice_1) >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceTwo'), voice_2) >>> score = auxjad.Score([staff]) >>> score.add_final_bar_line() >>> abjad.show(score) .. docs:: \new Score << \new Staff << \new Voice { \voiceOne c''1 d''1 e''1 f''1 } \new Voice { \voiceTwo c'2 d'2 e'2 f'2 g'2 a'2 b'2 c''2 \bar "|." } >> >> .. figure:: ../_images/Score-8mnllVCEoL.png >>> abjad.show(voice_1) .. docs:: \new Voice { \voiceOne c''1 d''1 e''1 f''1 } .. figure:: ../_images/Score-DPW54DDeyM.png >>> abjad.show(voice_2) .. docs:: \new Voice { \voiceTwo c'2 d'2 e'2 f'2 g'2 a'2 b'2 c''2 \bar "|." } .. figure:: ../_images/Score-ua8cZAITB5.png Setting ``to_each_voice`` to ``True`` will add a bar line to each voice in a staff: >>> voice_1 = abjad.Voice(r"c''1 d''1 e''1 f''1") >>> voice_2 = abjad.Voice(r"c'2 d'2 e'2 f'2 g'2 a'2 b'2 c''2") >>> staff = abjad.Staff([voice_1, voice_2], simultaneous=True) >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceOne'), voice_1) >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceTwo'), voice_2) >>> score = auxjad.Score([staff]) >>> score.add_final_bar_line(to_each_voice=True) >>> abjad.show(voice_1) .. docs:: \new Voice { \voiceOne c''1 d''1 e''1 f''1 \bar "|." } .. figure:: ../_images/Score-adtLRR3v1W.png >>> abjad.show(voice_2) .. docs:: \new Voice { \voiceTwo c'2 d'2 e'2 f'2 g'2 a'2 b'2 c''2 \bar "|." } .. figure:: ../_images/Score-DqhspXgvIJ.png .. warning:: If voices do not end together then manually adding bar lines will be required: >>> voice_1 = abjad.Voice(r"c''1 d''1 e''1 f''1") >>> voice_2 = abjad.Voice(r"c'1 d'1 e'1") >>> staff = abjad.Staff([voice_1, voice_2], simultaneous=True) >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceOne'), voice_1) >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceTwo'), voice_2) >>> score = auxjad.Score([staff]) >>> score.add_final_bar_line(to_each_voice=True) >>> abjad.show(score) .. docs:: \new Score << \new Staff << \new Voice { \voiceOne c''1 d''1 e''1 f''1 \bar "|." } \new Voice { \voiceTwo c'1 d'1 e'1 \bar "|." } >> >> .. figure:: ../_images/Score-duPkS4pJGc.png argument: The default bar line is of type ``'|.'``. To change this behaviour, call this method with an argument of type :obj:`str` or |abjad.BarLine| with the desired bar line type: >>> staff_1 = abjad.Staff(r"c''1 d''1 e''1 f''1") >>> staff_2 = abjad.Staff(r"c'1 d'1 e'1 f'1") >>> score = auxjad.Score([staff_1, staff_2]) >>> score.add_final_bar_line(abjad.BarLine(":|.")) >>> abjad.show(score) .. docs:: \new Score << \new Staff { c''1 d''1 e''1 f''1 \bar ":|." } \new Staff { c'1 d'1 e'1 f'1 \bar ":|." } >> .. figure:: ../_images/Score-3JvhD9DKvE.png """ if not isinstance(bar_line, (str, abjad.BarLine)): raise TypeError("argument must be 'str' or 'abjad.BarLine'") if not isinstance(to_each_voice, bool): raise TypeError("'to_each_voice' must be 'bool'") if isinstance(bar_line, str): bar_line = abjad.BarLine(bar_line) if not to_each_voice: for staff in abjad.Iteration(self).components(abjad.Staff): last_leaf = abjad._iterate._get_leaf(staff, -1) abjad.attach(bar_line, last_leaf, context='Staff') else: for staff in abjad.Iteration(self).components(abjad.Staff): voices = [voice for voice in abjad.Iteration(staff).components(abjad.Voice)] if len(voices) == 0: last_leaf = abjad._iterate._get_leaf(staff, -1) abjad.attach(bar_line, last_leaf, context='Staff') else: for voice in abjad.Iteration(self).components(abjad.Voice): last_leaf = abjad._iterate._get_leaf(voice, -1) abjad.attach(bar_line, last_leaf, context='Voice')
def __call__( self, complex_event_to_convert: events.abc.ComplexEvent, container_to_process: abjad.Container, ): if self._render_video: make_moment_duration = 8 else: make_moment_duration = 16 for staff_group in container_to_process: for staff in staff_group: last_leaf = abjad.get.leaf(staff, -1) try: abjad.attach( abjad.BarLine("|.", format_slot="absolute_after"), last_leaf) except Exception: pass abjad.attach( abjad.LilyPondLiteral(r"\undo \hide Staff.BarLine", format_slot="absolute_after"), last_leaf, ) first_leaf = abjad.get.leaf(staff, 0) # only attach proportional notation for videos if self._render_video: abjad.attach( abjad.LilyPondLiteral( "\\set Score.proportionalNotationDuration = #(ly:make-moment" " 1/{})".format(make_moment_duration)), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\override Staff.TimeSignature.style = #'single-digit" ), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\override SpacingSpanner.base-shortest-duration = #(ly:make-moment 1/{})" .format(make_moment_duration)), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\override Staff.Stem.stemlet-length = #0.75"), first_leaf, ) abjad.attach( abjad.LilyPondLiteral("\\set strictBeatBeaming = ##t"), first_leaf, ) abjad.attach( abjad.LilyPondLiteral( "\\override Staff.NoteHead.style = #'baroque"), first_leaf, ) last_leaf = abjad.get.leaf(staff, -1) try: abjad.attach( abjad.BarLine("|.", format_slot="absolute_after"), last_leaf) except Exception: pass
print("Stopping Hairpins ...") for staff in abjad.iterate(score["Staff Group 1"]).components(abjad.Staff): for rest in abjad.iterate(staff).components(abjad.Rest): previous_leaf = abjad.inspect(rest).leaf(-1) if isinstance(previous_leaf, abjad.Note): abjad.attach(abjad.StopHairpin(), rest) elif isinstance(previous_leaf, abjad.Chord): abjad.attach(abjad.StopHairpin(), rest) elif isinstance(previous_leaf, abjad.Rest): pass # attach instruments and clefs print("Adding attachments ...") bar_line = abjad.BarLine("||") metro = abjad.MetronomeMark((1, 4), 60) markup1 = abjad.Markup(r"\bold { A }") markup2 = abjad.Markup(r"\bold { B }") markup3 = abjad.Markup(r"\bold { C }") markup4 = abjad.Markup(r"\bold { D }") markup5 = abjad.Markup(r"\bold { E }") markup6 = abjad.Markup(r"\bold { F }") mark1 = abjad.RehearsalMark(markup=markup1) mark2 = abjad.RehearsalMark(markup=markup2) mark3 = abjad.RehearsalMark(markup=markup3) mark4 = abjad.RehearsalMark(markup=markup4) mark5 = abjad.RehearsalMark(markup=markup5) mark6 = abjad.RehearsalMark(markup=markup6) instruments1 = cyc([abjad.Flute(), abjad.AltoSaxophone(), abjad.Cello()])
def double_barlines_before_time_signatures(selection: abjad.Selection, *, context: Optional[str] = None, ) -> None: r"""Mutates an input |abjad.Selection| in place and has no return value; this function adds double bar lines before all time signatures. Basic usage: Whenever a new time signature appears, the function adds a double bar line before it: >>> staff = abjad.Staff( ... r"\time 3/4 c'2. \time 4/4 d'1 e'1 \time 6/4 f'2. g'2." ... ) >>> auxjad.mutate(staff[:]).double_barlines_before_time_signatures() >>> abjad.f(staff) \new Staff { \time 3/4 c'2. \bar "||" \time 4/4 d'1 e'1 \bar "||" \time 6/4 f'2. g'2. } .. figure:: ../_images/remove_repeated_time_signatures-2O7JyxN1CS.png Multi-measure rests: This function can handle multi-measure rests too. >>> staff = abjad.Staff( ... r"\time 3/4 R1 * 3/4 " ... r"\time 4/4 R1 * 2 " ... r"\time 6/4 R1 * 6/4 " ... r"\time 4/4 R1" ... ) >>> auxjad.mutate(staff[:]).double_barlines_before_time_signatures() >>> abjad.f(staff) \new Staff { \time 3/4 R1 * 3/4 \bar "||" \time 4/4 R1 * 2 \bar "||" \time 6/4 R1 * 3/2 \bar "||" \time 4/4 R1 } .. figure:: ../_images/remove_repeated_time_signatures-aYmnnFDdRh.png Input with bar lines: If the input selection already contains bar lines at poinst where a time signature change, the function will only replace those of type ``"|"`` or ``""``, keeping all others as they were. >>> staff = abjad.Staff( ... r"R1 " ... r"\time 3/4 c'2. " ... r"\time 4/4 d'1 " ... r"e'1 " ... r"\time 6/4 f'2. g'2. " ... r"\time 2/4 a'2" ... ) >>> abjad.attach(abjad.BarLine('.|:'), staff[0]) >>> abjad.attach(abjad.BarLine(':|.'), staff[1]) >>> abjad.attach(abjad.BarLine('|'), staff[3]) >>> abjad.attach(abjad.BarLine('!'), staff[5]) >>> auxjad.mutate(staff[:]).double_barlines_before_time_signatures() >>> abjad.f(staff) \new Staff { R1 \bar ".|:" \time 3/4 c'2. \bar ":|." \time 4/4 d'1 e'1 \bar "||" \time 6/4 f'2. g'2. \bar "!" \time 2/4 a'2 } .. figure:: ../_images/remove_repeated_time_signatures-jUymJWLdR7.png .. warning:: Attempting to add barlines to multiple staves in an |abjad.Score| at the same point in the score will raise an exception: .. code:: >>> up = abjad.Staff(r"\time 4/4 c'1 d'1 \time 6/4 e'1.") >>> down = abjad.Staff( ... r"\time 4/4 \clef bass c1 d1 \time 6/4 e1." ... ) >>> score = abjad.Score([up, down]) >>> auxjad.mutate(up[:]).double_barlines_before_time_signatures() >>> auxjad.mutate(down[:]).double_barlines_before_time_signatures() abjad.exceptions.PersistentIndicatorError: Can not attach ... abjad.Wrapper( context='Score', indicator=abjad.BarLine('||', format_slot='after', ), tag=abjad.Tag(), ) ... to Note('d1') in None because ... abjad.Wrapper( context='Score', indicator=abjad.BarLine('||', format_slot='after', ), tag=abjad.Tag(), ) ... is already attached to Note("d'1") in None. This is because, by default, bar lines belong to the score scope. In order to have bar lines on both staves (e.g. for easier part extraction), invoke this mutation with the argument ``context`` set to ``'Staff'`` so that the double bar lines become scoped to the staff instead of the score: >>> up = abjad.Staff(r"\time 4/4 c'1 d'1 \time 6/4 e'1.") >>> down = abjad.Staff(r"\time 4/4 \clef bass c1 d1 \time 6/4 e1.") >>> score = abjad.Score([up, down]) >>> auxjad.mutate(up[:]).double_barlines_before_time_signatures( ... context='Staff', ... ) >>> auxjad.mutate(down[:]).double_barlines_before_time_signatures( ... context='Staff', ... ) >>> abjad.f(score) \new Score << \new Staff { \time 4/4 c'1 d'1 \bar "||" \time 6/4 e'1. } \new Staff { \time 4/4 \clef "bass" c1 d1 \bar "||" \time 6/4 e1. } >> .. figure:: ../_images/remove_repeated_time_signatures-yD6KL6xbrV.png In this case, both individual staves will also have the bar lines: >>> abjad.f(up) \new Staff { \time 4/4 c'1 d'1 \bar "||" \time 6/4 e'1. } .. figure:: ../_images/remove_repeated_time_signatures-Zs1hSq2uwY.png >>> abjad.f(down) \new Staff { \time 4/4 \clef "bass" c1 d1 \bar "||" \time 6/4 e1. } .. figure:: ../_images/remove_repeated_time_signatures-QYOgyhLJ2f.png .. warning:: The input selection must be a contiguous logical voice. When dealing with a container with multiple subcontainers (e.g. a score containing multiple staves), the best approach is to cycle through these subcontainers, applying this function to them individually. """ if not isinstance(selection, abjad.Selection): raise TypeError("argument must be 'abjad.Selection'") if not selection.leaves().are_contiguous_logical_voice(): raise ValueError("argument must be contiguous logical voice") leaves = selection.leaves() for i, leaf in enumerate(leaves[1:], 1): time_signature = abjad.inspect(leaf).indicator(abjad.TimeSignature) if time_signature is not None: inspector = abjad.inspect(leaves[i - 1]) barline = inspector.indicator(abjad.BarLine) if barline is not None and barline.abbreviation in ('|', ''): abjad.detach(abjad.BarLine, leaves[i - 1]) barline = None if barline is None: if context is None: abjad.attach(abjad.BarLine("||"), leaves[i - 1]) else: abjad.attach(abjad.BarLine("||"), leaves[i - 1], context=context, )
def make_mozart_score(): r'''Makes Mozart score. ''' score_template = abjad.TwoStaffPianoScoreTemplate() score = score_template() # select the measures to use choices = abjad.demos.mozart.choose_mozart_measures() # create and populate the volta containers treble_volta = abjad.Container() bass_volta = abjad.Container() for choice in choices[:7]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) treble_volta.append(treble) bass_volta.append(bass) # abjad.attach indicators to the volta containers command = abjad.LilyPondCommand('repeat volta 2', 'before') abjad.attach(command, treble_volta) command = abjad.LilyPondCommand('repeat volta 2', 'before') abjad.attach(command, bass_volta) # append the volta containers to our staves score['RHVoice'].append(treble_volta) score['LHVoice'].append(bass_volta) # create and populate the alternative ending containers treble_alternative = abjad.Container() bass_alternative = abjad.Container() for choice in choices[7:9]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) treble_alternative.append(treble) bass_alternative.append(bass) # abjad.attach indicators to the alternative containers command = abjad.LilyPondCommand('alternative', 'before') abjad.attach(command, treble_alternative) command = abjad.LilyPondCommand('alternative', 'before') abjad.attach(command, bass_alternative) # append the alternative containers to our staves score['RHVoice'].append(treble_alternative) score['LHVoice'].append(bass_alternative) # create the remaining measures for choice in choices[9:]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) score['RHVoice'].append(treble) score['LHVoice'].append(bass) # abjad.attach indicators time_signature = abjad.TimeSignature((3, 8)) leaf = abjad.inspect(score['RHStaff']).get_leaf(0) abjad.attach(time_signature, leaf) bar_line = abjad.BarLine('|.') leaf = abjad.inspect(score['RHStaff']).get_leaf(-1) abjad.attach(bar_line, leaf) bar_line = abjad.BarLine('|.') leaf = abjad.inspect(score['LHStaff']).get_leaf(-1) abjad.attach(bar_line, leaf) # remove the default piano instrument and add a custom one: abjad.detach(abjad.Instrument, score['PianoStaff']) klavier = abjad.instrumenttools.Piano( name='Katzenklavier', short_name='kk.', ) leaf = abjad.inspect(score['PianoStaff']).get_leaf(0) abjad.attach(klavier, leaf) return score
elif isinstance(previous_leaf, abjad.Chord): abjad.attach(abjad.StopHairpin(), rest) elif isinstance(previous_leaf, abjad.Rest): pass # attach instruments and clefs literal = abjad.LilyPondLiteral(r"\tweak Dots.transparent ##t") for rest in abjad.select(score["Voice 5"]).components(abjad.Rest): abjad.attach(literal, rest) for rest in abjad.select(score["Voice 6"]).components(abjad.Rest): abjad.attach(literal, rest) print("Adding attachments ...") bar_line = abjad.BarLine("||") section_bar_line = abjad.BarLine("||") metro = abjad.MetronomeMark((1, 8), 60) markup1 = abjad.Markup(r"\bold { A }") markup2 = abjad.Markup(r"\bold { B }") markup3 = abjad.Markup(r"\bold { C }") markup4 = abjad.Markup(r"\bold { D }") markup5 = abjad.Markup(r"\bold { E }") markup6 = abjad.Markup(r"\bold { F }") mark1 = abjad.RehearsalMark(markup=markup1) mark2 = abjad.RehearsalMark(markup=markup2) mark3 = abjad.RehearsalMark(markup=markup3) mark4 = abjad.RehearsalMark(markup=markup4) mark5 = abjad.RehearsalMark(markup=markup5) mark6 = abjad.RehearsalMark(markup=markup6)
def test_example_of_usage_01(): material = abjad.Staff( r"\time 12/8 c8 c c r c c r c r c c r", lilypond_type="RhythmicStaff", ) phaser = auxjad.Phaser( material, step_size=abjad.Duration((1, 8)), ) notes = phaser.output_all() phased_staff = abjad.Staff( notes, lilypond_type="RhythmicStaff", ) repeater = auxjad.Repeater(material) notes = repeater(13) constant_staff = abjad.Staff( notes, lilypond_type="RhythmicStaff", ) score = abjad.Score([constant_staff, phased_staff]) measures = abjad.select(constant_staff[:]).group_by_measure() for measure in measures[:-1]: abjad.attach(abjad.BarLine(':..:'), measure[-1]) abjad.attach(abjad.BarLine(':|.'), constant_staff[-1]) assert abjad.lilypond(score) == abjad.String.normalize(r""" \new Score << \new RhythmicStaff { \time 12/8 c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":..:" c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 \bar ":|." } \new RhythmicStaff { \time 12/8 c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 c8 c8 c8 c8 c8 r8 c8 r8 c8 c8 r8 c8 c8 c8 r8 c8 r8 c8 r8 c8 c8 r8 c8 c8 c8 r8 c8 r8 c8 r8 c8 c8 r8 c8 c8 c8 r8 c8 c8 c8 r8 c8 c8 r8 c8 c8 c8 r8 c8 c8 r8 r8 c8 c8 r8 c8 c8 c8 r8 c8 c8 r8 c8 c8 c8 r8 c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 r8 c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 r8 c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 c8 c8 c8 r8 c8 c8 r8 c8 r8 c8 c8 r8 } >> """)
# Make pitches print('Adding pitch material ...') def cyc(lst): count = 0 while True: yield lst[count % len(lst)] count += 1 #attach instruments and clefs print('Adding attachments ...') bar_line = abjad.BarLine('||') metro = abjad.MetronomeMark((1, 4), 90) markup = abjad.Markup(r'\bold { Invocation }') mark = abjad.RehearsalMark(markup=markup) instruments = cyc([ abjad.SopraninoSaxophone(), abjad.SopranoSaxophone(), abjad.SopranoSaxophone(), abjad.SopranoSaxophone(), abjad.AltoSaxophone(), abjad.AltoSaxophone(), abjad.AltoSaxophone(), abjad.TenorSaxophone(), abjad.TenorSaxophone(), abjad.TenorSaxophone(),