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.

50 lines
1.0KB

  1. --[[
  2. name: midi chordify
  3. description: MIDI processor VST/AU. Notes go in, chords come out.
  4. author: osar.fr
  5. --]]
  6. require "include/protoplug"
  7. -- what kind of chord ?
  8. local chordStructure = {0, 3, 5, 7, 11}
  9. local blockEvents = {}
  10. function plugin.processBlock(samples, smax, midiBuf)
  11. blockEvents = {}
  12. -- analyse midi buffer and prepare a chord for each note
  13. for ev in midiBuf:eachEvent() do
  14. if ev:isNoteOn() then
  15. chordOn(ev)
  16. elseif ev:isNoteOff() then
  17. chordOff(ev)
  18. end
  19. end
  20. -- fill midi buffer with prepared notes
  21. midiBuf:clear()
  22. if #blockEvents>0 then
  23. for _,e in ipairs(blockEvents) do
  24. midiBuf:addEvent(e)
  25. end
  26. end
  27. end
  28. function chordOn(root)
  29. for _, offset in ipairs(chordStructure) do
  30. local newEv = midi.Event.noteOn(
  31. root:getChannel(),
  32. root:getNote()+offset,
  33. root:getVel())
  34. table.insert(blockEvents, newEv)
  35. end
  36. end
  37. function chordOff(root)
  38. for _, offset in ipairs(chordStructure) do
  39. local newEv = midi.Event.noteOff(
  40. root:getChannel(),
  41. root:getNote()+offset)
  42. table.insert(blockEvents, newEv)
  43. end
  44. end