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.

137 lines
3.7KB

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