#include "EnvelopeFreeEdit.h" #include "../Misc/Util.h" #include #include #include #include #include EnvelopeFreeEdit::EnvelopeFreeEdit(int x,int y, int w, int h, const char *label) :Fl_Box(x,y,w,h,label), Fl_Osc_Widget(this) { pair=NULL; currentpoint=-1; cpx=0; lastpoint=-1; } void EnvelopeFreeEdit::init(void) { oscRegister("Penvpoints"); oscRegister("Penvdt"); oscRegister("Penvval"); oscRegister("Penvsustain"); } void EnvelopeFreeEdit::OSC_raw(const char *msg) { const char *args = rtosc_argument_string(msg); if(strstr(msg,"Penvpoints") && !strcmp(args, "c")) { Penvpoints = rtosc_argument(msg, 0).i; } else if(strstr(msg,"Penvdt") && !strcmp(args, "b")) { rtosc_blob_t b = rtosc_argument(msg, 0).b; assert(b.len == MAX_ENVELOPE_POINTS); memcpy(Penvdt, b.data, MAX_ENVELOPE_POINTS); } else if(strstr(msg,"Penvval") && !strcmp(args, "b")) { rtosc_blob_t b = rtosc_argument(msg, 0).b; assert(b.len == MAX_ENVELOPE_POINTS); memcpy(Penvval, b.data, MAX_ENVELOPE_POINTS); } else if(strstr(msg,"Penvsustain") && !strcmp(args, "c")) { Penvsustain = rtosc_argument(msg, 0).i; } redraw(); do_callback(); } void EnvelopeFreeEdit::setpair(Fl_Box *pair_) { pair=pair_; } int EnvelopeFreeEdit::getpointx(int n) const { const int lx=w()-10; int npoints=Penvpoints; float sum=0; for(int i=1; iPfreemode==0) // env->converttofree(); const int npoints=Penvpoints; if (active_r()) fl_color(FL_BLACK); else fl_color(90,90,90); if (!active_r()) currentpoint=-1; fl_rectf(ox,oy,lx,ly); //Margins ox+=5;oy+=5;lx-=10;ly-=10; //draw the lines fl_color(FL_GRAY); fl_line_style(FL_SOLID); fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2); //draws the evelope points and lines Fl_Color alb=FL_WHITE; if (!active_r()) alb=fl_rgb_color(180,180,180); fl_color(alb); int oldxx=0,xx=0,oldyy=0,yy=getpointy(0); fl_rectf(ox-3,oy+yy-3,6,6); for (int i=1; i=0){ fl_color(FL_CYAN); fl_rectf(ox+getpointx(lastpoint)-5,oy+getpointy(lastpoint)-5,10,10); } //draw the sustain position if(Penvsustain>0){ fl_color(FL_YELLOW); xx=getpointx(Penvsustain); fl_line(ox+xx,oy+0,ox+xx,oy+ly); } //Show the envelope duration and the current line duration fl_font(FL_HELVETICA|FL_BOLD,10); float time=0.0; if (currentpoint<=0){ fl_color(alb); for(int i=1; iredraw(); } if (event==FL_RELEASE){ currentpoint=-1; redraw(); if (pair) pair->redraw(); } if (event==FL_DRAG && currentpoint>=0){ int ny=limit(127-(int) (y_*127.0/h()), 0, 127); Penvval[currentpoint]=ny; const int dx=(int)((x_-cpx)*0.1); const int newdt=limit(cpdt+dx,0,127); if(currentpoint!=0) Penvdt[currentpoint]=newdt; else Penvdt[currentpoint]=0; oscWrite(to_s("Penvdt")+to_s(currentpoint), "c", newdt); redraw(); if(pair) pair->redraw(); } return 1; } void EnvelopeFreeEdit::update(void) { oscWrite("Penvpoints"); oscWrite("Penvdt"); oscWrite("Penvval"); oscWrite("Penvsustain"); }