def test_Fader_19(): random.seed(48915) container = abjad.Container(r"c'4 d'8 e'8 f'4 ~ f'8. g'16") fader = auxjad.Fader(container) assert fader.mask == [1, 1, 1, 1, 1] fader = auxjad.Fader( container, fader_type='in', ) assert fader.mask == [0, 0, 0, 0, 0] fader() assert fader.mask == [0, 0, 0, 0, 0] fader() assert fader.mask == [0, 1, 0, 0, 0] fader() assert fader.mask == [0, 1, 1, 0, 0] staff = abjad.Staff(fader.current_window) assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 4/4 r4 d'8 e'8 r2 } """) fader.mask = [1, 0, 1, 1, 0] assert fader.mask == [1, 0, 1, 1, 0] notes = fader() staff = abjad.Staff(notes) abjad.f(staff) assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 4/4 c'4 r8 e'8 f'4.. r16 } """) fader.reset_mask() assert fader.mask == [0, 0, 0, 0, 0] notes = fader() staff = abjad.Staff(notes) abjad.f(staff) assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 4/4 R1 } """)
def test_Container___delitem___08(): """ Deletes leaf from nested container. """ voice = abjad.Voice("c'8 [ { d'8 e'8 } f'8 ]") leaves = abjad.select(voice).leaves() abjad.glissando(leaves) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando %! abjad.glissando(7) { d'8 \glissando %! abjad.glissando(7) e'8 \glissando %! abjad.glissando(7) } f'8 ] } """), abjad.f(voice) leaf = leaves[1] del voice[1][0] assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando %! abjad.glissando(7) { e'8 \glissando %! abjad.glissando(7) } f'8 ] } """), abjad.f(voice) assert abjad.wf.wellformed(voice) assert abjad.wf.wellformed(leaf)
def __call__( self, segment_metadata=None, previous_segment_metadata=None, ): r'''Calls segment-maker. Returns LilyPond file. ''' self._make_score() self._make_lilypond_file() self._configure_lilypond_file() self._interpret_music_makers() self._populate_time_signature_context() self._adjust_stems() self._attach_tempo_indicators() #self._attach_fermatas() self._add_manual_page_breaks() self._annotate_stages() self._annotate_leaf_indices() self._interpret_music_handlers() self._attach_slurs() self._tweak_tuplet_brackets() self._add_final_bar_line() self._add_final_markup() self._raise_duration() score_block = self.lilypond_file['score'] score = score_block['Score'] if not abjad.inspect_(score).is_well_formed(): for container in abjad.iterate(score).by_class(abjad.Container): if len(container) == 0: print(container) abjad.f(container) string = \ abjad.inspect_(score).tabulate_well_formedness_violations() string = '\n' + string raise Exception(string) segment_metadata = None return self.lilypond_file, segment_metadata
def __handle_save_command(self, command: SaveCommand) -> List[Command]: path = command.path # the path to save file to previous_save_file = self.current_file_path if path is None: # if there isn't a file currently open, warn if self.current_file_path is None: return [self.__get_empty_name_warning()] # else set the command file to the current file else: path = self.current_file_path file_status = self.__save_path_valid(path) if len(file_status) != 0 and not command.forced: return file_status self.current_file_path = path # attempt to write the score to the file try: with open(self.current_file_path, "w") as f: sys.stdout = f # abjad prints to stdout and we don't want that abjad.f(self.score) self.changed_since_saving = False except Exception as e: # restore the previous file name if something went amiss (we didn't save...) self.current_file_path = previous_save_file # TODO: BETTER EXCEPTIONS return [ SetStatusLineTextCommand("Error writing to file.", Position.CENTER) ] # if everything went fine, let the user know return [ self.get_file_name_command(), SetStatusLineTextCommand("Saved.", Position.CENTER), ]
import abjad import abjadext.rmakers staff = abjad.Staff( segment = ( abjad.PitchSegment( [ "e'", "ef'", "c'" "cs'" ] ) ) rhs = [(1, 4), (3, 8), (2, 4), (1, 8)] rhythms = [abjad.Duration(x) for x in rhs] zip(pitches, abjad.select(rhythms).logical_ties(pitched=True): for leaf in tie: leaf.written_pitch = pitch) ) abjad.f(staff)
import abjad import evans staff = abjad.Staff([abjad.Voice("c'4 c'4 c'4 c'4", name="Voice 1")], name="Staff 1") h = evans.GettatoHandler() h(staff) for voice in abjad.iterate(staff).components(abjad.Staff): print(voice.name) abjad.f(voice)
print(" ") file_name = os.path.basename(__file__) file_name = os.path.splitext(file_name)[0] illust_path = "../../muda_score/segments/illustrations" new_file = illust_path+"/"+str(file_name)+".ly" print(new_file) container = abjad.Container("c''4 d''8 e''16 e''32 e''4 e''4 e''4") meters = [(3, 4), (4, 4), (5, 4)] meters = [abjad.Meter(_) for _ in meters] argument = [(0, 4), (4, 4), (8, 4), (12, 4), (16, 4)] for meter in abjad.Meter.fit_meters(container, meters): print(meter.implied_time_signature) # for staff in score: # for container in staff: # leaf = abjad.get.leaf(container, 0) # time_signature = abjad.get.indicator(leaf, abjad.TimeSignature) # abjad.Meter.rewrite_meter(container[:], time_signature) # # abjad.f(container)
dur = AnnotatedDuration((3, 8)) dur.annotation = "note" print(dur.annotation) staff = abjad.Staff("c'1 d'1 c'1. d'1. c'1. d'1. ") abjad.hairpin("p < f", staff[:]) abjad.override(staff).dynamic_line_spanner.staff_padding = 3 durations = [(3, 4), (4, 4), (5, 4)] result = abjad.mutate.split( staff[:], durations, cyclic=True, ) abjad.f(result) meters = [abjad.Meter(_) for _ in durations] result2 = abjad.select(staff).leaves() result2 = result2.group_by # for measure, time_sig in zip(result2, meters): # print(measure) # abjad.Meter.rewrite_meter(measure, time_sig) # time_signatures = [] # for item in in_time_signatures: # time_signatures.append(abjad.Meter(item)) # abjad.mutate().split(music, in_time_signature, cyclic=True) # # selection
import abjad import tsmakers from abjadext import rmakers timespan_maker = tsmakers.DependentTimespanMaker( include_inner_starts=True, include_inner_stops=True, voice_names=('Viola Voice', ), ) abjad.f(timespan_maker) timespan_list = abjad.TimespanList([ tsmakers.PerformedTimespan( voice_name='Viola Voice', start_offset=(1, 4), stop_offset=(1, 1), ), tsmakers.PerformedTimespan( voice_name='Viola Voice', start_offset=(3, 4), stop_offset=(3, 2), ), ]) music_specifiers = { 'Violin Voice': None, 'Cello Voice': None, } target_timespan = abjad.Timespan((1, 2), (2, 1)) timespan_list = timespan_maker(
select = selector.group_by_measure() for time, measure in zip(time_signatures, measures): abjad.mutate(measure).rewrite_meter( time, maximum_dot_count=2, ) score = organi.ScoreTemplate() score = score() this = score['Piano_Staff'][0][1] this.append("c,,4") abjad.attach(abjad.TimeSignature((3, 4)), this[0]) staff_change = abjad.StaffChange(score['LH_Staff']) abjad.attach(staff_change, rh_staff[i]) abjad.f(this) staff_group = abjad.StaffGroup() staff1 = abjad.Staff("e4 f g f e") staff2 = abjad.Staff("c4 d e d c") staff_group.extend([staff1, staff2]) selection = abjad.select(staff_group[1]).leaves().logical_ties(pitched=True) length = len(selection) for lo, i in zip(selection, range(length)): pass def _make(music): del music[-1] abjad.attach(abjad.Fermata(), music[-1]) return music
site = "abjad.ScoreTemplate._make_global_context()" tag = abjad.Tag(site) global_rests = abjad.Context( lilypond_type="GlobalRests", name="Global_Rests", tag=tag, ) global_skips = abjad.Context( lilypond_type="GlobalSkips", name="Global_Skips", tag=tag, ) global_context = abjad.Context( [global_rests, global_skips], lilypond_type="GlobalContext", simultaneous=True, name="Global_Context", tag=tag, ) return global_context ### PUBLIC PROPERTIES ### @property def voice_abbreviations(self): """Gets voice abbreviations""" return super(ScoreTemplate, self).voice_abbreviations if __name__ == '__main__': score = ScoreTemplate() score_template = score() abjad.f(score_template)
import abjad def tremolo(speed): """ Makes a tremolo mark on single leaf. """ if isinstance(speed, int): while (speed == 8) or (speed == 16) or (speed == 32) or (speed == 64): return abjad.LilyPondLiteral(f":{speed}", "after") else: raise ValueError("int(4 || 8 || 16 || 32 || 64) expected") if __name__ == '__main__': one = tremolo(32) abjad.f(one) one = tremolo(8) abjad.f(one) one = tremolo(16) abjad.f(one) one = tremolo(64) abjad.f(one) #one = tremolo(99) #abjad.f(one) #one = tremolo('32') #abjad.f(one)
voice_10_timespan_list, voice_11_timespan_list, voice_12_timespan_list, voice_13_timespan_list, voice_14_timespan_list, voice_15_timespan_list, voice_16_timespan_list, voice_17_timespan_list, voice_18_timespan_list, voice_19_timespan_list, voice_20_timespan_list, voice_21_timespan_list, ] all_timespan_lists = abjad.TimespanList([]) all_timespan_lists = make_showable_list(all_timespans) # abjad.show(all_timespan_lists, # key='annotation', # scale=2 # ) offset_counter = abjad.meter.OffsetCounter(all_timespan_lists[:]) permitted_meters = abjad.meter.MeterList([(3, 4), (4, 4), (5, 4)]) fitted_meters = abjad.meter.Meter.fit_meters( argument=offset_counter, meters=permitted_meters, ) # abjad.show(fitted_meters, range_=(0, 5)) for x in fitted_meters: abjad.f(x)
import abjad segment = ( abjad.PitchSegment(["e'", "c'", "ds'", "cs'"]).retrograde().invert(3).multiply(2) ) durations = [(1, 4), (1, 4), (1, 4), (3, 8), (5, 8)] maker = abjad.LeafMaker() leaves = maker(segment, durations) staff1 = abjad.Staff(leaves) abjad.f(staff1) for pitches, rhythms
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) try: with abjad.Timer() as timer: abjad.persist(lilypond_file).as_midi(midi, remove_ly=True) count = int(timer.elapsed_time) counter = abjad.String("second").pluralize(count)
# abjad.attach(abjad.Clef("bass_8"), F_staff[0]) # staff = abjad.StaffGroup([G_staff, F_staff], lilypond_type="PianoStaff") # abjad.f(staff) # NO MICROTONAL for item, i in zip(num_pitches, range(len(num_pitches))): if isinstance(item, float): item = item - 0.5 num_pitches[i] = item # num_pitches.sort() maker = abjad.LeafMaker() num_pitches_notes = maker(num_pitches, (1, 1)) num_pitches_notes = abjad.Staff(num_pitches_notes) num_pitches_score = abjad.LilyPondFile.new(music=num_pitches_notes) abjad.f(num_pitches_score) pitches_up = [] pitches_down = [] pitch_range = abjad.PitchRange("[C2, G7]") treble_range = abjad.pitch.PitchRange("[C4, +inf]") for note in num_pitches: test1 = note in pitch_range test2 = note in treble_range if test1 is True and test2 is True: pitches_up.append(note) if test1 is True and test2 is False: pitches_down.append(note) random.seed(0)
import abjad def clef(name): """ Makes a clef before a specific leaf """ clef = abjad.Clef(name) if isinstance(clef, abjad.Clef): return abjad.LilyPondLiteral(f"{format(clef, 'lilypond')}", "before") if __name__ == '__main__': clef = clef('bass') abjad.f(clef)