import serial
ser = serial.Serial('/dev/ttyS0', 115200) # open serial port
#ttyS0
import time
import fluidsynth
fs = fluidsynth.Synth()
fs.start(driver="alsa")
## Your installation of FluidSynth may require a different driver.
## Use something like:
# fs.start(driver="pulseaudio")
#sfid = fs.sfload("example.sf2")
sfid0 = fs.sfload("Audio - Sound Font - Sonic Implants Session Drums.sf2")
sfid1 = fs.sfload("HS Acoustic Percussion.sf2")
sfid2 = fs.sfload("Drums Douglas Natural Studio Kit V2.0 (22,719KB).sf2")
sfid3 = fs.sfload("drums_ken_ardency.sf2")
sfid4 = fs.sfload("Percussion 2.sf2")
fs.program_select(0, sfid0, 0, 0)
fs.program_select(1, sfid1, 0, 0)
fs.program_select(2, sfid1, 0, 0)
fs.program_select(3, sfid1, 0, 0)
fs.program_select(4, sfid1, 0, 0)
loopFlag = True
print 'READY !'
while (loopFlag):
if (ser.in_waiting):
message = ser.read(3)
# lets get the command first
command = ord(message[0])
note = ord(message[1])
pitch = ord(message[2])
channel = 0
print "command - " + str(command) + " note - " + str(note) + " pitch - " + str(pitch)
#if command is over 143 it menas it start note
if command > 143:
#player.set_instrument(command - 144)
#player.note_on(note,pitch,command - 144)
fs.noteon(channel, note, pitch)
else :
#player.set_instrument(command - 128)
#player.note_off(note,pitch,command - 128)
fs.noteoff(channel, note)
print 'EXIT'
fs.delete()
ser.close()
#fs.noteon(0, 60, 30)
#fs.noteon(0, 67, 30)
#fs.noteon(0, 76, 30)
#time.sleep(3.0)
#fs.noteoff(0, 60)
#fs.noteoff(0, 67)
#fs.noteoff(0, 76)
Comments