Advertisement
talofer99

drums with fluidsynth

Mar 6th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import serial
  2. ser = serial.Serial('/dev/ttyACM0', 115200)  # open serial port
  3.  
  4.  
  5. import time
  6. import fluidsynth
  7.  
  8. fs = fluidsynth.Synth()
  9. fs.start(driver="alsa")
  10. ## Your installation of FluidSynth may require a different driver.
  11. ## Use something like:
  12. # fs.start(driver="pulseaudio")
  13.  
  14. #sfid = fs.sfload("example.sf2")
  15.  
  16. fs.program_select(0, sfid, 0, 0)
  17.  
  18.  
  19.  
  20.  
  21. loopFlag = True
  22.  
  23.  
  24. print 'READY !'
  25.  
  26. while (loopFlag):
  27.     if (ser.in_waiting):
  28.         message = ser.read(3)
  29.         # lets get the command first
  30.         command = ord(message[0])
  31.         note = ord(message[1])
  32.         pitch = ord(message[2])
  33.         channel = 0
  34.         print "command - " + str(command) + " note - " + str(note) + " pitch - " + str(pitch)
  35.         #if command is over 143 it menas it start note
  36.         if command > 143:
  37.             #player.set_instrument(command - 144)
  38.             #player.note_on(note,pitch,command - 144)
  39.             fs.noteon(channel, note, pitch)
  40.         else :
  41.             #player.set_instrument(command - 128)
  42.             #player.note_off(note,pitch,command - 128)
  43.             fs.noteoff(channel, note)
  44.  
  45.  
  46. print 'EXIT'
  47.  
  48. fs.delete()
  49. ser.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement