From fbe6ba3c97affa14f15389ed4922cf8aca826556 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 14 Aug 2009 19:36:39 -0700 Subject: [PATCH] Every function that uses songlen now uses tune.songlen, except initsonglines, not sure whats up with that function. And what happens now when you do ./ppt without a filename? (argv < 1). --- actions.c | 24 +++++++------- gui.c | 8 ++--- main.c | 1 + modes.c | 88 ++++++++++++-------------------------------------- notes | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pineapple.h | 2 ++ 6 files changed, 144 insertions(+), 84 deletions(-) create mode 100644 notes diff --git a/actions.c b/actions.c index 03a1109..8aa3b3d 100644 --- a/actions.c +++ b/actions.c @@ -67,10 +67,10 @@ void act_mvup(void){ void act_mvdown(void){ switch(currtab){ case 0: - if(songy < songlen - 1){ + if(songy < tune.songlen - 1){ songy++; }else{ - songy = songlen - 1; + songy = tune.songlen - 1; } break; case 1: @@ -117,10 +117,10 @@ void act_bigmvup(void){ void act_bigmvdown(void){ switch(currtab){ case 0: - if(songy < songlen - 8){ + if(songy < tune.songlen - 8){ songy += 8; }else{ - songy = songlen - 1; + songy = tune.songlen - 1; } break; case 1: @@ -139,7 +139,7 @@ void act_bigmvdown(void){ void act_mvbottom(void){ switch(currtab){ case 0: - songy = songlen - 1; + songy = tune.songlen - 1; break; case 1: tracky = tracklen - 1; @@ -532,10 +532,10 @@ void act_addline(void){ in->line[instry].param = 0; } }else if(currtab == 0){ - if(songlen < 256){ - memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); + if(tune.songlen < 256){ + memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (tune.songlen - songy - 1)); songy++; - songlen++; + tune.songlen++; memset(&song[songy], 0, sizeof(struct songline)); } } @@ -552,10 +552,10 @@ void act_delline(void){ if(instry >= in->length) instry = in->length - 1; } }else if(currtab == 0){ - if(songlen > 1){ - memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); - songlen--; - if(songy >= songlen) songy = songlen - 1; + if(tune.songlen > 1){ + memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (tune.songlen - songy - 1)); + tune.songlen--; + if(songy >= tune.songlen) songy = tune.songlen - 1; } } saved = 0; diff --git a/gui.c b/gui.c index 3452cf1..8467974 100644 --- a/gui.c +++ b/gui.c @@ -112,7 +112,7 @@ int freqkey(int c){ //\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\/\\ \\\ < void initsonglines() > .| -/// Calculates the frequency of key c. .\ +/// . .\ \\/\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\// void initsonglines(void){ for(int i=0; i < songlen; i++){ @@ -492,7 +492,7 @@ void drawsonged(int x, int y, int height){ if(songy < songoffs) songoffs = songy; if(songy >= songoffs + height) songoffs = songy - height + 1; - for(i = 0; i < songlen; i++){ + for(i = 0; i < tune.songlen; i++){ if(i >= songoffs && i - songoffs < height){ move(y + i - songoffs, x + 0); if(i == songy) attrset(A_BOLD); @@ -500,9 +500,9 @@ void drawsonged(int x, int y, int height){ snprintf(buf, sizeof(buf), "%02x", i); if(i == 0){ addch(ACS_ULCORNER); } - else if(i == songlen-1){ addch(ACS_LLCORNER); } + else if(i == tune.songlen-1){ addch(ACS_LLCORNER); } else if(i%4 == 0){ addch(ACS_LTEE); } - else if(i < songlen-1){ addch(ACS_VLINE); } + else if(i < tune.songlen-1){ addch(ACS_VLINE); } addch(' '); // should this line be highlighted? diff --git a/main.c b/main.c index 3554283..bce4b68 100644 --- a/main.c +++ b/main.c @@ -39,6 +39,7 @@ int main(int argc, char **argv){ if(argc > 1){ f = argv[1]; } + //what happens if we load with no filename? if(lft_loadfile(f,&tune) == 0){ fprintf(stderr, "loaded %s\n", f); diff --git a/modes.c b/modes.c index 2f49d56..7c5bb29 100644 --- a/modes.c +++ b/modes.c @@ -243,7 +243,7 @@ void _parsecmd(char cmd[]){ switch(currtab){ case 0: - songy = (goton>songlen)? songlen-1 : goton; + songy = (goton>tune.songlen)? tune.songlen-1 : goton; break; case 1: currtrack = (goton>0xff)? 0xff : goton; @@ -287,24 +287,7 @@ void normalmode(int c){ switch(c){ /* add line */ case 'a': - if(currtab == 2){ - struct instrument *in = &instrument[currinstr]; - - if(in->length < 256){ - memmove(&in->line[instry + 2], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1)); - instry++; - in->length++; - in->line[instry].cmd = '0'; - in->line[instry].param = 0; - } - }else if(currtab == 0){ - if(songlen < 256){ - memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); - songy++; - songlen++; - memset(&song[songy], 0, sizeof(struct songline)); - } - } + act_addline(); break; case '.': // if the last command was a replace, just insert the last thing @@ -347,7 +330,7 @@ void normalmode(int c){ case CTRL('E'): switch(currtab){ case 0: - if(songy<=songlen-2){ + if(songy<=tune.songlen-2){ if(songy==songoffs) songy++; songoffs++; @@ -389,8 +372,8 @@ void normalmode(int c){ case 'M': switch(currtab){ case 0: - songy = (songlen <= getmaxy(stdscr)-2)? - songlen/2 + songy = (tune.songlen <= getmaxy(stdscr)-2)? + tune.songlen/2 : ((getmaxy(stdscr)-6)/2) + songoffs; break; case 1: @@ -408,8 +391,8 @@ void normalmode(int c){ case 'L': switch(currtab){ case 0: - songy = (songlen <= getmaxy(stdscr)-2)? - songlen-1 + songy = (tune.songlen <= getmaxy(stdscr)-2)? + tune.songlen-1 : getmaxy(stdscr)-3+songoffs; break; case 1: @@ -494,12 +477,12 @@ void normalmode(int c){ //paste case 'p': if(currtab == 0){ - if(songlen < 256){ + if(tune.songlen < 256){ for(int i = 0; i < tcliplen; i++){ // insert new line - memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); + memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (tune.songlen - songy - 1)); songy++; - songlen++; + tune.songlen++; memset(&song[songy], 0, sizeof(struct songline)); // paste to new line @@ -570,21 +553,7 @@ void normalmode(int c){ c = nextchar(); switch(c){ case 'd': - if(currtab == 2){ - struct instrument *in = &instrument[currinstr]; - - if(in->length > 1){ - memmove(&in->line[instry + 0], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1)); - in->length--; - if(instry >= in->length) instry = in->length - 1; - } - }else if(currtab == 0){ - if(songlen > 1){ - memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); - songlen--; - if(songy >= songlen) songy = songlen - 1; - } - } + act_delline(); break; case 'k': if(currtab == 2){ @@ -602,10 +571,10 @@ void normalmode(int c){ songy--; int i; for(i=0; i<2; i++){ - if(songlen > 1){ - memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); - songlen--; - if(songy >= songlen) songy = songlen - 1; + if(tune.songlen > 1){ + memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (tune.songlen - songy - 1)); + tune.songlen--; + if(songy >= tune.songlen) songy = tune.songlen - 1; } } } @@ -625,10 +594,10 @@ void normalmode(int c){ }else if(currtab == 0){ int i; for(i=0; i<2; i++){ - if(songlen > 1){ - memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); - songlen--; - if(songy >= songlen) songy = songlen - 1; + if(tune.songlen > 1){ + memmove(&song[songy + 0], &song[songy + 1], sizeof(struct songline) * (tune.songlen - songy - 1)); + tune.songlen--; + if(songy >= tune.songlen) songy = tune.songlen - 1; } } } @@ -718,24 +687,7 @@ void normalmode(int c){ break; /* Add new line and enter insert mode */ case 'o': - if(currtab == 2){ - struct instrument *in = &instrument[currinstr]; - - if(in->length < 256){ - memmove(&in->line[instry + 2], &in->line[instry + 1], sizeof(struct instrline) * (in->length - instry - 1)); - instry++; - in->length++; - in->line[instry].cmd = '0'; - in->line[instry].param = 0; - } - }else if(currtab == 0){ - if(songlen < 256){ - memmove(&song[songy + 2], &song[songy + 1], sizeof(struct songline) * (songlen - songy - 1)); - songy++; - songlen++; - memset(&song[songy], 0, sizeof(struct songline)); - } - } + act_addline(); insertmode(); break; case 'h': diff --git a/notes b/notes new file mode 100644 index 0000000..861ca5c --- /dev/null +++ b/notes @@ -0,0 +1,105 @@ +These functions will be polymorphic,overloaded,whatever....in other words they +will change depending on whether you load a .mod,.song,or .ahx. + + +actions.c +---------- +act_trackinc +act_trackdec +act_transpinc +act_transpdec +act_noteinc +act_notedec +act_octaveinc +act_octavedec +act_instrinc +act_instrdec +act_fxinc +act_fxdec +act_paraminc +act_paramdec +act_addline +act_delline +act_clronething +act_clritall +act_clrinsongtab +act_clrintracktab +act_clrininstrtab + +gui.c +------ +initsonglines +inittracks +initinstrs +readsong? +readtrack? +readinstr +drawsonged +drawtracked +drawinstred +drawgui? + +modes.c +------- +_nextfreetrack +_nextfreeinstr +_insertc +_parsecmd +normalmode +cmdlinemode +insertmode +visualmode +visuallinemode + +(musicchip)file.c +------------------ +savefile +loadfile + +chip.c +------ +silence +iedplonk +startplaytrack +startplaysong +playroutine? +initchip? +interrupthandler? + + +also we need a struct that can hold any of the module types.... +struct pineapple_tune{ + char *type; //pineapple, mod, hively + + char *filename; //ht_Name[128] ?? + u8 callbacktime; //ht_speedmultiplier,bpm, etc ht_Tempo + char comment[1024]; + struct oscillator osc[4]; //ht_Channels || ht_Voices[MAX_CHANNELS] + struct instrument instr[256]; //*ht_Instruments + struct track trk[256]; //ht_Tracks[256][64] + struct song song[256]; //*ht_Positions + u8 trackpos; + u8 songpos; //ht_PosNr + int songlen; + int instrx, instry, instroffs; + int songx, songy, songoffs; + int trackx, tracky, trackoffs; + int currtrack, currinstr; //ht_TrackNr, ht_InstrumentNr, + int currtab; + int saved; +}; + +struct pineapple_tune *loadPineapple() will load the filename specified on the +command line and look at the header to figure out if its a .song or .hvl, then +call either musicchipfile's loadfile or hvl_replay.c's hvl_LoadTune. Then the file +will be converted to a struct pineapple_tune and returned. +The functions importHvl and importPt will convert hvl's and pt's to +the struct pineapple_tune. + +Then all the functions in hvl_replay.c will need to be changed in order to deal +with the struct pineapple_tune instead of struct hvl_tune. Then when you want to save +the file will stll be saved as .hvl, .ahx, or .song. + +Also once we get different audio drivers going we need to make that configurable so we +can know which callback function to use, etc. + diff --git a/pineapple.h b/pineapple.h index 59814aa..8b55d18 100644 --- a/pineapple.h +++ b/pineapple.h @@ -150,6 +150,8 @@ void act_viewinstrdec(void); void act_viewinstrinc(void); void act_viewtrackdec(void); void act_viewtrackinc(void); +void act_addline(void); +void act_delline(void); u8 trackpos; u8 playtrack; -- 2.11.4.GIT