def test_playnotecontainer(self): self.assert_(fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0)) time.sleep(0.25) fluidsynth.stop_NoteContainer(NoteContainer(["C", "E", "G"]), 0) self.assert_(fluidsynth.play_NoteContainer(NoteContainer(["E", "G", Note("C", 6)]), 0)) time.sleep(0.25) fluidsynth.stop_NoteContainer(NoteContainer(["E", "G", Note("C", 6)]), 0)
def play(self, events): notes_on = [e.to_ming_note() for e in events if e.command_type == 'NOTE_ON'] notes_off = [e.to_ming_note() for e in events if e.command_type == 'NOTE_OFF'] for note in notes_off: self.validator.add_gamer_note(note, 'NOTE_OFF') fluidsynth.stop_NoteContainer(NoteContainer(notes_off)) for note in notes_on: self.validator.add_gamer_note(note, 'NOTE_ON') fluidsynth.play_NoteContainer(NoteContainer(notes_on))
def test_playnotecontainer(self): self.assert_(fluidsynth.play_NoteContainer(NoteContainer(['C', 'E', 'G' ]), 0)) time.sleep(0.25) fluidsynth.stop_NoteContainer(NoteContainer(['C', 'E', 'G']), 0) self.assert_(fluidsynth.play_NoteContainer(NoteContainer(['E', 'G', Note('C', 6)]), 0)) time.sleep(0.25) fluidsynth.stop_NoteContainer(NoteContainer(['E', 'G', Note('C', 6)]), 0)
def stop_playing_notes(self): playing = [] for x in self.playing: if x[1] <= 1: if not self.no_fluidsynth: fluidsynth.stop_NoteContainer(x[0], self.last_chan) else: playing.append([x[0], x[1] - 1]) self.playing = playing
def test_playnotecontainer(self): self.assertTrue( fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0)) time.sleep(0.25) fluidsynth.stop_NoteContainer(NoteContainer(["C", "E", "G"]), 0) self.assertTrue( fluidsynth.play_NoteContainer( NoteContainer(["E", "G", Note("C", 6)]), 0)) time.sleep(0.25) fluidsynth.stop_NoteContainer(NoteContainer(["E", "G", Note("C", 6)]), 0)
def play_offset(off, sleep_s=0.2, song=sonata, repeats=5, down_octaves=1, instrument=None): song = song * repeats if instrument is not None: for i in range(off): fluidsynth.set_instrument(i+1, instrument) for i in range(len(song)+off): to_stop = i - off if to_stop >= 0: fluidsynth.stop_NoteContainer(NoteContainer([a + "-" + str(int(b)-down_octaves) for (a, b) in song[to_stop].split()]), channel=(to_stop%off)+1) if i < len(song): fluidsynth.play_NoteContainer(NoteContainer([a + "-" + str(int(b)-down_octaves) for (a, b) in song[i].split()]), channel=(i%off)+1, velocity=127) time.sleep(sleep_s)
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_notes(notes): currtime = 0 for note in sorted(notes): # print "Note:", note[0], note[1], note[2], "currtime:", currtime if currtime < note[0]: sleeptime = (note[0] - currtime) * secondsPerBeat time.sleep(sleeptime) currtime = note[0] if note[2] == 'E': fluidsynth.stop_NoteContainer(note[1], channel) if note[2] == 'S': fluidsynth.play_NoteContainer(note[1], channel, velocity=note[3])
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(self): intro = self.segments['intro'] fluidsynth.play_NoteContainer(intro.chord) time.sleep(0.25 * 8) fluidsynth.stop_NoteContainer(intro.chord) # intro, verse, chorus, verse, chorus, bridge, chorus play_pattern = [0, 1, 2, 1, 2, 3, 2] for segment_index in play_pattern: print('Playing {} segment'.format( Song.SEGMENT_ORDER[segment_index])) self.segments[Song.SEGMENT_ORDER[segment_index]].play() outro = self.segments['chorus'] for i in range(3): fluidsynth.play_NoteContainer(outro.chord) time.sleep(0.25 * 8) fluidsynth.stop_NoteContainer(outro.chord)
def play_smart_solo_over_chords(chord_list): fluidsynth.set_instrument(13, 45) fluidsynth.set_instrument(10, 108) fluidsynth.main_volume(13, 75) fluidsynth.main_volume(10, 100) solo = Track() bars = generate_solo(chord_list) for i in range(len(bars)): chord = NoteContainer(chords.from_shorthand(chord_list[i])) bar = bars[i] fluidsynth.play_NoteContainer(chord, 13) fluidsynth.play_Bar(bar, 10) fluidsynth.stop_NoteContainer(chord, 13) solo.add_bar(bar) return solo
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_stop_NoteContainer(noteContainer, duration): fluidsynth.play_NoteContainer(noteContainer) sleep(duration) fluidsynth.stop_NoteContainer(noteContainer)
# 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)
c = ChordTemplate() c.SetNotes('D-3', 'G-3', 'C-4', 'F-4', 'A-4') c.AddCharacter(ChordCharacter('D', 'm7', 'SoWhat')) templates.append(c) c = ChordTemplate() c.SetNotes('F-3', 'B-3', 'E-4', 'A-4', 'D-5') c.AddCharacter(ChordCharacter('D', '69', 'Fourths')) c.AddCharacter(ChordCharacter('D', '69', 'Fourths')) templates.append(c) #print(notes.is_valid_note("D#")) #nc = NoteContainer(['C', 'E', 'G']) # middle Aminor is A3, C4, E4 #a = Note('A-3') #n.from_int(44) #nc = NoteContainer() #nc += a nc1 = templates[0].GetContainer() nc2 = templates[1].GetContainer() #fluidsynth.init("AJH_Piano.sf2","coreaudio","foo.wav") fluidsynth.init("SalC5Light2.sf2", "coreaudio", "foo.wav") fluidsynth.play_NoteContainer(nc1) fluidsynth.midi.sleep(.2) fluidsynth.stop_NoteContainer(nc1) fluidsynth.play_NoteContainer(nc2) fluidsynth.midi.sleep(1) fluidsynth.stop_NoteContainer(nc2)
def stop_note(self): fluidsynth.stop_NoteContainer(self._current_note, 0)
def play_chord(self): fluidsynth.stop_NoteContainer(self.chord) fluidsynth.set_instrument(1, 0) fluidsynth.play_NoteContainer(self.chord)
def play_solo_bar_with_chord(chord_name): chord = NoteContainer(chords.from_shorthand(chord_name)) solo = solo_bar(chord_name) fluidsynth.play_NoteContainer(chord, 13) fluidsynth.play_Bar(solo, 10) fluidsynth.stop_NoteContainer(chord, 13)
if swing: if random() > 0.9: fluidsynth.play_Note(Note('A#', 2), 9, randrange(50, 100)) # hihat open elif random() > 0.6: fluidsynth.play_Note(Note('G#', 2), 9, randrange(100, 120)) # hihat closed if random() > 0.95: fluidsynth.play_Note(Note('E', 2), 9, 100) # snare elif t % 2 == 0: fluidsynth.play_Note(Note('A#', 2), 9, 100) # hihat open else: if random() > 0.9: fluidsynth.play_Note(Note('E', 2), 9, 100) # snare 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_NoteContainer(c, chord_channel) fluidsynth.stop_NoteContainer(c, chord_channel2) fluidsynth.stop_NoteContainer(c, chord_channel3) fluidsynth.stop_Note(l, bass_channel) fluidsynth.stop_Note(n, solo_channel) i += 1 print '-' * 20 loop += 1
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