~ubuntu-branches/ubuntu/hoary/kdeaddons/hoary

« back to all changes in this revision

Viewing changes to noatun-plugins/tippercanoe/syna.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2002-04-01 16:42:29 UTC
  • Revision ID: james.westby@ubuntu.com-20020401164229-oxc5htazpgzyqygi
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Synaescope - a pretty noatun visualization (based on P. Harrison's Synaesthesia)
 
2
   Copyright (C) 1997 Paul Francis Harrison <pfh@yoyo.cc.monash.edu.au>
 
3
                 2001 Charles Samuels <charles@kde.org>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
15
  You should have received a copy of the GNU General Public License along
 
16
  with this program; if not, write to the Free Software Foundation, Inc.,
 
17
  675 Mass Ave, Cambridge, MA 02139, USA.
 
18
*/
 
19
 
 
20
#ifndef SYNA_H
 
21
#define SYNA_H
 
22
 
 
23
#include "config.h"
 
24
#include <qlist.h>
 
25
#include "polygon.h"
 
26
 
 
27
//**************************************
 
28
//   For the incurably fiddle prone:   
 
29
 
 
30
// log2 of sample size
 
31
#define LogSize 9 
 
32
 
 
33
// overlap amount between samples. Set to 1 or 2 if you have a fast computer
 
34
#define Overlap 1 
 
35
 
 
36
// Brightness
 
37
#define Brightness 150
 
38
 
 
39
// Sample frequency
 
40
#define Frequency 22050
 
41
 
 
42
//***************************************
 
43
 
 
44
#define DefaultWidth  260
 
45
#define DefaultHeight 260
 
46
 
 
47
#define NumSamples (1<<LogSize)
 
48
#define RecSize (1<<LogSize-Overlap)
 
49
 
 
50
#ifndef __linux__
 
51
#warning This target has not been tested!
 
52
#endif
 
53
 
 
54
#ifdef __FreeBSD__
 
55
#include <machine/endian.h>
 
56
typedef unsigned short sampleType;
 
57
#else
 
58
#include <endian.h>
 
59
typedef short sampleType;
 
60
#endif
 
61
 
 
62
#if BYTE_ORDER == BIG_ENDIAN
 
63
#define BIGENDIAN
 
64
#else
 
65
#define LITTLEENDIAN
 
66
#endif
 
67
 
 
68
void error(const char *str, bool syscall=false);
 
69
void warning(const char *str, bool syscall=false);
 
70
 
 
71
enum SymbolID
 
72
{
 
73
        Speaker, Bulb,
 
74
        Play, Pause, Stop, SkipFwd, SkipBack,
 
75
        Handle, Pointer, Open, NoCD, Exit,
 
76
        Zero, One, Two, Three, Four,
 
77
        Five, Six, Seven, Eight, Nine,
 
78
        Slider, Selector, Plug, Loop, Box, Bar,
 
79
        Flame, Wave, Stars, Star, Diamond, Size, FgColor, BgColor,
 
80
        Save, Reset, TrackSelect,
 
81
        NotASymbol
 
82
};
 
83
 
 
84
// wrap 
 
85
struct BaseScreen
 
86
{
 
87
        virtual bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen) = 0;
 
88
        virtual void setPalette(unsigned char *palette) = 0;
 
89
        virtual void end() = 0;
 
90
        virtual int  sizeUpdate() = 0;
 
91
        virtual bool inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit) = 0;
 
92
        virtual void show() = 0;
 
93
};
 
94
 
 
95
struct SdlScreen : public BaseScreen
 
96
{
 
97
        bool init(int xHint, int yHint, int widthHint, int heightHint, bool fullscreen);
 
98
        void setPalette(unsigned char *palette);
 
99
        void end();
 
100
        int  sizeUpdate();
 
101
        bool inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit);
 
102
        void show();
 
103
        int winID();
 
104
};
 
105
 
 
106
// core
 
107
class Combiner
 
108
{
 
109
public:
 
110
        static unsigned short combine(unsigned short a,unsigned short b)
 
111
        {
 
112
                //Not that i want to give the compiler a hint or anything...
 
113
                unsigned char ah = a>>8, al = a&255, bh = b>>8, bl = b&255;
 
114
                if (ah < 64) ah *= 4; else ah = 255;
 
115
                if (al < 64) al *= 4; else al = 255;
 
116
                if (bh > ah) ah = bh;
 
117
                if (bl > al) al = bl;
 
118
                return ah*256+al;
 
119
        }
 
120
};
 
