def midi_from_melodies(melodies): notes = [[Note(x%Octave, 4 + x//Octave, 1/4) for x in melody] for melody in melodies] chords = [NoteSeq([melody_notes[i] for melody_notes in notes]) for i in range(len(melody))] midi = Midi(tempo=120) midi.seq_chords(chords) return midi
def harmonize_scale(forte): pitch_set = pcset.PC_SETS[forte] scale = numbers_to_noteseq(pitch_set) midi = Midi() t0 = midi.seq_notes(scale) t1 = midi.seq_chords(scale.harmonize(interval=3), time=t0 + 1) t2 = midi.seq_chords(scale.harmonize(interval=4), time=t1 + 1) midi.seq_chords(scale.harmonize(interval=5), time=t2 + 1) midi.write("midi/scales.midi")
def clean_freq(samples): "create freq samples" sample_size = len(samples) chords = [NoteSeq([Note(classes[i]) for i in sample]) for sample in samples] midi = Midi(1, tempo=tempo) for i in range(sample_size): midi.seq_chords([chords[i]], time=5*i) midi.write("temp.mid") subprocess.call("timidity temp.mid -Ow -o temp.wav".split(), stdout=subprocess.PIPE) rate, data = wavfile.read('temp.wav') return channel_freqs(data.T[0])[:sample_size*10:10].astype(int) / suppress_noise
def foo(): notes = NoteSeq("C4 D4") pprint(notes.verbose) #Value (1-12), Octave (default=5) and Duration note1 = Note("C4") pprint('Note1 verbose = ' + note1.verbose) #<NoteSeq: [<Note: 0, 5, 0.25>, <Note: 2, 5, 0.25>]> pprint('Note1 name = ' + note1.name) note1.midi_number note1.midi_dur note_blank = Note() pprint('Note_blank = ' + note_blank.verbose) #<Note: 0, 5, 0.25> (pitch, octave, duration) note = Note(2, 4, 1, 100) #Value, Octave, Duration, Volume pprint('Programmatic note = ' + note.verbose) #<Note: 1, 4, 1> pprint('Programmatic note name = ' + note.name) #notes = NoteSeq("D4 F#8 A Bb4") #note.harmonize(notes) scale = NoteSeq('G4') scale2 = NoteSeq('A4') scale += scale2 pprint('Scale: ' + scale.verbose) Dmajor = [2,4,6,7,9,11,13,14] foolist = [] for degree in Dmajor: foolist.append(Note(degree, 5, .25, 100)) pprint(foolist) fooSeq = NoteSeq(foolist) pprint('List of notes in NoteSeq: ' + fooSeq.verbose) #[<Note: 3, 5, 1>, <Note: 4, 5, 1>, etc.] midi = Midi(1, tempo=60) midi.seq_notes(fooSeq, track=0) midi.write("foo.mid") seq2 = NoteSeq("C4 D8 E8 C4 D8 E8 C4 D8 E8") midi2 = Midi(1, tempo=60) midi2.seq_notes(seq2, track=0) midi2.write("foo1.mid") chord1 = NoteSeq("C E G") chord2 = NoteSeq("D F A") chord3 = NoteSeq("E G B") chord4 = NoteSeq("F A C") seqlist = [chord1, chord2, chord3, chord4] pprint(seqlist) midi3 = Midi(1, tempo=60) midi3.seq_chords(seqlist, track=0) midi3.write('foochord.mid')
def write_midi(arg_notes_list, file_name='temp.mid', tempo=60): # Rebuild the list. This changes all Note objects to NoteSeq objects write_notes = [] for note in arg_notes_list: if isinstance(note, Note) or isinstance(note, Rest): next_entry = NoteSeq([note]) elif isinstance(note, NoteSeq): next_entry = note else: print 'write_midi: Attempting to write non-Note or NoteSeq object to midi' raise write_notes.append(next_entry) midi = Midi(1, tempo) midi.seq_chords(write_notes, track=0) midi.write(file_name)
def convert_chords_to_midi(chord_list, filename): '''Requires pyknon to create the midi...''' from pyknon.music import NoteSeq from pyknon.genmidi import Midi chord_prog = [] midi = Midi(1, tempo=90) for chord in chord_list: chord = chord.upper() chord = chord.replace('B', 'BB') chord = chord.replace('H', 'B') chord_prog.append(NoteSeq(chord)) midi.seq_chords(chord_prog, 0, 0) midi.write(filename)
def clean_freq(samples): "create freq samples" sample_size = len(samples) chords = [ NoteSeq([Note(classes[i]) for i in sample]) for sample in samples ] midi = Midi(1, tempo=tempo) for i in range(sample_size): midi.seq_chords([chords[i]], time=5 * i) midi.write("temp.mid") subprocess.call("timidity temp.mid -Ow -o temp.wav".split(), stdout=subprocess.PIPE) rate, data = wavfile.read('temp.wav') return channel_freqs( data.T[0])[:sample_size * 10:10].astype(int) / suppress_noise
def generatingFile(length,name): """ Generating with 3 track, one with chords one with high single notes one with low single notes length: who long one bar can be,example 1:4/4 0.75:3/4 0.5:2/5 """ midi = Midi(3, tempo=60) barSeqnotesLow=generatingBarsNotes(length,dataBaseNotesLow) barSeqnotesHigh=generatingBarsNotes(length,dataBaseNotesHigh) barSeqchords=generatingBarChords(length,dataBaseChords) midi.seq_notes(barSeqnotesLow,track=0) midi.seq_notes(barSeqnotesHigh,track=1) midi.seq_chords(barSeqchords,track=2) midi.write(name+".mid") os.system('fluidsynth -F %s.wav %s %s.mid' %(name,soundfont,name)) os.system('lame --preset insane %s.wav' %name) os.system('rm -Rf %s.wav' %name) #os.system('timidity -Or -o - %s.mid | lame -r - %s.mp3' %(name, name)) os.system('rm -Rf %s.mid' %name)
def play_chord(notes, tempo, duration): """ notes is a list of indices: [C1, C#1, D1, D#1, E1, F1, F#1, G1, G#1, A1, A#1, B1, C2, C#2, D2, D#2, E2, F2, F#2, G2, G#2, A2, A#2, B2] """ chord = [] for note in notes: chord.append( Note(value=(note % 12), octave=((note // 12) + 4), dur=duration)) filepath = "chord.mid" midi = Midi(tempo=tempo) midi.seq_chords([NoteSeq(chord)]) midi.write(filepath) pg.init() pg.mixer.music.load(filepath) pg.mixer.music.play() os.remove(filepath)
def midicreate(notelist,name,page): NoteList = [] for i in range(len(notelist)): if(notelist[i].scale=='Rest'): chord = Rest(notelist[i].tempo) elif(notelist[i].harmony==0): continue elif(notelist[i].harmony==2): chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo),Note(notelist[i+1].scale,dur=notelist[i].tempo)]) elif(notelist[i].harmony==3): chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo),Note(notelist[i+1].scale,dur=notelist[i].tempo),Note(notelist[i+2].scale,dur=notelist[i].tempo)]) elif(notelist[i].harmony==4): chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo),Note(notelist[i+1].scale,dur=notelist[i].tempo),Note(notelist[i+2].scale,dur=notelist[i].tempo),Note(notelist[i+3].scale,dur=notelist[i].tempo)]) else: chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo)]) NoteList.append(chord) midi = Midi(1, tempo=117) checktract = 0 midi.seq_chords(NoteList,track=0) midi.write(f"/home/ec2-user/Ourchord/MIDI/{page}/{name}.mid") # ---------------------------------------------------- 경로 수정
notes1 = NoteSeq("C4.'' B8' A4 D") notes2 = NoteSeq("E4 F G4. A8") m = Midi(2, tempo=100, instrument=[12, 14]) m.seq_notes(notes1, track=0) m.seq_notes(notes2, track=1) m.write("tracks.mid") # Chords on two tracks using the defaults chords1 = [NoteSeq("C2 E G"), NoteSeq("G2 B D")] chords2 = [NoteSeq("C,4 E"), NoteSeq("E, G"), NoteSeq("G, B"), NoteSeq("B, D'")] midi = Midi(2, tempo=60, instrument=[40, 20]) midi.seq_chords(chords1, track=0) midi.seq_chords(chords2, track=1) midi.write("chords.mid") # Notes on two tracks using percussion # In the MIDI library, the tracks and channels are numbered from 0, # While the MIDI Standard is numbered from 1, # So to use percussion you must use channel 9 in the library n1 = NoteSeq("C4 D E F") n2 = NoteSeq("C8 C G, G C' C G, G") m2 = Midi(2, tempo=123, channel=[0, 9], instrument=[20, 40]) m2.seq_notes(n1, track=0, channel=0) m2.seq_notes(n2, track=1, channel=9)
notes_list = [] for x in range(0,800): notes = [] for y in range(0,12): vol = int((255 - image.getpixel((x, y)))/2) if vol == 255: continue if vol: notes.append(Note(y, 5, 1/16, vol)) if len(notes): notes_list.append(NoteSeq(random.choice(notes).harmonize(NoteSeq(notes)))) # notes_list.append(NoteSeq(notes)) else: notes_list.append(Rest(1/16)) midi.seq_chords(notes_list) midi.write("test" + str(track) + ".mid") #image.show() # test for number of notes per frame # for x in range(0,800): # #(y,5,1/16,255-pix/2) # #print(' '.join((str(255 - image.getpixel((x,y))) for y in range(0,12)))) # val = len(list(filter(None,(255-image.getpixel((x,y)) for y in range(0,12))))) # if val > 8: # print(val) # First method
def test_seq_chords_with_rest(self): chords = [Rest(), NoteSeq("G B D")] midi = Midi() midi.seq_chords(chords)
def test_seq_chords(self): chords = [NoteSeq("C E G"), NoteSeq("G B D")] midi = Midi() midi.seq_chords(chords)
def midicreate(notelist, name): ''' onelist = [] twolist = [] threelist = [] fourlist = [] fivelsit = [] sixlist = [] sevenlist = [] eightlist = [] ninelist = [] tenlist = [] elevenlist = [] twelvelist = [] ''' #NoteList = [onelist, twolist, threelist, fourlist, fivelsit, sixlist, sevenlist, eightlist, ninelist, tenlist, elevenlist, twelvelist] NoteList = [] #print(notelist) for i in range(len(notelist)): #print(notelist[i][2],notelist[i][3],notelist[i][5]) if (notelist[i][3] == 'Rest'): chord = Rest(notelist[i][2]) elif (notelist[i][5] == 0): continue elif (notelist[i][5] == 2): chord = NoteSeq([ Note(notelist[i][3], dur=notelist[i][2]), Note(notelist[i + 1][3], dur=notelist[i][2]) ]) elif (notelist[i][5] == 3): chord = NoteSeq([ Note(notelist[i][3], dur=notelist[i][2]), Note(notelist[i + 1][3], dur=notelist[i][2]), Note(notelist[i + 2][3], dur=notelist[i][2]) ]) elif (notelist[i][5] == 4): chord = NoteSeq([ Note(notelist[i][3], dur=notelist[i][2]), Note(notelist[i + 1][3], dur=notelist[i][2]), Note(notelist[i + 2][3], dur=notelist[i][2]), Note(notelist[i + 3][3], dur=notelist[i][2]) ]) else: chord = NoteSeq([Note(notelist[i][3], dur=notelist[i][2])]) NoteList.append(chord) #else: #NoteList.append(Rest(notelist[i][2])) #print(NoteList) #seq = NoteSeq(NoteList) #midi = Midi(number_tracks=2, tempo=90) #midi.seq_notes(NoteList, track=0) #midi.seq_notes(notes2, track=0) midi = Midi(1, tempo=117) checktract = 0 ''' if(checktract<= tracknum): print(NoteList[checktract]) midi.seq_notes(NoteList[checktract], track=checktract) checktract=checktract+1 ''' midi.seq_chords(NoteList, track=0) midi.write(f"/home/ec2-user/Ourchord/MIDI/{name}.mid" ) # ---------------------------------------------------- 경로 수정
m.seq_notes(notes1, track=0) m.seq_notes(notes2, track=1) m.write("tracks.mid") # Chords on two tracks using the defaults chords1 = [NoteSeq("C2 E G"), NoteSeq("G2 B D")] chords2 = [ NoteSeq("C,4 E"), NoteSeq("E, G"), NoteSeq("G, B"), NoteSeq("B, D'") ] midi = Midi(2, tempo=60, instrument=[40, 20]) midi.seq_chords(chords1, track=0) midi.seq_chords(chords2, track=1) midi.write("chords.mid") # Notes on two tracks using percussion # In the MIDI library, the tracks and channels are numbered from 0, # While the MIDI Standard is numbered from 1, # So to use percussion you must use channel 9 in the library n1 = NoteSeq("C4 D E F") n2 = NoteSeq("C8 C G, G C' C G, G") m2 = Midi(2, tempo=123, channel=[0, 9], instrument=[20, 40]) m2.seq_notes(n1, track=0, channel=0) m2.seq_notes(n2, track=1, channel=9)
notes_list_high = [] notes_list_low = [] for x in range(0,800): notes = [] for y in range(0,12): vol = int(image.getpixel((x, y))/2) if vol == 127: continue if vol: notes.append(Note(y, 5, 1/16, vol)) if len(notes): seq = NoteSeq(notes) notes_list_high.append(NoteSeq(notes[0].harmonize(seq))) if len(notes) > 1: notes_list_low.append(NoteSeq(notes[len(notes)-1].harmonize(seq))) else: notes_list_low.append(Rest(1/16)) else: notes_list_high.append(Rest(1/32)) notes_list_low.append(Rest(1/32)) midi = Midi(tempo=90, instrument=instrument_high) midi.seq_chords(notes_list_high) midi.write("test-high.mid") midi = Midi(tempo=90, instrument=instrument_low) midi.seq_chords(notes_list_low) midi.write("test-low.mid")
major_chord, minor_chord, dim_chord] # Chord qualities: m d M m m M M (m) minor_chord_progression = [minor_chord, dim_chord, major_chord, minor_chord, \ minor_chord, major_chord, major_chord] ####### Generate C major chords ### C_maj_chords = [] for i in range(len(major_chord_progression)): C_maj_chords.append(major_chord_progression[i](C_major[i])) # Throw a "mistake" in there to hear the difference C_maj_chords.append([Note("C"), Note("F#"), Note("Bb")]) print "C major chords:", C_maj_chords midi = Midi(1, tempo=80) midi.seq_chords(map(NoteSeq, C_maj_chords)) midi.write("c_major_chords.mid") ####### Generate G minor chords ### G_minor = NoteSeq("G, A Bb C' D Eb F") G_min_chords = [] for i in range(len(minor_chord_progression)): G_min_chords.append(minor_chord_progression[i](G_minor[i])) print "G minor chords:", G_min_chords midi = Midi(1, tempo=80) midi.seq_chords(map(NoteSeq, G_min_chords)) midi.write("g_minor_chords.mid")
m.seq_notes(notes1, track=0) m.seq_notes(notes2, track=1) # m.write("tracks.mid") # Bunu dinlemek için uncomment edebilrisin. # Chords on two tracks using the defaults chords1 = [NoteSeq("C2 E G"), NoteSeq("G2 B D")] chords2 = [ NoteSeq("C,4 E"), NoteSeq("E, G"), NoteSeq("G, B"), NoteSeq("B, D'") ] midi = Midi(2, tempo=60, instrument=[40, 20]) midi.seq_chords(chords1, track=0) midi.seq_chords(chords2, track=1) #midi.write("chords.mid") # Bunu dinlemek için uncomment edebilrisin. # Notes on two tracks using percussion # In the MIDI library, the tracks and channels are numbered from 0, # While the MIDI Standard is numbered from 1, # So to use percussion you must use channel 9 in the library n1 = NoteSeq("C4 D E F") n2 = NoteSeq("C8 C G, G C' C G, G") m2 = Midi(2, tempo=123, channel=[0, 9], instrument=[20, 40, 60]) # toplamda 2 track ve 6 kanal ile bütün sesleri birleştir.