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.

65 lines
1.7KB

  1. -- harmograph
  2. local J = require "include/protojuce"
  3. function Harmograph(args)
  4. local bounds = args.bounds or J.Rectangle_int{15,0,480,330};
  5. local pageBack = args.pageBack or J.Colour.white;
  6. local pageFore = args.pageFore or J.Colour.black;
  7. local graphBack = args.graphBack or J.Colour.white;
  8. local graphFore = args.graphFore or J.Colour.black;
  9. local yMax = args.yMax or 500
  10. local pos = args.pos or 0
  11. local frame = J.Rectangle_int(4, 30, bounds.w-50, bounds.h-65)
  12. local outFrame = J.Rectangle_int(2, 28, frame.w+4, frame.h+4)
  13. local backBuffer = J.Image(J.Image.PixelFormat.RGB, bounds.w, bounds.h, true)
  14. -- initialize backbuffer
  15. do
  16. local g = J.Graphics(backBuffer)
  17. g:fillAll(pageBack)
  18. g:setColour(graphFore)
  19. g:drawRect(outFrame, 1)
  20. g:setColour(pageFore)
  21. -- draw the Y axis labels
  22. g:setFont(14)
  23. for pos, label in pairs{0=0; 0.5=50; 1=100} do
  24. local y = self.frame.y+((self.frame.h-10)*(1-pos))-6
  25. g:drawText(tostring(label), self.frame:getR()+3, y, 33, 20)
  26. end
  27. end
  28. local renderGraph = function()
  29. end
  30. renderGraph()
  31. local yfactor = 0.5*frame.h/yMax
  32. return {
  33. draw = function (g)
  34. g:setColour(J.Colour.black)
  35. for x=0,frame.w do
  36. if x==math.floor(pos*frame.w) then
  37. g:setColour(J.Colour.blue)
  38. g:drawLine(x+10, 10, x+10, 410)
  39. end
  40. local ls = makeLengths(x/graphW)
  41. g:setColour(J.Colour(64,64,64))
  42. for k,v in ipairs(ls) do
  43. g:setPixel(x+10, graphH-(v*3)*yfactor)
  44. end
  45. g:setColour(J.Colour(128,128,128))
  46. for k,v in ipairs(ls) do
  47. g:setPixel(x+10, graphH-(v*2)*yfactor)
  48. end
  49. g:setColour(J.Colour.black)
  50. for k,v in ipairs(ls) do
  51. g:setPixel(x+10, graphH-v*yfactor)
  52. end
  53. end
  54. end,
  55. }
  56. end
  57. return Harmograph