Advertisement
talofer99

python drums with fluydsynth

Mar 22nd, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import serial
  2. ser = serial.Serial('/dev/ttyS0', 115200)  # open serial port
  3. #ttyS0
  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. sfid0 = fs.sfload("Audio - Sound Font - Sonic Implants Session Drums.sf2")
  16. sfid1 = fs.sfload("HS Acoustic Percussion.sf2")
  17. sfid2 = fs.sfload("Drums Douglas Natural Studio Kit V2.0 (22,719KB).sf2")
  18. sfid3 = fs.sfload("drums_ken_ardency.sf2")
  19. sfid4 = fs.sfload("Percussion 2.sf2")
  20.  
  21. fs.program_select(0, sfid0, 0, 0)
  22. fs.program_select(1, sfid1, 0, 0)
  23. fs.program_select(2, sfid1, 0, 0)
  24. fs.program_select(3, sfid1, 0, 0)
  25. fs.program_select(4, sfid1, 0, 0)
  26.  
  27.  
  28.  
  29.  
  30. loopFlag = True
  31.  
  32.  
  33. print 'READY !'
  34.  
  35. while (loopFlag):
  36.     if (ser.in_waiting):
  37.         message = ser.read(3)
  38.         # lets get the command first
  39.         command = ord(message[0])
  40.         note = ord(message[1])
  41.         pitch = ord(message[2])
  42.         channel = 0
  43.         print "command - " + str(command) + " note - " + str(note) + " pitch - " + str(pitch)
  44.         #if command is over 143 it menas it start note
  45.         if command > 143:
  46.             #player.set_instrument(command - 144)
  47.             #player.note_on(note,pitch,command - 144)
  48.             fs.noteon(channel, note, pitch)
  49.         else :
  50.             #player.set_instrument(command - 128)
  51.             #player.note_off(note,pitch,command - 128)
  52.             fs.noteoff(channel, note)
  53.  
  54.  
  55. print 'EXIT'
  56.  
  57. fs.delete()
  58. ser.close()
  59.  
  60.  
  61. #fs.noteon(0, 60, 30)
  62. #fs.noteon(0, 67, 30)
  63. #fs.noteon(0, 76, 30)
  64.  
  65. #time.sleep(3.0)
  66.  
  67. #fs.noteoff(0, 60)
  68. #fs.noteoff(0, 67)
  69. #fs.noteoff(0, 76)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement