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 playSolution(solution): """ Plays back a given solution. INPUT: dict solution: NOTE: GUI passes in a list of the form: [["<singer><time>", int pitchnum], ...] Command-line interface uses a different representation than the GUI code. So, this function handles both cases until I update the GUI code to follow the CLI style. OUTPUT: True if playback is successful, False otherwise. """ # TODO(erickim)[2018-12-09] Not fond of using global canPlayback if not canPlayback: print "Warning: midi playback not supported. Did you install mingus?" return False if type(solution) is dict: track = sol2fluidsynth(solution) elif type(solution) is list: # Convert list-repr to dict repr soldict = {} for (key, pitchnum) in solution: dictkey = key[0] + "_" + key[1:] soldict[dictkey] = pitchnum track = sol2fluidsynth(soldict) else: raise ValueError("Unexpected type: {0}".format(type(solution))) try: fluidsynth.play_Track(track) fluidsynth.main_volume(1, 127) except Exception as e: print e return False return True
def print_and_play(self): if len(self.bars) == 0: raise Exception("Nothing to play") for n in self.get_notes(): print n fluidsynth.play_Track(self, 1, self.rate)
def playSolution(solution): """ Plays back a given solution. INPUT: dict solution: NOTE: GUI passes in a list of the form: [["<singer><time>", int pitchnum], ...] Command-line interface uses a different representation than the GUI code. So, this function handles both cases until I update the GUI code to follow the CLI style. OUTPUT: True if playback is successful, False otherwise. """ if type(solution) is dict: track = sol2fluidsynth(solution) elif type(solution) is list: # Convert list-repr to dict repr soldict = {} for (key,pitchnum) in solution: dictkey = key[0]+"_"+key[1:] soldict[dictkey] = pitchnum track = sol2fluidsynth(soldict) else: raise ValueError("Unexpected type: {0}".format(type(solution))) try: fluidsynth.play_Track(track) fluidsynth.main_volume(1, 127) except Exception as e: print e return False return True
def play(Gnumeric, range_string, bpm = 120): 'Play the music in some cells.' def track(range_string): top, left, bottom, right = u.parse_range_string(range_string) stuff = u.range_rendered_text_and_italic(Gnumeric, top, left, bottom, right) return to_track(stuff, key, upper, lower) fluidsynth.play_Track(track(range_string), bpm = bpm)
def playTrack(arr): fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa") SF2 = '/usr/share/sounds/sf2/FluidR3_GM.sf2' if not fluidsynth.init(SF2): print "Couldn't load soundfont", SF2 sys.exit(1) t = Track() for note in arr: t + note fluidsynth.play_Track(t,1)
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 test_track(self): b = Bar() b + Note('C') b + Note('E') b + Note('A') b + 'E' t = Track() t + b t + b self.assert_(fluidsynth.play_Track(t), 0)
def test_track(self): b = Bar() b + Note("C") b + Note("E") b + Note("A") b + "E" t = Track() t + b t + b self.assertTrue(fluidsynth.play_Track(t), 0)
def test_track(self): b = Bar() b + Note("C") b + Note("E") b + Note("A") b + "E" t = Track() t + b t + b self.assert_(fluidsynth.play_Track(t), 0)
def test_changing_bpm_track(self): b = Bar() n = NoteContainer(["C", "E", "G"]) n.bpm = 150 b + NoteContainer(["A", "C", "E"]) b + Note("E") b + n b + Note("Eb") t = Track() t + b t + b self.assertTrue(fluidsynth.play_Track(t), 0)
def test_changing_bpm_track(self): b = Bar() n = NoteContainer(['C', 'E', 'G']) n.bpm = 150 b + NoteContainer(['A', 'C', 'E']) b + Note('E') b + n b + Note('Eb') t = Track() t + b t + b self.assert_(fluidsynth.play_Track(t), 0)
def test_changing_bpm_track(self): b = Bar() n = NoteContainer(["C", "E", "G"]) n.bpm = 150 b + NoteContainer(["A", "C", "E"]) b + Note("E") b + n b + Note("Eb") t = Track() t + b t + b self.assert_(fluidsynth.play_Track(t), 0)
def on_play_button_clicked(self, *args): index = self.genome_view.get_selection().get_selected()[1] index = self.genome_list.get_path(index)[0] fluidsynth.play_Track(self.evolution9.current_generation[index].mingus_track)
def play_Music(filename): f = open(filename, 'rb') data = json.loads(f.read(), encoding='utf8') f.close() n = data['音符'] h = data['音高'] r = data['节拍'] l = data['组成'] k = data['调性'] t = Track() b = Bar('C', (4, 4)) b.place_rest(1) t.add_bar(b) name = 'CDEFGAB' symbol = '!@#$%^&' def tran(x): if x >= 'a': return ord(x) - 87 elif x == '0': return 0.5 else: return float(x) f = open(filename, 'rb') data = json.loads(f.read(), encoding='utf8') f.close() n = data['音符'] h = data['音高'] r = data['节拍'] l = data['组成'] k = data['调性'] t = Track() b = Bar('C', (4, 4)) b.place_rest(1) t.add_bar(b) name = 'CDEFGAB' symbol = '!@#$%^&' for i in range(len(l)): rn = list(map(tran, r[l[i]])) b = Bar('C', (4 * sum(rn)/8, 4)) for j in range(len(n[l[i]])): if n[l[i]][j] == '0': b.place_rest(8 / rn[j]) else: x = symbol.find(n[l[i]][j]) if x == -1: x = int(n[l[i]][j]) - 1 y = name[x] else: y = name[x] + '#' print(y) note = Note(y, int(h[l[i]][j])) note.transpose(k[i]) b.place_notes(note, 8 / rn[j]) t.add_bar(b) t2 = Track() b = Bar('C', (4, 4)) b.place_rest(1) t2.add_bar(b) for i in range(int(sum(map(sum, map(lambda x: map(tran, r[x]), l)))) // 8): b = Bar('C', (4, 4)) b.place_notes('C-3', 4) b.place_notes('C-7', 4) b.place_notes('C-5', 4) b.place_notes('C-7', 4) t2.add_bar(b) m = MidiFile() mt = MidiTrack(150) mt2 = MidiTrack(150) mt3 = MidiTrack(150) m.tracks = [mt,mt2,mt3] mt.set_instrument(1, 25) mt.play_Track(t) # for _, _, i in t2.get_notes(): # if i is not None: # i[0].set_channel(2) # mt2.set_instrument(2, 115) # mt2.play_Track(t2) # for _, _, i in t.get_notes(): # if i is not None: # i[0].set_channel(3) # mt3.set_instrument(3, 100) # mt3.track_data += mt3.controller_event(3, 7, 30) # mt3.play_Track(t) # m.write_file('D:/test.midi', False) # for i in range(len(l)): # rn = list(map(tran, r[l[i]])) # b = Bar('C', (4 * sum(rn) / 8, 4)) # for j in range(len(n[l[i]])): # # if i==0 and j==0: # # b.place_notes('D-4', 3) # # el # if n[l[i]][j] == '0': # b.place_rest(1 / rn[j]) # else: # x = symbol.find(n[l[i]][j]) # if x == -1: # x = int(n[l[i]][j]) - 1 # y = name[x] # else: # y = name[x] + '#' # print(y) # # note = Note(y, int(h[l[i]][j])) # note.transpose(k[i]) # #print(note) # print(rn[j]) # #print(b) # b.place_notes(note, 1 / rn[j]) # t.add_bar(b) # print(b) fluidsynth.init("D:\MyCode\MyPython\AiMusicCoach\GeneralUserSoftSynth\GeneralUserSoftSynth.sf2") fluidsynth.set_instrument(1, 1) #24=Nylon Guitar # 25=Steel Guitar # 26=Jazz Guitar # 27=Clean Guitar # 28=Muted Guitar # 29=Overdrive Guitar # 30=Distortion Guitar m.write_file('D:\MyCode\MyPython\AiMusicCoach\Backend\music_file\mysong.midi', False) os.system("d: && cd D:\\MyCode\\MyPython\\AiMusicCoach\\fluidsynth-x64\\bin && fluidsynth -F mysong.wav D:/MyCode/MyPython/AiMusicCoach/GeneralUserSoftSynth/GeneralUserSoftSynth.sf2 D:\MyCode\MyPython\AiMusicCoach\Backend\music_file\mysong.midi") fluidsynth.play_Track(t, channel=1, bpm=150)
# sequencer.py -- generates the wav import mingus.core.notes as notes import mingus.core.chords as chords import mingus.core.progressions as progressions from mingus.containers import * from mingus.midi import fluidsynth import code song_length = 6 tempo = 120 beats_per_measure = 4 total_measures = tempo / beats_per_measure * (song_length/60) key = "C" progression = ["Im", "IVm", "Im", "V7", "Im"] chords = progressions.to_chords(progression, key) track = Track() for chord in chords: track.add_notes(chord, 2) fluidsynth.init("ChoriumRevA.SF2") fluidsynth.play_Track(track, 1, tempo)
def play(self): fluidsynth.play_Track(self.track)
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)
def play_song(self): #Plays the song at 150 BPM using fluidsynth(make BPM a var later?) fluidsynth.play_Track(self.song, 1, 150) return
def start_track(track, bpm): # t = Thread(target=listen_to_user, args=()) # t.start() print("Playing track... (hit 'a' if you've Already heard enough)") fluidsynth.play_Track(track, 1, bpm)
p[0].append([p[1][0][0],p[1][0][1]]) def p_note_pitch_duration(p): 'note : pitch DASH duration' p[0] = [[p[1],p[3]]] def p_pitch_terminals(p): 'pitch : LETTER DASH NUMBER' p[0] = Note(''.join(p[1:4])) def p_duration_terminals(p): 'duration : NUMBER' p[0] = int(p[1]) def p_error(p): print("parser: syntax error") yacc.yacc() if __name__ == '__main__': fluidsynth.init('sounds/electricPiano.SF2','coreaudio') while 1: try: s = raw_input(">>> ") if s == 'q': break if s == '': continue except EOFError: break result = yacc.parse(s) fluidsynth.play_Track(result,1,bpm)
import time PATH_SOUNDFONT = "./TimGM6mb.sf2" from mingus.midi import fluidsynth fluidsynth.init(PATH_SOUNDFONT, "pulseaudio") time.sleep(1) from mingus.containers import Note, Track #fluidsynth.play_Note(Note("C-5")) track = Track() track.add_notes(["A-5", "D-5"], 2) track.add_notes(["B-5", "E-5"], 2) fluidsynth.play_Track(track) time.sleep(5)