def resolve_chord_tone(chord, tone, Ioctave): # play_progression([numeral], st.KEY, Ioctave=Ioctave) if st.ALTERNATIVE_CHORD_TONE_RESOLUTION == 1: fluidsynth.play_NoteContainer(chord) play_wait() fluidsynth.play_Note(tone) play_wait() root = chord[0] interval = NoteContainer([root, tone]) fluidsynth.play_NoteContainer(interval) elif st.ALTERNATIVE_CHORD_TONE_RESOLUTION == 2: fluidsynth.play_NoteContainer(chord) play_wait() tone_idx = [x for x in chord].index(tone) if tone_idx == 0: arpeggiate() elif tone_idx == 1: arpeggiate(invert=[1, 0, 2]) elif tone_idx == 2: arpeggiate(descending=True) else: raise Exception("This chord tone resolutions mode is only " "implemented for triads.") # fluidsynth.play_Note(Iup_note) # Iup_note = Note(st.KEY) # Iup_note.octave += 1 # fluidsynth.play_Note(Iup_note) else: fluidsynth.play_NoteContainer(chord) play_wait() fluidsynth.play_Note(tone) play_wait() arpeggiate() # sets NEWQUESTION = False
def main(): if not os.path.isfile('./data/probs.json'): print ('Creating json file...') fname = "./data/interval-5gram.csv" counts = get_counts(fname, 4) probs = get_probs(counts) with open('./data/probs.json', 'w') as outfile: json.dump(probs, outfile) with open('./data/probs.json', 'r') as infile: probs_dict = json.load(infile, encoding='utf-8') start_int = C4 melody = [] fluidsynth.init("/usr/share/sounds/sf2/FluidR3_GM.sf2", "alsa") streamer = stream_notes(probs_dict) for i in range(100): next_int = start_int + int(next(streamer)) next_note = Note() next_note.from_int(next_int) melody.append(next_note) start_int = next_int print(next_note) fluidsynth.play_Note(next_note) time.sleep(.2)
def playNote(angle, position, instr): fluidsynth.set_instrument(channel, instr) # transform angle note = int(((sin(angle[0]) + 1.0) / 2) * 100) volume = int(((sin(angle[1]) + 1.0) / 2) * 100) print note, volume fluidsynth.play_Note(note, channel, volume)
def play_note(note): """play_note determines which pad was 'hit' and send the play request to fluidsynth""" index = None if note == Note('B', 2): index = 0 elif note == Note('A', 2): index = 1 elif note == Note('G', 2): index = 2 elif note == Note('E', 2): index = 3 elif note == Note('C', 2): index = 4 elif note == Note('A', 3): index = 5 elif note == Note('B', 3): index = 6 elif note == Note('A#', 2): index = 7 elif note == Note('G#', 2): index = 8 if index != None and status == 'record': playing.append([index, tick]) recorded.append([index, tick, note]) recorded_buffer.append([index, tick]) fluidsynth.play_Note(note, 9, 100)
def play_note(note): """play_note determines which pad was 'hit' and send the play request to fluidsynth""" index = None if note == Note("B", 2): index = 0 elif note == Note("A", 2): index = 1 elif note == Note("G", 2): index = 2 elif note == Note("E", 2): index = 3 elif note == Note("C", 2): index = 4 elif note == Note("A", 3): index = 5 elif note == Note("B", 3): index = 6 elif note == Note("A#", 2): index = 7 elif note == Note("G#", 2): index = 8 if index != None and status == "record": playing.append([index, tick]) recorded.append([index, tick, note]) recorded_buffer.append([index, tick]) fluidsynth.play_Note(note, 9, 100)
def arpegiate_chord(self,note_length,chord,velocity,ascending=False): chord = NoteContainer().from_chord(chord) for x in chord: synth.play_Note(x,velocity=velocity) time.sleep(self.me_time*note_length) if ascending: velocity += 15
def play_notes(self): ''' The input is a vector of pairs input example: notes=[["E",4], ["D#",4], ["E",2]] HOW NOTES WORKS notes example = [note, note, note, note] note = [noteTone, noteType] noteTone is a string, examples: "E", "D#", "A-4", "B-5", "Cb" noteType is a integer, types: 1 -> Whole 2 -> Half 4 -> Quarter 8 -> Eighth 16 -> Sixteenth ''' for note in self.notes: note_tone = note[0] note_type = note[1] fluidsynth.play_Note(Note(note_tone)) time.sleep(1 / float(note_type))
def run(self): # need to use bank_select fluidsynth.set_instrument(PLAYER_CHANNEL, InstrumentNames["Acoustic Grand Piano"]) fluidsynth.play_Note(self.note) self.event.wait() fluidsynth.stop_Note(self.note)
def play_word(word, synth, word_duration=0.01): # word_duration = 10 for note in word: n = Note(int(note['midi'])) n.velocity = int(note['vel']) fluidsynth.play_Note(n, channel=1) time.sleep(word_duration)
def play(self): fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2', 'alsa') fluidsynth.set_instrument(0, self.instrument) # Use channel 0 self.previous = int(SoundGen.kNoteNone) # Previously played note self.shift = random.randint(-10, 5) # Allow the key to be shifted beat_tracker = int(0) # 4/4 time. while self.should_stop == False: v = random.randint(65, 75) if beat_tracker % 8 == 0: # First beat, strong v = random.randint(85, 95) elif (beat_tracker - 4) % 8 == 0: # Third beat, semi-strong v = random.randint(75, 85) elif beat_tracker % 2 == 1: # Off-beat, very soft v = random.randint(55, 65) # Random note length possible_lengths = [ 4 ] + [2] * 10 + [1] * 4 # 4 is 2 beats, 2 is 1 beat, 1 is half-beat if beat_tracker % 2 == 1: # avoid non-half-beat if currently in half-beat possible_lengths += [1] * 20 # Add weight to half-beat length = random.choice(possible_lengths) beat_tracker += length if self.previous != SoundGen.kNoteNone: fluidsynth.stop_Note(self.previous + self.shift, 0) self.previous = SoundGen.__next_note__(self.previous) fluidsynth.play_Note(self.previous + self.shift, 0, v) time.sleep(length * self.OneBeatLength)
def play(self): eighth_time = 0.125 beat_time = eighth_time * 2 bar_time = beat_time * self.beat_count fluidsynth.set_instrument(1, 0) fluidsynth.play_NoteContainer(self.chord) next_notes = list(self.melody.notes) playing_notes = [] for eighth in range(self.beat_count * 2): # bar boundary? if eighth % 8 == 0: self.play_chord() try: next_note = next_notes[0] except IndexError as e: # if this is the last note, the above will throw an IndexError pass if next_note.start_eighth == eighth: next_notes.remove(next_note) playing_notes.append(next_note) print('subbeat {}: PLAY FOR {}: {}'.format( eighth, next_note.eighth_count, next_note.note)) fluidsynth.set_instrument(1, 0) fluidsynth.play_Note(next_note.note) for mel_note in list(playing_notes): if eighth == mel_note.start_eighth + mel_note.eighth_count: print('subbeat {}: STOP {}'.format( eighth, mel_note.note)) # don't stop the note if the same note is being played somewhere else! note_played_elsewhere = False for note in playing_notes: # skip over this one, we're interested in other notes if note == mel_note: continue if note.note == mel_note.note: note_played_elsewhere = True if not note_played_elsewhere: fluidsynth.stop_Note(mel_note.note) playing_notes.remove(mel_note) time.sleep(eighth_time) # we should have played the exact # if it isn't, something went wrong somewhere if len(playing_notes) != 0: #raise RuntimeError('playing_notes wasn\'t empty at the end of segment.play()!') print('EOS playing_notes: {}'.format(playing_notes)) for mel_note in playing_notes: fluidsynth.stop_Note(mel_note.note) playing_notes.remove(mel_note)
def __init__(self, starting_note='C-3'): fluidsynth.init(path_to_instrument, audio_driver) self.starting_note = Note(starting_note) self.relative_major_scale = np.array([0, 2, 4, 5, 7, 9, 11]) self.scale = self.relative_major_scale + int(self.starting_note) self.note = Note(self.starting_note) self.bar = Bar() fluidsynth.play_Note(self.note)
def erreproduzitu_marrazkia(screen): fluidsynth.init( '/home/galtzagorri/Mahaigaina/Arachno SoundFont - Version 1.0.sf2', "alsa") for i in range(0, len(zerrenda)): print zerrenda[i].posy nota = (zerrenda[i].posy) % 127 fluidsynth.play_Note(nota, 1, 100) time.sleep(0.5)
def play_note(note): """play_note determines the coordinates of a note on the keyboard image and sends a request to play the note to the fluidsynth server""" global text octave_offset = (note.octave - LOWEST) * width if note.name in WHITE_KEYS: # Getting the x coordinate of a white key can be done automatically w = WHITE_KEYS.index(note.name) * white_key_width w = w + octave_offset # Add a list containing the x coordinate, the tick at the current time and # of course the note itself to playing_w playing_w.append([w, tick, note]) else: # For black keys I hard coded the x coordinates. It's ugly. i = BLACK_KEYS.index(note.name) if i == 0: w = 18 elif i == 1: w = 58 elif i == 2: w = 115 elif i == 3: w = 151 else: w = 187 w = w + octave_offset playing_b.append([w, tick, note]) # To find out what sort of chord is being played we have to look # at both the white and black keys, obviously: notes = playing_w + playing_b notes.sort() notenames = [] for n in notes: notenames.append(n[2].name) # Determine the chord det = chords.determine(notenames) if det != []: det = det[0] else: det = "" # And render it onto the text surface t = font.render(det, 2, (0,0,0)) text.fill((255,255,255)) text.blit(t, (0,0)) # Play the note fluidsynth.play_Note(note, channel, 100)
def play_note(note): """play_note determines the coordinates of a note on the keyboard image and sends a request to play the note to the fluidsynth server""" global text octave_offset = (note.octave - LOWEST) * width if note.name in WHITE_KEYS: # Getting the x coordinate of a white key can be done automatically w = WHITE_KEYS.index(note.name) * white_key_width w = w + octave_offset # Add a list containing the x coordinate, the tick at the current time and # of course the note itself to playing_w playing_w.append([w, tick, note]) else: # For black keys I hard coded the x coordinates. It's ugly. i = BLACK_KEYS.index(note.name) if i == 0: w = 18 elif i == 1: w = 58 elif i == 2: w = 115 elif i == 3: w = 151 else: w = 187 w = w + octave_offset playing_b.append([w, tick, note]) # To find out what sort of chord is being played we have to look # at both the white and black keys, obviously: notes = playing_w + playing_b notes.sort() notenames = [] for n in notes: notenames.append(n[2].name) # Determine the chord det = chords.determine(notenames) if det != []: det = det[0] else: det = "" # And render it onto the text surface t = font.render(det, 2, (0, 0, 0)) text.fill((255, 255, 255)) text.blit(t, (0, 0)) # Play the note fluidsynth.play_Note(note, channel, 100)
def play(self, volume = 127): ''' play - plays a note at specified volume if it was a note_on event and stops a note if it was a note_off event ''' self.note.velocity = volume if self.on_off: fluidsynth.play_Note(self.note,self.channel) else: fluidsynth.stop_Note(self.note, self.channel)
def play_Note(self, freq, keys, vol=1): """ """ next_note = self.lookup_Note(freq, keys) if next_note != self.current_note: if self.current_note: fluidsynth.stop_Note(Note(self.current_note),1) print "playing note {0}".format(next_note) fluidsynth.play_Note(Note(next_note),1) self.current_note = next_note
def playNotes(notes, xscale = 0.01): fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa") currTime = 0 for n in notes: waitTime = n.startx * xscale - currTime currTime = n.startx * xscale fluidsynth.play_Note(pow(n.energy, 0.2), 0, 100) print("Played %s, Waiting for %s " % (n, waitTime)) time.sleep(waitTime) fluidsynth.stop_everything()
def playNotes(notes, xscale=0.01): fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2', "alsa") currTime = 0 for n in notes: waitTime = n.startx * xscale - currTime currTime = n.startx * xscale fluidsynth.play_Note(pow(n.energy, 0.2), 0, 100) print("Played %s, Waiting for %s " % (n, waitTime)) time.sleep(waitTime) fluidsynth.stop_everything()
def playNotes(notes, xscale=0.01): currTime = 0 for n in notes: waitTime = n.startx * xscale - currTime currTime = n.startx * xscale fluidsynth.play_Note(n.height, 1, 127) print("Played %s " % n) #print("Waiting for %s " % waitTime) time.sleep(waitTime) fluidsynth.stop_everything()
def on_touch_move(self, touch): #add point to line, get new note for touch touch.ud[touch.uid].points += [touch.x, touch.y] newNote = self.getNote(touch.x, self.width) #if newNote isn't the same as what we saved #stop the note and start a new one if (newNote not in self.notesp.values()): fluidsynth.stop_Note(self.notesp[touch.uid], 1) self.notesp[touch.uid] = newNote fluidsynth.play_Note(self.notesp[touch.uid])
def playNotes(notes, xscale = 0.01): currTime = 0 for n in notes: waitTime = n.startx * xscale - currTime currTime = n.startx * xscale fluidsynth.play_Note(n.height, 1, 127) print("Played %s " % n) #print("Waiting for %s " % waitTime) time.sleep(waitTime) fluidsynth.stop_everything()
def play_basic_chord(chord): c = NoteContainer(chord) l = Note(c[0].name) l.octave_down() print ch.determine(chord)[0] # Play chord and lowered first note fluidsynth.play_NoteContainer(c) fluidsynth.play_Note(l) time.sleep(1.0) return c
def play_note(self, note_name, octave): """play_note determines the coordinates of a note on the keyboard image and sends a request to play the note to the fluidsynth server""" note = Note(note_name, octave) self.note_states[note] = self._tick, None # Play the note if self.start_time is None: self.start_time = time.time() fluidsynth.play_Note(note, current_channel, 100)
def play_notes(fs): key = random_key() print key # fs.play_Note(Note('C-5')) # fs.play_NoteContainer(NoteContainer(chords.major_triad(key))) # fs.play_Bar(get_bar_from_triad(chords.major_triad(key))) fs.play_Note(Note('Cb-4')) ## this is B-3, not B-4 fs.play_Note(Note('B-3')) # print(_make_ascending(chords.major_triad(key))) a = raw_input('hello?')
def playProgression(): progression = ["I", "vi", "ii", "iii7", "I7", "viidom7", "iii7", "V7"] key = "C" chords = progressions.to_chords(progression, key) if not fluidsynth.init(SF2): print "Couldn't load soundfont", SF2 sys.exit(1) while 1: i = 0 for chord in chords: c = NoteContainer(chords[i]) l = Note(c[0].name) p = c[1] l.octave_down() print ch.determine(chords[i])[0] # Play chord and lowered first note fluidsynth.play_NoteContainer(c) fluidsynth.play_Note(l) time.sleep(1.0) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.5: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.5: l = Note(intervals.second(c[0].name, key)) l.octave_up() fluidsynth.play_Note(l) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.5: fluidsynth.play_Note(c[-2]) time.sleep(0.25) fluidsynth.stop_NoteContainer(c) fluidsynth.stop_Note(l) fluidsynth.stop_Note(p) i += 1 print "-" * 20
def on_touch_down(self, touch): #draw pretty lines on screen, inspired by online demo color = (random(), random(), random()) with self.canvas: Color(*color) touch.ud[touch.uid] = Line(points=(touch.x, touch.y), width=5) for pos in self.getNote(touch.x, self.width, True): Bezier(points=[int(round(float(pos)*float(self.width))), 0, int(round(float(pos)*float(self.width))), Window.height], group='grid', dash_offset=4) #add note to notesp {} and start playing, by touch.uid if touch.uid in self.notesp: fluidsynth.stop_Note(self.notesp[touch.uid], 1) self.notesp[touch.uid] = self.getNote(touch.x, self.width) fluidsynth.play_Note(self.notesp[touch.uid])
def play_midi(midi_path, save_path, beats, midi_vel, stop_all,midi_device_nr): from mingus.midi import fluidsynth from mingus.containers.note import Note curr_path = lib.os.path.dirname(lib.os.path.abspath(__file__)) fluidsynth.init("/Users/js/Desktop/sounds/Nice-Keys-PlusSteinway-JNv2.0.sf2") f = open(save_path + '/play_midi.csv', 'w+') # open file to save log values f.write('time,beats,midi_note,midi_vel\n') # write first line with corresponding titles mid = lib.mido.MidiFile(midi_path+'.mid') # save parsed MIDI file using mido library s_times = [] # np.zeros((times[0],2)) # create an empty array to storenote events in the MIDI file #port = lib.mido.open_output(lib.mido.get_output_names()[midi_device_nr.value]) # open port to send MIDI messages all_time = 0 # aggregate time for all the messages msg_count = 0 # this is to count MIDI messages with note information all_messages = [] # create an ampty array to only store note information and their position in the score for msg in mid: # for every message in the midi file all_time += msg.time # the file stores midi time based on previous onset, we h if hasattr(msg, 'note'): # checks that the MIDI message is Note #all_time += msg.time # all_messages.append(msg) # adds note message from MIDI file to our playback thing s_times.append([msg_count, all_time]) # array to store note score time msg_count += 1 # count of how many note messages there are in total s_times = lib.np.array(s_times) # convert array to numpy.array yo = lib.copy.deepcopy(s_times) # deepcopy the array so the original doesn't get manipulated while True: if len(yo) != 0: # keep running the loop until there are no more notes to play #print 'here' if yo[0, 1] < beats.value: # if the playhead is larger than the first note in the array play the first note and then delete msgMIDI = all_messages[int(yo[0, 0])] # add note information and it's timing to the midi message to be sent if midi_vel.value > 127: msgMIDI.velocity = 127 else: msgMIDI.velocity = midi_vel.value # add velocity to the MIDI message to be sent f.write( # store values for later analysis "%f, %f, %f, %f\n" % (lib.time.time(), beats.value, all_messages[int(yo[0, 0])].note, midi_vel.value)) msgMIDI.channel = 0 note = Note(all_messages[int(yo[0, 0])].note-12) print note note.velocity = msgMIDI.velocity if msgMIDI.type == 'note_on': fluidsynth.play_Note(note) if msgMIDI.type == 'note_off': fluidsynth.stop_Note(note) #port.send(msgMIDI) # send the message using predefined port (midi device) yo = lib.np.delete(yo, 0, 0) # once the note has been played delete the first message #print beats.value/2 else: # if there are no more notes to play f.close # stop storing the values in csv stop_all.value = True # flag to indicate to the rest of the system that the file has finished. print 'MIDI Playback Finished' # print for use rto acknowledge break
def erreproduzitu_marrazkia2(screen): fluidsynth.init( '/home/galtzagorri/Mahaigaina/Arachno SoundFont - Version 1.0.sf2', "alsa") #fluidsynth.init('/home/galtzagorri/Mahaigaina/grand-piano-YDP-20160804.sf2',"alsa") for i in range(0, len(zerrenda)): print zerrenda[i].posy print zerrendaBase[i].posy nota = (zerrenda[i].posy) % 127 nota2 = (zerrendaBase[i].posy) % 126 t = threading.Thread(target=fluidsynth.play_Note(nota, 1, 100)) t2 = threading.Thread(target=fluidsynth.play_Note(nota2, 1, 100)) #t.start() #t2.start() #fluidsynth.play_Note(nota,1,100) #fluidsynth.play_Note(nota2,2,100) time.sleep(0.5)
def createPoly(view): colors = [ "#660000", "#990000", "#CC0000", "#FF0000", "#CC3333", "#FF6666", "#FF9999", "#FFCCCC", "#663300", "#993300", "#CC3300", "#FF3300", "#FF6600", "#FF6633", "#FF9966", "#FFCC99", "#996633", "#CC9900", "#FFCC00", "#FFFF00", "#FFFF33", "#FFFF66", "#FFFF99", "#FFFFCC", "#003300", "#006600", "#009900", "#00CC00", "#00FF00", "#66FF66", "#CCFFCC", "#003333", "#336666", "#009999", "#00CCCC", "#66CCCC", "#66FFCC", "#99FFCC", "#003399", "#0033FF", "#0066FF", "#00CCFF", "#00FFFF", "#99FFFF", "#CCFFFF", "#000066", "#000099", "#0000CC", "#0000FF", "#3366FF", "#3399FF", "#66CCFF", "#99CCFF", "#330066", "#660099", "#663399", "#9900CC", "#9933FF", "#9966FF", "#9999FF", "#CCCCFF", "#660066", "#990066", "#CC0099", "#FF0099", "#FF00FF", "#FF66FF", "#FF99FF", "#FFCCFF" ] Link = [0] * int( numONodes.get()) #Creating list to connect nodes, rounds any floats t.color(lineColor.get()) t.speed(0) t.penup() Link = getDots(Link, view) if view: t.tracer(0) else: t.tracer(1) for x in range(numONodes.get()): if rainbow.get() == 1: t.color(colors[x % 69]) t.penup() t.goto(Link[x]) t.pendown() value = int(x * float(degree.get())) fluidsynth.play_Note(value % 100, 100) if (value >= numONodes.get()): t.goto(Link[value % numONodes.get()]) else: t.goto(Link[value]) if (rainbow.get() == 0): t.dot(5, hitNodeColor.get( )) # before it goes back change the color of the targeted node t.goto(Link[x]) t.penup() t.goto( Link[0] ) #The pen needs to go back to the start so the next pattern can be drawn done()
def activateKey(key): if currentMode > 0 or key > 3: fluidsynth.play_Note(Note(notes[currentMode][key]), modeChannels[currentMode], 70) print notes[currentMode][key] #the 96tears mode is unlike other modes in that the first two switches are drums and the next two switches play chords elif key == 0: fluidsynth.play_Note(drumSnare, 3, 90) print "Snare" elif key == 1: fluidsynth.play_Note(drumBass, 3, 127) print "Bass" elif key == 2: fluidsynth.play_NoteContainer(chordC7, 2, 60) print "Chord C7" elif key == 3: fluidsynth.play_NoteContainer(chordG, 2, 60) print "Chord G" #calculate neopixel color, each key is a different shade of the rainbow positionProduct = key*255 notesLength = len(notes[currentMode]) wheelPosition = positionProduct/notesLength #print "Color:", wheelPosition for i in range(strip.numPixels()): if i >= lightSegments[key][0] and i <= lightSegments[key][1]: strip.setPixelColor(i, wheel(wheelPosition)) strip.show()
def trigger(self, obj, cx, cy): if cy < (self.height / 3): if obj == "orange": fluidsynth.play_Note(cy, 0, 80) elif obj == "yellow": fluidsynth.play_Note(cy, 1, 80) elif obj == "red": fluidsynth.play_Note(cy, 2, 100)
def synthComm(): # print "I AM IN synthComm" timeStart = time.time() fluidsynth.init(config.sf2Path) note = Note() ser = serial.Serial(config.megaPath, config.megaBaud,timeout = 1) fluidsynth.stop_Note(note) while config.playing: info = ser.readline() print info if info is not '' and len(info) == 9: # print info # print timeStart fluidsynth.stop_Note(note) # print "---" # print len(info) # print "---" timeElp, x, y, vel = parseInput(timeStart, info) n = pos2Num(x,y) # print n # print names[n] note = Note(names[n],octave) note.velocity = vel fluidsynth.play_Note(note) print "-----" print "Time: {0} \nPosition: {1},{2}\n Velocity: {3}".format(timeElp, x, y, vel) print "-----" else: fluidsynth.stop_Note(note) # config.userHits = np.hstack((config.userHits, np.array([[time],[vel],[x],[y]))) # when done, close out connection ser.close() # print " I HAVE CLOSED THE connection" return
def on_input(self, in_dict): # get touch keys touch = in_dict['touch'] note_list = [('G', 4), ('F', 4), ('E', 4), ('D', 4), ('C', 4), ('B', 3), ('A', 3)] for x in range(len(touch)): #print x, touch[x] if touch[x] and not self.last_touch[x]: #print note_list[x] fluidsynth.play_Note(Note(note_list[x][0], note_list[x][1]), 0, 100) self.last_touch = touch #print in_dict['dist1'], in_dict['dist2'], in_dict['dist3'] dist = in_dict['dist1'] if (dist < 250): if (len(self.dist1_notes) > 20): fluidsynth.stop_Note(self.dist1_notes[0], 1) self.dist1_notes = self.dist1_notes[1:] dist1_note = Note() dist1_note.from_int(dist / 2) fluidsynth.play_Note(dist1_note, 1, 80) self.dist1_notes.append(dist1_note) else: if (len(self.dist1_notes) > 0): fluidsynth.stop_Note(self.dist1_notes[0], 1) self.dist1_notes = self.dist1_notes[1:] dist = in_dict['dist2'] if (dist < 250): if (len(self.dist2_notes) > 40): fluidsynth.stop_Note(self.dist2_notes[0], 2) self.dist2_notes = self.dist2_notes[1:] dist_note = Note() dist_note.from_int(dist / 2) fluidsynth.play_Note(dist_note, 2, 80) self.dist2_notes.append(dist_note) else: if (len(self.dist2_notes) > 0): fluidsynth.stop_Note(self.dist2_notes[0], 2) self.dist2_notes = self.dist2_notes[1:] # for note in self.dist2_notes: # fluidsynth.stop_Note(note, 2) # self.dist2_notes = [] #TODO use distance 3 to play music from file dist = in_dict['dist3'] if (dist < 250): if (time.time() - self.last_detect_time) > 60: pygame.mixer.music.play() self.last_detect_time = time.time()
def play_chord(chord): c = play_basic_chord(chord) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.5: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.5: p = Note(intervals.second(c[0].name, key)) p.octave_up() fluidsynth.play_Note(p) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.5: fluidsynth.play_Note(c[-2]) time.sleep(0.25)
def play(): global n, n_1, n_2 for x in range(len(n)): note, note_1, note_2 = n[x], n_1[x], n_2[x] fluidsynth.play_Note(note, 1, note.velocity) fluidsynth.play_Note(note_2, 2, note_2.velocity) fluidsynth.play_Note(note_1, 3, note_1.velocity) sleep(.3) sleep(3) for x in range(len(n)): fluidsynth.stop_Note(n[x]) sleep(.2) fluidsynth.stop_Note(n_1[x]) sleep(.2) fluidsynth.stop_Note(n_2[x]) sleep(.2)
def runStateMachine(self): if self.stateChanged: self.stateChanged = False self.cbCh0.setCheckState( Qt.Checked if self.ch0State else Qt.Unchecked) self.cbCh1.setCheckState( Qt.Checked if self.ch1State else Qt.Unchecked) #self.cbCh0.setCheckState(self.ch0State) #State 1 1 if self.ch1State and self.ch0State: fluidsynth.stop_Note(self.soundCommand1, 0) fluidsynth.stop_Note(self.soundCommand2, 0) fluidsynth.play_Note(self.soundCommand3, 0, 100) self.lbStatus.setText("Status: Comando 3") self.updadeGraphView(self.circleNota3) #State 0 1 elif not self.ch1State and self.ch0State: fluidsynth.play_Note(self.soundCommand1, 0, 100) fluidsynth.stop_Note(self.soundCommand2, 0) fluidsynth.stop_Note(self.soundCommand3, 0) self.lbStatus.setText("Status: Comando 1") self.updadeGraphView(self.circleNota1) #State 1 0 elif self.ch1State and not self.ch0State: fluidsynth.stop_Note(self.soundCommand1, 0) fluidsynth.play_Note(self.soundCommand2, 0, 100) fluidsynth.stop_Note(self.soundCommand3, 0) self.lbStatus.setText("Status: Comando 2") self.updadeGraphView(self.circleNota2) #State 1 1 else: #fluidsynth.stop_everything() fluidsynth.stop_Note(self.soundCommand1, 0) fluidsynth.stop_Note(self.soundCommand2, 0) fluidsynth.stop_Note(self.soundCommand3, 0) self.lbStatus.setText("Status: Silencio") self.updadeGraphView(self.circleSilence)
is_not_start = lambda line: line != start_line is_not_stop = lambda line: not line.startswith(' }') for i in range(2, 14): t = time.time() file_name = str(i) + "-grams-epochs_hmm_" + epoch_size + ".json" with open(os.path.join(epochs_hmm_folder, file_name)) as istream: lines = dropwhile(is_not_start, istream) next(lines) lines = takewhile(is_not_stop, lines) text = '{' + ''.join(lines) + '}' data = json.loads(text) sequence = str(tuple(melody)) try: k = data[sequence].keys() v = data[sequence].values() melody.append(int(numpy.random.choice([*k], p=[*v]))) except KeyError: break if debug: print(melody) print("Time taken to get next interval: ", time.time() - t) print(tuple(melody)) note = 60 fluidsynth.play_Note(note, 0, 100) time.sleep(0.5) for i in range(len(melody)): note += melody[i] fluidsynth.play_Note(note, 0, 100) time.sleep(0.5) time.sleep(2.0)
def playnote( self, midinote, notevel=100, duration=1, channel=0 ): ''' play a note, but only let it exist for a short period of time ''' self.transientnotes.append( [ midinote, duration, channel ] ) fluidsynth.play_Note( midinote, channel, notevel ) #
if not fluidsynth.init(SF2): print "Couldn't load soundfont", SF2 sys.exit(1) while 1: i = 0 for chord in chords: c = NoteContainer(chords[i]) l = Note(c[0].name) p = c[1] l.octave_down() print ch.determine(chords[i])[0] # Play chord and lowered first note fluidsynth.play_NoteContainer(c) fluidsynth.play_Note(l) time.sleep(1.0) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.5: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.5: l = Note(intervals.second(c[0].name, key))
if not fluidsynth.init(SF2): print("Couldn't load soundfont", SF2) sys.exit(1) while 1: i = 0 for chord in chords: c = NoteContainer(chords[i]) l = Note(c[0].name) p = c[1] l.octave_down() print(ch.determine(chords[i])[0]) # Play chord and lowered first note fluidsynth.play_NoteContainer(c) fluidsynth.play_Note(l) time.sleep(1.0) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.50: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth
def startnote( self, midinote, notevel=100, channel=0 ): ''' start a note playing, usually from a midi input source. MUST END IT LATER. ''' fluidsynth.play_Note( midinote, channel, notevel ) #
from mingus.midi import fluidsynth fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2') fluidsynth.play_Note(64,0, 100)
def test_playnote(self): self.assertTrue(fluidsynth.play_Note(Note("C"))) time.sleep(0.25) fluidsynth.stop_Note(Note("C"))
fluidsynth.stop_Note(n) if t % 2 == 0: n = Note(choice(c).name) elif random() > 0.5: if random() < 0.46: n = Note(intervals.second(choice(c).name, key)) elif random() < 0.46: n = Note(intervals.seventh(choice(c).name, key)) else: n = Note(choice(c).name) if t > 0 and t < len(beats) - 1: if beats[t-1] and not beats[t+1]: n = Note(choice(c).name) fluidsynth.play_Note(n, solo_channel, randrange(80, 110)) print n if swing: if t % 2 == 0: time.sleep( (bar_length / (len(beats) * 3)) * 4) else: time.sleep( (bar_length / (len(beats) * 3)) * 2) else: time.sleep( bar_length / len(beats)) t += 1 fluidsynth.stop_Note(n, solo_channel) i += 1 print "-" * 20
def test_playnote(self): self.assert_(fluidsynth.play_Note(Note("C"))) time.sleep(0.25) fluidsynth.stop_Note(Note("C"))
def onBlackDown(self, event): self.fillcolor = "C0C0C0" fluidsynth.play_Note(self.note)
def play(): requested_keys = bottle.request.query.notes.split(",") for key in requested_keys: if unicode.isdigit(key): midi_key = config.MIDI_KEY_MAPPING[int(key)] fluidsynth.play_Note(midi_key)
if beat and play_solo and loop > solo_start and loop < solo_end: fluidsynth.stop_Note(n) if t % 2 == 0: n = Note(choice(c).name) elif random() > 0.5: if random() < 0.46: n = Note(intervals.second(choice(c).name, key)) elif random() < 0.46: n = Note(intervals.seventh(choice(c).name, key)) else: n = Note(choice(c).name) if t > 0 and t < len(beats) - 1: if beats[t - 1] and not beats[t + 1]: n = Note(choice(c).name) fluidsynth.play_Note(n, solo_channel, randrange(80, 110)) print(n) # Repeat chord on half of the bar if play_chords and t != 0 and loop > chord_start and loop < chord_end: if swing and random() > 0.95: fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75)) elif t % (len(beats) / 2) == 0 and t != 0: fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75)) # Play bass note if play_bass and t % 4 == 0 and t != 0: l = Note(choice(c).name) l.octave_down()
if r[1] <= 0.50: recorded_buffer.append([r[0], r[1]]) buffered += 1 else: break elif status == 'stopped': if event.key == K_r: status = 'record' if event.key == K_ESCAPE: quit = True if status == 'play': try: while recorded[played][1] <= tick: playing.append([recorded[played][0], recorded[played][1]]) fluidsynth.play_Note(recorded[played][2], 9, 100) played += 1 if played == len(recorded) - 1: status = 'stopped' except: pass # Update the recorded_buffer try: while need_buffer and recorded[buffered][1] <= high_barrier: recorded_buffer.append( [recorded[buffered][0], recorded[buffered][1]]) buffered += 1 if buffered >= len(recorded) - 1: buffered = len(recorded) - 1
def press_key(self, note): if self.is_sound_on: fluidsynth.play_Note(Note(note))
''' tester for mingus fluidsynth ''' from mingus.midi import fluidsynth from mingus.containers import Note import sys import time import random fluidsynth.init("../HS_Magic_Techno_Drums.SF2") names = ['A', 'Bb', 'B', 'C', 'Db','D','Eb', 'E', 'F', 'Gb','G','Ab'] # while(True): # n = Note(names[random.randrange(0,11,1)], random.randrange(1,4,1)) # n.velocity = random.randrange(40,100,1) # # fluidsynth.set_instrument(1, random.randrange(1,5,1), bank =1) # fluidsynth.play_Note(n) # time.sleep(.1*random.randrange(1,15,1)) # # fluidsynth.stop_Note(n) # time.sleep(.5*random.randrange(1,15,1)) # # fluidsynth.play_Note(n) for i in xrange(0,12): # for j in xrange(1,4): # n = Note(names[i],j) # fluidsynth.play_Note(n) # time.sleep(2) n = Note(names[i], 4) n.velocity = 127 fluidsynth.play_Note(n) time.sleep(1)
def play_high_note(n): l = Note(n) l.octave_up() print l fluidsynth.play_Note(l) return l
if beat and play_solo and loop > solo_start and loop < solo_end: fluidsynth.stop_Note(n) if t % 2 == 0: n = Note(choice(c).name) elif random() > 0.5: if random() < 0.46: n = Note(intervals.second(choice(c).name, key)) elif random() < 0.46: n = Note(intervals.seventh(choice(c).name, key)) else: n = Note(choice(c).name) if t > 0 and t < len(beats) - 1: if beats[t - 1] and not beats[t + 1]: n = Note(choice(c).name) fluidsynth.play_Note(n, solo_channel, randrange(80, 110)) print n # Repeat chord on half of the bar if play_chords and t != 0 and loop > chord_start and loop\ < chord_end: if swing and random() > 0.95: fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75)) elif t % (len(beats) / 2) == 0 and t != 0: fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75)) # Play bass note
if r[1] <= 0.50: recorded_buffer.append([r[0], r[1]]) buffered += 1 else: break elif status == 'stopped': if event.key == K_r: status = 'record' if event.key == K_ESCAPE: quit = True if status == 'play': try: while recorded[played][1] <= tick: playing.append([recorded[played][0], recorded[played][1]]) fluidsynth.play_Note(recorded[played][2], 9, 100) played += 1 if played == len(recorded) - 1: status = 'stopped' except: pass # Update the recorded_buffer try: while need_buffer and recorded[buffered][1] <= high_barrier: recorded_buffer.append([recorded[buffered][0], recorded[buffered][1]]) buffered += 1 if buffered >= len(recorded) - 1: buffered = len(recorded) - 1