def parse_tones_poly(self, filename, model_name): notes = Staff() # remove measure and tacts notes.remove_commands.append('Time_signature_engraver') notes.remove_commands.append('Bar_engraver') mala_voice = "" vela_voice = "" tones_dict = self.get_tones_dict_poly() for mala_tone, tone_length in tones_dict['m']: duration = self.get_duration_label(tone_length) if duration: mala_voice += mala_tone + duration + " " for vela_tone, tone_length in tones_dict['v']: duration = self.get_duration_label(tone_length) if duration: vela_voice += vela_tone + duration + " " mala_voice = Voice(mala_voice, name='mala voice') literal = LilyPondLiteral(r'\voiceOne') attach(literal, mala_voice) vela_voice = Voice(vela_voice, name='vela voice') literal = LilyPondLiteral(r'\voiceTwo') attach(literal, vela_voice) container = Container([mala_voice, vela_voice]) container.is_simultaneous = True notes.append(container) PersistenceManager(client=notes).as_pdf( os.path.join(SHEETS_DIR, model_name, filename))
def get_melody_staff(instrument_class, instrument_name, short_instrument_name): staff = Staff([]) staff.name = instrument_name instrument = instrument_class(instrument_name=instrument_name, short_instrument_name=short_instrument_name) attach(instrument, staff) add_time_signature(staff) add_tempo(staff) if instrument_name == 'Cello': attach(Clef('bass'), staff) return staff
def __call__(self): # Violin violin_staff = Staff( [Voice(name='Violin Voice')], name='Violin Staff', context_name='ViolinStaff', ) violin_tag = LilyPondCommand(r"tag #'violin", format_slot='before') attach(violin_tag, violin_staff) attach(Clef('treble'), violin_staff) attach(instrumenttools.Violin(), violin_staff) set_(violin_staff).midi_instrument = schemetools.Scheme( 'violin', force_quotes=True) # Viola viola_staff = Staff( [Voice(name='Viola Voice')], name='Viola Staff', context_name='ViolaStaff', ) viola_tag = LilyPondCommand(r"tag #'viola", format_slot='before') attach(viola_tag, viola_staff) attach(Clef('alto'), viola_staff) attach(instrumenttools.Viola(), viola_staff) set_(viola_staff).midi_instrument = schemetools.Scheme( 'viola', force_quotes=True) # Cello cello_staff = Staff( [Voice(name='Cello Voice')], name='Cello Staff', context_name='CelloStaff', ) cello_tag = LilyPondCommand(r"tag #'cello", format_slot='before') attach(cello_tag, cello_staff) attach(Clef('bass'), cello_staff) attach(instrumenttools.Cello(), cello_staff) set_(cello_staff).midi_instrument = schemetools.Scheme( 'cello', force_quotes=True) # Everything else staff_group = StaffGroup( [violin_staff, viola_staff, cello_staff], name='Trio Staff Group', ) score = Score( [staff_group], name='Trio Score', ) return score
def get_synthesizer_staff(): staff = Staff([], name='Synthesizer Staff') staff.name = 'Synthesizer' clef = Clef('treble') attach(clef, staff) synth = Instrument( instrument_name='Synthesizer', short_instrument_name='Syn' ) attach(synth, staff) add_time_signature(staff) add_tempo(staff) return staff
def parse_tones_mono(self, filename, model_name): notes = Staff() # remove measure and tacts notes.remove_commands.append('Time_signature_engraver') notes.remove_commands.append('Bar_engraver') for tone, tone_length in self.get_tones_dict_mono(): duration = self.get_duration_label(tone_length) if duration: tone += duration notes.append(tone) PersistenceManager(client=notes).as_pdf( os.path.join(SHEETS_DIR, model_name, filename))
def get_piano_staff(): piano_staff = StaffGroup() piano_staff.name = 'Piano' piano_staff.context_name = 'PianoStaff' upper_staff = Staff([]) upper_staff.name = 'Piano upper' add_time_signature(upper_staff) add_tempo(upper_staff) lower_staff = Staff([]) lower_staff.name = 'Piano lower' add_time_signature(lower_staff) add_tempo(lower_staff) piano_staff.append(upper_staff) piano_staff.append(lower_staff) piano = Piano(short_instrument_name='Pno') attach(piano, piano_staff) bass_clef = Clef('bass') attach(bass_clef, lower_staff) return piano_staff
def getSheetMusic(Melody, scale): print(scale) melodyNotes = [note_name(n,name_to_number(scale[0])).lower() for n in [note.value for note in Melody]] print(melodyNotes) durations = [int(1/note.dur) for note in Melody] octaves = [note.octave for note in Melody] abjadArr = [] for i in zip(melodyNotes, durations, octaves): abjadArr.append(i[0] + octaveDict[i[2]] + str(i[1])) abjadString = ' '.join(abjadArr) staff = Staff(abjadString) #attach(KeySignature('c','major'), staff[0]) attach(KeySignature(scale[0],scale[1]), staff[0]) attach(TimeSignature((3,4)),staff[0]) #attach(Clef("bass"), staff[0]) show(staff)
def make_bartok_score(): score = Score([]) piano_staff = StaffGroup([], context_name='PianoStaff') upper_staff = Staff([]) lower_staff = Staff([]) piano_staff.append(upper_staff) piano_staff.append(lower_staff) score.append(piano_staff) upper_measures = [] upper_measures.append(Measure((2, 4), [])) upper_measures.append(Measure((3, 4), [])) upper_measures.append(Measure((2, 4), [])) upper_measures.append(Measure((2, 4), [])) upper_measures.append(Measure((2, 4), [])) lower_measures = copy.deepcopy(upper_measures) upper_staff.extend(upper_measures) lower_staff.extend(lower_measures) upper_measures[0].extend("a'8 g'8 f'8 e'8") upper_measures[1].extend("d'4 g'8 f'8 e'8 d'8") upper_measures[2].extend("c'8 d'16 e'16 f'8 e'8") upper_measures[3].append("d'2") upper_measures[4].append("d'2") lower_measures[0].extend("b4 d'8 c'8") lower_measures[1].extend("b8 a8 af4 c'8 bf8") lower_measures[2].extend("a8 g8 fs8 g16 a16") upper_voice = Voice("b2", name='upper voice') command = indicatortools.LilyPondCommand('voiceOne') attach(command, upper_voice) lower_voice = Voice("b4 a4", name='lower voice') command = indicatortools.LilyPondCommand('voiceTwo') attach(command, lower_voice) lower_measures[3].extend([upper_voice, lower_voice]) lower_measures[3].is_simultaneous = True upper_voice = Voice("b2", name='upper voice') command = indicatortools.LilyPondCommand('voiceOne') attach(command, upper_voice) lower_voice = Voice("g2", name='lower voice') command = indicatortools.LilyPondCommand('voiceTwo') attach(command, lower_voice) lower_measures[4].extend([upper_voice, lower_voice]) lower_measures[4].is_simultaneous = True clef = Clef('bass') attach(clef, lower_staff) dynamic = Dynamic('pp') attach(dynamic, upper_measures[0][0]) dynamic = Dynamic('mp') attach(dynamic, upper_measures[1][1]) dynamic = Dynamic('pp') attach(dynamic, lower_measures[0][1]) dynamic = Dynamic('mp') attach(dynamic, lower_measures[1][3]) score.add_final_bar_line() selector = select().by_leaf(flatten=True) upper_leaves = selector(upper_staff) lower_leaves = selector(lower_staff) beam = Beam() attach(beam, upper_leaves[:4]) beam = Beam() attach(beam, lower_leaves[1:5]) beam = Beam() attach(beam, lower_leaves[6:10]) slur = Slur() attach(slur, upper_leaves[:5]) slur = Slur() attach(slur, upper_leaves[5:]) slur = Slur() attach(slur, lower_leaves[1:6]) crescendo = Crescendo() attach(crescendo, upper_leaves[-7:-2]) decrescendo = Decrescendo() attach(decrescendo, upper_leaves[-2:]) markup = Markup('ritard.') text_spanner = spannertools.TextSpanner() override(text_spanner).text_spanner.bound_details__left__text = markup attach(text_spanner, upper_leaves[-7:]) tie = Tie() attach(tie, upper_leaves[-2:]) note_1 = lower_staff[-2]['upper voice'][0] note_2 = lower_staff[-1]['upper voice'][0] notes = [note_1, note_2] tie = Tie() attach(tie, notes) return score
def __call__(self): voice = Voice(name='Example Voice') staff = Staff([voice], name='Example Staff') score = Score([staff], name='Example Score') return score