def generate_composition(pattern, progression_type, nb_bars, key="C", rythm=60):
    fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument
    newComposition = Composition()

    progression_list = on_progression_type_change(progression_type, nb_bars)
    left_hand = generate_pattern(progression_list, key, pattern, nb_bars)
    newComposition.add_track(left_hand)
    MidiFileOut.write_Composition("myComposition.mid", newComposition, rythm, False)
Exemple #2
0
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')
Exemple #3
0
	def output_midi(self):
		c = Composition()
		print 
		print "Writing MIDI file %s..." % self.output_file
		for s in self.instruments:
			if hasattr(s, 'bar'):
				s.track + s.bar
			c.add_track(s.track)
		
		MidiFileOut.write_Composition(self.output_file, c, self.bpm , 0)
def generate_composition(pattern_index, progression_type, nb_bars, mode='none', key="C", rythm=60):
    fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument
    newComposition = Composition()
    progression_list = on_progression_type_change(progression_type, nb_bars)
    
     # truc pour la main droite
    if nb_bars == 1 :
        phrase_list = choose_phrases(key, mode, nb_bars)
        right_hand = use_phrase(phrase_list, progression_list, nb_bars, pattern_index, mode='none', key="C")
    else :
        chorus = generate_chorus(progression_list, pattern_index, mode, key)
        #chorus retourne : une phrase de debut, une phrase de fin, 3 bars fixes
        phrase_list = choose_first_phrases(nb_bars, key, mode, chorus[1], chorus[2], pattern_index)
        right_hand = generate_long_right_hand(phrase_list, progression_list, nb_bars, pattern_index, mode, key, chorus)
    
    newComposition.add_track(right_hand)
    
    left_hand = generate_pattern(progression_list, key, pattern_index, nb_bars)
    newComposition.add_track(left_hand)
    MidiFileOut.write_Composition("myCompo.mid", newComposition, rythm, False)
   
    return newComposition
Exemple #5
0
                   major_scale[6],
                   seventh]

    return blues_scale

def down_octave(bar):
    for chord in [beat[2] for beat in bar]:
        for note in chord:
            note.octave_down()

    return bar

if __name__ == '__main__':
    key = 'C'

    rhythm_track = Track()
    melody_track = Track()

    progression = standard_progression()

    for chord in progression:
        rhythm_track.add_bar(make_rhythm_bar(chord, key))
        melody_track.add_bar(make_melody_bar(key))

    composition = Composition()
    composition.add_track(melody_track)
    composition.add_track(rhythm_track)

    MidiFileOut.write_Composition('blues.mid', composition)

def save_as_midi(name, composition, rythm):
    MidiFileOut.write_Composition(name+".mid", composition, rythm, False)
Exemple #7
0
chords_bars = []
for chord in chords_list:
	chord_nc = NoteContainer(chords.from_shorthand(chord))
	bar = Bar()
	bar.place_notes(chord_nc, 1)
	chords_bars.append(bar)
solo_track = Track()
chords_track = Track()
for _ in range(num_progressions):
	for bar in generate_solo(chords_list):
		solo_track.add_bar(bar)
	for bar in chords_bars:
		chords_track.add_bar(bar)

guitar = MidiInstrument()
guitar.instrument_nr = 26
solo_track.instrument = guitar

piano = MidiInstrument()
piano.instrument_nr = 0
chords_track.instrument = piano

song = Composition()
song.add_track(solo_track)
song.add_track(chords_track)

MidiFileOut.write_Composition("test.mid", song)

filename = "test.mid"
call("timidity -Ow {0}".format(filename), shell=True)
# fluidsynth -F test.wav -i -n -T wav soundfont.sf2 test.mid