121
 
 
122
class Interface;
 
123
 
 
124
class Core
 
125
{
 
126
public:
 
127
        Core();
 
128
        ~Core();
 
129
 
 
130
        inline unsigned char *output() { return (unsigned char*)outputBmp.data; }
 
131
        inline unsigned char *lastOutput() { return (unsigned char*)lastOutputBmp.data; }
 
132
        inline unsigned char *lastLastOutput() { return (unsigned char*)lastLastOutputBmp.data; }
 
133
        
 
134
        void allocOutput(int w,int h);
 
135
        void interfaceInit();
 
136
        //void coreInit();
 
137
        void setStarSize(double size);
 
138
        void setupPalette(double);
 
139
        
 
140
        bool go();
 
141
        bool calculate();
 
142
        
 
143
        void toDefaults();
 
144
        void fade();
 
145
        void fadeFade();
 
146
        inline void fadePixelWave(int x, int y, int where, int step);
 
147
        void fadeWave();
 
148
        inline void fadePixelHeat(int x,int y,int where,int step);
 
149
        void fadeHeat();
 
150
 
 
151
        void fft(double*, double*);
 
152
        
 
153
        inline void addPixel(int x, int y, int br1, int br2);
 
154
        inline void addPixelFast(unsigned char *p, int br1, int br2);
 
155
        inline unsigned char getPixel(int x, int y, int where);
 
156
        
 
157
        static int bitReverser(int);
 
158
 
 
159
 
 
160
public:
 
161
        BaseScreen *screen;
 
162
        Interface *interface;
 
163
        sampleType *data;
 
164
        Bitmap<unsigned short> outputBmp, lastOutputBmp, lastLastOutputBmp;
 
165
        PolygonEngine<unsigned short,Combiner,2> polygonEngine;
 
166
 
 
167
        double cosTable[NumSamples], negSinTable[NumSamples];
 
168
        int bitReverse[NumSamples];
 
169
        int scaleDown[256];
 
170
        int maxStarRadius;
 
171
 
 
172
 
 
173
public:
 
174
        int outWidth, outHeight;
 
175
        SymbolID fadeMode;
 
176
        bool pointsAreDiamonds;
 
177
 
 
178
        double brightnessTwiddler; 
 
179
        double starSize; 
 
180
 
 
181
        double fgRedSlider, fgGreenSlider, bgRedSlider, bgGreenSlider;
 
182
        SymbolID state;
 
183
 
 
184
        int windX, windY, windWidth, windHeight;
 
185
};
 
186
 
 
187
extern Core *core;
 
188
 
 
189
inline unsigned char Core::getPixel(int x,int y,int where)
 
190
{
 
191
        if (x < 0 || y < 0 || x >= outWidth || y >= outHeight) return 0;
 
192
        return lastOutput()[where];
 
193
}
 
194
 
 
195
 
 
196
struct Button;
 
197
 
 
198
struct UIObject
 
199
{
 
200
        int visibleMask, activeMask;
 
201
        double x,y,width,height;
 
202
        bool active;
 
203
 
 
204
        virtual int go(bool mouseDown,bool mouseClick,bool mouseOver,
 
205
                        double x, double y, double scale, char &hotKey, int &action)
 
206
                = 0;
 
207
 
 
208
        virtual void handleKey(char key, int &action) = 0;
 
209
        void changed();
 
210
};
 
211
 
 
212
class Interface
 
213
{
 
214
public:
 
215
        Interface();
 
216
        ~Interface();
 
217
        bool go();
 
218
        void syncToState();
 
219
        void setupPalette();
 
220
 
 
221
        void putString(char *string,int x,int y,int red,int blue);
 
222
        
 
223
protected:
 
224
        void addUI(UIObject *obj);
 
225
        void changeState(int transitionSymbol);
 
226
        
 
227
private:
 
228
        QList<UIObject> uiObjects; 
 
229
        Button *stateButton, *starsButton, *waveButton, *flameButton, *starButton, *diamondButton;
 
230
        int mouseButtons;
 
231
 
 
232
        int visibleMask;
 
233
        int mouseX, mouseY, lastX, lastY, countDown;
 
234
 
 
235
};
 
236
 
 
237
 
 
238
#endif 
 
239