[Git]Ignore work files.
[synaesthesia.git] / syna.h
blob45c21bf0af72a3302c5e0d4c984226d4524bf351
1 /* Synaesthesia - program to display sound graphically
2 Copyright (C) 1997 Paul Francis Harrison
3 Copyright (C) 2009 RafaƂ Rzepecki <divided.mind@gmail.com>
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 The author may be contacted at:
20 phar6@student.monash.edu.au
22 27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
25 #include "config.h"
27 #include "polygon.h"
29 /***************************************/
30 /* For the incurably fiddle prone: */
32 /* log2 of sample size */
33 #define LogSize 10 //was 9
35 /* Brightness */
36 #define Brightness 150
38 /* Sample frequency*/
39 #define Frequency 22050
41 #define DefaultWidth 200
42 #define DefaultHeight 200
44 /***************************************/
46 #define NumSamples (1<<LogSize)
47 #define RecSize (1<<LogSize-Overlap)
49 #ifdef __FreeBSD__
51 typedef unsigned short sampleType;
53 #else
55 typedef short sampleType;
57 #ifndef __linux__
59 #warning This target has not been tested!
61 #endif
62 #endif
64 #ifdef __FreeBSD__
65 #include <machine/endian.h>
66 #else
67 #include <endian.h>
68 #endif
70 #if BYTE_ORDER == BIG_ENDIAN
71 #define BIGENDIAN
72 #else
73 #define LITTLEENDIAN
74 #endif
76 void error(char *str,bool syscall=false);
77 void inline attempt(int x,char *y,bool syscall=false) { if (x == -1) error(y,syscall); }
78 void warning(char *str,bool syscall=false);
79 void inline attemptNoDie(int x,char *y,bool syscall=false) { if (x == -1) warning(y,syscall); }
81 /* *wrap */
82 struct BaseScreen {
83 virtual bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen) = 0;
84 virtual void setPalette(unsigned char *palette) = 0;
85 virtual void end() = 0;
86 virtual void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit) = 0;
87 virtual void show() = 0;
88 virtual void toggleFullScreen() { }
91 struct SvgaScreen : public BaseScreen {
92 bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen);
93 void setPalette(unsigned char *palette);
94 void end();
95 void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit);
96 void show();
99 struct RawScreen : public BaseScreen {
100 RawScreen(int _fps): fps(_fps) {}
101 ~RawScreen() { end(); }
102 bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen);
103 void setPalette(unsigned char *palette);
104 void end();
105 void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit);
106 void show();
107 private:
108 int fps;
111 struct SdlScreen : public BaseScreen {
112 bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen);
113 void setPalette(unsigned char *palette);
114 void end();
115 void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit);
116 void show();
117 void toggleFullScreen();
120 struct XScreen : public BaseScreen {
121 bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen);
122 void setPalette(unsigned char *palette);
123 void end();
124 void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit);
125 void show();
128 /* core */
129 extern BaseScreen *screen;
130 extern sampleType *data;
131 extern Bitmap<unsigned short> outputBmp, lastOutputBmp, lastLastOutputBmp;
132 #define output ((unsigned char*)outputBmp.data)
133 #define lastOutput ((unsigned char*)lastOutputBmp.data)
134 #define lastLastOutput ((unsigned char*)lastLastOutputBmp.data)
136 struct Combiner {
137 static unsigned short combine(unsigned short a,unsigned short b) {
138 //Not that i want to give the compiler a hint or anything...
139 unsigned char ah = a>>8, al = a&255, bh = b>>8, bl = b&255;
140 if (ah < 64) ah *= 4; else ah = 255;
141 if (al < 64) al *= 4; else al = 255;
142 if (bh > ah) ah = bh;
143 if (bl > al) al = bl;
144 return ah*256+al;
148 extern PolygonEngine<unsigned short,Combiner,2> polygonEngine;
150 extern int outWidth, outHeight;
152 void allocOutput(int w,int h);
154 void coreInit();
155 void setStarSize(double size);
156 int coreGo();
157 void fade();
159 /* ui */
160 void interfaceInit();
161 void interfaceSyncToState();
162 void interfaceEnd();
163 bool interfaceGo();
165 enum SymbolID {
166 Speaker, Bulb,
167 Play, Pause, Stop, SkipFwd, SkipBack,
168 Handle, Pointer, Open, NoCD, Exit,
169 Zero, One, Two, Three, Four,
170 Five, Six, Seven, Eight, Nine,
171 Slider, Selector, Plug, Loop, Box, Bar,
172 Flame, Wave, Stars, Star, Diamond, Size, FgColor, BgColor,
173 Save, Reset, TrackSelect,
174 NotASymbol
177 /* State information */
179 extern SymbolID state;
180 extern int track, frames;
181 extern double trackProgress;
182 extern char **playList;
183 extern int playListLength, playListPosition;
184 extern SymbolID fadeMode;
185 extern bool pointsAreDiamonds;
186 extern double brightnessTwiddler;
187 extern double starSize;
188 extern double fgRedSlider, fgGreenSlider, bgRedSlider, bgGreenSlider;
190 extern double volume;
192 void setStateToDefaults();
193 void saveConfig();
195 void putString(char *string,int x,int y,int red,int blue);
197 /* sound */
198 enum SoundSource { SourceLine, SourceCD, SourcePipe, SourceESD };
200 void cdOpen(char *cdromName);
201 void cdClose(void);
202 void cdGetStatus(int &track, int &frames, SymbolID &state);
203 void cdPlay(int trackFrame, int endFrame=-1);
204 void cdStop(void);
205 void cdPause(void);
206 void cdResume(void);
207 void cdEject(void);
208 void cdCloseTray(void);
209 int cdGetTrackCount(void);
210 int cdGetTrackFrame(int track);
211 void openSound(SoundSource sound, int downFactor, char *dspName, char *mixerName);
212 void closeSound();
213 void setupMixer(double &loudness);
214 void setVolume(double loudness);
215 int getNextFragment(void);