Timing is correct now! Forgot to update samples_per_tick when parsing the 0xf effect.
[pineappletracker.git] / main.c
blobd968eeff1fd68e22d78df6016708e88a76905720
1 /* vi:set ts=8 sts=8 sw=8 noexpandtab: */
2 #include <stdio.h>
4 #include <SDL/SDL.h>
6 #ifndef WINDOWS
7 #include <err.h>
8 #endif
10 #ifdef JACK
11 #include <jack/jack.h>
12 #endif
14 #include "pineapple.h"
15 #include "filetypes.h"
16 #include "hvl_replay.h"
17 #include "gui.h"
19 u8 (*sdl_init)(void);
20 pineapple_tune *importHvl(struct hvl_tune *ht);
22 // TODO: make hvl.c
23 //\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\/\\
24 \\\ < struct pineapple_tune *importHvl(struct hvl_tune *ht) > .|
25 /// Gives you a struct pineapple_tune from a struct *hvl_tune. .\
26 \\/\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\//
27 pineapple_tune *importHvl(struct hvl_tune *ht) {
28 pineapple_tune *tune;
29 tune = (pineapple_tune*) malloc(sizeof(pineapple_tune));
30 if(!tune) {
31 fprintf(stderr, "couldn't malloc pineapple_tune *tune!\n");
32 return NULL;
35 tune->type = AHX;
37 tune->songlen = ht->ht_PositionNr;
38 /* TODO: turn songpos and trackpos into pointers */
39 /* lolwat */
40 //tune->songpos = ht->ht_PosNr;
41 //tune->trackpos = &ht->ht_NoteNr;
43 tune->tracklen = ht->ht_TrackLength;
44 for(int i = 0; i < tune->songlen; i++) {
45 for(int j = 0; j < ht->ht_Channels; j++){
46 tune->sng[i].track[j] = ht->ht_Positions[i].pos_Track[j];
47 tune->sng[i].transp[j] = ht->ht_Positions[i].pos_Transpose[j];
51 for(int i = 0; i < ht->ht_TrackNr; i++) {
52 for(int j = 0; j < tune->tracklen; j++) {
53 tune->trk[i].line[j].note = ht->ht_Tracks[i][j].stp_Note;
54 tune->trk[i].line[j].instr = ht->ht_Tracks[i][j].stp_Instrument;
55 tune->trk[i].line[j].cmd[0] = ht->ht_Tracks[i][j].stp_FX;
56 //fprintf(stderr, "fx: %i \n", ht->ht_Tracks[i][j].stp_FX);
57 tune->trk[i].line[j].param[0] = ht->ht_Tracks[i][j].stp_FXParam;
58 tune->trk[i].line[j].cmd[1] = ht->ht_Tracks[i][j].stp_FXb;
59 tune->trk[i].line[j].param[1] = ht->ht_Tracks[i][j].stp_FXbParam;
63 tune->iedplonk = hvl_iedplonk;
65 return tune;
68 int main(int argc, char **argv){
69 //----------------------------------\\
70 // parse those args :^)
71 //----------------------------------//
72 /*tune = (pineapple_tune*) malloc(sizeof(pineapple_tune));
73 if(!tune) {
74 fprintf(stderr, "couldn't malloc pineapple_tune *tune!\n");
75 return 1;
79 initinstrs();
81 if(argc > 1){
82 if((tune = lft_loadfile(argv[1]))){
83 fprintf(stderr, "loaded %s\n", argv[1]);
84 sdl_init = lft_sdl_init;
85 //TODO make 48000 configurable as 'samplefreq'
86 }else if((htTune = hvl_LoadTune(argv[1], 48000, 4))){
87 fprintf(stderr, "loading ahx/hvl...\n");
88 fprintf(stderr, "loaded %s\n", argv[1]);
89 hvl_InitReplayer();
90 tune = importHvl(htTune);
91 sdl_init = hvl_sdl_init;
92 hvl_InitSubsong(htTune,0);
93 }else{
94 fprintf(stderr, "couldn't load %s\n", argv[1]);
95 fprintf(stderr, "loading empty tune");
96 tune = lft_loadfile("");
97 sdl_init = lft_sdl_init;
98 //hvl_InitSubsong(htTune, 0);
100 }else{
101 //what happens if we load with no filename?
102 // make an empty tune?
103 //tune = pt_empty_tune();
104 /* FIXME: the function below segfaults! */
105 tune = lft_loadfile("");
108 if(sdl_init() == 0){
109 //----------------------------------\\
110 // begin image&sound
111 //----------------------------------//
112 initchip();
113 initgui();
115 SDL_PauseAudio(0);
117 //----------------------------------\\
118 // ACTUALLY start the program
119 //----------------------------------//
120 eventloop();
122 SDL_Quit();
124 free(tune);
125 if(htTune)
126 hvl_FreeTune(htTune);
127 return 0;