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.

596 lines
16KB

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