desc:VeloCurve v1 //options:no_meter in_pin:none out_pin:none @init ext_noinit=1; //R=G=B=220; R=G=B=30; gfx_clear = R+G*256+B*65536; //-- Funcctions for JEEZ ---------------// function gfx_set(r,g,b,a) ( gfx_r=r; gfx_g=g; gfx_b=b; gfx_a=a; ); function gfx_rect(x,y,w,h, filled) ( !filled ? ( w-=1; h-=1; // correct values gfx_x=x;gfx_y=y; // start point gfx_lineto(x+w,y); gfx_lineto(x+w,y+h); gfx_lineto(x,y+h); gfx_lineto(x,y); ) : ( gfx_rect(x,y,w,h); ); ); //------------------------------------------------------------------------------ //------------------ function pointIN(p_x, p_y) ( // if point in obj area p_x >= this.x && p_x <= this.x+this.w && p_y >= this.y && p_y <= this.y+this.h; ); function mouseIN() ( // if mouse in obj area mouse_cap&1==0 && this.pointIN(mouse_x, mouse_y); ); //------------------ function mouseDown() ( // if mouse has been pressed in obj area mouse_cap&1==1 && this.pointIN(mouse_ox,mouse_oy); ); function mouseUp() ( // if mouse released(anywhere) and has been pressed in obj area mouse_cap&1==0 && this.pointIN(mouse_ox,mouse_oy); ); function mouseClick() ( // if mouse released in obj area and has been pressed in obj area mouse_cap&1==0 && last_mouse_cap&1==1 && this.pointIN(mouse_x, mouse_y) && this.pointIN(mouse_ox,mouse_oy); ); /*---------------------------------------------------------- -- Curve functions ----------------------------------------- ----------------------------------------------------------*/ //-- Init curve ----------------------------------- function Curve_Init(x,y,w,h, mem_offs, n_pnts) local(i) ( this.x = x; this.y = y; // curve wnd x,y this.w = w; this.h = h; // curve wnd w,h this.n_pnts = n_pnts; // number of curve points //-- curve-points coords list ---------- //-- xx[0]...xx[n_pnts-1] and yy[0]...yy[n_pnts-1] this.xx = mem_offs; // x-coord mem slots offs this.yy = mem_offs + n_pnts; // y-coord mem slots offs //-- def pnts values ------------------- i=0; loop(n_pnts, this.xx[i] = this.yy[i] = i/(n_pnts-1); i+=1; ); ); //-- Apply curve to value ------------------------- function Curve_App_to_Val(in_val) instance(xx,yy, n_pnts, out_val) local(x1,y1,x2,y2, i) ( //-- for 0...n_pnts-1 ------ i=0; loop(n_pnts-1, x1 = xx[i]; y1 = yy[i]; x2 = xx[i+1]; y2 = yy[i+1]; // only for simplification in_val>=x1 && in_val= xx[n_pnts-1] ? out_val = yy[n_pnts-1]; this.in_val = in_val; // store in_val for drawing out_val; // return ); //------------------------------------------------ //-- Draw Curve(main function) ------------------- //------------------------------------------------ function Curve_Draw() instance(x,y,w,h, xx,yy, n_pnts, cap_pnt, in_val,out_val) local(gx0,gy0, gx1,gy1, gx2,gy2, lx,ly, lval, lval_w, lval_h, i) ( //-- Origin(use "|_" view ) -- gx0 = x; // min x; gy0 = y + h; // min y; //-- Draw bg, contour etc -------------------- gfx_set(1,1,1, 0.1); gfx_rect(0, 0, gfx_w,gfx_h, 0); //-- +1,+1; -1,-1,+3,+3 - именно так! gfx_set(0.04,0.04,0.04,1); gfx_rect(x,y,w+1,h+1,1); gfx_set(0,0,0,1); gfx_rect(x-2,y-2,w+5,h+5,0); //-- Guide line -------------- gfx_set(1,0,0,0.3); gfx_line(gx0, gy0, x+w, y, 1); //-- Draw grid ------------------------------- //gfx_setfont(1,"Calibri", 14); //gfx_setfont(1,"Arial", 14); i=0; loop(5, lval = sprintf(#,"%d", ceil(i*127)); gfx_measurestr(lval, lval_w, lval_h); lx = x + w*i; ly = y + h*(1-i); //-- lines --- i>0 && i<1 ? ( gfx_set(0,1,0, 0.12); gfx_line(lx, y, lx, y+h, 1); gfx_line(x, ly, x+w, ly, 1); ); //-- values -- gfx_set(0.6,0.6,0.6,0.7); i ? ( gfx_x = lx - lval_w/2; gfx_y = y+h+5; gfx_drawstr(lval); gfx_x = x - lval_w - 7; gfx_y = ly - lval_h/2; gfx_drawstr(lval); ) : ( gfx_x = lx - lval_w -7; gfx_y = y+h+5; gfx_drawstr(lval); ); i+=0.25 ); //-- Draw curve, cap pnts -------------------- i=0; loop(n_pnts, gx1 = x + xx[i]*w; gy1 = y + h - yy[i]*h; gx2 = x + xx[i+1]*w; gy2 = y + h - yy[i+1]*h; //-- draw points ----------- gfx_set(0.6,0.6,0.6,0.8); gfx_circle(gx1, gy1, 2,1); // point //-- draw crv line, area --- i < n_pnts-1 ? ( // ! don't draw last line, area gfx_line(gx1,gy1, gx2,gy2, 1); // pnt to pnt line //gfx_set(1,1,1,0.03); // area color //gfx_triangle(gx1,gy1, gx2-1,gy2-1, gx2,gy0, gx1,gy0); // ); //-- capture pnt --------- mouse_cap&1 ? ( (!last_mouse_cap&1 && // if mouse pressed in point mouse_x > gx1-10 && mouse_x < gx1+10 && mouse_y > gy1-10 && mouse_y < gy1+10; ) ? ( cap_pnt = i; // capture current point ); ) : ( cap_pnt = -1; // reset cap_pnt if mouse released ); i+=1; ); //-- Change captured point coord ------------- cap_pnt >= 0 ? ( cap_pnt > 0 && cap_pnt < n_pnts-1 ? // don't change first-last x-coord xx[cap_pnt] = max( min(1, (mouse_x-gx0)/w ), 0); yy[cap_pnt] = max( min(1, (gy0-mouse_y)/h ), 0); //-- upd points values ----- i=0; loop(n_pnts, i < cap_pnt ? ( xx[i]>xx[cap_pnt] ? xx[i]=xx[cap_pnt]; yy[i]>yy[cap_pnt] ? yy[i]=yy[cap_pnt]; ); i > cap_pnt ? ( xx[i]>> gfx_drawnumber(out_msg3,0); // last output velo //-------------------------------------------- ); //-------------------------------------------------------------- //-- CheckBox -------------------------------------------------- //-------------------------------------------------------------- function checkBox_New(x,y,w,h, lbl, state) ( this.x=x; this.y=y; this.w=w; this.h=h; this.lbl=lbl; this.state=state; ); //-- Draw checkBox --------------------- function checkBox_Draw() instance(x,y,w,h, lbl, state) ( gfx_set(0.08,0.08,0.08,1); gfx_rect(x,y,w,h,1); gfx_set(1,1,0.06, 0.07 + state/3); gfx_rect(x+4,y+4,h-9,h-9, 1); gfx_rect(x+4,y+4,h-8,h-8, 0); gfx_set(0.6,0.6,0.6,0.8); //gfx_setfont(1,"Calibri", 14); gfx_x = x + h; gfx_y = y + (h - gfx_texth)/2; gfx_drawstr(lbl); mouse_cap&1 ? ( (!last_mouse_cap&1 && // if mouse pressed in point mouse_x > x && mouse_x < x+h && mouse_y > y && mouse_y < y+h; ) ? ( state = !state ); ); ); //-------------------------------------------------------------- //-- New spinBox ----------------------------------------------- //-------------------------------------------------------------- function spinBox_New(x,y,w,h, val,min_val,max_val,val_step) ( this.x=x; this.y=y; this.w=w; this.h=h; this.val = val; this.min_val = min_val; this.max_val = max_val; this.val_step = val_step; this.cap_val = min_val-1; ); //-- Set spinBox value ----------------- function spinBox_set_value() instance(x,y,w,h, val,min_val,max_val,val_step, cap_val) local(K) ( cap_val x+w-16 ? ( mouse_oy < y+h/2 ? val+=val_step : val-=val_step; val = min( max(val, min_val), max_val); ); //-- drag(value area) ------ this.mouseDown() && mouse_ox < x+w-16 ? this.spinBox_set_value(); this.mouseUp() ? ( this.cap_val = min_val-1; // reset cap_val(set < min) mouse_ox = mouse_oy = -1; // reset ox,oy ); //-- Draw arrows ----------- //gfx_set(0,0,0,1); // clr1 gfx_set(0.6,0.6,0.6,0.9); // clr2 cx = x+w-8; cy = y+h/2; gfx_x=cx-2; gfx_y=cy-2; gfx_lineto(cx, cy-4); gfx_lineto(cx+2, cy-2); //up gfx_x=cx-2; gfx_y=cy+2; gfx_lineto(cx, cy+4); gfx_lineto(cx+2, cy+2); //down //-- Draw value ------------ val_str = sprintf(#, "%g", val); // var1 gfx_measurestr(val_str, val_w, val_h); gfx_x = x+5; gfx_y = y+(h-val_h)/2; gfx_drawstr(val_str); ); //-------------------------------------------------------------- //-- RangeBox -------------------------------------------------- //-------------------------------------------------------------- function note_rangeBox_Draw() ( noteRng1.spinBox_Draw(); noteRng1.val>noteRng2.val ? noteRng2.val=noteRng1.val; noteRng2.spinBox_Draw(); noteRng1.val>noteRng2.val ? noteRng1.val=noteRng2.val; ); //-------------------------------------------------------------- //-- Draw Label ------------------------------------------------ //-------------------------------------------------------------- function label_New(x,y,w,h, lbl) ( this.x=x; this.y=y; this.w=w; this.h=h; this.lbl = lbl; ); function label_Draw() instance(x,y,w,h, lbl) ( gfx_set(0.6,0.6,0.6,0.8); //gfx_setfont(1,"Calibri", 14); gfx_x = x; gfx_y = y + (h - gfx_texth)/2; gfx_drawstr(lbl); ); /*-------------------------------------------------------------- ---- Create Controls ------------------------------------------- --------------------------------------------------------------*/ crv.Curve_Init(40,20,720,240, 0, 6); // init curve!(x,y,w,h, mem_offs, n_pnts) //------------------------------------------------ Apply_lbl.label_New(crv.x, crv.y + crv.h + 30, 100, 18, "Apply curve to:"); //Npoints_lbl.label_New(crv.x+crv.w/4*3, crv.y + crv.h + 30, 70, 18, "Curve Points:"); //-------------------------------------------------------------- //args = (x,y,w,h, lbl, state) note_chbx.checkBox_New(crv.x + crv.w/4, crv.y + crv.h + 30, 60,18, "Notes", 1); cc_chbx.checkBox_New(crv.x + crv.w/2, crv.y + crv.h + 30, 40,18, "CC", 0); //------------------------------------------------ //args = (x,y,w,h, val,min_val,max_val,val_step) noteRng1.spinBox_New(note_chbx.x+note_chbx.w+5, crv.y + crv.h + 30, 40,18, 0, 0,127,1); noteRng2.spinBox_New(noteRng1.x+noteRng1.w+5, crv.y + crv.h + 30, 40,18, 127, 0,127,1); ccNum.spinBox_New(cc_chbx.x+cc_chbx.w+5, crv.y + crv.h + 30, 40,18, 0, 0,127,1); //--Need fix! //pointsNum.spinBox_New(Npoints_lbl.x+Npoints_lbl.w+5, crv.y + crv.h + 30, 40,18, crv.n_pnts, 3,10,1); @slider @serialize file_mem(0, crv.xx, crv.n_pnts*2 ); // ser curve points @block while (midirecv(offset,msg1,msg2,msg3)) ( // REAPER 4.59+ syntax while() msgType = msg1&240; (note_chbx.state && msgType==144 && msg2>=noteRng1.val && msg2<=noteRng2.val && msg3>0) || (cc_chbx.state && msgType==176 && msg2==ccNum.val) ? ( in_msg3 = msg3; out_msg3 = ceil( crv.Curve_App_to_Val(in_msg3/127)*127 ); // for test midisend(offset,msg1,msg2,out_msg3); ) : ( midisend(offset,msg1,msg2,msg3); // passthrough other events ); ); @sample @gfx 800 340 function Update_Coords() ( crv.w = max(gfx_w-crv.x-40,720); // update crv w crv.h = max(gfx_h-crv.y-80,240); // update crv h //-- update y ---------- Apply_lbl.y = Npoints_lbl.y = noteRng1.y = noteRng2.y = note_chbx.y = cc_chbx.y = ccNum.y = pointsNum.y = crv.y + crv.h + 30; //-- update x ---------- note_chbx.x = crv.x + crv.w/4; // update w noteRng1.x = note_chbx.x + note_chbx.w+5; noteRng2.x = noteRng1.x + noteRng1.w+5; cc_chbx.x = crv.x + crv.w/2; // update w ccNum.x = cc_chbx.x + cc_chbx.w+5; //Npoints_lbl.x = crv.x+ crv.w/4*3; //pointsNum.x = Npoints_lbl.x + Npoints_lbl.w + 5; ); //-- Draw Controls ------------------------------- function Draw_Controls() ( gfx_setfont(1,"Calibri", 14); // For All Apply_lbl.label_Draw(); //Npoints_lbl.label_Draw(); note_chbx.checkBox_Draw(); note_rangeBox_Draw(); cc_chbx.checkBox_Draw(); ccNum.spinBox_Draw(); //pointsNum.spinBox_Draw(); ); //-- Main Draw function -------------------------- function main_draw() ( //-- mouse and modkeys --------------- //-- L or R mouse pressed -- (mouse_cap&1 && !(last_mouse_cap&1)) || (mouse_cap&2 && !(last_mouse_cap&2)) ? ( mouse_ox = mouse_x; mouse_oy = mouse_y; ); Ctrl = mouse_cap&4==4; //-- Ctrl state Shift = mouse_cap&8==8; //-- Shift state Alt = mouse_cap&16==16; //-- Shift state //-- Main functions etc -- last_wnd_w != gfx_w || last_wnd_h != gfx_h ? Update_Coords(); Draw_Controls(); crv.Curve_Draw(); //------------------------ last_mouse_cap = mouse_cap; last_x = mouse_x; last_y = mouse_y; last_wnd_w = gfx_w; last_wnd_h = gfx_h; //char = gfx_getchar(); ); //---------------------------- main_draw();