def main(): fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa") solution = [52,52,53,55,55,53,52,50,48,48,50,52,52,50,50] #testSol = [1,3,53,55,55,53,52,50,48,48,50,52,52,50,50] population = createInitialPopulation(250, len(solution)) #t = Track() #for note in findMostFit(population,solution): # t + note #fluidsynth.play_Track(t,1) generation = 1 highestFitness = calcFitness(findMostFit(population, solution), solution) print("Generation: 1") print("Initial Highest Fitness: " + str(highestFitness)) #print(calcFitness(testSol,solution)) while highestFitness < 1: population = createNewPopulation(population, solution, .01) generation = generation + 1 highestFitness = calcFitness(findMostFit(population, solution), solution) print("Generation: " + str(generation)) print("Highest Fitness level: " + str(highestFitness)) if generation % 10 == 0: print("hi") t = Track() for noteInt in findMostFit(population,solution): newNote = Note() newNote.from_int(noteInt) t + newNote fluidsynth.play_Track(t,1) #time.sleep(10) t = Track() for note in findMostFit(population,solution): t + note fluidsynth.play_Track(t,1)
def vector_to_midi(arr, filename="nice.midi"): track = Track() for note_arr in arr: note_num = int(np.argmax(note_arr)) note = Note() note.from_int(note_num - 3) track.add_notes(note) write_Track(filename, track) print("Done!")
scales.Ionian('C') #音对象 from mingus.containers import Note #C4音对象 n = Note('C') #变为C5 n.set_note('C', 5) #音对象属性 n.name #十二音名 n.octave #第几八度 n.dynamics #其它属性 #音对象方法 int(n) #音对象的数值 c = Note() c.from_int(12) #使用数值创建音对象 c.octave_up() #升八度 c.octave_down() #降八度 c.change_octave(2) #升n八度 c.transpose('3', up=True) #向上升三度 c.augment() #升半音 c.diminish() #降半音 c.remove_redundant_accidentals() #清理多余升降号(只能成对清理,烂) #谱容器 from mingus.containers import NoteContainer #创建谱容器对象(继承列表,完全可以按列表操作,不用看下面的) n = NoteContainer(['A-3', 'C-5', 'B-4']) n.add_note('F-1') # 0位加音 n.remove_note('B', 4) #删音 n.empty() #清空
simple_chordIII = ["E-2", ["G-2", "B-2", "E-3"]] simple_chordIV = ["F-2", ["A-2", "C-3", "F-3"]] simple_chordV = ["G-2", ["B-2", "D-3", "G-3"]] simple_chordVI = ["A-2", ["C-3", "E-3", "A-3"]] simple_chordV7 = ["G-2", ["B-2", "D-3", "F-3"]] simple_chordIi = ["C-3", ["E-3", "G-3", "C-4"]] complex_chordI = [["C-2", "E-2", "G-2", "C-3"], "E-2", "G-2", "C-3"] complex_chordII = [["D-2", "F-2", "A-2", "D-3"], "F-2", "A-2", "D-3"] complex_chordIII = [["E-2", "G-2", "B-2", "E-3"], "G-2", "B-2", "E-3"] complex_chordIV = [["F-2", "A-2", "C-3", "F-3"], "A-2", "C-3", "F-3"] complex_chordV = [["G-2", "B-2", "D-3", "G-3"], "B-2", "D-3", "G-3"] complex_chordVI = [["A-2", "C-3", "E-3", "A-3"], "C-3", "E-3", "A-3"] complex_chordV7 = [["G-2", "B-2", "D-3", "F-3"], "B-2", "D-3", "F-3"] complex_chordIi = [["C-3", "E-3", "G-3", "C-4"], "E-3", "G-3", "C-4"] snare = Note() snare.from_int(26) highhat = Note() highhat.from_int(30) base = Note() base.from_int(23) hightom = Note() hightom.from_int(38) midtom = Note() midtom.from_int(36) lowtom = Note() lowtom.from_int(35) cymbal = Note() cymbal.from_int(37) startbasepercussion = [base, None, base, None] starthighhatpercussion = [highhat, None, highhat, None] transitioncymbalpercussion = [cymbal]
for direction_ind in range(0, 2): if interval_directions[direction_ind] == "down": base_octave = 4 else: base_octave = 3 if base_note == "G" or base_note == "A" or base_note == "B": base_octave -= 1 basen = Note(base_note, base_octave) baseb = Bar() baseb.set_meter((1,4)) baseb.place_notes(basen, 4) midi_file_out.write_Bar("base_note.mid", baseb, 100, 0) intervaln = Note() direction_sign = 2 * (direction_ind - 0.5) intervaln.from_int(int(int(basen) + direction_sign * (interval_values[interval_ind]))) intervalb = Bar() intervalb.set_meter((2,4)) intervalb.place_notes(intervaln, 4) midi_file_out.write_Bar("interval_note.mid", intervalb, 100, 0) os.system("timidity --output-24bit -A120 base_note.mid -Ow -o base_note.wav") os.system("timidity --output-24bit -A120 interval_note.mid -Ow -o interval_note.wav") os.system("sox base_note.wav base_note_short.wav trim 0 1.5") os.system("sox interval_note.wav interval_note_short.wav trim 0 4.5") os.system("sox instructions/" + interval_names[interval_ind] + ".wav instructions.wav trim 0 1.5") os.system("sox base_note_short.wav interval_note_short.wav instructions.wav combined.wav") os.system("lame -a --tt 'Id " + interval_directions[direction_ind] + " " +
if has_user_timeout > HAS_USER_WAIT: has_user = False elif has_user and detect_timer > DETECT_WAIT: detect_timer = 0 print('========= BLINK =========') fluidsynth.play_NoteContainer(notes) for note in notes: print(note, int(note), note.next_octave, (BASE_OCTAVE + note.next_octave) * 12) new_note = (int(note) + 1) % 12 if new_note == 0: note.next_octave = not note.next_octave note = note.from_int((BASE_OCTAVE + note.next_octave) * 12 + new_note) else: has_user_counter += 1 has_user_timeout = 0 if not has_user and has_user_counter > HAS_USER_WAIT: has_user = True octave = 0 cv2.namedWindow('Cam View', cv2.WINDOW_NORMAL) cv2.imshow('Cam View', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cam.release()
from mingus.midi import fluidsynth from mingus.containers import Note, Track import time fluidsynth.init("Timbre.sf2", fluidsynth.midi) a = 43 b = Note() while True: b.from_int(a) print a fluidsynth.play_Note(b, channel=9) time.sleep(1) a += 1 snare = 26 rimshot = 25 electricsnare = 28 openhighhat = 34 base = 23 high_tom = 38 mid_tom = 36 low_tom = 35 hit_hat = 30 cymbal = 37
def row_to_note_simple(self, row): base_note = 48 note = Note() note.from_int(row+base_note) return note
def note_from_int(value): c = Note() c.from_int(value) return c
from mingus.containers import Track, Bar, Note snaretrack = Track() basetrack = Track() highhattrack = Track() tomtrack = Track() cymbaltrack = Track() snare = Note() snare.from_int(26) highhat = Note() highhat.from_int(30) openhighhat = Note() openhighhat.from_int(34) base = Note() base.from_int(23) hightom = Note() hightom.from_int(38) midtom = Note() midtom.from_int(36) lowtom = Note() lowtom.from_int(35) cymbal = Note() cymbal.from_int(37) rimshot = Note() rimshot.from_int(25) electricsnare = Note() electricsnare.from_int(28) ridecymbal = Note() ridecymbal.from_int(47) crashcymbal = Note() crashcymbal.from_int(45)
20.75, 21.0, 21.25, 21.5, 21.75, 22.0, 22.25, 22.5, 22.75, 23.0, 23.25, 23.5, 23.75, 24.0, 24.25, 24.5, 24.75, 25.0, 25.25, 25.5, 25.75, 26.0, 26.25, 26.5, 26.75, 27.0, 27.25, 27.5, 27.75, 28.0, 28.25, 28.5, 28.75, 29.0, 29.25, 29.5, 29.75, 30.0, 30.25, 30.5, 30.75, 31.0, 31.25, 31.5, 31.75 ] downbeatpossiblevalues = [ 0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.0 ] possiblenote = ["C", "D", "E", "F", "G", "A", "B"] initialized = False uiplayer = FluidSynthSequencer() fluidsynth.init('goodtry.sf2', uiplayer) cymbal = Note() cymbal.from_int(37) snare = Note() snare.from_int(26) highhat = Note() highhat.from_int(30) base = NoteContainer() basenote = Note() basenote.from_int(23) base.add_note(basenote) soundtrack = Track() starttrack = Track() starttrack.add_notes(highhat, 1) starttrack.add_notes(highhat, 1) starttrack.add_notes(highhat, 1) starttrack.add_notes(highhat, 1)