Audio plugin host https://kx.studio/carla
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.

126 lines
3.4KB

  1. class PADnoteHarmonicProfile: public Fl_Box, public Fl_Osc_Widget
  2. {
  3. public:
  4. PADnoteHarmonicProfile(int x,int y, int w, int h, const char *label=0)
  5. :Fl_Box(x,y,w,h,label), smps(new float[w]), realbw(0.0f)
  6. {
  7. memset(smps, 0, w*sizeof(float));
  8. }
  9. ~PADnoteHarmonicProfile(void)
  10. {
  11. osc->removeLink(loc, (Fl_Osc_Widget*) this);
  12. delete[] smps;
  13. }
  14. void init(void)
  15. {
  16. Fl_Osc_Pane *og = fetch_osc_pane(this);
  17. assert(og);
  18. loc = og->base + "profile";
  19. osc = og->osc;
  20. assert(osc);
  21. osc->createLink(loc, (Fl_Osc_Widget*) this);
  22. update();
  23. }
  24. void update(void)
  25. {
  26. osc->write(loc, "i", w());
  27. }
  28. void OSC_value(unsigned N, void *data, const char *name) override
  29. {
  30. assert(!strcmp(name, "profile"));
  31. assert(N==w()*sizeof(float));
  32. memcpy(smps, data, N);
  33. redraw();
  34. }
  35. void OSC_value(float x, const char *name) override
  36. {
  37. assert(!strcmp(name, "profile"));
  38. realbw = x;
  39. redraw();
  40. }
  41. void draw(void)
  42. {
  43. int ox=x(),oy=y(),lx=w(),ly=h();
  44. const bool active=active_r();
  45. if(!visible())
  46. return;
  47. if (damage()!=1){
  48. fl_color(fl_color_average(FL_BLACK,
  49. FL_BACKGROUND_COLOR, 0.5 ));
  50. fl_rectf(ox,oy,lx,ly);
  51. }
  52. //draw the equivalent bandwidth
  53. if (active) fl_color(220,220,220);
  54. else fl_color(160,165,165);
  55. fl_line_style(FL_DASH);
  56. int rbw=(int)(realbw*(lx-1.0)/2.0);
  57. fl_begin_line();
  58. for(int i=lx/2-rbw;i<(lx/2+rbw); ++i)
  59. fl_vertex(ox+i,oy);
  60. fl_end_line();
  61. fl_line_style(FL_DASH);
  62. if(active)
  63. fl_color(200,200,200);
  64. else
  65. fl_color(160,160,160);
  66. for (int i=1;i<10;i++){
  67. const int kx=(int)(lx/10.0*i);
  68. fl_line(ox + kx, oy, ox + kx, oy + ly - 1);
  69. }
  70. for (int i=1;i<5;i++){
  71. const int ky=(int)(ly/5.0*i);
  72. fl_line(ox,oy+ly-ky,ox+lx,oy+ly-ky-1);
  73. }
  74. fl_color(120,120,120);
  75. fl_line_style(FL_DASH);
  76. fl_line(ox+lx/2,oy,ox+lx/2,oy+ly);
  77. //draw the graph
  78. fl_line_style(FL_SOLID);
  79. if (active)
  80. fl_color(180,210,240);
  81. else
  82. fl_color(150,150,155);
  83. fl_color(fl_color_add_alpha(fl_color(), 127));
  84. fl_begin_polygon();
  85. fl_vertex(ox, oy + h());
  86. for (int i=0; i<lx; ++i){
  87. int val=(int) ((ly-2)*smps[i]);
  88. fl_vertex(ox+i,oy+ly-1-val);
  89. }
  90. fl_vertex(ox + w(), oy + h());
  91. fl_end_polygon();
  92. fl_line_style(FL_DASH);
  93. if (active)
  94. fl_color(0,100,220);
  95. else
  96. fl_color(150,160,170);
  97. fl_line(ox+lx/2-rbw,oy,ox+lx/2-rbw,oy+ly-1);
  98. fl_line(ox+lx/2+rbw,oy,ox+lx/2+rbw,oy+ly-1);
  99. fl_line_style(0);
  100. }
  101. private:
  102. float *smps;
  103. float realbw;
  104. };