zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

Fl_PADnoteHarmonicProfile.h (3826B)


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