Put jack driver stuff in drivers/jack/jack_audio.c
[pineappletracker.git] / actions.c
blob03a11095ebbc561a45e2d2cf27c019adb29b1aa6
1 /* vi:set ts=8 sts=8 sw=8 noexpandtab: */
2 #include "pineapple.h"
3 #include "gui.h"
5 #include <string.h>
7 static u8 _oldfxparam = 0;
9 /* move cursor left one column */
10 void act_mvleft(void){
11 switch(currtab){
12 case 0:
13 if(songx) songx--;
14 break;
15 case 1:
16 if(trackx) trackx--;
17 break;
18 case 2:
19 if(instrx) instrx--;
20 break;
24 /* move cursor right one column */
25 void act_mvright(void){
26 switch(currtab){
27 case 0:
28 if(songx < 15) songx++;
29 break;
30 case 1:
31 if(trackx < 9) trackx++;
32 break;
33 case 2:
34 if(instrx < 2) instrx++;
35 break;
39 /* move cursor up 1 line */
40 void act_mvup(void){
41 switch(currtab){
42 case 0:
43 if(songy){
44 songy--;
45 }else{
46 songy = 0;
48 break;
49 case 1:
50 if(tracky){
51 tracky--;
52 }else{
53 tracky = 0;
55 break;
56 case 2:
57 if(instry){
58 instry--;
59 }else{
60 instry = 0;
62 break;
66 /* move cursor down 1 line */
67 void act_mvdown(void){
68 switch(currtab){
69 case 0:
70 if(songy < songlen - 1){
71 songy++;
72 }else{
73 songy = songlen - 1;
75 break;
76 case 1:
77 if(tracky < tracklen - 1){
78 tracky++;
79 }else{
80 tracky = tracklen - 1;
82 break;
83 case 2:
84 if(instry < instrument[currinstr].length - 1){
85 instry++;
86 }else{
87 instry = instrument[currinstr].length - 1;
89 break;
93 /* move cursor up 8 lines */
94 void act_bigmvup(void){
95 switch(currtab){
96 case 0:
97 if(songy >= 8){
98 songy -= 8;
99 }else{
100 songy = 0;
102 break;
103 case 1:
104 if(tracky >= 8){
105 tracky -= 8;
106 }else{
107 tracky = 0;
109 break;
110 case 2:
111 if(instry >= 8) instry -= 8;
112 break;
116 /* move cursor down 8 lines */
117 void act_bigmvdown(void){
118 switch(currtab){
119 case 0:
120 if(songy < songlen - 8){
121 songy += 8;
122 }else{
123 songy = songlen - 1;
125 break;
126 case 1:
127 if(tracky < tracklen - 8){
128 tracky += 8;
129 }else{
130 tracky = tracklen - 1;
132 break;
133 case 2:
134 if(instry < instrument[currinstr].length - 8) instry += 8;
135 break;
139 void act_mvbottom(void){
140 switch(currtab){
141 case 0:
142 songy = songlen - 1;
143 break;
144 case 1:
145 tracky = tracklen - 1;
146 break;
147 case 2:
148 instry = instrument[currinstr].length - 1;
149 break;
153 void act_mvtop(void){
154 switch(currtab){
155 case 0:
156 songy = 0;
157 break;
158 case 1:
159 tracky = 0;
160 break;
161 case 2:
162 instry = 0;
163 break;
167 void act_viewtrackinc(void){
168 if(currtrack < 0xff){
169 currtrack++;
170 }else if(currtrack == 0xff){
171 currtrack = 1;
173 if(playtrack){
174 startplaytrack(currtrack);
178 void act_viewtrackdec(void){
179 if(currtrack > 1){
180 currtrack--;
181 }else if(currtrack == 1){
182 currtrack = 0xff;
184 if(playtrack){
185 startplaytrack(currtrack);
189 void act_viewinstrinc(void){
190 if(currinstr == 0xff) currinstr = 0x01;
191 else currinstr++;
194 void act_viewinstrdec(void){
195 if(currinstr == 1) currinstr = 0xff;
196 else currinstr--;
199 void act_trackinc(void){
200 if( (songx%2)==0 ){
201 if(songx >= 240 && songx < 256){
202 song[songy].track[songx/4] -= 240;
203 }else{
204 song[songy].track[songx/4] += 16;
206 }else{
207 if( (song[songy].track[songx/4] % 16) == 15){
208 song[songy].track[songx/4] -= 15;
209 }else{
210 song[songy].track[songx/4]++;
213 saved = 0;
216 void act_trackdec(void){
217 if( (songx%2)==0 ){
218 if(songx <= 15 && songx >= 0){
219 song[songy].track[songx/4] += 240;
220 }else{
221 song[songy].track[songx/4] -= 16;
223 }else{
224 if( (song[songy].track[songx/4] % 16) == 0){
225 song[songy].track[songx/4] += 15;
226 }else{
227 song[songy].track[songx/4]--;
230 saved = 0;
233 void act_transpinc(void){
234 if( (songx%2)==0 ){
235 if(songx >= 240 && songx < 256){
236 song[songy].transp[songx/4] -= 240;
237 }else{
238 song[songy].transp[songx/4] += 16;
240 }else{
241 if( (song[songy].transp[songx/4] % 16) == 15){
242 song[songy].transp[songx/4] -= 15;
243 }else{
244 song[songy].transp[songx/4]++;
247 saved = 0;
250 void act_transpdec(void){
251 if( (songx%2)==0 ){
252 if(songx <= 15 && songx >= 0){
253 song[songy].transp[songx/4] += 240;
254 }else{
255 song[songy].transp[songx/4] -= 16;
257 }else{
258 if( (song[songy].transp[songx/4] % 16) == 0){
259 song[songy].transp[songx/4] += 15;
260 }else{
261 song[songy].transp[songx/4]--;
264 saved = 0;
267 void act_undo(void){
270 void act_noteinc(void){
271 if(currtab==1){
272 // if current note < H7
273 if( track[currtrack].line[tracky].note < 96 ){
274 track[currtrack].line[tracky].note++;
275 }else{
276 track[currtrack].line[tracky].note = 0;
278 }else if(currtab==2){
279 if( instrument[currinstr].line[instry].param < 96 ){
280 instrument[currinstr].line[instry].param++;
281 }else{
282 instrument[currinstr].line[instry].param = 0;
285 saved = 0;
288 void act_notedec(void){
289 if(currtab==1){
290 if( track[currtrack].line[tracky].note > 0 ){
291 track[currtrack].line[tracky].note--;
292 }else{
293 track[currtrack].line[tracky].note = 96;
295 }else if(currtab==2){
296 if( instrument[currinstr].line[instry].param > 0 ){
297 instrument[currinstr].line[instry].param--;
298 }else{
299 instrument[currinstr].line[instry].param = 96;
302 saved = 0;
305 void act_octaveinc(void){
306 if(currtab==1){
307 if( track[currtrack].line[tracky].note+12 <= 96 ){
308 track[currtrack].line[tracky].note+=12;
309 }else{
310 track[currtrack].line[tracky].note %= 12;
312 }else if(currtab==2){ if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
313 if( instrument[currinstr].line[instry].param+12 <= 96 ){
314 instrument[currinstr].line[instry].param+=12;
315 }else{
316 instrument[currinstr].line[instry].param %= 12;
320 saved = 0;
323 void act_octavedec(void){
324 if(currtab==1){
325 if( track[currtrack].line[tracky].note-12 > 0 ){
326 track[currtrack].line[tracky].note-=12;
327 }else{
328 track[currtrack].line[tracky].note = 84 + track[currtrack].line[tracky].note;
330 }else if(currtab==2){
331 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
332 if( instrument[currinstr].line[instry].param-12 > 0 ){
333 instrument[currinstr].line[instry].param-=12;
334 }else{
335 instrument[currinstr].line[instry].param = 84 + instrument[currinstr].line[instry].param;
339 saved = 0;
342 void act_instrinc(void){
343 switch(trackx){
344 case 2:
345 SETHI(track[currtrack].line[tracky].instr,
346 hexinc(track[currtrack].line[tracky].instr >> 4) );
347 break;
348 case 3:
349 SETLO(track[currtrack].line[tracky].instr,
350 hexinc(track[currtrack].line[tracky].instr & 0x0f) );
351 break;
353 saved = 0;
356 void act_instrdec(void){
357 switch(trackx){
358 case 2:
359 SETHI(track[currtrack].line[tracky].instr,
360 hexdec(track[currtrack].line[tracky].instr >> 4) );
361 break;
362 case 3:
363 SETLO(track[currtrack].line[tracky].instr,
364 hexdec(track[currtrack].line[tracky].instr & 0x0f) );
365 break;
367 saved = 0;
370 void act_fxinc(void){
371 if(currtab==1){
372 currcmd = track[currtrack].line[tracky].cmd[trackx % 2];
373 // there must be a better way to do this...
374 if((unsigned long)currcmd == (unsigned long)NULL){
375 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[0];
376 }else{
377 for(int z = 0; z < strlen(validcmds); z++){
378 if(currcmd == validcmds[z]){
379 if(z == (strlen(validcmds)-1)){
380 track[currtrack].line[tracky].cmd[trackx % 2] = (unsigned long)NULL;
381 }else{
382 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[z+1];
384 continue;
388 }else if(currtab==2){
389 currcmd = instrument[currinstr].line[instry].cmd;
390 for(int z = 0; z < strlen(validcmds); z++){
391 if(currcmd == validcmds[z]){
392 if(z == (strlen(validcmds)-1)){
393 instrument[currinstr].line[instry].cmd = validcmds[0];
394 }else{
395 instrument[currinstr].line[instry].cmd = validcmds[z+1];
396 if(_oldfxparam)
397 instrument[currinstr].line[instry].param = _oldfxparam;
400 // when switching to the note command, change to param if it's
401 // higher than H7
402 if((instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '=')
403 //&& _oldfxparam
404 && instrument[currinstr].line[instry].param>96){
405 // save current param
406 _oldfxparam = instrument[currinstr].line[instry].param;
407 instrument[currinstr].line[instry].param = 96; //H7
408 }else if(_oldfxparam){
409 instrument[currinstr].line[instry].param = _oldfxparam;
410 _oldfxparam = 0;
413 continue;
417 saved = 0;
420 void act_fxdec(void){
421 if(currtab==1){
422 currcmd = track[currtrack].line[tracky].cmd[trackx % 2];
423 if((unsigned long)currcmd == (unsigned long)NULL){
424 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[strlen(validcmds)-1];
425 }else{
426 for(int z = 0; z < strlen(validcmds); z++){
427 if(currcmd == validcmds[z]){
428 if(z==0){
429 track[currtrack].line[tracky].cmd[trackx % 2] = (unsigned long)NULL;
430 }else{
431 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[z-1];
433 continue;
437 }else if(currtab==2){
438 currcmd = instrument[currinstr].line[instry].cmd;
439 for(int z = 0; z < strlen(validcmds); z++){
440 if(currcmd == validcmds[z]){
441 if(z==0){
442 instrument[currinstr].line[instry].cmd = validcmds[strlen(validcmds)-1];
443 }else{
444 instrument[currinstr].line[instry].cmd = validcmds[z-1];
445 if(_oldfxparam)
446 instrument[currinstr].line[instry].param = _oldfxparam;
449 // when switching to the note command, change to param if it's
450 // higher than H7
451 if((instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '=')
452 //&& _oldfxparam
453 && instrument[currinstr].line[instry].param>96){
454 // save current param
455 _oldfxparam = instrument[currinstr].line[instry].param;
456 instrument[currinstr].line[instry].param = 96; //H7
457 }else if(_oldfxparam){
458 instrument[currinstr].line[instry].param = _oldfxparam;
459 _oldfxparam = 0;
462 continue;
466 saved = 0;
469 void act_paraminc(void){
470 if(currtab==1){
471 if((trackx==5 && track[currtrack].line[tracky].cmd[0])
472 || (trackx==8 && track[currtrack].line[tracky].cmd[1])){
473 SETHI(track[currtrack].line[tracky].param[(trackx - 1) % 2],
474 hexinc(track[currtrack].line[tracky].param[(trackx - 1) % 2] >> 4) );
475 return;
476 }else if((trackx==6 && track[currtrack].line[tracky].cmd[0])
477 || (trackx==9 && track[currtrack].line[tracky].cmd[1])){
478 SETLO(track[currtrack].line[tracky].param[trackx % 2],
479 hexinc(track[currtrack].line[tracky].param[trackx % 2] & 0x0f) );
480 return;
482 }else if(currtab == 2){
483 if(instrx == 1){
484 SETHI(instrument[currinstr].line[instry].param,
485 hexinc(instrument[currinstr].line[instry].param >> 4) );
486 return;
487 }else if(instrx == 2){
488 SETLO(instrument[currinstr].line[instry].param,
489 hexinc(instrument[currinstr].line[instry].param & 0x0f) );
490 return;
493 saved = 0;
496 void act_paramdec(void){
497 if(currtab==1){
498 if((trackx==5 && track[currtrack].line[tracky].cmd[0])
499 || (trackx==8 && track[currtrack].line[tracky].cmd[1])){
500 SETHI(track[currtrack].line[tracky].param[(trackx-1) % 2],
501 hexdec(track[currtrack].line[tracky].param[(trackx-1) % 2] >> 4) );
502 return;
503 }else if((trackx==6 && track[currtrack].line[tracky].cmd[0])
504 || (trackx==9 && track[currtrack].line[tracky].cmd[1])){
505 SETLO(track[currtrack].line[tracky].param[trackx % 2],
506 hexdec(track[currtrack].line[tracky].param[trackx % 2] & 0x0f) );
507 return;
509 }else if(currtab == 2){
510 if(instrx == 1){
511 SETHI(instrument[currinstr].line[instry].param,
512 hexdec(instrument[currinstr].line[instry].param >> 4) );
513 return;
514 }else if(instrx == 2){
515 SETLO(instrument[currinstr].line[instry].param,
516 hexdec(instrument[currinstr].line[instry].param & 0x0f) );
517 return;
520 saved = 0;
523 void act_addline(void){
524 if(currtab == 2){
525 struct instrument *in = &instrument[currinstr];
527 if(in->length < 256){
528 memmove(&in->line[instry + 2], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1));
529 instry++;
530 in->length++;
531 in->line[instry].cmd = '0';
532 in->line[instry].param = 0;
534 }else if(currtab == 0){
535 if(songlen < 256){
536 memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1));
537 songy++;
538 songlen++;
539 memset(&song[songy], 0, sizeof(struct songline));
542 saved = 0;
545 void act_delline(void){
546 if(currtab == 2){
547 struct instrument *in = &instrument[currinstr];
549 if(in->length > 1){
550 memmove(&in->line[instry + 0], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1));
551 in->length--;
552 if(instry >= in->length) instry = in->length - 1;
554 }else if(currtab == 0){
555 if(songlen > 1){
556 memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1));
557 songlen--;
558 if(songy >= songlen) songy = songlen - 1;
561 saved = 0;
564 void act_clronething(void){
565 if(currtab == 0){
566 if( (songx%4) < 2){
567 if( (songx%2)==0 ){
568 song[songy].track[songx/4] = (song[songy].track[songx/4] - song[songy].track[songx/4]) + song[songy].track[songx/4]%16;
569 }else{
570 song[songy].track[songx/4] -= song[songy].track[songx/4]%16;
572 }else{
573 if( (songx%2)==0 ){
574 song[songy].transp[songx/4] = (song[songy].transp[songx/4] - song[songy].transp[songx/4]) + song[songy].transp[songx/4]%16;
575 }else{
576 song[songy].transp[songx/4] -= song[songy].transp[songx/4]%16;
579 //memcpy(&tclip, &song[songy], sizeof(struct songline));
580 }else if(currtab == 1){
581 switch(trackx){
582 case 0:
583 memcpy(&tclip, &track[currtrack].line[tracky], sizeof(struct trackline));
584 track[currtrack].line[tracky].note = 0;
585 track[currtrack].line[tracky].instr = 0;
586 //memmove
587 break;
588 case 2:
589 memcpy(&tclip, &track[currtrack].line[tracky].instr, sizeof(struct trackline));
590 SETHI(track[currtrack].line[tracky].instr, 0);
591 break;
592 case 3:
593 memcpy(&tclip, &track[currtrack].line[tracky].instr, sizeof(struct trackline));
594 SETLO(track[currtrack].line[tracky].instr, 0);
595 break;
596 case 4:
597 track[currtrack].line[tracky].cmd[0] = 0;
598 break;
599 case 5:
600 SETHI(track[currtrack].line[tracky].param[0],0);
601 break;
602 case 6:
603 SETLO(track[currtrack].line[tracky].param[0],0);
604 break;
605 case 7:
606 track[currtrack].line[tracky].cmd[1] = 0;
607 break;
608 case 8:
609 SETHI(track[currtrack].line[tracky].param[1],0);
610 break;
611 case 9:
612 SETLO(track[currtrack].line[tracky].param[1],0);
613 break;
614 default:
615 setdisplay("in ACT_CLRONETHING");
616 break;
618 }else if(currtab == 2){
619 if(instrx == 0){
620 instrument[currinstr].line[instry].cmd = '0';
621 }else if(instrx == 1){
622 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
623 instrument[currinstr].line[instry].param = 0;
624 }else{
625 SETHI(instrument[currinstr].line[instry].param,0);
627 }else if(instrx == 2){
628 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
629 instrument[currinstr].line[instry].param = 0;
630 }else{
631 SETLO(instrument[currinstr].line[instry].param,0);
635 saved = 0;
638 void act_clritall(void){
639 if(currtab == 0){
640 for(int ci = 0; ci < 4; ci++){
641 song[songy].track[ci] = 0;
642 song[songy].transp[ci] = 0;
644 }else if(currtab == 1){
645 track[currtrack].line[tracky].note = 0;
646 track[currtrack].line[tracky].instr = 0;
647 SETHI(track[currtrack].line[tracky].instr, 0);
648 SETLO(track[currtrack].line[tracky].instr, 0);
649 track[currtrack].line[tracky].cmd[0] = 0;
650 SETHI(track[currtrack].line[tracky].param[0],0);
651 SETLO(track[currtrack].line[tracky].param[0],0);
652 track[currtrack].line[tracky].cmd[1] = 0;
653 SETHI(track[currtrack].line[tracky].param[1],0);
654 SETLO(track[currtrack].line[tracky].param[1],0);
655 }else if(currtab == 2){
656 instrument[currinstr].line[instry].cmd = '0';
657 instrument[currinstr].line[instry].param = 0;
659 saved = 0;
662 // clear line y in the song tab
663 void act_clrinsongtab(int y){
664 for(int ci = 0; ci < 4; ci++){
665 song[songy].track[ci] = 0;
666 song[songy].transp[ci] = 0;
668 saved = 0;
671 void act_clrintracktab(int t, int y){
672 track[t].line[y].note = 0;
673 track[t].line[y].instr = 0;
674 SETHI(track[t].line[y].instr, 0);
675 SETLO(track[t].line[y].instr, 0);
676 track[t].line[y].cmd[0] = 0;
677 SETHI(track[t].line[y].param[0],0);
678 SETLO(track[t].line[y].param[0],0);
679 track[t].line[y].cmd[1] = 0;
680 SETHI(track[t].line[y].param[1],0);
681 SETLO(track[t].line[y].param[1],0);
682 saved = 0;
685 void act_clrininstrtab(int instr, int y){
686 instrument[instr].line[y].cmd = '0';
687 instrument[instr].line[y].param = 0;
688 saved = 0;