FreeEditUI.fl (16190B)
1 # data file for the Fltk User Interface Designer (fluid) 2 version 1.0110 3 header_name {.h} 4 code_name {.cxx} 5 decl {\#include <FL/Fl_File_Chooser.H>} {} 6 7 decl {\#include <FL/Fl_Box.H>} {public 8 } 9 10 decl {\#include <FL/Fl_Group.H>} {public 11 } 12 13 decl {\#include <FL/Fl_Box.H>} {public 14 } 15 16 decl {\#include <FL/fl_draw.H>} {public 17 } 18 19 decl {\#include <FL/Fl_Value_Input.H>} {public 20 } 21 22 decl {\#include <FL/fl_ask.H>} {public 23 } 24 25 decl {\#include<sys/stat.h>} {} 26 27 decl {\#include <stdio.h>} {} 28 29 decl {\#include <string>} {} 30 31 decl {\#include "Control.h"} {public 32 } 33 34 decl {\#include <math.h>} {} 35 36 decl {\#include "FreeEdit.h"} {public 37 } 38 39 decl {\#include <FL/Fl_Group.H>} {public 40 } 41 42 class FreeEditUI {open : {public Fl_Box} 43 } { 44 Function {FreeEditUI(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} { 45 code {max_value_fl=min_value_fl=value_fl=position_fl=NULL; 46 free_edit=NULL; 47 control=NULL; 48 49 current_point=-1; 50 selected_point=-1; 51 52 default_value=1.0;} {} 53 } 54 Function {~FreeEditUI()} {} { 55 code {} {} 56 } 57 Function {init(FreeEdit *free_edit_,Control *control_)} {open 58 } { 59 code {free_edit=free_edit_; 60 control=control_; 61 free_edit->update_curve();} {} 62 } 63 Function {init_value_io(Fl_Value_Input *value_fl_,Fl_Value_Input *position_fl_,Fl_Value_Input *min_value_fl_,Fl_Value_Input *max_value_fl_)} {} { 64 code {value_fl=value_fl_; 65 position_fl=position_fl_; 66 min_value_fl=min_value_fl_; 67 max_value_fl=max_value_fl_; 68 69 if (free_edit){ 70 free_edit->extreme_y.set_min(min_value_fl->value()); 71 free_edit->extreme_y.set_max(max_value_fl->value()); 72 };} {} 73 } 74 Function {get_color(Fl_Color c)} {return_type Fl_Color 75 } { 76 code {if (free_edit->get_enabled()) return c; 77 78 return fl_color_average(c,fl_rgb_color(178,178,178),0.1);} {} 79 } 80 Function {draw()} {open 81 } { 82 code {int ox=x(),oy=y(),lx=w(),ly=h(); 83 84 //fl_color(FL_WHITE); 85 fl_color(get_color(color())); 86 fl_rectf(ox,oy,lx,ly); 87 88 //fl_color(FL_GRAY); 89 fl_color(get_color(labelcolor())); 90 //draw grid 91 fl_line_style(FL_SOLID); 92 for (int ncoord=0;ncoord<2;ncoord++){ 93 FreeEditExtremes *extreme=(ncoord==0)?&free_edit->extreme_x:&free_edit->extreme_y; 94 if (extreme->get_scale()==FE_LOG){//logarithmic scale 95 float p10=pow(10,floor(log10(extreme->get_min()))); 96 int psteps=(int)(floor(log10(extreme->get_max()/extreme->get_min())))+1; 97 for (int k=1;k<=psteps;k++){ 98 for (int i=1;i<10;i++){ 99 if (i==1) fl_line_style(FL_SOLID); 100 else if(i==5) fl_line_style(FL_DASH); 101 else fl_line_style(FL_DOT); 102 float fpos=extreme->real_value_to_coord(p10*i); 103 if ((fpos>0.0)&&(fpos<1.0)){ 104 if (ncoord==0){ 105 int pos=(int)(fpos*lx); 106 fl_line(ox+pos,oy,ox+pos,oy+ly); 107 }else{ 108 int pos=(int)(ly-1-fpos*ly); 109 fl_line(ox,oy+pos,ox+lx,oy+pos); 110 }; 111 }; 112 }; 113 p10*=10.0; 114 }; 115 }else{//linear scale 116 float diff=extreme->get_max()-extreme->get_min(); 117 float stepsize=pow(10,floor(log10( fabs(diff))))*0.1; 118 if (stepsize>=1e-6){ 119 int nsteps=(int)(fabs(diff)/stepsize)+1; 120 if (nsteps>25) { 121 nsteps/=5; 122 stepsize*=5.0; 123 }; 124 float min=extreme->get_min(); 125 float max=extreme->get_max(); 126 float min1=(min<max)?min:max; 127 int kstep=(int)(floor(min1/stepsize)); 128 min1=kstep*stepsize; 129 for (int i=0;i<nsteps;i++){ 130 float fpos=extreme->real_value_to_coord(min1+i*stepsize); 131 int ks=(i+kstep)%10; if (ks<0) ks+=10; 132 if (ks==0) fl_line_style(FL_SOLID); 133 else if (ks==5) fl_line_style(FL_DASH); 134 else fl_line_style(FL_DOT); 135 if ((fpos>0.0)&&(fpos<1.0)){ 136 if (ncoord==0){ 137 int pos=(int)(fpos*lx); 138 fl_line(ox+pos,oy,ox+pos,oy+ly); 139 }else{ 140 int pos=(int)(ly-1-fpos*ly); 141 fl_line(ox,oy+pos,ox+lx,oy+pos); 142 }; 143 }; 144 }; 145 }; 146 }; 147 }; 148 149 150 151 //draw the line 152 fl_line_style(FL_SOLID,2); 153 fl_color(get_color(labelcolor())); 154 float *data=new float[lx]; 155 156 157 free_edit->get_curve(lx,data,false); 158 int oldy=0; 159 for (int i=0;i<lx;i++){ 160 int newy=(int)((1.0-data[i])*ly); 161 if (i) fl_line(ox+i-1,oy+oldy,ox+i,oy+newy); 162 oldy=newy; 163 }; 164 165 delete[]data; 166 167 //draw points 168 fl_line_style(FL_SOLID,3); 169 for (int i=0;i<free_edit->get_npoints();i++){ 170 if (!free_edit->is_enabled(i)) continue; 171 fl_color(FL_BLACK); 172 int x=(int)(free_edit->get_posx(i)*lx); 173 int y=(int)((1.0-free_edit->get_posy(i))*ly); 174 fl_circle(ox+x,oy+y,3); 175 if (i==selected_point){ 176 fl_color(get_color(FL_RED)); 177 fl_circle(ox+x,oy+y,4); 178 fl_circle(ox+x,oy+y,5); 179 }; 180 }; 181 182 183 /* 184 //test 185 { 186 fl_color(FL_RED); 187 fl_line_style(FL_SOLID); 188 189 free_edit->update_curve(); 190 191 int oldy=0; 192 //printf("draw %g\\n",free_edit->get_value(8000.0)); 193 //printf("d %g\\n",free_edit->curve.data[1000]); 194 195 for (int i=0;i<lx;i++){ 196 //int m=(int)(((float)i/(float)lx)*(free_edit->curve.size-1)); 197 //REALTYPE y=free_edit->curve.data[m]; 198 REALTYPE freq=i/(float)lx*25000.0; 199 REALTYPE y=free_edit->get_value(freq); 200 //if (i<20) printf("%d %g\\n",i,y); 201 //printf("%g %g\\n",freq,y); 202 203 204 int newy=(int)((1.0-y)*ly); 205 206 if (i) fl_line(ox+i-1,oy+oldy,ox+i,oy+newy); 207 oldy=newy; 208 }; 209 }; 210 */ 211 212 213 214 215 /* 216 217 218 fl_color(FL_RED); 219 fl_line_style(FL_SOLID); 220 221 222 int samplerate=44100; 223 224 225 int nfreq=lx; 226 float *freq1=new float [nfreq]; 227 float *freq2=new float [nfreq]; 228 float *tmpfreq1=new float [nfreq*2]; 229 230 for (int i=0;i<nfreq;i++) tmpfreq1[i]=0.0; 231 232 for (int i=0;i<nfreq;i++) freq1[i]=data[i]; 233 234 //convert to log spectrum 235 236 float minfreq=20.0; 237 float maxfreq=0.5*samplerate; 238 for (int i=0;i<nfreq;i++){ 239 float freqx=i/(float) nfreq; 240 float x=exp(log(minfreq)+freqx*(log(maxfreq)-log(minfreq)))/maxfreq*nfreq; 241 float y=0.0; 242 int x0=(int)floor(x); if (x0>=nfreq) x0=nfreq-1; 243 int x1=x0+1; if (x1>=nfreq) x1=nfreq-1; 244 float xp=x-x0; 245 if (x<nfreq){ 246 y=freq1[x0]*(1.0-xp)+freq1[x1]*xp; 247 }; 248 tmpfreq1[i]=y; 249 }; 250 251 252 //increase bandwidth of each harmonic 253 int n=2; 254 float bandwidth=free_edit->get_posy(0); 255 float a=1.0-exp(-bandwidth*bandwidth*nfreq*0.002); 256 a=pow(a,n); 257 printf("%g\\n",a); 258 259 for (int k=0;k<n;k++){ 260 tmpfreq1[0]=0.0; 261 for (int i=1;i<nfreq;i++){ 262 tmpfreq1[i]=tmpfreq1[i-1]*a+tmpfreq1[i]*(1.0-a); 263 }; 264 tmpfreq1[nfreq-1]=0.0; 265 for (int i=nfreq-2;i>0;i--){ 266 tmpfreq1[i]=tmpfreq1[i+1]*a+tmpfreq1[i]*(1.0-a); 267 }; 268 }; 269 270 //convert back to linear spectrum 271 // for (int i=0;i<nfreq;i++) freq2[i]=0.0; 272 // for (int i=0;i<nfreq;i++) freq2[i]=tmpfreq1[i]; 273 274 freq2[0]=0; 275 for (int i=1;i<nfreq;i++){ 276 float freqx=i/(float) nfreq; 277 float x=log((freqx*maxfreq)/minfreq)/log(maxfreq/minfreq)*nfreq; 278 // printf("%g\\n",x); 279 float y=0.0; 280 int x0=(int)floor(x); if (x0>=nfreq) x0=nfreq-1; 281 int x1=x0+1; if (x1>=nfreq) x1=nfreq-1; 282 float xp=x-x0; 283 if (x<nfreq){ 284 y=tmpfreq1[x0]*(1.0-xp)+tmpfreq1[x1]*xp; 285 }; 286 freq2[i]=y; 287 }; 288 289 290 291 292 293 for (int i=0;i<lx;i++){ 294 295 REALTYPE y=freq2[i]; 296 297 int newy=(int)((1.0-y)*ly); 298 299 300 if (i) fl_line(ox+i-1,oy+oldy,ox+i,oy+newy); 301 oldy=newy; 302 }; 303 304 delete [] freq1; 305 delete [] freq2; 306 delete [] tmpfreq1; 307 // delete [] tmpfreq2; 308 */} {} 309 } 310 Function {handle(int event)} {return_type int 311 } { 312 code {if (!free_edit->get_enabled()) return Fl_Box::handle(event); 313 314 int ox=x(),oy=y(),lx=w(),ly=h(); 315 float px=(Fl::event_x()-ox)/(float)lx; 316 float py=1.0-(Fl::event_y()-oy)/(float)ly; 317 if (px<0) px=0; 318 else if (px>1.0) px=1.0; 319 if (py<0) py=0; 320 else if (py>1.0) py=1.0; 321 322 int closest=-1; 323 float xyrap=(float)ly/(float)lx; 324 for (int i=0;i<free_edit->get_npoints();i++){ 325 if (!free_edit->is_enabled(i)) continue; 326 float d=pow(px-free_edit->get_posx(i),2)+pow(py-free_edit->get_posy(i),2)*xyrap; 327 if (d<0.0005) { 328 closest=i; 329 break; 330 331 }; 332 }; 333 334 335 if (event==FL_PUSH){ 336 if (closest>=0) { 337 if (Fl::event_button()==1) selected_point=current_point=closest; 338 if ((Fl::event_button()==3)&&(closest>=2)) { 339 free_edit->set_enabled(closest,false); 340 current_point=selected_point=-1; 341 }; 342 }else{ 343 for (int i=0;i<free_edit->get_npoints();i++){ 344 if (!free_edit->is_enabled(i)){ 345 selected_point=closest=current_point=i; 346 free_edit->set_posx(current_point,px); 347 free_edit->set_posy(current_point,py); 348 free_edit->set_enabled(i,true); 349 break; 350 }; 351 }; 352 }; 353 refresh_value(); 354 redraw(); 355 update_curve(); 356 return true; 357 }; 358 if (event==FL_RELEASE){ 359 current_point=-1; 360 refresh_value(); 361 update_curve(); 362 if (control) control->update_process_parameters(); 363 return true; 364 }; 365 366 if (event==FL_DRAG){ 367 if (current_point>=0){ 368 if (current_point>=2) free_edit->set_posx(current_point,px); 369 free_edit->set_posy(current_point,py); 370 redraw(); 371 }; 372 refresh_value(); 373 update_curve(); 374 return true; 375 }; 376 377 return Fl_Box::handle(event);} {} 378 } 379 Function {refresh_value()} {} { 380 code {if (!value_fl) return; 381 value_fl->deactivate(); 382 position_fl->deactivate(); 383 if (selected_point<0) return; 384 if (!free_edit->is_enabled(selected_point)) return; 385 value_fl->activate(); 386 position_fl->activate(); 387 388 float val=free_edit->extreme_y.coord_to_real_value(free_edit->get_posy(selected_point)); 389 val=((int)(val*10000.0))/10000.0; 390 value_fl->value(val); 391 392 393 float pos=free_edit->extreme_x.coord_to_real_value(free_edit->get_posx(selected_point)); 394 pos=((int)(pos*1000.0))/1000.0; 395 position_fl->value(pos);} {} 396 } 397 Function {set_selected_value(float val)} {} { 398 code {if (!value_fl) return; 399 if (selected_point<0) return; 400 if (!free_edit->is_enabled(selected_point)) return; 401 402 free_edit->set_posy(selected_point,free_edit->extreme_y.real_value_to_coord(val)); 403 redraw(); 404 update_curve();} {} 405 } 406 Function {set_selected_position(float pos)} {} { 407 code {if (!value_fl) return; 408 if (selected_point<0) return; 409 if (!free_edit->is_enabled(selected_point)) return; 410 411 free_edit->set_posx(selected_point,free_edit->extreme_x.real_value_to_coord(pos)); 412 redraw(); 413 update_curve();} {} 414 } 415 Function {set_min_value(float val)} {open 416 } { 417 code {unselect(); 418 419 free_edit->extreme_y.set_min(val); 420 redraw(); 421 update_curve();} {} 422 } 423 Function {set_max_value(float val)} {open 424 } { 425 code {unselect(); 426 427 free_edit->extreme_y.set_max(val); 428 redraw(); 429 update_curve();} {} 430 } 431 Function {unselect()} {} { 432 code {selected_point=-1; 433 refresh_value(); 434 redraw();} {} 435 } 436 Function {set_smooth(float smooth)} {} { 437 code {free_edit->set_smooth(smooth); 438 redraw(); 439 update_curve();} {} 440 } 441 Function {set_interp_mode(int interp_mode)} {} { 442 code {free_edit->set_interp_mode((FreeEdit::INTERP_MODE)interp_mode); 443 redraw(); 444 update_curve();} {} 445 } 446 Function {clear()} {} { 447 code {for (int i=2;i<free_edit->get_npoints();i++) free_edit->set_enabled(i,false); 448 free_edit->set_all_values(default_value); 449 redraw(); 450 update_curve();} {} 451 } 452 Function {update_curve()} {} { 453 code {free_edit->update_curve();} {} 454 } 455 decl {int current_point,selected_point;} {public 456 } 457 decl {Fl_Value_Input *value_fl,*position_fl,*min_value_fl,*max_value_fl;} {public 458 } 459 decl {FreeEdit *free_edit;} {public 460 } 461 decl {float default_value;} {public 462 } 463 decl {Control *control;} {public 464 } 465 } 466 467 class FreeEditControls {open : {public Fl_Group} 468 } { 469 Function {FreeEditControls(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} { 470 code {free_edit_ui=NULL;} {} 471 } 472 Function {~FreeEditControls()} {} { 473 code {hide();} {} 474 } 475 Function {init(FreeEditUI *free_edit_ui_,FREE_EDIT_EXTREME_SCALE scale_x=FE_LINEAR,float min_x=0.0,float max_x=1.0,FREE_EDIT_EXTREME_SCALE scale_val=FE_LINEAR,float min_val=0.0,float max_val=1.0,float default_value=1.0)} {open 476 } { 477 code {free_edit_ui=free_edit_ui_; 478 479 make_window(); 480 end(); 481 482 free_edit_ui->init_value_io(free_edit_value_fl,free_edit_position_fl,free_edit_min_value_fl,free_edit_max_value_fl); 483 feui->resize(this->x(),this->y(),this->w(),this->h()); 484 485 FreeEdit *fe=free_edit_ui->free_edit; 486 487 fe->extreme_x.set_min(min_x); 488 fe->extreme_x.set_max(max_x); 489 fe->extreme_x.set_scale(scale_x); 490 491 fe->extreme_y.set_min(min_val); 492 fe->extreme_y.set_max(max_val); 493 fe->extreme_y.set_scale(scale_val); 494 495 free_edit_min_value_fl->value(min_val); 496 free_edit_max_value_fl->value(max_val); 497 free_edit_ui->default_value=default_value; 498 fe->set_all_values(default_value); 499 500 enabled_check->value(fe->get_enabled());} {} 501 } 502 Function {update_parameters()} {open 503 } { 504 code {if (free_edit_ui->control) free_edit_ui->control->update_process_parameters();} {} 505 } 506 Function {make_window()} {open 507 } { 508 Fl_Window feui {open 509 xywh {245 395 85 210} type Double color 50 labelfont 1 510 class Fl_Group visible 511 } { 512 Fl_Group {} {open 513 xywh {0 0 85 210} box PLASTIC_THIN_UP_BOX color 52 labeltype ENGRAVED_LABEL labelsize 10 align 0 514 } { 515 Fl_Value_Input free_edit_min_value_fl { 516 label {Val.Min} 517 callback {free_edit_ui->unselect(); 518 free_edit_ui->set_min_value(o->value()); 519 update_parameters();} 520 xywh {5 110 50 15} labelsize 10 align 5 minimum -10000 maximum 10000 textfont 1 textsize 10 521 } 522 Fl_Value_Input free_edit_max_value_fl { 523 label {Val.Max} 524 callback {free_edit_ui->unselect(); 525 free_edit_ui->set_max_value(o->value()); 526 update_parameters();} 527 xywh {5 140 50 15} labelsize 10 align 5 minimum -10000 maximum 10000 value 1 textfont 1 textsize 10 528 } 529 Fl_Value_Input free_edit_value_fl { 530 label Value 531 callback {free_edit_ui->set_selected_value(o->value()); 532 update_parameters();} 533 xywh {5 75 70 15} labelfont 1 labelsize 10 align 5 minimum 0.03 maximum 100 value 0.5 textfont 1 textsize 10 deactivate 534 } 535 Fl_Roller free_edit_smooth { 536 label Sm 537 callback {free_edit_ui->set_smooth(o->value()); 538 update_parameters();} 539 tooltip {Smooth function} xywh {60 110 15 45} labelsize 10 align 1 when 4 minimum 1 maximum 0 step 0.01 540 } 541 Fl_Choice free_edit_interpolate { 542 label Interpolate 543 callback {free_edit_ui->set_interp_mode(o->value()); 544 update_parameters();} 545 xywh {5 170 70 15} down_box BORDER_BOX labelsize 11 align 5 textfont 1 textsize 10 546 } { 547 MenuItem {} { 548 label Linear 549 xywh {10 10 36 21} labelfont 1 labelsize 10 550 } 551 MenuItem {} { 552 label Cosine 553 xywh {10 10 36 21} labelfont 1 labelsize 10 554 } 555 } 556 Fl_Button {} { 557 label clear 558 callback {if (!fl_choice("Delete all points?","No","Yes",NULL)) return; 559 free_edit_ui->clear(); 560 update_parameters();} 561 xywh {5 190 75 15} labelsize 12 562 } 563 Fl_Light_Button enabled_check { 564 label Enable 565 callback {free_edit_ui->free_edit->set_enabled(o->value()); 566 free_edit_ui->update_curve(); 567 free_edit_ui->redraw(); 568 update_parameters();} 569 xywh {5 5 75 20} color 7 selection_color 88 labelfont 1 570 } 571 Fl_Value_Input free_edit_position_fl { 572 label Position 573 callback {free_edit_ui->set_selected_position(o->value()); 574 update_parameters();} 575 xywh {5 45 70 15} labelsize 10 align 5 minimum 0.0001 maximum 10000 value 1 textfont 1 textsize 10 deactivate 576 } 577 } 578 } 579 } 580 Function {refresh()} {open 581 } { 582 code {enabled_check->value(free_edit_ui->free_edit->get_enabled()); 583 584 free_edit_min_value_fl->value(free_edit_ui->free_edit->extreme_y.get_min()); 585 free_edit_max_value_fl->value(free_edit_ui->free_edit->extreme_y.get_max()); 586 free_edit_interpolate->value(free_edit_ui->free_edit->get_interp_mode()); 587 free_edit_smooth->value(free_edit_ui->free_edit->get_smooth()); 588 589 free_edit_ui->update_curve(); 590 free_edit_ui->redraw(); 591 update_parameters();} {selected 592 } 593 } 594 decl {FreeEditUI *free_edit_ui;} {} 595 }