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 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(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 stop_Note(self): """ """ if self.current_note: fluidsynth.stop_Note(Note(self.current_note),1) print "stopping note" self.current_note = ""
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 on_touch_up(self, touch): #delete the note and line on_touch_up try: if len(self.notesp) <= 1: self.canvas.remove_group('grid') self.canvas.remove(touch.ud[touch.uid]) fluidsynth.stop_Note(self.notesp[touch.uid], 1) del self.notesp[touch.uid] except: pass
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 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 stop_note(self, note_enum): stop = 0 play = self.convert_note(note_enum) for note in self.playing_notes: if play == note: stop = note self.playing_notes.remove(note) break fluidsynth.stop_Note(stop, 1) return
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 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 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 update( self, dt ): ## check if any midi events have happened if self.midiin.poll(): midi_events = self.midiin.read(10) #not sure what 10 is for # convert them into regular pygame events. midi_evs = pygame.midi.midis2events(midi_events, self.midiin.device_id) for m_e in midi_evs: pygame.fastevent.post( m_e ) i=0 while i < len(self.transientnotes): self.transientnotes[i][1] -= dt if self.transientnotes[i][1] < 0: fluidsynth.stop_Note( self.transientnotes[i][0], self.transientnotes[i][2] ) # stop note del self.transientnotes[i] else: i += 1
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 update(self, dt): ## checkt of er enige midi processen zijn. if self.midiin.poll(): midi_events = self.midiin.read(10) # convert naar pygame events midi_evs = pygame.midi.midis2events(midi_events, self.midiin.device_id) for m_e in midi_evs: pygame.fastevent.post(m_e) i = 0 while i < len(self.transientnotes): self.transientnotes[i][1] -= dt if self.transientnotes[i][1] < 0: fluidsynth.stop_Note(self.transientnotes[i][0], self.transientnotes[i][2]) # stop note del self.transientnotes[i] else: i += 1
def update(self, dt): ## check if any midi events have happened if self.midiin.poll(): midi_events = self.midiin.read(10) #not sure what 10 is for # convert them into regular pygame events. midi_evs = pygame.midi.midis2events(midi_events, self.midiin.device_id) for m_e in midi_evs: pygame.fastevent.post(m_e) i = 0 while i < len(self.transientnotes): self.transientnotes[i][1] -= dt if self.transientnotes[i][1] < 0: fluidsynth.stop_Note(self.transientnotes[i][0], self.transientnotes[i][2]) # stop note del self.transientnotes[i] else: i += 1
def tick(self): self._tick += 0.001 to_delete = [] for note, (start_t, end_t) in self.note_states.items(): diff = self._tick - start_t if diff < VISUAL_FADEOUT: w = self._get_visual_offset(note) if note.name in WHITE_KEYS: pressed.fill( (0, ((VISUAL_FADEOUT - diff) / VISUAL_FADEOUT) * 255, 124)) screen.blit(pressed, (w, 0), None, pygame.BLEND_SUB) else: pressed.fill( (((VISUAL_FADEOUT - diff) / VISUAL_FADEOUT) * 125, 0, 125)) screen.blit(pressed, (w, 1), (0, 0, 19, 68), pygame.BLEND_ADD) if end_t is not None and (self._tick - end_t) > NOTE_STOP_TIMEOUT: fluidsynth.stop_Note(note, current_channel) to_delete.append(note) for note in to_delete: del self.note_states[note]
def deactivateKey(key): if currentMode > 0 or key > 3: fluidsynth.stop_Note(Note(notes[currentMode][key]), modeChannels[currentMode]) elif key == 0: fluidsynth.stop_Note(drumSnare, 3) elif key == 1: fluidsynth.stop_Note(drumBass, 3) elif key == 2: fluidsynth.stop_NoteContainer(chordC7, 2) elif key == 3: fluidsynth.stop_NoteContainer(chordG, 2) for i in range(strip.numPixels()): if i >= lightSegments[key][0] and i <= lightSegments[key][1]: strip.setPixelColor(i, Color(0,0,0)) strip.show()
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 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 play_sequence(sequence, separation_seconds): for note_str in sequence: note = Note(note_str) fluidsynth.play_Note(note) fluidsynth.midi.sleep(seconds=separation_seconds) fluidsynth.stop_Note(note)
def endnote( self, midinote, channel=0 ): ''' the counterpart to starting a note. this ends it. ''' fluidsynth.stop_Note( midinote, channel ) # stop note
def on_input(self, in_dict): # get touch keys touch = in_dict['touch'] delta_touch = touch ^ self.last_touch self.last_touch = touch if (delta_touch & 0x01): if (touch & 0x01): fluidsynth.play_Note(ord('A'), 0, 100) else: fluidsynth.stop_Note(ord('A'), 0) if (delta_touch & 0x02): if (touch & 0x02): fluidsynth.play_Note(ord('B'), 0, 100) else: fluidsynth.stop_Note(ord('B'), 0) if (delta_touch & 0x04): if (touch & 0x04): fluidsynth.play_Note(ord('C'), 0, 100) else: fluidsynth.stop_Note(ord('C'), 0) if (delta_touch & 0x08): if (touch & 0x08): fluidsynth.play_Note(ord('D'), 0, 100) else: fluidsynth.stop_Note(ord('D'), 0) if (delta_touch & 0x10): if (touch & 0x10): fluidsynth.play_Note(ord('E'), 0, 100) else: fluidsynth.stop_Note(ord('E'), 0) if (delta_touch & 0x20): if (touch & 0x20): fluidsynth.play_Note(ord('F'), 0, 100) else: fluidsynth.stop_Note(ord('F'), 0) if (delta_touch & 0x40): if (touch & 0x40): fluidsynth.play_Note(ord('G'), 0, 100) else: fluidsynth.stop_Note(ord('G'), 0) dist1 = in_dict['dist3'] if (dist1 < 180): dist1_note = Note() dist1_note.from_int(in_dict['dist3'] / 2) fluidsynth.play_Note(dist1_note, 1, 20)
def note_off(self, channel, pitch, velocity=100): note = Note() note.from_int(pitch) note.velocity = velocity fluidsynth.stop_Note(note, channel)
def endnote(self, midinote, channel=0): ''' the counterpart to starting a note. this ends it. ''' fluidsynth.stop_Note(midinote, channel) # stop note
def process_events(keyslice): """ this function handles keypresses and executes various other functions like sound, pygame stuff, and history when a key is pressed Note: this function is terribly written, we understand. It's a hackathon, and it does work. """ keypressed, keyunpressed = piano.on_frame() k = keypressed if (k[0] == True or k[1] == True) and history[0] == False: KEYS[0] = 1 keyslice.notesActive[0] = True fluidsynth.play_Note(Note("F-3")) history[0] = True if k[2] == True and history[1] == False: KEYS[1] = 1 keyslice.notesActive[1] = True fluidsynth.play_Note(Note("F#-3")) history[1] = True if (k[3] == True or k[4] == True) and history[2] == False: KEYS[2] = 1 keyslice.notesActive[2] = True fluidsynth.play_Note(Note("G-3")) history[2] = True if k[5] == True and history[3] == False: KEYS[3] = 1 keyslice.notesActive[3] = True fluidsynth.play_Note(Note("G#-3")) history[3] = True if (k[6] == True or k[7] == True) and history[4] == False: KEYS[4] = 1 keyslice.notesActive[4] = True fluidsynth.play_Note(Note("A-3")) history[4] = True if k[8] == True and history[5] == False: KEYS[5] = 1 keyslice.notesActive[5] = True fluidsynth.play_Note(Note("A#-3")) history[5] = True if (k[9] == True or k[10] == True) and history[6] == False: KEYS[6] = 1 keyslice.notesActive[6] = True fluidsynth.play_Note(Note("B-3")) history[6] = True if (k[11] == True or k[12] == True) and history[7] == False: KEYS[7] = 1 keyslice.notesActive[7] = True fluidsynth.play_Note(Note("C-4")) history[7] = True if k[13] == True and history[8] == False: KEYS[8] = 1 keyslice.notesActive[8] = True fluidsynth.play_Note(Note("C#-4")) history[8] = True if (k[14] == True or k[15] == True) and history[9] == False: KEYS[9] = 1 keyslice.notesActive[9] = True fluidsynth.play_Note(Note("D-4")) history[9] = True if k[16] == True and history[10] == False: KEYS[10] = 1 keyslice.notesActive[10] = True fluidsynth.play_Note(Note("D#-4")) history[10] = True if (k[17] == True or k[18] == True) and history[11] == False: KEYS[11] = 1 keyslice.notesActive[11] = True fluidsynth.play_Note(Note("E-4")) history[11] = True if (k[19] == True or k[20] == True) and history[12] == False: KEYS[12] = 1 keyslice.notesActive[12] = True fluidsynth.play_Note(Note("F-4")) history[12] = True if k[21] == True and history[13] == False: KEYS[13] = 1 keyslice.notesActive[13] = True fluidsynth.play_Note(Note("F#-4")) history[13] = True if (k[22] == True or k[23] == True) and history[14] == False: KEYS[14] = 1 keyslice.notesActive[14] = True fluidsynth.play_Note(Note("G-4")) history[14] = True if k[24] == True and history[15] == False: KEYS[15] = 1 keyslice.notesActive[15] = True fluidsynth.play_Note(Note("G#-4")) history[15] = True if (k[25] == True or k[26] == True) and history[16] == False: KEYS[16] = 1 keyslice.notesActive[16] = True fluidsynth.play_Note(Note("A-4")) history[16] = True if k[27] == True and history[17] == False: KEYS[17] = 1 keyslice.notesActive[17] = True fluidsynth.play_Note(Note("A#-4")) history[17] = True if (k[28] == True or k[29] == True) and history[18] == False: KEYS[18] = 1 keyslice.notesActive[18] = True fluidsynth.play_Note(Note("B-4")) history[18] = True if (k[30] == True or k[31] == True) and history[19] == False: KEYS[19] = 1 keyslice.notesActive[19] = True fluidsynth.play_Note(Note("C-5")) history[19] = True if k[32] == True and history[20] == False: KEYS[20] = 1 keyslice.notesActive[20] = True fluidsynth.play_Note(Note("C#-5")) history[20] = True if (k[33] == True or k[34] == True) and history[21] == False: KEYS[21] = 1 keyslice.notesActive[21] = True fluidsynth.play_Note(Note("D-5")) history[21] = True if k[35] == True and history[22] == False: KEYS[22] = 1 keyslice.notesActive[22] = True fluidsynth.play_Note(Note("D#-5")) history[22] = True if (k[36] == True or k[37] == True) and history[23] == False: KEYS[23] = 1 keyslice.notesActive[23] = True fluidsynth.play_Note(Note("E-5")) history[23] = True k = keyunpressed if k[0] == True and k[1] == True: KEYS[0] = 0 keyslice.notesActive[0] = False fluidsynth.stop_Note(Note("F-3")) history[0] = False if k[2] == True: KEYS[1] = 0 keyslice.notesActive[1] = False fluidsynth.stop_Note(Note("F#-3")) history[1] = False if k[3] == True and k[4] == True: KEYS[2] = 0 keyslice.notesActive[2] = False fluidsynth.stop_Note(Note("G-3")) history[2] = False if k[5] == True: KEYS[3] = 0 keyslice.notesActive[3] = False fluidsynth.stop_Note(Note("G#-3")) history[3] = False if k[6] == True and k[7] == True: KEYS[4] = 0 keyslice.notesActive[4] = False fluidsynth.stop_Note(Note("A-3")) history[4] = False if k[8] == True: KEYS[5] = 0 keyslice.notesActive[5] = False fluidsynth.stop_Note(Note("A#-3")) history[5] = False if k[9] == True and k[10] == True: KEYS[6] = 0 keyslice.notesActive[6] = False fluidsynth.stop_Note(Note("B-3")) history[6] = False if k[11] == True and k[12] == True: KEYS[7] = 0 keyslice.notesActive[7] = False fluidsynth.stop_Note(Note("C-4")) history[7] = False if k[13] == True: KEYS[8] = 0 keyslice.notesActive[8] = False fluidsynth.stop_Note(Note("C#-4")) history[8] = False if k[14] == True and k[15] == True: KEYS[9] = 0 keyslice.notesActive[9] = False fluidsynth.stop_Note(Note("D-4")) history[9] = False if k[16] == True: KEYS[10] = 0 keyslice.notesActive[10] = False fluidsynth.stop_Note(Note("D#-4")) history[10] = False if k[17] == True and k[18] == True: KEYS[11] = 0 keyslice.notesActive[11] = False fluidsynth.stop_Note(Note("E-4")) history[11] = False if k[19] == True and k[20] == True: KEYS[12] = 0 keyslice.notesActive[12] = False fluidsynth.stop_Note(Note("F-4")) history[12] = False if k[21] == True: KEYS[13] = 0 keyslice.notesActive[13] = False fluidsynth.stop_Note(Note("F#-4")) history[13] = False if k[22] == True and k[23] == True: KEYS[14] = 0 keyslice.notesActive[14] = False fluidsynth.stop_Note(Note("G-4")) history[14] = False if k[24] == True: KEYS[15] = 0 keyslice.notesActive[15] = False fluidsynth.stop_Note(Note("G#-4")) history[15] = False if k[25] == True and k[26] == True: KEYS[16] = 0 keyslice.notesActive[16] = False fluidsynth.stop_Note(Note("A-4")) history[16] = False if k[27] == True: KEYS[17] = 0 keyslice.notesActive[17] = False fluidsynth.stop_Note(Note("A#-4")) history[17] = False if k[28] == True and k[29] == True: KEYS[18] = 0 keyslice.notesActive[18] = False fluidsynth.stop_Note(Note("B-4")) history[18] = False if k[30] == True and k[31] == True: KEYS[19] = 0 keyslice.notesActive[19] = False fluidsynth.stop_Note(Note("C-5")) history[19] = False if k[32] == True: KEYS[20] = 0 keyslice.notesActive[20] = False fluidsynth.stop_Note(Note("C#-5")) history[20] = False if k[33] == True and k[34] == True: KEYS[21] = 0 keyslice.notesActive[21] = False fluidsynth.stop_Note(Note("D-5")) history[21] = False if k[35] == True: KEYS[22] = 0 keyslice.notesActive[22] = False fluidsynth.stop_Note(Note("D#-5")) history[22] = False if k[36] == True and k[37] == True: KEYS[23] = 0 keyslice.notesActive[23] = False fluidsynth.stop_Note(Note("E-5")) history[23] = False return keyslice
def stop(self): if not self.no_fluidsynth: for x in range(128): fluidsynth.stop_Note(x, self.last_chan)
def stop_all(self): for note in self.playing_notes: fluidsynth.stop_Note(note, 1) del self.playing_notes[:] return
def stop(self): self.should_stop = True if self.previous != SoundGen.kNoteNone: # Won't actually kill SoundGen just yet, but at least will stop the sound instantly. fluidsynth.stop_Note(self.previous + self.shift, 0)
fluidsynth.init('GeneralUser GS v1.471.sf2', 'alsa') else: fluidsynth.init('GeneralUser GS v1.471.sf2') fluidsynth.set_instrument(1, int(sys.argv[1]), int(sys.argv[2])) c = Note("C-4") e = Note("E-4") g = Note("G-4") fluidsynth.play_Note(c) time.sleep(2) fluidsynth.play_Note(e) time.sleep(2) fluidsynth.play_Note(g) time.sleep(2) fluidsynth.stop_Note(c) fluidsynth.stop_Note(e) fluidsynth.stop_Note(g) time.sleep(2) nc = NoteContainer(["C-4", "E-4", "G-4"]) nc.velocity = 70 fluidsynth.play_NoteContainer(nc) time.sleep(2) fluidsynth.stop_NoteContainer(nc)
# 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 if random() > 0.50: 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.50: 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 test_playnote(self): self.assertTrue(fluidsynth.play_Note(Note("C"))) time.sleep(0.25) fluidsynth.stop_Note(Note("C"))
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)
# Blit the picture of one octave OCTAVES times. for x in range(OCTAVES): screen.blit(key_graphic, (x * width,0)) # Blit the text surface screen.blit(text, (0,height)) # Check all the white keys for note in playing_w: diff = tick - note[1] # If a is past its prime, remove it, otherwise blit the pressed surface # with a 'cool' fading effect. if diff > FADEOUT: fluidsynth.stop_Note(note[2], channel) playing_w.remove(note) else: pressed.fill((0, (FADEOUT - diff) / FADEOUT * 255, 124)) screen.blit(pressed, (note[0], 0), None , pygame.BLEND_SUB) # Now check all the black keys. This redundancy could have been # prevented, but it isn't any less clear like this for note in playing_b: diff = tick - note[1] # Instead of SUB we ADD this time, and change the coloration if diff > FADEOUT: fluidsynth.stop_Note(note[2], channel) playing_b.remove(note) else:
def playNote(self, note, beats): seconds = beats*60/self.bpm n = Note(note+"-5") fluidsynth.play_Note(n) time.sleep(seconds); fluidsynth.stop_Note(n)
def generate_accompaniment(net_output_chords): generated_chords = [] chords = [] for chord in net_output_chords: root, key = (chord.split(":")) print(root, key) if key == 'maj': chords.append(ch.major_triad(root)) if key == 'min': chords.append(ch.minor_triad(root)) print(chords) key = chords[0][0] print('key', key) if not fluidsynth.init(SF2): print("Couldn't load soundfont", SF2) sys.exit(1) print(dir(fluidsynth.midi)) # fluidsynth.midi.start_audio_output() fluidsynth.midi.start_recording() phrase = 0 while phrase == 0: i = 0 for chord in chords: print("chord", chord) c = NoteContainer(chords[i]) generated_chords.append([{'note':cc.name.replace("B#","B").replace("E#","E").replace("##","#"), 'octave':cc.octave} for cc in c]) l = Note(c[0].name) p = c[1] l.octave_down() print(ch.determine(chords[i])[0]) # Play chord and lowered first note # fluidsynth.midi.MidiFileOut.write_NoteContainer("test.mid", c) print("NEW CHORD = ", c) if PLAY_ENABLED: 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 if random() > 0.50: 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.50: 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) phrase = 1 return generated_chords
from mingus.containers.Note import Note from mingus.midi import fluidsynth import time fluidsynth.init("soundfonts/trumpet.sf2", "alsa") fluidsynth.play_Note(Note("C-4")) time.sleep(1) fluidsynth.stop_Note(Note("C-4")) fluidsynth.play_Note(Note("F#-4")) time.sleep(1) fluidsynth.stop_Note(Note("F#-4")) fluidsynth.play_Note(Note("G-4")) time.sleep(1) fluidsynth.stop_Note(Note("G-4")) fluidsynth.play_Note(Note("C-5")) time.sleep(1) fluidsynth.stop_Note(Note("C-5"))
def endnote(self, midinote, channel=0): ''' Dit stopt de note ''' fluidsynth.stop_Note(midinote, channel) # stop note
def stop(note): fluidsynth.stop_Note(note)
def test_playnote(self): self.assert_(fluidsynth.play_Note(Note("C"))) time.sleep(0.25) fluidsynth.stop_Note(Note("C"))
def test_playnote(self): self.assert_(fluidsynth.play_Note(Note('C'))) time.sleep(0.25) fluidsynth.stop_Note(Note('C'))
screen.blit(key_graphic, (x * width, 0)) # Blit the text surface screen.blit(text, (0, height)) # Check all the white keys for note in playing_w: diff = tick - note[1] # If a is past its prime, remove it, otherwise blit the pressed surface # with a 'cool' fading effect. if diff > FADEOUT: fluidsynth.stop_Note(note[2], channel) playing_w.remove(note) else: pressed.fill((0, ((FADEOUT - diff) / FADEOUT) * 255, 124)) screen.blit(pressed, (note[0], 0), None, pygame.BLEND_SUB) # Now check all the black keys. This redundancy could have been prevented, # but it isn't any less clear like this for note in playing_b: diff = tick - note[1] # Instead of SUB we ADD this time, and change the coloration if diff > FADEOUT: fluidsynth.stop_Note(note[2], channel)
def play_midi(midi_note, velocity): if velocity == 0: fluidsynth.stop_Note(midi_note, SYNTH_CHANNEL) else: fluidsynth.play_Note(midi_note, SYNTH_CHANNEL, velocity)
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 stop(note, octave): fluidsynth.stop_Note(Note(note, octave), SYNTH_CHANNEL)
randrange(50, 75)) else: fluidsynth.play_NoteContainer(c, chord_channel2, randrange(50, 75)) if double_time: beats = [random() > 0.5 for x in range((loop % 2 + 1) * 8)] else: beats = [random() > 0.5 for x in range(8)] t = 0 for beat in beats: # Play random note 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
def playNote(self, note, beats): seconds = beats * 60 / self.bpm n = Note(note + "-5") fluidsynth.play_Note(n) time.sleep(seconds) fluidsynth.stop_Note(n)