def __init__(self, genome, evolution, generation, individual_id, parent_1 = '', parent_2 = '', grade = 0.0, status = 'created'): self.evolution = evolution self.generation = generation self.parent_1 = parent_1 self.parent_2 = parent_2 self.grade = grade self.status = status self.individual_id = individual_id self.set_genome(genome) self.mingus_track = Track() for n in self.note_list: self.mingus_track.add_notes(n.mingus_note, n.mingus_duration) self.name = self.evolution + '-' + str(self.generation) + '-' + str(self.individual_id) return
def setUp(self): self.commonbar = Bar() self.ebar = Bar('E', (4, 4)) self.fbar = Bar('F', (6, 8)) self.tbar = Bar('C', (4, 4)) self.mbar = Bar('C', (4, 4)) for y in [self.commonbar, self.ebar, self.fbar]: map(lambda x: y + x, ['C', 'E', 'G', 'B']) map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [ 'C', 'E', 'G', 'B', 'C', 'E', ]) map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E']) map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C']) self.track1 = Track() self.track1 + self.commonbar self.track2 = Track() self.track2 + self.commonbar self.track2 + self.ebar self.composition1 = Composition() self.composition1.add_track(self.track1) self.composition2 = Composition() self.composition2.add_track(self.track1) self.composition2.add_track(self.track2)
def test_transpose(self): t = Track() t + "C" t + "E" t.transpose("3") s = Track() s + "E" s + "G#" self.assertEqual(s, t)
def _set_up_metronome(self): metronome = Track() bar = Bar('C', (4, 4)) metronome.add_bar(bar) kick = MidiPercussion.BassDrum1 kick.velocity = 120 for i in range(4): bar.place_notes(kick, value.quarter) return metronome
def generate_pattern(progression_list, key = "C", pattern_index = 0, nb_bars=1): pattern = patterns.PATTERNS[pattern_index] t = Track() for progression in progression_list: progression = progression_to_int(progression) for p in progression : # permet d'avancer dans la progression des mesures previews_note = None p_key = get_progression_key(p, key) b = Bar(key, (4, 4)) position_note = 0 already_used=[] for pattern_note in pattern : if position_note not in already_used : is_chord = chord_length(pattern_note, pattern, position_note) if is_chord[2] : note_list = [] # c est un accord for p_note in pattern[is_chord[0]:is_chord[1]+1] : note_str = get_note_pattern(p_note, p_key) note = Note(note_str, p_note[5]) if previews_note is not None: if p_note[4]=='+': if int(note) < previews_note : note.octave_up() elif p_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) note_list.append(note) for n in range(is_chord[0], is_chord[1]+1): already_used.append(n) b.place_notes(note_list, pattern_note[1]) else : note_str = get_note_pattern(pattern_note, p_key) note = Note(note_str, pattern_note[5]) if previews_note is not None: if pattern_note[4]=='+': if int(note) < previews_note : note.octave_up() elif pattern_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) b.place_notes(note, pattern_note[1]) already_used.append(position_note) position_note+=1 t.add_bar(b) return t
def test_transpose(self): t = Track() t + 'C' t + 'E' t.transpose('3') s = Track() s + 'E' s + 'G#' self.assertEqual(s, t)
def _create_track(self): tp = Track(self.i) b = Bar( (4,4) ) for (i, note) in enumerate( self.bassline ): if note in ['r','R']: tp.add_notes(None,4) continue tp + (note+'-'+ str(self.octave[i])) return tp
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')
def play_prog( self ): ''' Saves chords to track and plays using fluidsynth. ''' ch = progressions.to_chords(self.get_progression(self.progression), self.get_key()) nc = map(NoteContainer, ch) t = Track() for chord in nc: t.add_notes(chord) fluidsynth.play_Track(t)
def save_midi( self ): '''Opens save dialog, converts progression list to chords in track, saves track midi. ''' file_name = tkFileDialog.asksaveasfilename() ch = progressions.to_chords(self.get_progression(self.progression), self.get_key()) nc = map(NoteContainer, ch) t = Track() for chord in nc: t.add_notes(chord) MidiFileOut.write_Track( file_name,t)
def toTrack(key, meter, melody): _, base = meter t = Track() for mb in melody: b = Bar(key, meter) for mn in mb.split(): nr = mn.split(':') n = nr[0] r = base if len(nr) > 1: r = int(nr[1]) ok = b.place_notes(n, r) t.add_bar(b) return t
class song(object): def __init__(self, genome, evolution, generation, individual_id, parent_1 = '', parent_2 = '', grade = 0.0, status = 'created'): self.evolution = evolution self.generation = generation self.parent_1 = parent_1 self.parent_2 = parent_2 self.grade = grade self.status = status self.individual_id = individual_id self.set_genome(genome) self.mingus_track = Track() for n in self.note_list: self.mingus_track.add_notes(n.mingus_note, n.mingus_duration) self.name = self.evolution + '-' + str(self.generation) + '-' + str(self.individual_id) return @property def selected(self): return self.status == 'selected' def set_genome(self, genome): if type(genome) is list: self.note_list = genome self.genome = rttl.dump(genome) elif type(genome) is unicode: self.genome = genome self.note_list = rttl.parse(genome) self.int_list = rttl.to_int(self.note_list)
def use_phrase(phrase_list, progression_list, nb_bars, pattern_index, mode='none', key="C"): print(str(progression_list)) t = Track() if nb_bars == 1 : nb_p = 0 for progression in progression_list[0] : if nb_p%4 == 0 : phrase = get_phrase(progression, phrase_list) print("boucle phrase doit apparaitre trois fois") last_note = None nb_bars = 0 for bars in phrase[1][3] : list_bar = generate_bar(last_note, bars, key, mode, progression, progression_list, nb_p+nb_bars, pattern_index) b = list_bar[0] last_note = list_bar[1] nb_bars+=1 t.add_bar(b) last_bar = bars if phrase[1][1] < 4 : # composer le reste TODO en attendant on met du vide last_bar_notes = list_bar[2] print("lala "+str(last_bar_notes)) next_index = nb_p+4 if next_index < 9 : next_progression = progression_list[0][next_index] next_phrase = get_phrase(next_progression, phrase_list) first_bar = next_phrase[1][3][0] first_bar_list = generate_bar(last_note, first_bar, key, mode, next_progression, progression_list, nb_p+4, pattern_index) first_bar_notes = first_bar_list[2] nb_notes_to_generate = get_nb_note_needed(last_bar, first_bar) print "****************** je vais generer la transition ! ****************" transition_bar = generate_transition(first_bar_notes, last_bar_notes, nb_notes_to_generate, pattern_index, key) print "***************************** Fini ! ******************************" for transition in transition_bar : t.add_bar(transition) """for i in range(len(transition_bar)): t.add_bar(transition_bar[i])""" else : list_end = generate_end_bars(bars, list_bar[2], pattern_index, key, mode) for end_bar in list_end : t.add_bar(end_bar) break nb_p +=1 else : nb_p +=1 continue return t
class song(object): def __init__( self, genome, evolution, generation, individual_id, parent_1="", parent_2="", grade=0.0, status="created" ): self.evolution = evolution self.generation = generation self.parent_1 = parent_1 self.parent_2 = parent_2 self.grade = grade self.status = status self.individual_id = individual_id self.set_genome(genome) self.mingus_track = Track() for n in self.note_list: self.mingus_track.add_notes(n.mingus_note, n.mingus_duration) self.name = self.evolution + "-" + str(self.generation) + "-" + str(self.individual_id) return @property def selected(self): return self.status == "selected" def set_genome(self, genome): if type(genome) is list: self.note_list = genome self.genome = rttl.dump(genome) elif type(genome) is unicode: self.genome = genome self.note_list = rttl.parse(genome) self.int_list = rttl.to_int(self.note_list)
def __init__( self, genome, evolution, generation, individual_id, parent_1="", parent_2="", grade=0.0, status="created" ): self.evolution = evolution self.generation = generation self.parent_1 = parent_1 self.parent_2 = parent_2 self.grade = grade self.status = status self.individual_id = individual_id self.set_genome(genome) self.mingus_track = Track() for n in self.note_list: self.mingus_track.add_notes(n.mingus_note, n.mingus_duration) self.name = self.evolution + "-" + str(self.generation) + "-" + str(self.individual_id) return
while repeat >= 0: for i in range(len(composition.tracks)): m.tracks[i].play_Track(composition.tracks[i]) repeat -= 1 return m.write_file(file, verbose) if __name__ == '__main__': from mingus.containers.NoteContainer import NoteContainer from mingus.containers.Bar import Bar from mingus.containers.Track import Track from mingus.containers.Instrument import MidiInstrument b = Bar() b2 = Bar('Ab', (3, 4)) n = NoteContainer(['A', 'C', 'E']) t = Track() b + n b + [] b + n b + n b2 + n b2 + n b2 + [] t + b t + b m = MidiInstrument() m.instrument_nr = 13 t.instrument = m t.name = 'Track Name Test' write_NoteContainer('test.mid', n) write_Bar('test2.mid', b)
def generate_pattern(progression_list, key = "C", pattern = ((1, 4, 1, "none", '=', 3), (3, 4, 2,"none", '+', 3), (5, 4, 3, "none", '+', 3), (6, 4, 4, "none", '+', 3)), nb_bars=1): #pattern = ((1, 4, 1, "none", '=', 3), (5, 4, 1, "none", '+', 3), (1, 4, 2, "none", '+', 3), (6, 4, 2, "none", '+', 3), (1, 4, 3, "none", '=', 3), (5, 4, 3, "none", '+', 3), (1, 4, 4, "none", '+', 3), (6, 4, 4, "none", '+', 3)) #pattern = ((1, 8, 1, "none", '=', 2), (5, 8, 1, "none", '+', 2), (1, 8, 1.5, "none", '=', 2), (5, 8, 1.5, "none", '+', 2), (2, 8, 2, "diese", '=', 2), (3, 8, 2.5, "none", '+', 2), (1, 8, 3, "none", '=', 2), (5, 8, 3, "none", '+', 2), (1, 8, 3.5, "none", '=', 2), (5, 8, 3.5, "none", '+', 2), (2, 8, 4, "diese", '=', 2), (3, 8, 4.5, "none", '+', 2)) #pattern = ((1, 8, 1, "none", '=', 3), (5, 8, 1, "none", '+', 3), (1, 8, 1.5, "none", '=', 3), (5, 8, 1.5, "none", '+', 3), (2, 8, 2, "diese", '-', 3), (3, 8, 2.5, "none", '+', 3), (1, 8, 3, "none", '=', 3), (5, 8, 3, "none", '+', 3), (1, 8, 3.5, "none", '=', 3), (5, 8, 3.5, "none", '+', 3), (1, 8, 4, "none", '=', 3), (6, 8, 4, "none", '+', 3), (1, 8, 4.5, "none", '=', 3), (6, 8, 4.5, "none", '+', 3)) t = Track() for progression in progression_list: progression = progression_to_int(progression) for p in progression : # permet d'avancer dans la progression des mesures previews_note = None p_key = get_progression_key(p, key) b = Bar(key, (4, 4)) position_note = 0 already_used=[] for pattern_note in pattern : if position_note not in already_used : is_chord = chord_length(pattern_note, pattern, position_note) if is_chord[2] : note_list = [] # c est un accord for p_note in pattern[is_chord[0]:is_chord[1]+1] : note_str = get_note_pattern(p_note, p_key) note = Note(note_str, p_note[5]) if previews_note is not None: if p_note[4]=='+': if int(note) < previews_note : note.octave_up() elif p_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) note_list.append(note) for n in range(is_chord[0], is_chord[1]+1): already_used.append(n) b.place_notes(note_list, pattern_note[1]) else : note_str = get_note_pattern(pattern_note, p_key) note = Note(note_str, pattern_note[5]) if previews_note is not None: if pattern_note[4]=='+': if int(note) < previews_note : note.octave_up() elif pattern_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) b.place_notes(note, pattern_note[1]) already_used.append(position_note) position_note+=1 t.add_bar(b) print(str(t)) #track = LilyPond.from_Track(t) #test = LilyPond.to_png(track, "left_hand") #MidiFileOut.write_Track("test_midi.mid", t) return t
def setUp(self): self.i = Track(Instrument()) self.p = Track(Piano()) self.g = Track(Guitar()) self.tr = Track()
def from_Bar(bar): c = Composition() t = Track() t.add_bar(bar) c.add_track(t) return _composition2musicxml(c).toprettyxml()
def generate_long_right_hand(phrase_list, progression_list, nb_bars, pattern_index, mode, key, chorus): t = Track() k = 0 # on parcours la liste de phrases for phrase in phrase_list : k += 1 previews_note = None nb_p = 0 for bar in phrase[1][3] : list_bar = generate_bar(previews_note, bar, key, mode, 'I', progression_list, nb_p, pattern_index) b = list_bar[0] last_note = list_bar[1] nb_bars+=1 t.add_bar(b) last_bar = bar nb_p+=1 if phrase[1][1] < 4 : # composer le reste TODO en attendant on met du vide last_bar_notes = list_bar[2] next_index = nb_p+4 if next_index < 9 : next_progression = progression_list[0][next_index] next_phrase = chorus[1] first_bar = next_phrase[1][3][0] first_bar_list = generate_bar(last_note, first_bar, key, mode, next_progression, progression_list, nb_p+4, pattern_index) first_bar_notes = first_bar_list[2] nb_notes_to_generate = get_nb_note_needed(last_bar, first_bar) print "****************** je vais generer la transition ! ****************" transition_bar = generate_transition(first_bar_notes, last_bar_notes, nb_notes_to_generate, pattern_index, key) print "***************************** Fini ! ******************************" for i in range(len(transition_bar)): t.add_bar(transition_bar[i]) # on ajoute le refrain for chorus_bars in chorus[0][2] : t.add_bar(chorus_bars) if k == len(phrase_list) : list_end = generate_end_bars(chorus[0][2][1], chorus[3], pattern_index, key, mode) for end_bar in list_end : t.add_bar(end_bar) #generer transition vers la phrase suivante #ou generer la fin for i in range(2): b = Bar(key, (4,4)) b.place_rest(1) t.add_bar(b) #generer phrase + genererer transition # ajouter refrain # si ce n'est pas la fin : generer transition entre refrain et prochaine phrase # sinon, generer fin return t
while repeat >= 0: for i in range(len(composition.tracks)): m.tracks[i].play_Track(composition.tracks[i]) repeat -= 1 return m.write_file(file) if __name__ == "__main__": from mingus.containers.NoteContainer import NoteContainer from mingus.containers.Bar import Bar from mingus.containers.Track import Track from mingus.containers.Instrument import MidiInstrument b = Bar() b2 = Bar('Ab', (3,4)) n = NoteContainer(["A", "C", "E"]) t = Track() b + n b + [] b + n b + n b2 + n b2 + n b2 + [] t + b t + b m = MidiInstrument() m.instrument_nr = 13 t.instrument = m t.name = "Track Name Test" write_NoteContainer("test.mid", n) write_Bar("test2.mid", b)
from mingus.midi import fluidsynth import mingus.core.progressions as progressions from mingus.containers import NoteContainer from mingus.containers.Track import Track import sys fluidsynth.init(sys.argv[1]) pro = sys.stdin.read().split() ch = progressions.to_chords(pro, "C") nc = map(NoteContainer, ch) t = Track() for chord in nc: t.add_notes(chord) fluidsynth.play_Track(t)