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

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