Audio plugin host https://kx.studio/carla
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.

VirKeyboard.fl 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. # data file for the Fltk User Interface Designer (fluid)
  2. version 1.0302
  3. header_name {.h}
  4. code_name {.cc}
  5. decl {//Copyright (c) 2002-2005 Nasca Octavian Paul} {private local
  6. }
  7. decl {//License: GNU GPL version 2 or later} {private local
  8. }
  9. decl {\#include <cstdlib>} {public local
  10. }
  11. decl {\#include <FL/fl_draw.H>} {public local
  12. }
  13. decl {\#include <FL/Fl_Box.H>} {public local
  14. }
  15. decl {\#include "../globals.h"} {public local
  16. }
  17. decl {\#include "../Misc/Util.h"} {public local
  18. }
  19. decl {\#include "WidgetPDial.h"} {public local
  20. }
  21. decl {\#include "Fl_Osc_Counter.H"} {public local
  22. }
  23. decl {\#include "common.H"} {public local
  24. }
  25. decl {\#ifdef NTK_GUI
  26. \#include "FL/Fl_Shared_Image.H"
  27. \#endif} {public local
  28. }
  29. decl {const int keyspos[12]={0,-1,1,-2,2,3,-4,4,-5,5,-6,6};} {private local
  30. }
  31. decl {const int keysoct1qwerty[]={'q','2','w','3','e','r','5','t','6','y','7','u','i','9','o','0','p','[','=',']','\\\\',FL_Enter,0};} {private local
  32. }
  33. decl {const int keysoct2qwerty[]={'z','s','x','d','c','v','g','b','h','n','j','m',',','l','.',';','/',0};} {private local
  34. }
  35. decl {const int keysoct1dw[]={'\\'','2',',','3','.','p','5','y','6','f','7','g','c','9','r','0','l','/',']','=','\\\\',FL_Enter,0};} {private local
  36. }
  37. decl {const int keysoct2dw[]={';','o','q','e','j','k','i','x','d','b','h','m','w','n','v','s','z',0};} {private local
  38. }
  39. decl {const int keysoct1qwertz[]={'q','2','w','3','e','r','5','t','6','z','7','u','i','9','o','0','p',252,'\\'','+','\\\\',FL_Enter,0};} {private local
  40. }
  41. decl {const int keysoct2qwertz[]={'y','s','x','d','c','v','g','b','h','n','j','m',',','l','.',246,'-',0};} {private local
  42. }
  43. decl {const int keysoct1az[]={'a',233,'z','\\"','e','r','(','t','-','y',232,'u','i',231,'o',224,'p',65106,'=','$',0};} {private local
  44. }
  45. decl {const int keysoct2az[]={'w','s','x','d','c','v','g','b','h','n','j',',',';','l',':','m','!',0};} {private local
  46. }
  47. class VirKeys {open : {public Fl_Box, public Fl_Osc_Widget}
  48. } {
  49. decl {static const int N_OCT=6;} {private local
  50. }
  51. decl {static const int SIZE_WHITE=14;} {private local
  52. }
  53. decl {static const int SIZE_BLACK=8;} {private local
  54. }
  55. Function {VirKeys(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label),Fl_Osc_Widget()} {} {
  56. code {} {}
  57. }
  58. Function {OSC_value(int layout)} {} {
  59. code {
  60. keylayout = layout;
  61. } {}
  62. }
  63. Function {init(Fl_Osc_Interface *osc_, std::string loc_)} {open
  64. } {
  65. code {osc=osc_;
  66. osc->createLink("/config/cfg.VirKeybLayout", this);
  67. osc->requestValue("/config/cfg.VirKeybLayout");
  68. loc=loc_;
  69. for (int i=0;i<N_OCT*12+1;i++) pressed[i]=0;
  70. keylayout=0;
  71. midich=0;
  72. midivel=100;
  73. midioct=2;
  74. keyoct1=3;
  75. keyoct2=2;
  76. rndvelocity=0;} {selected
  77. }
  78. }
  79. Function {draw()} {} {
  80. code {int ox=x(),oy=y(),lx=w(),ly=h()-1,i;
  81. \#ifdef NTK_GUI
  82. \#ifdef CARLA_VERSION_STRING
  83. Fl_Image *white_up = Fl_Shared_Image::get( gUiPixmapPath + "/white_key.png" );
  84. Fl_Image *white_down = Fl_Shared_Image::get( gUiPixmapPath + "/white_key_pressed.png" );
  85. Fl_Image *black_up = Fl_Shared_Image::get( gUiPixmapPath + "/black_key.png" );
  86. Fl_Image *black_down = Fl_Shared_Image::get( gUiPixmapPath + "/black_key_pressed.png" );
  87. \#else
  88. Fl_Image *white_up = Fl_Shared_Image::get( PIXMAP_PATH "white_key.png" );
  89. Fl_Image *white_down = Fl_Shared_Image::get( PIXMAP_PATH "white_key_pressed.png" );
  90. Fl_Image *black_up = Fl_Shared_Image::get( PIXMAP_PATH "black_key.png" );
  91. Fl_Image *black_down = Fl_Shared_Image::get( PIXMAP_PATH "black_key_pressed.png" );
  92. \#endif
  93. //On error fetch everything from source directory
  94. if(!(white_up&&white_down&&black_up&&black_down)) {
  95. white_up = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/white_key.png");
  96. white_down = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/white_key_pressed.png");
  97. black_up = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/black_key.png");
  98. black_down = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/black_key_pressed.png");
  99. }
  100. Fl_Image *key;
  101. for (i=0;i<N_OCT*12;i++) {
  102. int noct=i/12;
  103. int kv=keyspos[i%12];
  104. if (kv>=0){//white keys
  105. if (pressed[i]==0)
  106. key = white_up;
  107. else
  108. key = white_down;
  109. key->draw( ox + (kv + 7 * noct ) * white_up->w() + 3, oy );
  110. }
  111. }
  112. for (i=0;i<N_OCT*12;i++){
  113. int noct=i/12;
  114. int kv=keyspos[i%12];
  115. if ( kv < 0 ) {
  116. kv=keyspos[(i+1)%12];
  117. if (pressed[i]==0)
  118. key = black_up;
  119. else
  120. key = black_down;
  121. key->draw( ox + (kv + 7 * noct ) * white_up->w() - black_up->w() / 2 + 2, oy );
  122. }
  123. }
  124. \#else
  125. if (damage()!=1){
  126. fl_color(250,240,230);
  127. fl_rectf(ox,oy,lx,ly);
  128. fl_color(FL_BLACK);
  129. fl_line(ox,oy,ox+lx,oy);
  130. fl_line(ox,oy+ly,ox+lx,oy+ly);
  131. for (i=0;i<N_OCT*7+1;i++){
  132. fl_line(ox+i*SIZE_WHITE,oy,ox+i*SIZE_WHITE,oy+ly);
  133. int ik=i%7;
  134. if ((ik==1)||(ik==2)||(ik==4)||(ik==5)||(ik==6))
  135. fl_rectf(ox+i*SIZE_WHITE-SIZE_BLACK/2,oy,
  136. SIZE_BLACK+1,ly*3/5);
  137. }
  138. }
  139. for (i=0;i<N_OCT*12;i++){
  140. // if (pressed[i]==0) continue;
  141. int noct=i/12;
  142. int kv=keyspos[i%12];
  143. if (kv>=0){//white keys
  144. if (pressed[i]==0) fl_color(250,240,230);
  145. else fl_color(FL_BLUE);
  146. fl_rectf(ox+(kv+7*noct)*SIZE_WHITE+3,oy+ly*3/5+2,
  147. SIZE_WHITE-4,ly*2/5-3);
  148. } else {//black keys
  149. kv=keyspos[(i+1)%12];
  150. if (pressed[i]==0) fl_color(FL_BLACK);
  151. else fl_color(FL_BLUE);
  152. fl_rectf(ox+(kv+7*noct)*SIZE_WHITE-SIZE_BLACK/2+2,oy+2,
  153. SIZE_BLACK-3,ly*3/5-5);
  154. }
  155. }
  156. \#endif} {}
  157. }
  158. Function {handle(int event)} {return_type int
  159. } {
  160. code {int i;
  161. int ly=h();
  162. int x_=Fl::event_x()-x();
  163. int y_=Fl::event_y()-y();
  164. if ( (x_<0)&&(x_>w()) && (y_<0)&&(y_>h())){
  165. return(0);
  166. };
  167. if ((event==FL_PUSH)||(event==FL_DRAG)||(event==FL_RELEASE)){
  168. int kpos=-1;
  169. if (y_>ly*3/5){//white keys
  170. int pos=x_/SIZE_WHITE;
  171. if (pos<0) return(1);
  172. for (i=0;i<12;i++) {
  173. if (pos%7==keyspos[i]) {
  174. kpos=pos/7*12+i;
  175. break;
  176. };
  177. };
  178. } else {//black keys
  179. int pos=(x_+SIZE_WHITE/2)/SIZE_WHITE;
  180. if (pos<0) return(1);
  181. for (i=1;i<12;i++) {
  182. if (pos%7==-keyspos[i]) {
  183. kpos=pos/7*12+i;
  184. break;
  185. };
  186. };
  187. };
  188. if ((kpos!=-1)&&((event==FL_PUSH)||(event==FL_DRAG))&&
  189. (Fl::event_shift()==0)) {
  190. presskey(kpos,1,1);
  191. };
  192. if ((event==FL_PUSH)&&(Fl::event_shift()!=0)) {
  193. if (pressed[kpos]==0) presskey(kpos,0,1);
  194. else releasekey(kpos,1);
  195. };
  196. if ((event==FL_RELEASE)&&(Fl::event_shift()==0))
  197. releaseallkeys(1);
  198. take_focus();
  199. };
  200. const int *keysoct1=keysoct1qwerty;
  201. const int *keysoct2=keysoct2qwerty;
  202. if (keylayout==2) {
  203. keysoct1=keysoct1dw;
  204. keysoct2=keysoct2dw;
  205. }else if (keylayout==3) {
  206. keysoct1=keysoct1qwertz;
  207. keysoct2=keysoct2qwertz;
  208. }else if (keylayout==4) {
  209. keysoct1=keysoct1az;
  210. keysoct2=keysoct2az;
  211. };
  212. if ((event==FL_KEYDOWN)||(event==FL_KEYUP)){
  213. int key=Fl::event_key();
  214. int kpos=-1;
  215. for (i=0;keysoct1[i]!=0;i++) if (key==keysoct1[i]) kpos=i+12*keyoct1;
  216. for (i=0;keysoct2[i]!=0;i++) if (key==keysoct2[i]) kpos=i+12*keyoct2;
  217. if (kpos==-1) return(0);
  218. if ((event==FL_KEYUP) && (Fl::event_key(key)==0) && (Fl::get_key(key)!=0)) return(0);
  219. if (event==FL_KEYDOWN) presskey(kpos,0,2);
  220. else releasekey(kpos,2);
  221. };
  222. return(1);} {}
  223. }
  224. Function {presskey(int nk,int exclusive,int type)} {} {
  225. code {//Exclusive means that multiple keys can be pressed at once
  226. //when the user uses the shift key
  227. if (nk>=N_OCT*12) return;
  228. if ((nk<0)&&(exclusive==0)) {
  229. releaseallkeys(type);
  230. return;
  231. };
  232. if (nk<0) return;
  233. if (pressed[nk]!=0) return;//the key is already pressed
  234. if (exclusive!=0) releaseallkeys(type);
  235. pressed[nk]=type;
  236. damage(1);
  237. float vel=midivel;
  238. if (rndvelocity!=0){
  239. vel=midivel*(127.0-rndvelocity)/127.0+(rand()/RAND_MAX)*rndvelocity;
  240. };
  241. osc->write(loc+"noteOn", "iii", midich,nk+midioct*12,(int)vel);} {}
  242. }
  243. Function {releasekey(int nk,int type)} {} {
  244. code {if ((nk<0)||(nk>=N_OCT*12)) return;
  245. if (pressed[nk]==0) return;//the key is not pressed
  246. if ((type!=0)&&(pressed[nk]!=type)) return;
  247. pressed[nk]=0;
  248. damage(1);
  249. osc->write(loc+"noteOff", "ii", midich,nk+12*midioct);} {}
  250. }
  251. Function {releaseallkeys(int type)} {} {
  252. code {for (int i=0;i<N_OCT*12;i++) releasekey(i,type);} {}
  253. }
  254. decl {int pressed[N_OCT*12+1];} {private local
  255. }
  256. decl {unsigned char midich;} {public local
  257. }
  258. decl {int keylayout;} {public local
  259. }
  260. decl {unsigned char midivel;} {public local
  261. }
  262. decl {char midioct,keyoct1,keyoct2;} {public local
  263. }
  264. decl {unsigned char rndvelocity;} {public local
  265. }
  266. decl {Fl_Osc_Interface *osc;} {private local
  267. }
  268. decl {std::string loc;} {private local
  269. }
  270. }
  271. class VirKeyboard {open
  272. } {
  273. Function {make_window()} {open
  274. } {
  275. Fl_Window virkeyboardwindow {
  276. label {Virtual Keyboard - ZynAddSubFX}
  277. callback {releaseallkeys();
  278. virkeyboardwindow->hide();} open
  279. xywh {103 620 650 130} type Double visible
  280. } {
  281. Fl_Box virkeys {
  282. label Keyboard
  283. xywh {10 10 590 80} box FLAT_BOX color 17
  284. code0 {o->init(osc,loc);}
  285. class VirKeys
  286. }
  287. Fl_Counter {} {
  288. label {"qwer.." Oct}
  289. callback {releaseallkeys();
  290. virkeys->keyoct1=(int) o->value();
  291. virkeys->take_focus();}
  292. tooltip {keys "q2w3er5t6y..." octave} xywh {380 95 45 15} type Simple labelsize 10 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 10
  293. code0 {o->value(virkeys->keyoct1);}
  294. }
  295. Fl_Counter {} {
  296. label {"zxcv.." Oct}
  297. callback {releaseallkeys();
  298. virkeys->keyoct2=(int) o->value();
  299. virkeys->take_focus();}
  300. tooltip {keys "zsxdcvgbh..." octave} xywh {380 110 45 15} type Simple labelsize 10 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 10
  301. code0 {o->value(virkeys->keyoct2);}
  302. }
  303. Fl_Value_Slider {} {
  304. label Vel
  305. callback {virkeys->midivel=(int) o->value();
  306. virkeys->take_focus();}
  307. tooltip Velocity xywh {95 105 100 15} type {Horz Knob} box NO_BOX labelsize 10 align 5 minimum 1 maximum 127 step 1
  308. code0 {o->value(virkeys->midivel);}
  309. }
  310. Fl_Counter {} {
  311. label {Oct.}
  312. callback {releaseallkeys();
  313. virkeys->midioct=(int) o->value();
  314. virkeys->take_focus();}
  315. tooltip {Midi Octave} xywh {255 100 55 20} type Simple labelsize 11 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 11
  316. code0 {o->value(virkeys->midioct);}
  317. }
  318. Fl_Button {} {
  319. label Close
  320. callback {releaseallkeys();
  321. virkeyboardwindow->hide();}
  322. xywh {545 105 55 20} box THIN_UP_BOX
  323. }
  324. Fl_Value_Slider {} {
  325. label Cval
  326. callback {int ctl=midictl;
  327. osc->write("/setController", "iii", virkeys->midich,ctl,(int) o->value());
  328. virkeys->take_focus();}
  329. tooltip {Controller value} xywh {605 10 15 115} type {Vert Fill} box ENGRAVED_BOX selection_color 229 labelsize 8 align 5 minimum 127 maximum 0 step 1 value 64 textsize 7
  330. }
  331. Fl_Choice {} {
  332. label Controller
  333. callback {switch((int) o->value()+1){
  334. case 1: midictl=C_modwheel; break;
  335. case 2: midictl=C_volume; break;
  336. case 3: midictl=C_panning; break;
  337. case 4: midictl=C_expression; break;
  338. case 5: midictl=C_sustain; break;
  339. case 6: midictl=C_portamento; break;
  340. case 7: midictl=C_filterq; break;
  341. case 8: midictl=C_filtercutoff; break;
  342. case 9: midictl=C_bandwidth; break;
  343. case 10: midictl=C_fmamp; break;
  344. case 11: midictl=C_resonance_center; break;
  345. case 12: midictl=C_resonance_bandwidth; break;
  346. default: midictl=C_NULL; break;
  347. };
  348. virkeys->take_focus();}
  349. xywh {435 105 100 15} down_box BORDER_BOX labelsize 10 align 5 when 6 textfont 1 textsize 10
  350. code0 {midictl=C_filtercutoff;o->value(7);}
  351. } {
  352. MenuItem {} {
  353. label {01: Mod.Wheel}
  354. xywh {0 0 100 20} labelfont 1 labelsize 10
  355. }
  356. MenuItem {} {
  357. label {07: Volume}
  358. xywh {10 10 100 20} labelfont 1 labelsize 10
  359. }
  360. MenuItem {} {
  361. label {10: Panning}
  362. xywh {20 20 100 20} labelfont 1 labelsize 10
  363. }
  364. MenuItem {} {
  365. label {11: Expression}
  366. xywh {30 30 100 20} labelfont 1 labelsize 10
  367. }
  368. MenuItem {} {
  369. label {64: Sustain}
  370. xywh {40 40 100 20} labelfont 1 labelsize 10
  371. }
  372. MenuItem {} {
  373. label {65: Portamento}
  374. xywh {50 50 100 20} labelfont 1 labelsize 10
  375. }
  376. MenuItem {} {
  377. label {71: Filter Q}
  378. xywh {60 60 100 20} labelfont 1 labelsize 10
  379. }
  380. MenuItem {} {
  381. label {74: Filter Freq.}
  382. xywh {70 70 100 20} labelfont 1 labelsize 10
  383. }
  384. MenuItem {} {
  385. label {75: Bandwidth}
  386. xywh {80 80 100 20} labelfont 1 labelsize 10
  387. }
  388. MenuItem {} {
  389. label {76: FM Gain}
  390. xywh {90 90 100 20} labelfont 1 labelsize 10
  391. }
  392. MenuItem {} {
  393. label {77: Res. c. freq}
  394. xywh {100 100 100 20} labelfont 1 labelsize 10
  395. }
  396. MenuItem {} {
  397. label {78: Res. bw.}
  398. xywh {110 110 100 20} labelfont 1 labelsize 10
  399. }
  400. }
  401. Fl_Roller pitchwheelroller {
  402. label Pwh
  403. callback {osc->write("/setController", "iii", virkeys->midich,C_pitchwheel,-(int) o->value());
  404. virkeys->take_focus();}
  405. tooltip {Pitch Wheel} xywh {625 10 20 95} labelsize 8 align 1 when 3 minimum -8192 maximum 8192 step 64
  406. }
  407. Fl_Button {} {
  408. label R
  409. callback {pitchwheelroller->value(0);
  410. pitchwheelroller->do_callback();}
  411. tooltip {Reset Pitch Bend} xywh {625 110 20 15} box THIN_UP_BOX labelfont 1
  412. }
  413. Fl_Dial {} {
  414. label Vrnd
  415. callback {virkeys->rndvelocity=(int) o->value();}
  416. tooltip {Velocity Randomness} xywh {205 105 20 20} box ROUND_UP_BOX labelsize 10 align 129 maximum 127 step 1
  417. code0 {o->value(virkeys->rndvelocity);}
  418. class WidgetPDial
  419. }
  420. Fl_Choice partrcv {
  421. label {MIDI Ch.}
  422. callback {releaseallkeys();
  423. virkeys->midich=(int) o->value();
  424. virkeys->take_focus();} open
  425. tooltip {Send to Midi Channel} xywh {20 105 65 20} down_box BORDER_BOX labelsize 10 align 5 textfont 1 textsize 10
  426. code0 {char nrstr[10]; for(int i=0;i<NUM_MIDI_CHANNELS;i++){sprintf(nrstr,"Chn%d",i+1);if (i!=9) o->add(nrstr); else o->add("Drum10");};}
  427. code1 {o->value(virkeys->midich);}
  428. } {}
  429. }
  430. }
  431. Function {VirKeyboard(Fl_Osc_Interface *osc_, std::string loc_)} {open
  432. } {
  433. code {osc=osc_;
  434. loc=loc_;
  435. midictl=75;
  436. make_window();} {}
  437. }
  438. Function {~VirKeyboard()} {open
  439. } {
  440. code {delete virkeyboardwindow;} {}
  441. }
  442. Function {show()} {open
  443. } {
  444. code {virkeyboardwindow->show();} {}
  445. }
  446. Function {releaseallkeys()} {open
  447. } {
  448. code {virkeys->releaseallkeys(0);} {}
  449. }
  450. decl {int midictl;} {private local
  451. }
  452. decl {Fl_Osc_Interface *osc;} {private local
  453. }
  454. decl {std::string loc;} {private local
  455. }
  456. }