예제 #1
0
    def dump(self, score, fname):
        res= score_template
        score_dict= {}
        num, denom= score.time_signature
        score_dict['time_key']= '%s/%s' % (num, 2**denom)
        
        instruments_str= []
        i= 0
        for instrument in score.instruments:
            notes= score.get_notes(relative_to='semi_breve', instrument=instrument)
            chords= ChordGroup.group_notes(notes)
            groups= FigureGroup.group_figures(chords)

            notes_str= ' '.join((g.to_string() for g in groups))
            instrument_str= instrument_template % dict(notes=notes_str)
            instruments_str.append(instrument_str)

        if len(score.annotations) > 0:
            annotations= score.get_annotations(relative_to='semi_breve')

            annotations_str= []
            for a in annotations:
                annotations_str.append('"%s"%s' % (a.text, get_duration_str(a.duration)))
            
            annotations_str= annotation_template % dict(words=' '.join(annotations_str)) 
            instruments_str.append(annotations_str)
                
            
        score_dict['instruments']= '\n\n'.join(instruments_str)
        res%=score_dict
        f= open(fname, 'w')
        f.write(res)
        f.close()
예제 #2
0
from electrozart import PlayedNote
from utils.fraction import Fraction
from base import ChordGroup, FigureGroup

def note(start, duration):
    return PlayedNote(1, start, duration, 100)

tresillo= Fraction(1,3)
corchea= Fraction(1,2)
notes= [note(0, tresillo), 
        note(tresillo, tresillo), 
        note(tresillo*2, tresillo),
        note(1, tresillo),
        note(1, tresillo),
        note(1, tresillo),
        note(tresillo + 1, tresillo*2),
        note(2, corchea),
        note(corchea+2, corchea)]



chords= ChordGroup.group_notes(notes)       
figures= FigureGroup.group_figures(chords)