def make_small_example( score: abjad.Score, path: str, size: float = None, staff_size: float = 20, resolution: int = 500, header_block=abjad.Block("header"), ) -> subprocess.Popen: includes = ["lilypond-book-preamble.ly"] score_block = abjad.Block("score") score_block.items.append(score) layout_block = abjad.Block("layout") layout_block.items.append(r"indent = 0\mm") layout_block.items.append(r"short-indent = 0\mm") layout_block.items.append(r"ragged-last = ##f") layout_block.items.append(r"ragged-right = ##f") lilypond_file = abjad.LilyPondFile( lilypond_version_token=abjad.LilyPondVersionToken(LILYPOND_VERSION), global_staff_size=staff_size, includes=includes, items=[layout_block, header_block, score_block], ) write_lily_file(lilypond_file, path) return render_lily_file(path, write2png=True, resolution=resolution, output_name=path)
def _make_markup_score_block(selection): import abjad selection = copy.deepcopy(selection) staff = abjad.Staff(selection) staff.lilypond_type = 'RhythmicStaff' staff.remove_commands.append('Time_signature_engraver') staff.remove_commands.append('Staff_symbol_engraver') abjad.override(staff).stem.direction = abjad.Up abjad.override(staff).stem.length = 5 abjad.override(staff).tuplet_bracket.bracket_visibility = True abjad.override(staff).tuplet_bracket.direction = abjad.Up abjad.override(staff).tuplet_bracket.minimum_length = 4 abjad.override(staff).tuplet_bracket.padding = 1.25 abjad.override(staff).tuplet_bracket.shorten_pair = (-1, -1.5) scheme = abjad.Scheme('ly:spanner::set-spacing-rods') abjad.override(staff).tuplet_bracket.springs_and_rods = scheme abjad.override(staff).tuplet_number.font_size = 0 scheme = abjad.Scheme('tuplet-number::calc-fraction-text') abjad.override(staff).tuplet_number.text = scheme abjad.setting(staff).tuplet_full_length = True layout_block = abjad.Block(name='layout') layout_block.indent = 0 layout_block.ragged_right = True score = abjad.Score([staff]) abjad.override(score).spacing_spanner.spacing_increment = 0.5 abjad.setting(score).proportional_notation_duration = False return score, layout_block
def test_LilyPondParser__lilypondfile__ScoreBlock_01(): target = abjad.Block(name="score") target.items.append(abjad.Score()) parser = abjad.parser.LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def convert(self, *args, **kwargs) -> abjad.Block: score = super().convert(*args, **kwargs) score_block = abjad.Block(name="score") score_block.items.append(score) if not self.render_video: score_block.items.append(self.layout_block) # if self.render_video: # score_block.items.append(self.midi_block) return score_block
def as_midi(self, midi_file_path=None, remove_ly=False, **keywords): """ Persists client as MIDI file. Autogenerates file path when ``midi_file_path`` is none. .. container:: example >>> staff = abjad.Staff("c'4 e'4 d'4 f'4") >>> for x in persist(staff).as_midi(): # doctest: +SKIP ... x ... '/Users/josiah/.abjad/output/1415.midi' 0.07831692695617676 1.0882699489593506 Returns output path, elapsed formatting time and elapsed rendering time. """ import abjad assert hasattr(self._client, '__illustrate__') illustration = self._client.__illustrate__(**keywords) assert hasattr(illustration, 'score_block') block = abjad.Block(name='midi') print("illustration", illustration) illustration.score_block.items.append(block) if midi_file_path is not None: midi_file_path = os.path.expanduser(midi_file_path) without_extension = os.path.splitext(midi_file_path)[0] ly_file_path = '{}.ly'.format(without_extension) else: ly_file_path = None result = type(self)(illustration).as_ly(ly_file_path, **keywords) print("result", result) # 这里生成了 ly 文件 ly_file_path, abjad_formatting_time = result timer = abjad.Timer() with timer: success = abjad.IOManager.run_lilypond(ly_file_path) lilypond_rendering_time = timer.elapsed_time if os.name == 'nt': extension = 'mid' else: extension = 'midi' midi_file_path = '{}.{}'.format( os.path.splitext(ly_file_path)[0], extension, ) if remove_ly: os.remove(ly_file_path) return ( midi_file_path, abjad_formatting_time, lilypond_rendering_time, success, )
def _make_header_block( instrument_tag: typing.Optional[str]) -> abjad.Block: header_block = abjad.Block("header") header_block.title = '"ohne Titel (2)"' header_block.year = '"2021"' header_block.composer = '"Levin Eric Zimmermann"' header_block.tagline = '"oT(2) // 2021"' if instrument_tag: header_block.instrument = '"{} part book"'.format( ot2_constants.instruments. INSTRUMENT_ID_TO_LONG_INSTRUMENT_NAME[instrument_tag]) return header_block
def illustrate( name: str, *abjad_score: abjad.Score, add_book_preamble: bool = True, add_ekmeheji: bool = True, title: str = None, ): margin = 0 layout_block = abjad.Block("layout") layout_block.items.append(r"short-indent = {}\mm".format(margin)) layout_block.items.append(r"ragged-last = ##f") layout_block.items.append(r"indent = {}\mm".format(margin)) paper_block = abjad.Block("paper") paper_block.items.append(r"""#(define fonts (make-pango-font-tree "EB Garamond" "Nimbus Sans" "Luxi Mono" (/ staff-height pt 20)))""") paper_block.items.append(r"""score-system-spacing = #'((basic-distance . 30) (minimum-distance . 18) (padding . 1) (stretchability . 12))""") includes = [] if add_ekmeheji: includes.append("ekme-heji-ref-c-not-tuned.ily") if add_book_preamble: includes.append("lilypond-book-preamble.ly") lilypond_file = abjad.LilyPondFile( items=list(abjad_score) + [paper_block, layout_block], includes=includes, ) if title: header_block = abjad.Block("header") header_block.title = title header_block.tagline = '""' lilypond_file.items.append(header_block) abjad.persist.as_pdf( lilypond_file, f"{ot2_constants.paths.ILLUSTRATIONS_PATH}/{name}.pdf")
def _make_paper_block(self) -> abjad.Block: paper_block = abjad.Block("paper") if not self._render_video: paper_block.items.append(r"""#(define fonts (make-pango-font-tree "EB Garamond" "Nimbus Sans" "Luxi Mono" (/ staff-height pt 20)))""") paper_block.items.append(r"""score-system-spacing = #'((basic-distance . 30) (minimum-distance . 18) (padding . 1) (stretchability . 12))""") return paper_block
def _render_file(self): print("Rendering file ...") abjad.SegmentMaker.comment_measure_numbers(self.score_template) score_block = abjad.Block(name="score") score_block.items.append(self.score_template) score_file = abjad.LilyPondFile(items=[score_block], includes=self.score_includes) for leaf in abjad.iterate(self.score_template).leaves(): literal = abjad.LilyPondLiteral("", "absolute_before") abjad.attach(literal, leaf, tag=None) for container in abjad.iterate(self.score_template).components( abjad.Container): if hasattr(container, "_main_leaf"): literal = abjad.LilyPondLiteral("", "absolute_after") abjad.attach(literal, container, tag=None) else: literal = abjad.LilyPondLiteral("", "absolute_before") abjad.attach(literal, container, tag=None) literal = abjad.LilyPondLiteral("", "closing") abjad.attach(literal, container, tag=None) directory = self.current_directory pdf_path = baca.Path(f"{directory}/illustration.pdf") if pdf_path.exists(): pdf_path.unlink() print(f"Persisting {pdf_path.trim()} ...") result = abjad.persist.as_pdf( score_file, pdf_path, align_tags=79, ) success = result[3] if success is False: print("LilyPond failed!") if pdf_path.exists(): print(f"Opening {pdf_path.trim()} ...") os.system(f"open {pdf_path}") with open(f"{directory}/illustration.ly") as pointer_1: score_lines = pointer_1.readlines() build_path = self.current_directory.parent.with_name("build") build_path /= "score" lines = score_lines[7:-1] # was 15:-1 with open(f"{build_path}/{self.segment_name}.ly", "w") as fp: fp.writelines(lines)
def _make_lilypond_file(self, midi=None): import abjad template = abjad.TwoStaffPianoScoreTemplate() score = template() self._score = score rh_voice = score['RHVoice'] lh_voice = score['LHVoice'] self._populate_rhythms(rh_voice, self.rh_rhythm_maker) self._populate_rhythms(lh_voice, self.lh_rhythm_maker) self._populate_pitches(rh_voice, self.rh_pitch_range) self._populate_pitches(lh_voice, self.lh_pitch_range) template.attach_defaults(score) stylesheet_path = pathlib.Path( '..', '..', 'stylesheets', 'stylesheet.ily', ) lilypond_file = abjad.LilyPondFile.new( music=score, includes=[stylesheet_path], use_relative_includes=True, ) if midi: for block in lilypond_file.items[:]: if block.name in ('layout', 'paper'): lilypond_file.items.remove(block) block = abjad.Block(name='midi') lilypond_file.items.append(block) if self.include_layout_ly: score_block = lilypond_file.score_block score = score_block.items[0] assert isinstance(score, abjad.Score) include = abjad.Container() string = r'\include "layout.ly"' literal = abjad.LilyPondLiteral(string, 'opening') abjad.attach(literal, include) container = abjad.Container( [include, score], is_simultaneous=True, ) score_block.items[:] = [container] return lilypond_file
def illustrate_noises(): score_converter = _make_standard_score_converter( _make_standard_sequential_converter( converters.frontends.abjad. FastSequentialEventToDurationLineBasedQuantizedAbjadContainerConverter( ))) sequential_event = events.basic.SequentialEvent([ ot2_events.noises.Noise(1, 2, 1, parameters.volumes.WesternVolume("mf")) ]) score = score_converter.convert( events.basic.SimultaneousEvent([sequential_event])) score_block = abjad.Block("score") score_block.items.append(score) illustrate( "noise_0", score_block, add_book_preamble=True, add_ekmeheji=False, )
def _make_score_block(self, make_layout_block: bool = False ) -> abjad.LilyPondFile: score_block = super()._make_score_block(make_layout_block) local_header = abjad.Block("header") local_header.piece = abjad.Markup( abjad.MarkupCommand( "center-column", [ abjad.MarkupCommand("vspace", 0), abjad.MarkupCommand( "rounded-box", [ abjad.MarkupCommand("fontsize", 1.5), abjad.MarkupCommand("smallCaps"), "{}".format(self.title), ], ), ], )) score_block.items.append(local_header) return score_block
def illustrate_clarinet_fingerings(): score_converter = _make_standard_score_converter() nth_fingering = 0 for ( pitch, data, ) in (ot2_constants.instruments. CLARINET_MICROTONAL_PITCHES_TO_FINGERING_AND_EMBOUCHURE.items()): pitch = parameters.pitches.JustIntonationPitch(pitch) fingering, embouchure = data note = events.music.NoteLike(pitch, 1) if fingering: note.playing_indicators.fingering.cc = fingering.cc note.playing_indicators.fingering.rh = fingering.rh note.playing_indicators.fingering.lh = fingering.lh if embouchure: note.notation_indicators.markup.content = embouchure note.notation_indicators.markup.direction = "up" sequential_event = events.basic.SequentialEvent([note]) score = score_converter.convert( events.basic.SimultaneousEvent([sequential_event])) score_block = abjad.Block("score") score_block.items.append(score) name = f"clarinet/fingering_{nth_fingering}" nth_fingering += 1 illustrate( name, score_block, add_book_preamble=False, add_ekmeheji=True, )
for _ in range(numerator): note = abjad.Note.from_pitch_and_duration( -18, (1, denominator)) notes.append(note) notes[0].written_pitch = -23 abjad.attach(time_signature, notes[0]) abjad.attach(metronome_mark, notes[0]) measure = abjad.Container(notes) staff.append(measure) lilypond_file = abjad.LilyPondFile.new(music=score) block_names = ("layout", "paper") for item in lilypond_file.items[:]: if getattr(item, "name", None) in block_names: lilypond_file.items.remove(item) block = abjad.Block(name="midi") lilypond_file.items.append(block) for item in lilypond_file.items[:]: if getattr(item, "name", None) == "header": lilypond_file.items.remove(item) abjad.f(lilypond_file) try: segment_directory = ide.Path(__file__).parent score_directory = segment_directory.contents stem = f"{{score_directory.name}}-{{segment_directory.name}}-clicktrack" midi = stem + ".midi" except: traceback.print_exc() sys.exit(1)
def make_tableaux_chart(fundamental_patterns, subdivisions): print("instantiating parser, staff group, and patterns ...") parser = abjad.rhythmtrees.RhythmTreeParser() print("beginning loop ...") for i, fundamental_pattern in enumerate(fundamental_patterns): print(fundamental_pattern) print("gathering pattern ...") print("permuting pattern ...") for permutation in list( set([_ for _ in itertools.permutations(fundamental_pattern)])): permutation = list(permutation) print(permutation) title = fr"Mutations of {permutation}" final_patterns = [] parsed_patterns = abjad.Staff(lilypond_type="RhythmicStaff") for num_indices in range(len(permutation) + 1): print("gathing number of possible dividable beats ...") if num_indices == 0: print("do not subdivide!") print("converting to string ...") subgrouped_permutation = ( f"(1 {evans.nested_list_to_rtm(permutation)})") print("gathing number of rotatable positions ...") l_ = -1 for symbol in subgrouped_permutation: if symbol.isdigit(): l_ = l_ + 1 for y in range(l_): print("rotating ...") rotation = evans.rotate_tree( rtm_string=subgrouped_permutation, n=y) print(rotation) print("funneling rotation to 1 ...") for funnel in evans.funnel_inner_tree_to_x( rtm_string=rotation, x=1): print("caching funnel ...") print(funnel) final_patterns.append(funnel) else: print("subdivide!") print("gathering possible subdivisions ...") for division_group in itertools.combinations_with_replacement( subdivisions, num_indices): division_group = list(division_group) print("gathering possible subdivision locations ...") possible_indices = [_ for _ in range(len(permutation))] for index_group in itertools.combinations( possible_indices, num_indices): index_group = list(index_group) print("adding subgroups ...") subdivided_permutation = add_subgroups( input_list=permutation, index_list=index_group, subgroup_list=division_group, ) print("converting to string ...") subgrouped_permutation = evans.nested_list_to_rtm( subdivided_permutation) print(subgrouped_permutation) print("gathing number of rotatable positions ...") l_ = -1 for symbol in subgrouped_permutation: if symbol.isdigit(): l_ = l_ + 1 for y in range(l_): print("rotating ...") rotation = evans.rotate_tree( rtm_string=subgrouped_permutation, n=y) print(rotation) print("funneling rotation to 1 ...") for funnel in evans.funnel_inner_tree_to_x( rtm_string=rotation, x=1): print("caching funnel ...") print(funnel) final_patterns.append(funnel) print("parsing cached funnels ...") for pattern in final_patterns: print(pattern) pair = (1, 2) time_signature = abjad.TimeSignature(pair) rhythm_tree_list = parser(pattern) rhythm_tree_container = rhythm_tree_list[0] r = rhythm_tree_container(pair) m = abjad.Markup(fr"\markup {pattern}", direction=abjad.Up, literal=True) abjad.attach(m, abjad.select(r).leaves()[0]) abjad.attach(time_signature, abjad.select(r).leaves()[0]) print("adding parsed funnel to staff ...") parsed_patterns.extend(r) print("adding staff to staff group ...") score = abjad.Score([parsed_patterns]) scheme = abjad.SchemeMoment((1, 50)) abjad.setting(score).proportional_notation_duration = scheme new_brackets = evans.NoteheadBracketMaker() for staff in abjad.select(score).components(abjad.Staff): new_brackets(staff) abjad.override(score).TupletBracket.bracket_visibility = True print("rendering staff group ...") file = abjad.LilyPondFile( items=[ score, abjad.Block(name="layout"), abjad.Block(name="header") ], includes=[ "/Users/evansdsg2/abjad/docs/source/_stylesheets/abjad.ily" ], global_staff_size=14, default_paper_size=("11x17landscape", "portrait"), ) file.layout_block.items.append("indent = 0") file.header_block.items.append("tagline = ##f") file.header_block.items.append(f'title = "{title}"') abjad.show(file)
def main(name: str, ignore_accidentals_higher_than_semitone: bool = True) -> None: pitch = 7 note_duration = fractions.Fraction(1, 1) staff = [] for nth in range(23): diff_written = fractions.Fraction(nth - 11, 12) diff_true = fractions.Fraction(nth - 11, 6) note = abjad.Note(abjad.NamedPitch(pitch + diff_true), note_duration) if diff_written == 0: marking = None else: marking = "{}/{}".format(diff_written.numerator, diff_written.denominator) marking = abjad.MarkupCommand("fraction {} {}".format( abs(diff_written.numerator), diff_written.denominator)) if diff_written > 0: prefix = "+" else: prefix = "-" if marking: markup = abjad.Markup( [abjad.MarkupCommand("abs-fontsize", 8, [prefix, marking])], direction="up", ) abjad.attach(markup, note) staff.append(note) if nth == 11: abjad.Accidental.respell_with_flats(staff) abjad.Accidental.respell_with_sharps(staff[17:]) if ignore_accidentals_higher_than_semitone: staff = staff[5:18] staff = abjad.Staff(staff) abjad.attach(lily.mk_no_time_signature(), staff[0]) abjad.attach(abjad.TimeSignature((len(staff), 1)), staff[0]) abjad.attach( abjad.LilyPondLiteral( "\\override Score.SpacingSpanner.strict-note-spacing = ##t", format_slot="before", ), staff[0], ) abjad.attach( abjad.LilyPondLiteral("\\newSpacingSection", format_slot="before"), staff[0]) abjad.attach( abjad.LilyPondLiteral( "\\override Score.SpacingSpanner.base-shortest-duration = #(ly:make-moment" + " 1/16)", format_slot="before", ), staff[0], ) sco = abjad.Score([staff]) header_block = abjad.Block("header") header_block.piece = abjad.Markup( abjad.MarkupCommand( "center-column", [ abjad.MarkupCommand("fontsize", -1.5), abjad.MarkupCommand("smallCaps"), "12-tone accidentals", abjad.MarkupCommand("vspace", -0.35), ], )) lily.make_small_example(sco, name, header_block=header_block)
def illustrate_microtonal_pitches_for_sustaining_instrument( sustaining_instrument_tag: str, add_ratio: bool = False, make_clarinet_version: bool = True, ): # first collect all relevant pitches filtered_time_brackets = ot2_constants.time_brackets_container.TIME_BRACKETS.filter( sustaining_instrument_tag) relevant_pitches_as_exponents = set([]) for time_bracket in filtered_time_brackets: for tagged_event in time_bracket: if tagged_event.tag == sustaining_instrument_tag: pitch_or_pitches_per_event = tuple( filter( bool, tagged_event.get_parameter("pitch_or_pitches", flat=True))) for pitch_or_pitches in pitch_or_pitches_per_event: for pitch in pitch_or_pitches: relevant_pitches_as_exponents.add(pitch.exponents) print( f"{sustaining_instrument_tag} has to play {len(relevant_pitches_as_exponents)} different pitch classes!" ) relevant_pitches = sorted( map(parameters.pitches.JustIntonationPitch, relevant_pitches_as_exponents)) score_converter = _make_standard_score_converter() sequential_event = events.basic.SequentialEvent([]) for pitch in relevant_pitches: note = events.music.NoteLike([], 1) note.notation_indicators.cent_deviation.deviation = ( pitch.cent_deviation_from_closest_western_pitch_class) if add_ratio: note.notation_indicators.markup.content = ( f"{pitch.numerator}/{pitch.denominator}") note.notation_indicators.markup.direction = "^" is_sustaining_instrument_1 = ( sustaining_instrument_tag == ot2_constants.instruments.ID_SUS1) if is_sustaining_instrument_1 and make_clarinet_version: pitch += parameters.pitches.JustIntonationPitch("9/8") note.pitch_or_pitches = pitch # if is_sustaining_instrument_1: # ot2_constants.instruments.apply_clarient_fingerings(note) sequential_event.append(note) score = score_converter.convert( events.basic.SimultaneousEvent([sequential_event])) abjad.attach( abjad.LilyPondLiteral( "\\override Score.SpacingSpanner spacing-increment = 4"), abjad.get.leaf(score, 0), ) abjad.attach( abjad.LilyPondLiteral("\\omit Staff.BarLine"), abjad.get.leaf(score, 0), ) abjad.attach( abjad.LilyPondLiteral( "\\override Score.BarNumber.break-visibility = ##(#f #f #f)"), abjad.get.leaf(score, 0), ) abjad.attach( abjad.LilyPondLiteral("\\omit Staff.TimeSignature"), abjad.get.leaf(score, 0), ) score_block = abjad.Block("score") score_block.items.append(score) name = f"{sustaining_instrument_tag}_microtonal_pitches" if add_ratio: name += "_with_ratios" illustrate( name, score_block, add_book_preamble=False, add_ekmeheji=True, title= f'"Pitch list for {ot2_constants.instruments.INSTRUMENT_ID_TO_LONG_INSTRUMENT_NAME[sustaining_instrument_tag]}"', )
abjad.attach(abjad.Clef("bass"), staff1[0]) abjad.attach(abjad.Clef("treble"), staff1[4]) abjad.attach(abjad.Clef("treble^8"), staff1[-2]) h2(staff2) abjad.attach(abjad.Clef("bass"), staff2[0]) group = abjad.StaffGroup([staff1, staff2]) score = abjad.Score([group]) moment = "#(ly:make-moment 1 25)" abjad.setting(score).proportional_notation_duration = moment file = abjad.LilyPondFile( items=[ score, abjad.Block(name="layout"), ], includes=[ "/Users/evansdsg2/abjad/docs/source/_stylesheets/abjad.ily", "/Users/evansdsg2/abjad/docs/source/_stylesheets/ekmelos-ji-accidental-markups.ily", ], ) file.layout_block.items.append(r'\accidentalStyle "dodecaphonic"') abjad.show(file)
def _notate(name: str, instrument: str, scale: tuple) -> None: for add_harmonics in (False, True): if add_harmonics: harmonics_dict = { key: value[0] for key, value in globals_.RATIO2ARTIFICAL_HARMONIC_PITCHCLASS_AND_ARTIFICIAL_HARMONIC_OCTAVE.items() } if instrument == "violin": clef = abjad.Clef("treble") header_distance = -0.4 elif instrument == "viola": clef = abjad.Clef("alto") header_distance = -1 elif instrument == "cello": clef = abjad.Clef("bass") header_distance = -1 else: raise NotImplementedError(instrument) staff = abjad.Staff([]) for idx, pitch in enumerate(scale): abjad_pitch = lily.convert2abjad_pitch(pitch, globals_.RATIO2PITCHCLASS) if add_harmonics: ( _, octave, ) = globals_.RATIO2ARTIFICAL_HARMONIC_PITCHCLASS_AND_ARTIFICIAL_HARMONIC_OCTAVE[ pitch.register(0) ] harmonic_pitch = lily.convert2abjad_pitch( pitch + ji.JIPitch([octave]), harmonics_dict ) chord = abjad.Chord( sorted([abjad_pitch, harmonic_pitch]), abjad.Duration(1) ) abjad.tweak(chord.note_heads[1]).style = "harmonic" staff.append(chord) else: staff.append(abjad.Note(abjad_pitch, abjad.Duration(1))) abjad.attach(lily.mk_no_time_signature(), staff[0]) abjad.attach(abjad.TimeSignature((len(staff), 1)), staff[0]) abjad.attach(clef, staff[0]) abjad.attach( abjad.LilyPondLiteral( "\\override Score.SpacingSpanner.strict-note-spacing = ##t", format_slot="before", ), staff[0], ) abjad.attach( abjad.LilyPondLiteral("\\newSpacingSection", format_slot="before"), staff[0] ) abjad.attach( abjad.LilyPondLiteral( "\\override Score.SpacingSpanner.base-shortest-duration =" " #(ly:make-moment" + " 1/8)", format_slot="before", ), staff[0], ) abjad.attach( abjad.LilyPondLiteral("\\accidentalStyle dodecaphonic", "before"), staff[0], ) sco = abjad.Score([staff]) if add_harmonics: descr = "scale for {} with artificial harmonics".format(instrument) else: descr = "scale for {}".format(instrument) header_block = abjad.Block("header") header_block.piece = abjad.Markup( abjad.MarkupCommand( "center-column", [ abjad.MarkupCommand("fontsize", -1.5), abjad.MarkupCommand("smallCaps"), descr, abjad.MarkupCommand("vspace", header_distance), ], ) ) final_file_name = "{}/pictures/scale_{}".format(name, instrument) if add_harmonics: final_file_name = "{}_artificial_harmonics".format(final_file_name) lily.make_small_example(sco, final_file_name, header_block=header_block)
abjad.Meter.rewrite_meter(shard, abjad.Meter((4, 4))) abjad.label.with_start_offsets(voice, clock_time=True) for handler, staff in zip(handlers, group): handler(staff) for handler, staff in zip(handlers_2, group_2): handler(staff) for handler, staff in zip(handlers_3, quartet_group): handler(staff) moment = "#(ly:make-moment 1 10)" abjad.setting(score).proportional_notation_duration = moment block = abjad.Block(name="score") block.items.append(score) style = '"dodecaphonic"' layout = abjad.Block(name="layout") layout.items.append(rf"\accidentalStyle {style}") file = abjad.LilyPondFile(items=[ r'\include "/Users/gregoryevans/abjad/abjad/_stylesheets/ekmelos-ji-accidental-markups.ily"', r'\include "/Users/gregoryevans/scores/polillas/polillas/build/score_stylesheet.ily"', layout, block, ]) evans.make_sc_file( score=score,
def layout_block(self) -> abjad.Block: layout_block = abjad.Block("layout") layout_block.items.append(r"short-indent = {}\mm".format(self._margin)) layout_block.items.append(r"ragged-last = ##f") layout_block.items.append(r"indent = {}\mm".format(self._margin)) return layout_block
s.fork(oboe_part) s.fork(bassoon_part) # have the session wait for the child processes to finish (return) s.wait_for_children_to_finish() performance = s.stop_transcribing() score1 = performance.to_score() performance2 = s.start_transcribing() # start the oboe and bassoon parts as two parallel child processes s.fork(oboe_part) s.fork(bassoon_part) # have the session wait for the child processes to finish (return) s.wait_for_children_to_finish() s.stop_transcribing() score2 = performance2.to_score() score1_block = abjad.Block(name="score") score1_block.items.append(score1.to_abjad(wrap_as_file=False)) score2_block = abjad.Block(name="score") score2_block.items.append(score2.to_abjad(wrap_as_file=False)) lilypond_file = abjad.LilyPondFile(items=[score1_block, score2_block]) s.kill() def test_results(): return (performance, performance2, score1, score2, abjad.lilypond(lilypond_file))
def midi_block(self) -> abjad.Block: return abjad.Block(name="midi")
def run( self, metadata=None, midi=None, previous_metadata=None, ) -> abjad.LilyPondFile: """ Runs segment-maker. """ self._metadata = metadata self.midi = midi self.previous_metadata = previous_metadata score = self.score_template() # SKIPS ####################################################################### assert len(self.time_signatures) time_signatures_abjad = [ abjad.TimeSignature(_) for _ in self.time_signatures ] for time_sig in time_signatures_abjad: skip = abjad.Skip(1, multiplier=(time_sig)) # print(skip) score["Global_Context"].append(skip) global_context = score["Global_Context"] for time_sig in time_signatures_abjad: skip = abjad.Skip(1, multiplier=(time_sig)) # print(skip) score["Global_Context_II"].append(skip) # score["Global_Context_III"].append(skip) print("making skips") # select skips to attach TIME SIGNATURES mylist = self.time_signatures for i, element in enumerate(mylist): previous_element = mylist[i - 1] if i > 0 else None current_element = element # next_element = mylist[i+1] if i < len(mylist)-1 else None if current_element != previous_element: i = mylist.index(current_element) abjad.attach(time_signatures_abjad[i], global_context[i], tag=abjad.Tag("scaling time signatures")) # VOICE ONE ################################################################### voice_one = score['RH_Voice_One'] # initial rest if self.initial_rest_voice_one is not None: rh_voice_one_initial_rest = self._make_initial_rest( self.initial_rest_voice_one) voice_one.extend(rh_voice_one_initial_rest) print("making initial rest voice one") # make measures if self.durations_voice_one is not None and self.make_those_chords_voice_one is False: rh_voice_one_measures = self._make_measures( self.durations_voice_one, self.rhythm_maker_voice_one, self.pitches_voice_one, self.legato_voice_one, ) voice_one.extend(rh_voice_one_measures) print("making measures voice one") # make chords if self.chords_voice_one is not None: rh_voice_one_chords = self._make_chords(self.chords_voice_one) voice_one.extend(rh_voice_one_chords) print("making chords voice one") # make those chords if self.make_those_chords_voice_one is True: measures = self._make_those_chords( self.time_signatures, self.durations_voice_one, self.rhythm_maker_voice_one, self.pitches_voice_one, self.rest_interval_voice_one, ) voice_one.extend(measures) self._rewrite_meter_and_tie(voice_one, self.time_signatures) print( "making those chords voice one, rewriting meter, and attaching ties" ) # rewrite meter if self.durations_voice_one or self.chords_voice_one is not None: if self.make_those_chords_voice_one is False: voice_one = voice_one self._rewrite_meter(voice_one, self.time_signatures) print("rewriting meter voice one") # attach indicators if self.post_process_voice_one is not None: self.post_process_voice_one(voice_one, score) # VOICE TWO ################################################################### voice_two = score['RH_Voice_Two'] # initial rest if self.initial_rest_voice_two is not None: rh_voice_two_initial_rest = self._make_initial_rest( self.initial_rest_voice_two) voice_two.extend(rh_voice_two_initial_rest) print("making initial rest voice two") # make measures if self.durations_voice_two is not None and self.make_those_chords_voice_two is False: rh_voice_two_measures = self._make_measures( self.durations_voice_two, self.rhythm_maker_voice_two, self.pitches_voice_two, self.legato_voice_two, ) voice_two.extend(rh_voice_two_measures) print("making measures voice two") # make chords if self.chords_voice_two is not None: rh_voice_two_chords = self._make_chords(self.chords_voice_two) voice_two.extend(rh_voice_two_chords) print("making chords voice two") # make those chords if self.make_those_chords_voice_two is True: measures = self._make_those_chords( self.time_signatures, self.durations_voice_two, self.rhythm_maker_voice_two, self.pitches_voice_two, self.rest_interval_voice_two, ) voice_two.extend(measures) self._rewrite_meter_and_tie(voice_two, self.time_signatures) print( "making those chords voice two, rewriting meter, and attaching ties" ) # rewrite meter if self.durations_voice_two or self.chords_voice_two is not None: if self.make_those_chords_voice_two is False: voice_two = voice_two self._rewrite_meter(voice_two, self.time_signatures) print("rewriting meter voice two") # attach indicators if self.post_process_voice_two is not None: self.post_process_voice_two(voice_two, score) # VOICE THREE ################################################################# voice_three = score['RH_Voice_Three'] # initial rest if self.initial_rest_voice_three is not None: rh_voice_three_initial_rest = self._make_initial_rest( self.initial_rest_voice_three) voice_three.extend(rh_voice_three_initial_rest) print("making initial rest voice three") # make measures if self.durations_voice_three is not None and self.make_those_chords_voice_three is False: rh_voice_three_measures = self._make_measures( self.durations_voice_three, self.rhythm_maker_voice_three, self.pitches_voice_three, self.legato_voice_three, ) voice_three.extend(rh_voice_three_measures) print("making measures voice three") # make chords if self.chords_voice_three is not None: rh_voice_three_chords = self._make_chords(self.chords_voice_three) voice_three.extend(rh_voice_three_chords) print("making chords voice three") # make those chords if self.make_those_chords_voice_three is True: measures = self._make_those_chords( self.time_signatures, self.durations_voice_three, self.rhythm_maker_voice_three, self.pitches_voice_three, self.rest_interval_voice_three, ) voice_three.extend(measures) self._rewrite_meter_and_tie(voice_three, self.time_signatures) print( "making those chords voice three, rewriting meter, and attaching ties" ) # rewrite meter if self.durations_voice_three or self.chords_voice_three is not None: if self.make_those_chords_voice_three is False: voice_three = voice_three self._rewrite_meter(voice_three, self.time_signatures) print("rewriting meter voice three") # attach indicators if self.post_process_voice_three is not None: self.post_process_voice_three(voice_three) self._rewrite_meter(voice_three, self.time_signatures) # VOICE FOUR (LEFT HAND) ###################################################### voice_four = score['LH_Voice_Four'] # initial rest if self.initial_rest_voice_four is not None: lh_voice_four_initial_rest = self.initial_rest_voice_four voice_four.extend(lh_voice_four_initial_rest) print("making initial rest voice four") # make measures if self.durations_voice_four is not None and self.make_those_chords_voice_four is False: lh_voice_four_measures = self._make_measures( self.durations_voice_four, self.rhythm_maker_voice_four, self.pitches_voice_four, self.legato_voice_four, ) voice_four.extend(lh_voice_four_measures) print("making measures voice four") # make chords if self.chords_voice_four is not None: lh_voice_four_chords = self._make_chords(self.chords_voice_four) voice_four.extend(lh_voice_four_chords) print("making chords voice four") # make those chords if self.make_those_chords_voice_four is True: measures = self._make_those_chords( self.time_signatures, self.durations_voice_four, self.rhythm_maker_voice_four, self.pitches_voice_four, self.rest_interval_voice_four, ) voice_four.extend(measures) self._rewrite_meter_and_tie(voice_four, self.time_signatures) print( "making those chords voice four, rewriting meter, and attaching ties" ) # rewrite meter if self.durations_voice_four or self.chords_voice_four is not None: if self.make_those_chords_voice_four is False: voice_four = voice_four self._rewrite_meter(voice_four, self.time_signatures) print("rewriting meter voice four") # attach indicators if self.post_process_voice_four is not None: self.post_process_voice_four(voice_four, score) # VOICE FIVE (LEFT HAND) ###################################################### voice_five = score['LH_Voice_Five'] # initial rest if self.initial_rest_voice_five is not None: rh_voice_five_initial_rest = self._make_initial_rest( self.initial_rest_voice_five) voice_five.extend(rh_voice_five_initial_rest) print("making initial rest voice five") # make measures if self.durations_voice_five is not None and self.make_those_chords_voice_five is False: rh_voice_five_measures = self._make_measures( self.durations_voice_five, self.rhythm_maker_voice_five, self.pitches_voice_five, self.legato_voice_five, ) voice_five.extend(rh_voice_five_measures) print("making measures voice five") # make chords if self.chords_voice_five is not None: rh_voice_five_chords = self._make_chords(self.chords_voice_five) voice_five.extend(rh_voice_five_chords) print("making chords voice five") # make those chords if self.make_those_chords_voice_five is True: measures = self._make_those_chords( self.time_signatures, self.durations_voice_five, self.rhythm_maker_voice_five, self.pitches_voice_five, self.rest_interval_voice_five, ) voice_five.extend(measures) self._rewrite_meter_and_tie(voice_five, self.time_signatures) print( "making those chords voice five, rewriting meter, and attaching ties" ) # rewrite meter if self.durations_voice_five or self.chords_voice_five is not None: if self.make_those_chords_voice_five is False: voice_five = voice_five self._rewrite_meter(voice_five, self.time_signatures) print("rewriting meter voice five") # attach indicators if self.post_process_voice_five is not None: self.post_process_voice_five(voice_five) # STAFF GROUP ################################################################# # attach indicators if self.post_process_staffgroup is not None: self.post_process_staffgroup(score) # ELECTRONICS ################################################################# electronics = score['RH_Voice_One_Electronics'] # make chords if self.chords_voice_one_elec is not None: electronics_chords = self._make_chords(self.chords_voice_one_elec) electronics.extend(electronics_chords) if self.post_process_electronics is not None: self.post_process_electronics(electronics, score) # SCORE ####################################################################### if self.collect is False: organ_group = score['Piano_Staff'] abjad.setting(organ_group).midi_instrument = abjad.scheme.Scheme( 'Flute', force_quotes=True) abjad.attach(abjad.instruments.Flute(), organ_group[0][0][0]) lilypond_file = abjad.LilyPondFile.new( score, includes=self.includes, ) midi_block = abjad.Block(name="midi") layout_block = abjad.Block(name="layout") lilypond_file["score"].items.append(layout_block) lilypond_file["score"].items.append(midi_block) else: self._add_midi_instruments(score) lilypond_file = abjad.LilyPondFile.new( score, includes=self.includes, ) return lilypond_file