def to_png(self): c = Composition() c.set_author(self.author) c.set_title(self.title) c.add_track(self.track) ly_string = LilyPond.from_Composition(c) #print ly_string LilyPond.to_png(ly_string, self.title)
def index(): if request.method == 'POST': keys = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] meters = [(2,2), (2,4), (3,4), (4,4)] bars = int(request.form['bars']) key = keys[int(request.form['key'])] meter = meters[int(request.form['meter'])] scale = int(request.form['scale']) composition = Composition() composition.set_author("by givemeasheet.com", "*****@*****.**") composition.set_title("%d bars exercise in %s" % (bars, key)) track = Track(Guitar()) dificulty = 3 if scale == 0: scale = scales.diatonic(key) scale_name = "Natural Major" elif scale == 1: scale = scales.natural_minor(key) scale_name = "Natural Minor" elif scale == 2: scale = scales.harmonic_minor(key) scale_name = "Minor Harmonic" elif scale == 3: scale = scales.melodic_minor(key) scale_name = "Minor Melodic" composition.subtitle = scale_name for bar in range(0,bars): bar = Bar(key, meter) while not bar.is_full(): # Random note index = randrange(dificulty) note = Note(scale[index]) possibles = get_possibles(bar) bar.place_notes(note, possibles[randrange(len(possibles))]) track.add_bar(bar) composition.add_track(track) l = LilyPond.from_Composition(composition) u = uuid.uuid1() file_name = "/var/www/givemeasheet/givemeasheet/static/sheets/%s" % u.hex LilyPond.save_string_and_execute_LilyPond(l, file_name, "-fpng") sheet="/static/sheets/%s.png" % os.path.basename(file_name) midi="/static/sheets/%s.midi" % os.path.basename(file_name) MidiFileOut.write_Composition("%s.midi" % file_name, composition) return render_template('index.html', sheet=sheet, midi=midi) else: return render_template('index.html')