Load ht->ht_Tracks into tune->struct track trk[]. Seems I got it working for lft...
[pineappletracker.git] / player.c
blobd603feab76fc06999f7c7890c2be00d201d80abe
1 /* vi:set ts=8 sts=8 sw=8 noexpandtab: */
2 #include <stdio.h>
3 #include <SDL/SDL.h>
4 #include <caca.h>
5 #ifndef WINDOWS
6 #include <err.h>
7 #endif
9 #include "pineapple.h"
10 #include "filetypes.h"
12 void audiocb(void *userdata, Uint8 *buf, int len) {
13 int i;
15 for(i = 0; i < len; i++) {
16 buf[i] = interrupthandler();
20 int main(int argc, char **argv){
21 SDL_AudioSpec requested, obtained;
23 int quit = 0;
24 int xo, yo;
25 int i, j, k;
26 int meter[4];
28 static char chars[10] =
30 '+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W'
33 caca_display_t *dp;
34 caca_canvas_t *cv;
35 caca_canvas_t *pineapple;
37 if(SDL_Init( SDL_INIT_AUDIO ) < 0){
38 err(1, "Couldnt initialize SDL\n");
39 exit(1);
42 cv = caca_create_canvas(80, 24);
43 pineapple = caca_create_canvas(0, 0);
44 if((cv == NULL) || (pineapple == NULL)){
45 printf("failed to create canvas\n");
46 return 1;
48 dp = caca_create_display(cv);
49 caca_set_display_time(dp, 20000);
50 if(dp == NULL){
51 printf("Failed to create display\n");
52 return 1;
55 caca_import_file(pineapple, "./pineapple", "");
57 atexit(SDL_Quit);
59 requested.freq = 48000;
60 requested.format = AUDIO_U8;
61 requested.samples = 4096;
62 requested.callback = audiocb;
63 requested.channels = 1;
65 if(SDL_OpenAudio(&requested, &obtained) == -1){
66 err(1, "SDL_OpenAudio");
69 initchip();
71 lft_loadfile(argv[1]);
73 SDL_PauseAudio(0);
74 silence();
75 startplaysong(0);
78 while(!quit)
80 caca_event_t ev;
81 caca_set_color_ansi(cv, CACA_DEFAULT, CACA_DEFAULT);
82 caca_clear_canvas(cv);
83 xo = caca_get_canvas_width(cv);
84 yo = caca_get_canvas_height(cv);
85 //caca_blit(cv, 0, 0, pineapple, NULL);
86 caca_blit(cv, 55, 0, pineapple, NULL);
87 caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
88 caca_put_str(cv, (xo - strlen("pineapple player")) / 2, (yo / 2) - 5, "pineapple player");
89 caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
90 caca_printf(cv, (xo - strlen("song pos -> ")) / 2, (yo / 2) - 3, "song pos -> %x", songpos);
92 for(i = 0; i < 4; i ++)
93 meter[i] = (osc[i].volume*20)/255;
94 /* note visualizer */
95 i = 0;
96 for(j = 0; j < 25; j=j+6){
97 for(k = 0; k < 4; k++){
98 caca_draw_line(cv, (((xo/2)+10)-j)-k, yo, (((xo/2)+10)-j)-k, yo - meter[i],
99 chars[caca_rand(0, 9)]);
101 i++;
104 for(i = 0; i < 4; i ++)
105 caca_printf(cv, 0, i, "%0x", osc[i].volume);
107 while(caca_get_event(dp, CACA_EVENT_ANY, &ev, 0))
109 if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS)
111 switch(caca_get_event_key_ch(&ev))
113 case 'q':
114 case 'Q':
115 case CACA_KEY_ESCAPE:
116 quit = 1;
117 break;
121 caca_refresh_display(dp);
123 silence();
124 caca_free_display(dp);
125 caca_free_canvas(cv);
126 return 0;