annotate src/projectm-1.0/main.cxx @ 1920:a6d84a2cfaa7

projectm-1.0: add the new files this time
author Kieran Clancy <clancy.kieran+audacious@gmail.com>
date Sun, 30 Sep 2007 13:46:31 +0930
parents
children 47a4e93ed7ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1920
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
1 /*
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
2 projectM v1.01 - xmms-projectm.sourceforge.net
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
3 --------------------------------------------------
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
4
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
5 Lead Developers: Carmelo Piccione (carmelo.piccione@gmail.com) &
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
6 Peter Sperl (peter@sperl.com)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
7
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
8 We have also been advised by some professors at CMU, namely Roger B. Dannenberg.
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
9 http://www-2.cs.cmu.edu/~rbd/
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
10
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
11 The inspiration for this program was Milkdrop by Ryan Geiss. Obviously.
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
12
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
13 This code is distributed under the GPL.
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
14
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
15
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
16 THANKS FOR THE CODE!!!
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
17 -------------------------------------------------
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
18 The base for this program was andy@nobugs.org's XMMS plugin tutorial
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
19 http://www.xmms.org/docs/vis-plugin.html
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
20
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
21 We used some FFT code by Takuya OOURA instead of XMMS' built-in fft code
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
22 fftsg.c - http://momonga.t.u-tokyo.ac.jp/~ooura/fft.html
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
23
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
24 and some beat detection code was inspired by Frederic Patin @
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
25 www.gamedev.net/reference/programming/features/beatdetection/
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
26
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
27 */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
28
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
30 #include <string.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
31 #include <string>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
32 #include <stdlib.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
33 #include <unistd.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
34 #include <fcntl.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
35 #include <SDL/SDL.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
36 #include <SDL/SDL_thread.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
37 #include <GL/gl.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
38 #include <GL/glu.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
39 extern "C" {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
40 #include <audacious/util.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
41 #include <audacious/plugin.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
42 #include <audacious/auddrct.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
43 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
44 #include <math.h>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
45 #include "ConfigFile.h"
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
46
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
47 #include <libprojectM/BeatDetect.hpp>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
48 #include <libprojectM/PCM.hpp>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
49 #include <libprojectM/projectM.hpp>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
50 #include <libprojectM/KeyHandler.hpp>
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
51 #include "sdltoprojectM.h"
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
52 #include "video_init.h"
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
53
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
54 #define CONFIG_FILE "/share/projectM/config.inp"
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
55
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
56 // Forward declarations
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
57 extern "C" void projectM_xmms_init(void);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
58 extern "C" void projectM_cleanup(void);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
59 extern "C" void projectM_about(void);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
60 extern "C" void projectM_configure(void);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
61 extern "C" void projectM_playback_start(void);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
62 extern "C" void projectM_playback_stop(void);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
63 extern "C" void projectM_render_pcm(gint16 pcm_data[2][512]);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
64 extern "C" void projectM_render_freq(gint16 pcm_data[2][256]);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
65 extern "C" int worker_func(void*);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
66 std::string read_config();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
67 void saveSnapshotToFile();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
68
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
69 extern "C" VisPlugin projectM_vtable;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
70
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
71 //extern preset_t * active_preset;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
72
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
73 //FILE * debugFile = fopen("./dwrite-dump", "wb");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
74
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
75 // Callback functions
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
76
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
77 // Our worker thread
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
78 SDL_Thread *worker_thread = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
79 SDL_sem *sem = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
80 SDL_mutex *mutex = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
81
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
82 SDL_Event event;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
83
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
84 SDL_Surface *screen;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
85
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
86
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
87 projectM * globalPM = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
88
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
89 int maxsamples=512;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
90
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
91 int texsize=512;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
92 int gx=32,gy=24;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
93 int wvw=400,wvh=400;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
94 int fvw=1024,fvh=768;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
95 int fps=35, fullscreen=0;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
96
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
97 // char *title;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
98
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
99 gint disable_projectm(void *something) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
100 projectM_vtable.disable_plugin(&projectM_vtable);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
101 return 0;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
102 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
103
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
104 Uint32 get_xmms_title(Uint32 something, void *somethingelse) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
105 static char check_title = 1;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
106 static int last_pos;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
107 static char *last_title = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
108 int pos;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
109 char *title = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
110
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
111 //Nice optimization, but we want the title no matter what so I can display it when the song changes
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
112 #if 0
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
113 if(!(globalPM->showtitle%2)) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
114 /* Repeat less often when not showing title */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
115 return 1000;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
116 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
117 #endif
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
118
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
119 pos = audacious_drct_pl_get_pos();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
120 /* Only check every 1 second for title change, otherwise check pos */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
121 if(check_title || pos != last_pos) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
122 title = audacious_drct_pl_get_title(pos);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
123 if(title && (!last_title || strcmp(last_title,title))) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
124 globalPM->renderer->title = title;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
125 globalPM->renderer->drawtitle = 1;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
126 g_free(last_title);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
127 last_title = title;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
128 } else if(title && last_title != title) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
129 /* New copy of last title */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
130 g_free(title);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
131 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
132 check_title = !check_title;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
133 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
134 last_pos = pos;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
135 /* Repeat every 500ms */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
136 return 500;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
137 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
138
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
139 int capture = 0;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
140
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
141 int worker_func(void*)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
142 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
143 // char projectM_data[1024];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
144 SDL_TimerID title_timer = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
145 std::string config_file;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
146 config_file = read_config();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
147
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
148 ConfigFile config(config_file);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
149
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
150 int wvw = config.read<int>( "Window Width", 512 );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
151 int wvh = config.read<int>( "Window Height", 512 );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
152 int fullscreen = 0;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
153 if (config.read("Fullscreen", true)) fullscreen = 1;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
154 else fullscreen = 0;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
155
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
156 init_display(wvw,wvh,&fvw,&fvh,fullscreen);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
157 SDL_WM_SetCaption("projectM v1.00", "projectM v1.00");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
158
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
159
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
160 /** Initialise projectM */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
161
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
162 globalPM = new projectM(config_file);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
163
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
164 title_timer = SDL_AddTimer(500, (SDL_NewTimerCallback) get_xmms_title, NULL);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
165 /** Initialise the thread */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
166 // SDL_SemTryWait(sem);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
167 while ( SDL_SemValue(sem)==1 ) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
168 projectMEvent evt;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
169 projectMKeycode key;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
170 projectMModifier mod;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
171
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
172 /** Process SDL events */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
173 SDL_Event event;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
174 while ( SDL_PollEvent( &event ) ) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
175 /** Translate into projectM codes and process */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
176 evt = sdl2pmEvent( event );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
177
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
178 key = sdl2pmKeycode( event.key.keysym.sym );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
179 mod = sdl2pmModifier( event.key.keysym.mod );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
180
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
181 if ( evt == PROJECTM_KEYDOWN ) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
182
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
183 if(key == PROJECTM_K_c)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
184 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
185 //SDL_SaveBMP(screen, "/home/pete/1.bmp");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
186 saveSnapshotToFile();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
187 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
188 if(key == PROJECTM_K_v)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
189 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
190 // capture++;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
191 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
192 if(key == PROJECTM_K_f)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
193 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
194
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
195
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
196 int w, h;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
197 if (fullscreen == 0) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
198 w = fvw;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
199 h = fvh;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
200 } else {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
201 w = wvw;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
202 h = wvh;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
203 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
204 globalPM->fullscreen = fullscreen ^= 1;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
205 resize_display(w, h, fullscreen);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
206 globalPM->projectM_resetGL( w, h );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
207 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
208 else globalPM->key_handler(evt,key,mod);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
209
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
210 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
211 else if ( evt == PROJECTM_VIDEORESIZE )
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
212 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
213
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
214
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
215
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
216 wvw=event.resize.w;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
217 wvh=event.resize.h;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
218
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
219
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
220 resize_display(wvw,wvh,fullscreen);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
221 globalPM->projectM_resetGL( wvw, wvh );
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
222
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
223 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
224 else if ( evt == PROJECTM_VIDEOQUIT ) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
225
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
226 (void) g_idle_add((GSourceFunc) disable_projectm, NULL);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
227 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
228 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
229
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
230 /** Add the waveform data */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
231
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
232
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
233 /** Render the new frame */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
234 // strcpy(title,xmms_remote_get_playlist_title(projectM_vtable.xmms_session, xmms_remote_get_playlist_pos(projectM_vtable.xmms_session)));
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
235
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
236 //printf("%s\n",title);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
237 // strcpy(globalPM->title,title);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
238 //SDL_mutexP(mutex);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
239 globalPM->renderFrame();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
240 //SDL_mutexV(mutex);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
241
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
242
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
243 SDL_GL_SwapBuffers();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
244
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
245 if (capture % 2 == 1) saveSnapshotToFile();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
246 // SDL_SemPost(sem);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
247 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
248
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
249
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
250
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
251 printf("Worker thread: Exiting\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
252 if(title_timer)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
253 SDL_RemoveTimer(title_timer);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
254 delete globalPM;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
255 globalPM = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
256 close_display();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
257
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
258 return 0;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
259 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
260
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
261 extern "C" void projectM_xmms_init(void)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
262 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
263
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
264 printf("projectM plugin: Initializing\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
265
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
266 SDL_EnableUNICODE(1);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
267
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
268 mutex = SDL_CreateMutex();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
269 sem = SDL_CreateSemaphore(1);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
270 worker_thread = SDL_CreateThread ( *worker_func, NULL);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
271
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
272 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
273
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
274
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
275
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
276 extern "C"void projectM_cleanup(void)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
277 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
278
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
279 if(worker_thread) {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
280 SDL_SemWait(sem);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
281 SDL_WaitThread(worker_thread, NULL);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
282 SDL_DestroyMutex(mutex);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
283 SDL_DestroySemaphore(sem);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
284 SDL_Quit();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
285 worker_thread = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
286 sem = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
287 mutex = NULL;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
288 printf("projectM plugin: Cleanup completed\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
289 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
290 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
291 extern "C" void projectM_about(void)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
292 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
293 printf("projectM plugin: About\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
294 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
295 extern "C" void projectM_configure(void)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
296 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
297 printf("projectM plugin: Configure\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
298 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
299 extern "C" void projectM_playback_start(void)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
300 {//thread_control = GO;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
301 printf("projectM plugin: Playback starting\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
302 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
303 extern "C" void projectM_playback_stop(void)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
304 {//thread_control = STOP;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
305 printf("projectM plugin: Playback stopping\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
306 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
307 extern "C" void projectM_render_pcm(gint16 pcm_data[2][512])
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
308 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
309 //SDL_mutexP(mutex);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
310
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
311 if(globalPM)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
312 globalPM->beatDetect->pcm->addPCM16(pcm_data);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
313
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
314 //SDL_mutexV(mutex);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
315
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
316 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
317
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
318 extern "C" void projectM_render_freq(gint16 freq_data[2][256])
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
319 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
320 printf("NO GOOD\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
321 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
322
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
323 std::string read_config()
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
324 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
325
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
326 // int n;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
327
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
328 char num[512];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
329 FILE *in;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
330 FILE *out;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
331
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
332 char* home;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
333 char projectM_home[1024];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
334 char projectM_config[1024];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
335
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
336 strcpy(projectM_config, PROJECTM_PREFIX);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
337 strcpy(projectM_config+strlen(PROJECTM_PREFIX), CONFIG_FILE);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
338 projectM_config[strlen(PROJECTM_PREFIX)+strlen(CONFIG_FILE)]='\0';
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
339 printf("dir:%s \n",projectM_config);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
340 home=getenv("HOME");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
341 strcpy(projectM_home, home);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
342 strcpy(projectM_home+strlen(home), "/.projectM/config.inp");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
343 projectM_home[strlen(home)+strlen("/.projectM/config.inp")]='\0';
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
344
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
345
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
346 if ((in = fopen(projectM_home, "r")) != 0)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
347 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
348 printf("reading ~/.projectM/config.inp \n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
349 fclose(in);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
350 return std::string(projectM_home);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
351 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
352 else
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
353 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
354 printf("trying to create ~/.projectM/config.inp \n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
355
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
356 strcpy(projectM_home, home);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
357 strcpy(projectM_home+strlen(home), "/.projectM");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
358 projectM_home[strlen(home)+strlen("/.projectM")]='\0';
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
359 mkdir(projectM_home,0755);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
360
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
361 strcpy(projectM_home, home);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
362 strcpy(projectM_home+strlen(home), "/.projectM/config.inp");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
363 projectM_home[strlen(home)+strlen("/.projectM/config.inp")]='\0';
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
364
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
365 if((out = fopen(projectM_home,"w"))!=0)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
366 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
367
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
368 if ((in = fopen(projectM_config, "r")) != 0)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
369 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
370
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
371 while(fgets(num,80,in)!=NULL)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
372 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
373 fputs(num,out);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
374 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
375 fclose(in);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
376 fclose(out);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
377
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
378
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
379 if ((in = fopen(projectM_home, "r")) != 0)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
380 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
381 printf("created ~/.projectM/config.inp successfully\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
382 fclose(in);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
383 return std::string(projectM_home);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
384 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
385 else{printf("This shouldn't happen, using implementation defualts\n");abort();}
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
386 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
387 else{printf("Cannot find projectM default config, using implementation defaults\n");abort();}
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
388 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
389 else
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
390 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
391 printf("Cannot create ~/.projectM/config.inp, using default config file\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
392 if ((in = fopen(projectM_config, "r")) != 0)
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
393 { printf("Successfully opened default config file\n");
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
394 fclose(in);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
395 return std::string(projectM_config);}
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
396 else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n"); abort();}
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
397
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
398 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
399
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
400 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
401
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
402
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
403
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
404 abort();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
405 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
406
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
407 int frame = 1;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
408 char dumpPath[128];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
409
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
410
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
411 void saveSnapshotToFile()
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
412 {
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
413
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
414 SDL_Surface * bitmap;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
415
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
416 GLint viewport[4];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
417 long bytewidth;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
418 GLint width, height;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
419 long bytes;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
420
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
421 glReadBuffer(GL_FRONT);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
422 glGetIntegerv(GL_VIEWPORT, viewport);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
423
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
424 width = viewport[2];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
425 height = viewport[3];
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
426
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
427 bytewidth = width * 4;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
428 bytewidth = (bytewidth + 3) & ~3;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
429 bytes = bytewidth * height;
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
430
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
431 /*
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
432 glFinish();
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
433 glPixelStorei(GL_PACK_ALIGNMENT, 4);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
434 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
435 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
436 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
437 */
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
438
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
439
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
440 bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,0,0,0,0);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
441 glReadPixels(0, 0, width, height,
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
442 GL_BGRA,
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
443 GL_UNSIGNED_INT_8_8_8_8_REV,
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
444 bitmap->pixels);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
445
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
446 sprintf(dumpPath, "/home/pete/.projectM/%.8d.bmp", frame++);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
447
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
448 SDL_SaveBMP(bitmap, dumpPath);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
449
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
450 SDL_FreeSurface(bitmap);
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
451
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
452
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
453 }
a6d84a2cfaa7 projectm-1.0: add the new files this time
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
diff changeset
454