* Mod parser parses patterns, just got to figure out what the period values mean...
[pineappletracker.git] / actions.c
blob80f8edc2881f6364d10b9e86a54ec58ce5bed9c4
1 /* vi:set ts=8 sts=8 sw=8 noexpandtab: */
2 #include "pineapple.h"
3 #include "gui.h"
5 static u8 _oldfxparam = 0;
7 /* move cursor left one column */
8 void act_mvleft(void){
9 switch(currtab){
10 case 0:
11 if(songx) songx--;
12 break;
13 case 1:
14 if(trackx) trackx--;
15 break;
16 case 2:
17 if(instrx) instrx--;
18 break;
22 /* move cursor right one column */
23 void act_mvright(void){
24 switch(currtab){
25 case 0:
26 if(songx < 15) songx++;
27 break;
28 case 1:
29 if(trackx < 9) trackx++;
30 break;
31 case 2:
32 if(instrx < 2) instrx++;
33 break;
37 /* move cursor up 1 line */
38 void act_mvup(void){
39 switch(currtab){
40 case 0:
41 if(songy){
42 songy--;
43 }else{
44 songy = 0;
46 break;
47 case 1:
48 if(tracky){
49 tracky--;
50 }else{
51 tracky = 0;
53 break;
54 case 2:
55 if(instry){
56 instry--;
57 }else{
58 instry = 0;
60 break;
64 /* move cursor down 1 line */
65 void act_mvdown(void){
66 switch(currtab){
67 case 0:
68 if(songy < songlen - 1){
69 songy++;
70 }else{
71 songy = songlen - 1;
73 break;
74 case 1:
75 if(tracky < tracklen - 1){
76 tracky++;
77 }else{
78 tracky = tracklen - 1;
80 break;
81 case 2:
82 if(instry < instrument[currinstr].length - 1){
83 instry++;
84 }else{
85 instry = instrument[currinstr].length - 1;
87 break;
91 /* move cursor up 8 lines */
92 void act_bigmvup(void){
93 switch(currtab){
94 case 0:
95 if(songy >= 8){
96 songy -= 8;
97 }else{
98 songy = 0;
100 break;
101 case 1:
102 if(tracky >= 8){
103 tracky -= 8;
104 }else{
105 tracky = 0;
107 break;
108 case 2:
109 if(instry >= 8) instry -= 8;
110 break;
114 /* move cursor down 8 lines */
115 void act_bigmvdown(void){
116 switch(currtab){
117 case 0:
118 if(songy < songlen - 8){
119 songy += 8;
120 }else{
121 songy = songlen - 1;
123 break;
124 case 1:
125 if(tracky < tracklen - 8){
126 tracky += 8;
127 }else{
128 tracky = tracklen - 1;
130 break;
131 case 2:
132 if(instry < instrument[currinstr].length - 8) instry += 8;
133 break;
137 void act_mvbottom(void){
138 switch(currtab){
139 case 0:
140 songy = songlen - 1;
141 break;
142 case 1:
143 tracky = tracklen - 1;
144 break;
145 case 2:
146 instry = instrument[currinstr].length - 1;
147 break;
151 void act_mvtop(void){
152 switch(currtab){
153 case 0:
154 songy = 0;
155 break;
156 case 1:
157 tracky = 0;
158 break;
159 case 2:
160 instry = 0;
161 break;
165 void act_viewtrackinc(void){
166 if(currtrack < 0xff){
167 currtrack++;
168 }else if(currtrack == 0xff){
169 currtrack = 1;
171 if(playtrack){
172 startplaytrack(currtrack);
176 void act_viewtrackdec(void){
177 if(currtrack > 1){
178 currtrack--;
179 }else if(currtrack == 1){
180 currtrack = 0xff;
182 if(playtrack){
183 startplaytrack(currtrack);
187 void act_viewinstrinc(void){
188 if(currinstr == 0xff) currinstr = 0x01;
189 else currinstr++;
192 void act_viewinstrdec(void){
193 if(currinstr == 1) currinstr = 0xff;
194 else currinstr--;
197 void act_trackinc(void){
198 if( (songx%2)==0 ){
199 if(songx >= 240 && songx < 256){
200 song[songy].track[songx/4] -= 240;
201 }else{
202 song[songy].track[songx/4] += 16;
204 }else{
205 if( (song[songy].track[songx/4] % 16) == 15){
206 song[songy].track[songx/4] -= 15;
207 }else{
208 song[songy].track[songx/4]++;
211 saved = 0;
214 void act_trackdec(void){
215 if( (songx%2)==0 ){
216 if(songx <= 15 && songx >= 0){
217 song[songy].track[songx/4] += 240;
218 }else{
219 song[songy].track[songx/4] -= 16;
221 }else{
222 if( (song[songy].track[songx/4] % 16) == 0){
223 song[songy].track[songx/4] += 15;
224 }else{
225 song[songy].track[songx/4]--;
228 saved = 0;
231 void act_transpinc(void){
232 if( (songx%2)==0 ){
233 if(songx >= 240 && songx < 256){
234 song[songy].transp[songx/4] -= 240;
235 }else{
236 song[songy].transp[songx/4] += 16;
238 }else{
239 if( (song[songy].transp[songx/4] % 16) == 15){
240 song[songy].transp[songx/4] -= 15;
241 }else{
242 song[songy].transp[songx/4]++;
245 saved = 0;
248 void act_transpdec(void){
249 if( (songx%2)==0 ){
250 if(songx <= 15 && songx >= 0){
251 song[songy].transp[songx/4] += 240;
252 }else{
253 song[songy].transp[songx/4] -= 16;
255 }else{
256 if( (song[songy].transp[songx/4] % 16) == 0){
257 song[songy].transp[songx/4] += 15;
258 }else{
259 song[songy].transp[songx/4]--;
262 saved = 0;
265 void act_undo(void){
268 void act_noteinc(void){
269 if(currtab==1){
270 // if current note < H7
271 if( track[currtrack].line[tracky].note < 96 ){
272 track[currtrack].line[tracky].note++;
273 }else{
274 track[currtrack].line[tracky].note = 0;
276 }else if(currtab==2){
277 if( instrument[currinstr].line[instry].param < 96 ){
278 instrument[currinstr].line[instry].param++;
279 }else{
280 instrument[currinstr].line[instry].param = 0;
283 saved = 0;
286 void act_notedec(void){
287 if(currtab==1){
288 if( track[currtrack].line[tracky].note > 0 ){
289 track[currtrack].line[tracky].note--;
290 }else{
291 track[currtrack].line[tracky].note = 96;
293 }else if(currtab==2){
294 if( instrument[currinstr].line[instry].param > 0 ){
295 instrument[currinstr].line[instry].param--;
296 }else{
297 instrument[currinstr].line[instry].param = 96;
300 saved = 0;
303 void act_octaveinc(void){
304 if(currtab==1){
305 if( track[currtrack].line[tracky].note+12 <= 96 ){
306 track[currtrack].line[tracky].note+=12;
307 }else{
308 track[currtrack].line[tracky].note %= 12;
310 }else if(currtab==2){ if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
311 if( instrument[currinstr].line[instry].param+12 <= 96 ){
312 instrument[currinstr].line[instry].param+=12;
313 }else{
314 instrument[currinstr].line[instry].param %= 12;
318 saved = 0;
321 void act_octavedec(void){
322 if(currtab==1){
323 if( track[currtrack].line[tracky].note-12 > 0 ){
324 track[currtrack].line[tracky].note-=12;
325 }else{
326 track[currtrack].line[tracky].note = 84 + track[currtrack].line[tracky].note;
328 }else if(currtab==2){
329 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
330 if( instrument[currinstr].line[instry].param-12 > 0 ){
331 instrument[currinstr].line[instry].param-=12;
332 }else{
333 instrument[currinstr].line[instry].param = 84 + instrument[currinstr].line[instry].param;
337 saved = 0;
340 void act_instrinc(void){
341 switch(trackx){
342 case 2:
343 SETHI(track[currtrack].line[tracky].instr,
344 hexinc(track[currtrack].line[tracky].instr >> 4) );
345 break;
346 case 3:
347 SETLO(track[currtrack].line[tracky].instr,
348 hexinc(track[currtrack].line[tracky].instr & 0x0f) );
349 break;
351 saved = 0;
354 void act_instrdec(void){
355 switch(trackx){
356 case 2:
357 SETHI(track[currtrack].line[tracky].instr,
358 hexdec(track[currtrack].line[tracky].instr >> 4) );
359 break;
360 case 3:
361 SETLO(track[currtrack].line[tracky].instr,
362 hexdec(track[currtrack].line[tracky].instr & 0x0f) );
363 break;
365 saved = 0;
368 void act_fxinc(void){
369 if(currtab==1){
370 currcmd = track[currtrack].line[tracky].cmd[trackx % 2];
371 // there must be a better way to do this...
372 if((unsigned long)currcmd == (unsigned long)NULL){
373 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[0];
374 }else{
375 for(int z = 0; z < strlen(validcmds); z++){
376 if(currcmd == validcmds[z]){
377 if(z == (strlen(validcmds)-1)){
378 track[currtrack].line[tracky].cmd[trackx % 2] = (unsigned long)NULL;
379 }else{
380 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[z+1];
382 continue;
386 }else if(currtab==2){
387 currcmd = instrument[currinstr].line[instry].cmd;
388 for(int z = 0; z < strlen(validcmds); z++){
389 if(currcmd == validcmds[z]){
390 if(z == (strlen(validcmds)-1)){
391 instrument[currinstr].line[instry].cmd = validcmds[0];
392 }else{
393 instrument[currinstr].line[instry].cmd = validcmds[z+1];
394 if(_oldfxparam)
395 instrument[currinstr].line[instry].param = _oldfxparam;
398 // when switching to the note command, change to param if it's
399 // higher than H7
400 if((instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '=')
401 //&& _oldfxparam
402 && instrument[currinstr].line[instry].param>96){
403 // save current param
404 _oldfxparam = instrument[currinstr].line[instry].param;
405 instrument[currinstr].line[instry].param = 96; //H7
406 }else if(_oldfxparam){
407 instrument[currinstr].line[instry].param = _oldfxparam;
408 _oldfxparam = 0;
411 continue;
415 saved = 0;
418 void act_fxdec(void){
419 if(currtab==1){
420 currcmd = track[currtrack].line[tracky].cmd[trackx % 2];
421 if((unsigned long)currcmd == (unsigned long)NULL){
422 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[strlen(validcmds)-1];
423 }else{
424 for(int z = 0; z < strlen(validcmds); z++){
425 if(currcmd == validcmds[z]){
426 if(z==0){
427 track[currtrack].line[tracky].cmd[trackx % 2] = (unsigned long)NULL;
428 }else{
429 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[z-1];
431 continue;
435 }else if(currtab==2){
436 currcmd = instrument[currinstr].line[instry].cmd;
437 for(int z = 0; z < strlen(validcmds); z++){
438 if(currcmd == validcmds[z]){
439 if(z==0){
440 instrument[currinstr].line[instry].cmd = validcmds[strlen(validcmds)-1];
441 }else{
442 instrument[currinstr].line[instry].cmd = validcmds[z-1];
443 if(_oldfxparam)
444 instrument[currinstr].line[instry].param = _oldfxparam;
447 // when switching to the note command, change to param if it's
448 // higher than H7
449 if((instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '=')
450 //&& _oldfxparam
451 && instrument[currinstr].line[instry].param>96){
452 // save current param
453 _oldfxparam = instrument[currinstr].line[instry].param;
454 instrument[currinstr].line[instry].param = 96; //H7
455 }else if(_oldfxparam){
456 instrument[currinstr].line[instry].param = _oldfxparam;
457 _oldfxparam = 0;
460 continue;
464 saved = 0;
467 void act_paraminc(void){
468 if(currtab==1){
469 if((trackx==5 && track[currtrack].line[tracky].cmd[0])
470 || (trackx==8 && track[currtrack].line[tracky].cmd[1])){
471 SETHI(track[currtrack].line[tracky].param[(trackx - 1) % 2],
472 hexinc(track[currtrack].line[tracky].param[(trackx - 1) % 2] >> 4) );
473 return;
474 }else if((trackx==6 && track[currtrack].line[tracky].cmd[0])
475 || (trackx==9 && track[currtrack].line[tracky].cmd[1])){
476 SETLO(track[currtrack].line[tracky].param[trackx % 2],
477 hexinc(track[currtrack].line[tracky].param[trackx % 2] & 0x0f) );
478 return;
480 }else if(currtab == 2){
481 if(instrx == 1){
482 SETHI(instrument[currinstr].line[instry].param,
483 hexinc(instrument[currinstr].line[instry].param >> 4) );
484 return;
485 }else if(instrx == 2){
486 SETLO(instrument[currinstr].line[instry].param,
487 hexinc(instrument[currinstr].line[instry].param & 0x0f) );
488 return;
491 saved = 0;
494 void act_paramdec(void){
495 if(currtab==1){
496 if((trackx==5 && track[currtrack].line[tracky].cmd[0])
497 || (trackx==8 && track[currtrack].line[tracky].cmd[1])){
498 SETHI(track[currtrack].line[tracky].param[(trackx-1) % 2],
499 hexdec(track[currtrack].line[tracky].param[(trackx-1) % 2] >> 4) );
500 return;
501 }else if((trackx==6 && track[currtrack].line[tracky].cmd[0])
502 || (trackx==9 && track[currtrack].line[tracky].cmd[1])){
503 SETLO(track[currtrack].line[tracky].param[trackx % 2],
504 hexdec(track[currtrack].line[tracky].param[trackx % 2] & 0x0f) );
505 return;
507 }else if(currtab == 2){
508 if(instrx == 1){
509 SETHI(instrument[currinstr].line[instry].param,
510 hexdec(instrument[currinstr].line[instry].param >> 4) );
511 return;
512 }else if(instrx == 2){
513 SETLO(instrument[currinstr].line[instry].param,
514 hexdec(instrument[currinstr].line[instry].param & 0x0f) );
515 return;
518 saved = 0;
521 void act_addline(void){
522 if(currtab == 2){
523 struct instrument *in = &instrument[currinstr];
525 if(in->length < 256){
526 memmove(&in->line[instry + 2], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1));
527 instry++;
528 in->length++;
529 in->line[instry].cmd = '0';
530 in->line[instry].param = 0;
532 }else if(currtab == 0){
533 if(songlen < 256){
534 memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1));
535 songy++;
536 songlen++;
537 memset(&song[songy], 0, sizeof(struct songline));
540 saved = 0;
543 void act_delline(void){
544 if(currtab == 2){
545 struct instrument *in = &instrument[currinstr];
547 if(in->length > 1){
548 memmove(&in->line[instry + 0], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1));
549 in->length--;
550 if(instry >= in->length) instry = in->length - 1;
552 }else if(currtab == 0){
553 if(songlen > 1){
554 memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1));
555 songlen--;
556 if(songy >= songlen) songy = songlen - 1;
559 saved = 0;
562 void act_clronething(void){
563 if(currtab == 0){
564 if( (songx%4) < 2){
565 if( (songx%2)==0 ){
566 song[songy].track[songx/4] = (song[songy].track[songx/4] - song[songy].track[songx/4]) + song[songy].track[songx/4]%16;
567 }else{
568 song[songy].track[songx/4] -= song[songy].track[songx/4]%16;
570 }else{
571 if( (songx%2)==0 ){
572 song[songy].transp[songx/4] = (song[songy].transp[songx/4] - song[songy].transp[songx/4]) + song[songy].transp[songx/4]%16;
573 }else{
574 song[songy].transp[songx/4] -= song[songy].transp[songx/4]%16;
577 //memcpy(&tclip, &song[songy], sizeof(struct songline));
578 }else if(currtab == 1){
579 switch(trackx){
580 case 0:
581 memcpy(&tclip, &track[currtrack].line[tracky], sizeof(struct trackline));
582 track[currtrack].line[tracky].note = 0;
583 track[currtrack].line[tracky].instr = 0;
584 //memmove
585 break;
586 case 2:
587 memcpy(&tclip, &track[currtrack].line[tracky].instr, sizeof(struct trackline));
588 SETHI(track[currtrack].line[tracky].instr, 0);
589 break;
590 case 3:
591 memcpy(&tclip, &track[currtrack].line[tracky].instr, sizeof(struct trackline));
592 SETLO(track[currtrack].line[tracky].instr, 0);
593 break;
594 case 4:
595 track[currtrack].line[tracky].cmd[0] = 0;
596 break;
597 case 5:
598 SETHI(track[currtrack].line[tracky].param[0],0);
599 break;
600 case 6:
601 SETLO(track[currtrack].line[tracky].param[0],0);
602 break;
603 case 7:
604 track[currtrack].line[tracky].cmd[1] = 0;
605 break;
606 case 8:
607 SETHI(track[currtrack].line[tracky].param[1],0);
608 break;
609 case 9:
610 SETLO(track[currtrack].line[tracky].param[1],0);
611 break;
612 default:
613 setdisplay("in ACT_CLRONETHING");
614 break;
616 }else if(currtab == 2){
617 if(instrx == 0){
618 instrument[currinstr].line[instry].cmd = '0';
619 }else if(instrx == 1){
620 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
621 instrument[currinstr].line[instry].param = 0;
622 }else{
623 SETHI(instrument[currinstr].line[instry].param,0);
625 }else if(instrx == 2){
626 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
627 instrument[currinstr].line[instry].param = 0;
628 }else{
629 SETLO(instrument[currinstr].line[instry].param,0);
633 saved = 0;
636 void act_clritall(void){
637 if(currtab == 0){
638 for(int ci = 0; ci < 4; ci++){
639 song[songy].track[ci] = 0;
640 song[songy].transp[ci] = 0;
642 }else if(currtab == 1){
643 track[currtrack].line[tracky].note = 0;
644 track[currtrack].line[tracky].instr = 0;
645 SETHI(track[currtrack].line[tracky].instr, 0);
646 SETLO(track[currtrack].line[tracky].instr, 0);
647 track[currtrack].line[tracky].cmd[0] = 0;
648 SETHI(track[currtrack].line[tracky].param[0],0);
649 SETLO(track[currtrack].line[tracky].param[0],0);
650 track[currtrack].line[tracky].cmd[1] = 0;
651 SETHI(track[currtrack].line[tracky].param[1],0);
652 SETLO(track[currtrack].line[tracky].param[1],0);
653 }else if(currtab == 2){
654 instrument[currinstr].line[instry].cmd = '0';
655 instrument[currinstr].line[instry].param = 0;
657 saved = 0;
660 // clear line y in the song tab
661 void act_clrinsongtab(int y){
662 for(int ci = 0; ci < 4; ci++){
663 song[songy].track[ci] = 0;
664 song[songy].transp[ci] = 0;
666 saved = 0;
669 void act_clrintracktab(int t, int y){
670 track[t].line[y].note = 0;
671 track[t].line[y].instr = 0;
672 SETHI(track[t].line[y].instr, 0);
673 SETLO(track[t].line[y].instr, 0);
674 track[t].line[y].cmd[0] = 0;
675 SETHI(track[t].line[y].param[0],0);
676 SETLO(track[t].line[y].param[0],0);
677 track[t].line[y].cmd[1] = 0;
678 SETHI(track[t].line[y].param[1],0);
679 SETLO(track[t].line[y].param[1],0);
680 saved = 0;
683 void act_clrininstrtab(int instr, int y){
684 instrument[instr].line[y].cmd = '0';
685 instrument[instr].line[y].param = 0;
686 saved = 0;