Ejemplo n.º 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()
Ejemplo n.º 2
0
    def to_string(self, multiply_duration=1):
        chord_duration= min(self.notes, key=lambda x:x.duration).duration
        chord_notes= [n.copy() for n in self.notes]
        for n in chord_notes:
            n.duration= chord_duration
        durations= split_durations(chord_duration, multiply_duration)

        res= []
        notes_str= ' '.join((get_pitch_str(n) for n in chord_notes))
        for duration in durations:
            chord_str= '<%s>%s' % (notes_str, get_duration_str(duration))
            res.append(chord_str)
        
        res= ' ~'.join(res)
        if self.duration > chord_duration:
            #import ipdb;ipdb.set_trace()
            chord_notes= [n.copy() for n in self.notes if n.duration > chord_duration]
            for n in chord_notes:
                n.duration-= chord_duration
            res= '%s ~ %s' % (res, ChordGroup(chord_notes).to_string())
        return res