Extra "ports" of juce-based plugins using the distrho build system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1021B

  1. --[[
  2. name: soundfile test
  3. description: A simple demo that plays an audio file.
  4. author: osar.fr
  5. --]]
  6. require "include/protoplug"
  7. local path = "C:\\temp\\pluck44.wav"
  8. local wave, len
  9. -- 'prepareToPlay' will be triggered when the host sample rate is known,
  10. -- so we can load sound files with automatic sample rate conversion:
  11. plugin.addHandler('prepareToPlay', function()
  12. local readr = juce.AudioFormatReader(path)
  13. if readr==nil then error ("can't open wave: "..path) end
  14. wave, len = readr:readToFloat(2) -- require 2 channels
  15. end)
  16. polyGen.initTracks(8)
  17. function polyGen.VTrack:noteOn(note, vel, ev)
  18. self.playing = true
  19. self.wavepos = 0
  20. end
  21. function polyGen.VTrack:noteOff(note, ev)
  22. self.playing = false
  23. end
  24. function polyGen.VTrack:addProcessBlock(samples, smax)
  25. for i = 0,smax do
  26. if self.playing and self.wavepos < len then
  27. self.wavepos = self.wavepos + 1
  28. samples[0][i] = samples[0][i] + wave[0][self.wavepos] -- left
  29. samples[1][i] = samples[1][i] + wave[1][self.wavepos] -- right
  30. end
  31. end
  32. end