* Wish I were a good writer.
[pineappletracker.git] / actions.c
blob74c018db1e3018948ffd8bdb5845563d5d6fe3a2
1 /* vi:set ts=4 sts=4 sw=4 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_viewtrackinc(void){
138 if(currtrack < 0xff){
139 currtrack++;
140 }else if(currtrack == 0xff){
141 currtrack = 1;
143 if(playtrack){
144 startplaytrack(currtrack);
148 void act_viewtrackdec(void){
149 if(currtrack > 1){
150 currtrack--;
151 }else if(currtrack == 1){
152 currtrack = 0xff;
154 if(playtrack){
155 startplaytrack(currtrack);
159 void act_viewinstrinc(void){
160 if(currinstr == 0xff) currinstr = 0x01;
161 else currinstr++;
164 void act_viewinstrdec(void){
165 if(currinstr == 1) currinstr = 0xff;
166 else currinstr--;
169 void act_trackinc(void){
170 if( (songx%2)==0 ){
171 if(songx >= 240 && songx < 256){
172 song[songy].track[songx/4] -= 240;
173 }else{
174 song[songy].track[songx/4] += 16;
176 }else{
177 if( (song[songy].track[songx/4] % 16) == 15){
178 song[songy].track[songx/4] -= 15;
179 }else{
180 song[songy].track[songx/4]++;
183 saved = 0;
186 void act_trackdec(void){
187 if( (songx%2)==0 ){
188 if(songx <= 15 && songx >= 0){
189 song[songy].track[songx/4] += 240;
190 }else{
191 song[songy].track[songx/4] -= 16;
193 }else{
194 if( (song[songy].track[songx/4] % 16) == 0){
195 song[songy].track[songx/4] += 15;
196 }else{
197 song[songy].track[songx/4]--;
200 saved = 0;
203 void act_transpinc(void){
204 if( (songx%2)==0 ){
205 if(songx >= 240 && songx < 256){
206 song[songy].transp[songx/4] -= 240;
207 }else{
208 song[songy].transp[songx/4] += 16;
210 }else{
211 if( (song[songy].transp[songx/4] % 16) == 15){
212 song[songy].transp[songx/4] -= 15;
213 }else{
214 song[songy].transp[songx/4]++;
217 saved = 0;
220 void act_transpdec(void){
221 if( (songx%2)==0 ){
222 if(songx <= 15 && songx >= 0){
223 song[songy].transp[songx/4] += 240;
224 }else{
225 song[songy].transp[songx/4] -= 16;
227 }else{
228 if( (song[songy].transp[songx/4] % 16) == 0){
229 song[songy].transp[songx/4] += 15;
230 }else{
231 song[songy].transp[songx/4]--;
234 saved = 0;
237 void act_undo(void){
240 void act_noteinc(void){
241 if(currtab==1){
242 // if current note < H7
243 if( track[currtrack].line[tracky].note < 96 ){
244 track[currtrack].line[tracky].note++;
245 }else{
246 track[currtrack].line[tracky].note = 0;
248 }else if(currtab==2){
249 if( instrument[currinstr].line[instry].param < 96 ){
250 instrument[currinstr].line[instry].param++;
251 }else{
252 instrument[currinstr].line[instry].param = 0;
255 saved = 0;
258 void act_notedec(void){
259 if(currtab==1){
260 if( track[currtrack].line[tracky].note > 0 ){
261 track[currtrack].line[tracky].note--;
262 }else{
263 track[currtrack].line[tracky].note = 96;
265 }else if(currtab==2){
266 if( instrument[currinstr].line[instry].param > 0 ){
267 instrument[currinstr].line[instry].param--;
268 }else{
269 instrument[currinstr].line[instry].param = 96;
272 saved = 0;
275 void act_octaveinc(void){
276 if(currtab==1){
277 if( track[currtrack].line[tracky].note+12 <= 96 ){
278 track[currtrack].line[tracky].note+=12;
279 }else{
280 track[currtrack].line[tracky].note %= 12;
282 }else if(currtab==2){ if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
283 if( instrument[currinstr].line[instry].param+12 <= 96 ){
284 instrument[currinstr].line[instry].param+=12;
285 }else{
286 instrument[currinstr].line[instry].param %= 12;
290 saved = 0;
293 void act_octavedec(void){
294 if(currtab==1){
295 if( track[currtrack].line[tracky].note-12 > 0 ){
296 track[currtrack].line[tracky].note-=12;
297 }else{
298 track[currtrack].line[tracky].note = 84 + track[currtrack].line[tracky].note;
300 }else if(currtab==2){
301 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
302 if( instrument[currinstr].line[instry].param-12 > 0 ){
303 instrument[currinstr].line[instry].param-=12;
304 }else{
305 instrument[currinstr].line[instry].param = 84 + instrument[currinstr].line[instry].param;
309 saved = 0;
312 void act_instrinc(void){
313 switch(trackx){
314 case 2:
315 SETHI(track[currtrack].line[tracky].instr,
316 hexinc(track[currtrack].line[tracky].instr >> 4) );
317 break;
318 case 3:
319 SETLO(track[currtrack].line[tracky].instr,
320 hexinc(track[currtrack].line[tracky].instr & 0x0f) );
321 break;
323 saved = 0;
326 void act_instrdec(void){
327 switch(trackx){
328 case 2:
329 SETHI(track[currtrack].line[tracky].instr,
330 hexdec(track[currtrack].line[tracky].instr >> 4) );
331 break;
332 case 3:
333 SETLO(track[currtrack].line[tracky].instr,
334 hexdec(track[currtrack].line[tracky].instr & 0x0f) );
335 break;
337 saved = 0;
340 void act_fxinc(void){
341 if(currtab==1){
342 currcmd = track[currtrack].line[tracky].cmd[trackx % 2];
343 // there must be a better way to do this...
344 if((unsigned long)currcmd == (unsigned long)NULL){
345 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[0];
346 }else{
347 for(int z = 0; z < strlen(validcmds); z++){
348 if(currcmd == validcmds[z]){
349 if(z == (strlen(validcmds)-1)){
350 track[currtrack].line[tracky].cmd[trackx % 2] = (unsigned long)NULL;
351 }else{
352 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[z+1];
354 continue;
358 }else if(currtab==2){
359 currcmd = instrument[currinstr].line[instry].cmd;
360 for(int z = 0; z < strlen(validcmds); z++){
361 if(currcmd == validcmds[z]){
362 if(z == (strlen(validcmds)-1)){
363 instrument[currinstr].line[instry].cmd = validcmds[0];
364 }else{
365 instrument[currinstr].line[instry].cmd = validcmds[z+1];
366 if(_oldfxparam)
367 instrument[currinstr].line[instry].param = _oldfxparam;
370 // when switching to the note command, change to param if it's
371 // higher than H7
372 if((instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '=')
373 //&& _oldfxparam
374 && instrument[currinstr].line[instry].param>96){
375 // save current param
376 _oldfxparam = instrument[currinstr].line[instry].param;
377 instrument[currinstr].line[instry].param = 96; //H7
378 }else if(_oldfxparam){
379 instrument[currinstr].line[instry].param = _oldfxparam;
380 _oldfxparam = 0;
383 continue;
387 saved = 0;
390 void act_fxdec(void){
391 if(currtab==1){
392 currcmd = track[currtrack].line[tracky].cmd[trackx % 2];
393 if((unsigned long)currcmd == (unsigned long)NULL){
394 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[strlen(validcmds)-1];
395 }else{
396 for(int z = 0; z < strlen(validcmds); z++){
397 if(currcmd == validcmds[z]){
398 if(z==0){
399 track[currtrack].line[tracky].cmd[trackx % 2] = (unsigned long)NULL;
400 }else{
401 track[currtrack].line[tracky].cmd[trackx % 2] = validcmds[z-1];
403 continue;
407 }else if(currtab==2){
408 currcmd = instrument[currinstr].line[instry].cmd;
409 for(int z = 0; z < strlen(validcmds); z++){
410 if(currcmd == validcmds[z]){
411 if(z==0){
412 instrument[currinstr].line[instry].cmd = validcmds[strlen(validcmds)-1];
413 }else{
414 instrument[currinstr].line[instry].cmd = validcmds[z-1];
415 if(_oldfxparam)
416 instrument[currinstr].line[instry].param = _oldfxparam;
419 // when switching to the note command, change to param if it's
420 // higher than H7
421 if((instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '=')
422 //&& _oldfxparam
423 && instrument[currinstr].line[instry].param>96){
424 // save current param
425 _oldfxparam = instrument[currinstr].line[instry].param;
426 instrument[currinstr].line[instry].param = 96; //H7
427 }else if(_oldfxparam){
428 instrument[currinstr].line[instry].param = _oldfxparam;
429 _oldfxparam = 0;
432 continue;
436 saved = 0;
439 void act_paraminc(void){
440 if(currtab==1){
441 if((trackx==5 && track[currtrack].line[tracky].cmd[0])
442 || (trackx==8 && track[currtrack].line[tracky].cmd[1])){
443 SETHI(track[currtrack].line[tracky].param[(trackx - 1) % 2],
444 hexinc(track[currtrack].line[tracky].param[(trackx - 1) % 2] >> 4) );
445 return;
446 }else if((trackx==6 && track[currtrack].line[tracky].cmd[0])
447 || (trackx==9 && track[currtrack].line[tracky].cmd[1])){
448 SETLO(track[currtrack].line[tracky].param[trackx % 2],
449 hexinc(track[currtrack].line[tracky].param[trackx % 2] & 0x0f) );
450 return;
452 }else if(currtab == 2){
453 if(instrx == 1){
454 SETHI(instrument[currinstr].line[instry].param,
455 hexinc(instrument[currinstr].line[instry].param >> 4) );
456 return;
457 }else if(instrx == 2){
458 SETLO(instrument[currinstr].line[instry].param,
459 hexinc(instrument[currinstr].line[instry].param & 0x0f) );
460 return;
463 saved = 0;
466 void act_paramdec(void){
467 if(currtab==1){
468 if((trackx==5 && track[currtrack].line[tracky].cmd[0])
469 || (trackx==8 && track[currtrack].line[tracky].cmd[1])){
470 SETHI(track[currtrack].line[tracky].param[(trackx-1) % 2],
471 hexdec(track[currtrack].line[tracky].param[(trackx-1) % 2] >> 4) );
472 return;
473 }else if((trackx==6 && track[currtrack].line[tracky].cmd[0])
474 || (trackx==9 && track[currtrack].line[tracky].cmd[1])){
475 SETLO(track[currtrack].line[tracky].param[trackx % 2],
476 hexdec(track[currtrack].line[tracky].param[trackx % 2] & 0x0f) );
477 return;
479 }else if(currtab == 2){
480 if(instrx == 1){
481 SETHI(instrument[currinstr].line[instry].param,
482 hexdec(instrument[currinstr].line[instry].param >> 4) );
483 return;
484 }else if(instrx == 2){
485 SETLO(instrument[currinstr].line[instry].param,
486 hexdec(instrument[currinstr].line[instry].param & 0x0f) );
487 return;
490 saved = 0;
493 void act_addline(void){
494 if(currtab == 2){
495 struct instrument *in = &instrument[currinstr];
497 if(in->length < 256){
498 memmove(&in->line[instry + 2], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1));
499 instry++;
500 in->length++;
501 in->line[instry].cmd = '0';
502 in->line[instry].param = 0;
504 }else if(currtab == 0){
505 if(songlen < 256){
506 memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1));
507 songy++;
508 songlen++;
509 memset(&song[songy], 0, sizeof(struct songline));
512 saved = 0;
515 void act_delline(void){
516 if(currtab == 2){
517 struct instrument *in = &instrument[currinstr];
519 if(in->length > 1){
520 memmove(&in->line[instry + 0], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1));
521 in->length--;
522 if(instry >= in->length) instry = in->length - 1;
524 }else if(currtab == 0){
525 if(songlen > 1){
526 memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1));
527 songlen--;
528 if(songy >= songlen) songy = songlen - 1;
531 saved = 0;
534 void act_clronething(void){
535 if(currtab == 0){
536 if( (songx%4) < 2){
537 if( (songx%2)==0 ){
538 song[songy].track[songx/4] = (song[songy].track[songx/4] - song[songy].track[songx/4]) + song[songy].track[songx/4]%16;
539 }else{
540 song[songy].track[songx/4] -= song[songy].track[songx/4]%16;
542 }else{
543 if( (songx%2)==0 ){
544 song[songy].transp[songx/4] = (song[songy].transp[songx/4] - song[songy].transp[songx/4]) + song[songy].transp[songx/4]%16;
545 }else{
546 song[songy].transp[songx/4] -= song[songy].transp[songx/4]%16;
549 //memcpy(&tclip, &song[songy], sizeof(struct songline));
550 }else if(currtab == 1){
551 switch(trackx){
552 case 0:
553 memcpy(&tclip, &track[currtrack].line[tracky], sizeof(struct trackline));
554 track[currtrack].line[tracky].note = 0;
555 track[currtrack].line[tracky].instr = 0;
556 //memmove
557 break;
558 case 2:
559 memcpy(&tclip, &track[currtrack].line[tracky].instr, sizeof(struct trackline));
560 SETHI(track[currtrack].line[tracky].instr, 0);
561 break;
562 case 3:
563 memcpy(&tclip, &track[currtrack].line[tracky].instr, sizeof(struct trackline));
564 SETLO(track[currtrack].line[tracky].instr, 0);
565 break;
566 case 4:
567 track[currtrack].line[tracky].cmd[0] = 0;
568 break;
569 case 5:
570 SETHI(track[currtrack].line[tracky].param[0],0);
571 break;
572 case 6:
573 SETLO(track[currtrack].line[tracky].param[0],0);
574 break;
575 case 7:
576 track[currtrack].line[tracky].cmd[1] = 0;
577 break;
578 case 8:
579 SETHI(track[currtrack].line[tracky].param[1],0);
580 break;
581 case 9:
582 SETLO(track[currtrack].line[tracky].param[1],0);
583 break;
584 default:
585 setdisplay("in ACT_CLRONETHING");
586 break;
588 }else if(currtab == 2){
589 if(instrx == 0){
590 instrument[currinstr].line[instry].cmd = '0';
591 }else if(instrx == 1){
592 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
593 instrument[currinstr].line[instry].param = 0;
594 }else{
595 SETHI(instrument[currinstr].line[instry].param,0);
597 }else if(instrx == 2){
598 if(instrument[currinstr].line[instry].cmd == '+' || instrument[currinstr].line[instry].cmd == '='){
599 instrument[currinstr].line[instry].param = 0;
600 }else{
601 SETLO(instrument[currinstr].line[instry].param,0);
605 saved = 0;
608 void act_clritall(void){
609 if(currtab == 0){
610 for(int ci = 0; ci < 4; ci++){
611 song[songy].track[ci] = 0;
612 song[songy].transp[ci] = 0;
614 }else if(currtab == 1){
615 track[currtrack].line[tracky].note = 0;
616 track[currtrack].line[tracky].instr = 0;
617 SETHI(track[currtrack].line[tracky].instr, 0);
618 SETLO(track[currtrack].line[tracky].instr, 0);
619 track[currtrack].line[tracky].cmd[0] = 0;
620 SETHI(track[currtrack].line[tracky].param[0],0);
621 SETLO(track[currtrack].line[tracky].param[0],0);
622 track[currtrack].line[tracky].cmd[1] = 0;
623 SETHI(track[currtrack].line[tracky].param[1],0);
624 SETLO(track[currtrack].line[tracky].param[1],0);
625 }else if(currtab == 2){
626 instrument[currinstr].line[instry].cmd = '0';
627 instrument[currinstr].line[instry].param = 0;
629 saved = 0;
632 // clear line y in the song tab
633 void act_clrinsongtab(int y){
634 for(int ci = 0; ci < 4; ci++){
635 song[songy].track[ci] = 0;
636 song[songy].transp[ci] = 0;
638 saved = 0;
641 void act_clrintracktab(int t, int y){
642 track[t].line[y].note = 0;
643 track[t].line[y].instr = 0;
644 SETHI(track[t].line[y].instr, 0);
645 SETLO(track[t].line[y].instr, 0);
646 track[t].line[y].cmd[0] = 0;
647 SETHI(track[t].line[y].param[0],0);
648 SETLO(track[t].line[y].param[0],0);
649 track[t].line[y].cmd[1] = 0;
650 SETHI(track[t].line[y].param[1],0);
651 SETLO(track[t].line[y].param[1],0);
652 saved = 0;
655 void act_clrininstrtab(int instr, int y){
656 instrument[instr].line[y].cmd = '0';
657 instrument[instr].line[y].param = 0;
658 saved = 0;