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.

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