1 
2 /*
3  *  Diverse Bristol audio routines.
4  *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5  *
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 3 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BRIGHTONINTERNALS_H
23 #define BRIGHTONINTERNALS_H
24 
25 #include <stdio.h>
26 
27 #include "brightondevflags.h"
28 #include "brightonevents.h"
29 #include "brightonvectorgraphics.h"
30 
31 #define BRIGHTON_ST_CLOCK	0
32 #define BRIGHTON_ST_REQ		1
33 #define BRIGHTON_ST_CANCEL	2 /* Cancel single callback */
34 #define BRIGHTON_ST_FIRST	BRIGHTON_ST_CANCEL
35 
36 #define BRIGHTON_FT_CLOCK		0
37 #define BRIGHTON_FT_REQ			1
38 #define BRIGHTON_FT_STOP		2
39 #define BRIGHTON_FT_START		3
40 #define BRIGHTON_FT_STEP		4
41 #define BRIGHTON_FT_RESET		5
42 #define BRIGHTON_FT_CANCEL		6 /* Cancel all */
43 #define BRIGHTON_FT_TICKTIME	7
44 #define BRIGHTON_FT_DUTYCYCLE	8
45 
46 #define isblue(x,y,z) \
47 			((x >= 0) && \
48 			(y != NULL) && \
49 			(z != NULL) && \
50 			((z[x] < 0) || \
51 			((y[z[x]].red == 0) && \
52 			(y[z[x]].green == 0) && \
53 			(y[z[x]].blue == 0xffff))))
54 
55 /*
56  * Some return codes.
57  */
58 #define BRIGHTON_OK 0
59 #define BRIGHTON_XISSUE 1
60 
61 #include "brighton.h"
62 
63 /*
64  * Shadow rendering
65  */
66 #define BRIGHTON_STATIC 1
67 #define BRIGHTON_DYNAMIC 2
68 typedef struct BrightonShadow {
69 	unsigned int flags;
70 	brightonCoord *coords;
71 	int *mask;
72 	int minx, maxx, miny, maxy;
73 	int ccount;
74 } brightonShadow;
75 
76 /*
77  * palette flags
78  */
79 #define BRIGHTON_CMAP_SIZE 16384
80 #define BRIGHTON_INACTIVE_COLOR 0x01
81 #define BRIGHTON_QR_QSIZE 128
82 #define BRIGHTON_QR_COLORS 24
83 typedef struct BrightonPalette {
84 	unsigned int flags;
85 	int uses;
86 	unsigned short red, green, blue;
87 	long pixel;
88 	void *color;
89 	void *gc;
90 } brightonPalette;
91 
92 /*
93  * Flags are for preferred rendering.
94 #define BRIGHTON_ANTIALIAS 0x01
95  */
96 typedef struct BrightonBitmap {
97 	unsigned int flags;
98 	struct BrightonBitmap *next, *last;
99 	int uses;
100 	char *name;
101 	int width, height, ncolors, ctabsize, istatic, ostatic;
102 	int *pixels;
103 	int *colormap;
104 } brightonBitmap;
105 
106 #include "brightondev.h"
107 
108 /*
109  * Flags for brightonPanel.flags - LSW.
110  */
111 #define BRIGHTON_ACTIVE 0x80000000
112 #define TOO_SMALL 0x02
113 #define BRIGHTON_GREYSCALE 0x04
114 #define BRIGHTON_DEV_ACTIVE 0x08
115 #define BRIGHTON_SET_SIZE 0x010
116 typedef struct BrightonPanel {
117 	unsigned int flags;
118 	struct BrightonPanel *next, *last;
119 	int x, y;
120 	unsigned int width, height, depth, border;
121 	brightonBitmap *image;
122 	brightonBitmap *surface;
123 	brightonBitmap *canvas; /* surface overlaid with image */
124 	brightonResource *resource;
125 	struct BrightonDevice **devices;
126 	brightonSize *locations;
127 	int activedev;
128 } brightonPanel;
129 
130 #define BRIGHTON_DEFAULT_DISPLAY ":0.0"
131 #define BRIGHTON_NAMESIZE 64
132 #define BRIGHTON_LIB_DEBUG		0x00010000
133 #define BRIGHTON_BIMAGE			0x00020000
134 #define BRIGHTON_ANTIALIAS_1	0x00040000
135 #define BRIGHTON_ANTIALIAS_2	0x00080000
136 #define BRIGHTON_ANTIALIAS_3	0x00100000
137 #define BRIGHTON_ANTIALIAS_4	0x00200000
138 #define BRIGHTON_ANTIALIAS_5	0x00400000
139 #define _BRIGHTON_WINDOW		0x00800000
140 #define BRIGHTON_BVIMAGE		0x01000000
141 typedef struct BrightonDisplay {
142 	unsigned int flags;
143 	struct BrightonDisplay *next, *last;
144 	brightonPalette *palette;
145 	void *display; /* this type depends on underlying window system */
146 	void *image; /* this type depends on underlying window system */
147 	struct BrightonWindow *bwin;
148 	char name[BRIGHTON_NAMESIZE];
149 	int width, height, depth;
150 } brightonDisplay;
151 
152 /*
153  * Flags for brightonWindow.flags
154  */
155 #define BRIGHTON_NO_DRAW		0x00000001
156 /* SET_SIZE, DEV_ACTIVE are in here too */
157 #define BRIGHTON_BUSY			0x00000020
158 #define BRIGHTON_NO_LOGO		0x00000040
159 #define BRIGHTON_NO_ASPECT		0x00000080
160 #define _BRIGHTON_POST			0x00000100
161 #define BRIGHTON_DEBUG			0x00000200
162 #define BRIGHTON_EXITING		0x00000400
163 #define BRIGHTON_AUTOZOOM		0x00000800
164 #define BRIGHTON_SET_RAISE		0x00001000
165 #define BRIGHTON_SET_LOWER		0x00002000
166 #define _BRIGHTON_SET_HEIGHT	0x00004000
167 #define BRIGHTON_ROTARY_UD		0x00008000
168 
169 #define BRIGHTON_ITEM_COUNT		512 /* max devices per panel */
170 /*
171  * These are used to hold items that have been placed on the top layer. We
172  * need this structure since these items may be inserted and removed.
173  */
174 #define BRIGHTON_LAYER_PUT		0x01
175 #define BRIGHTON_LAYER_PLACE	0x02
176 #define BRIGHTON_LAYER_ALL		0x04
177 typedef struct BrightonLayerItem {
178 	int flags;
179 	int id;
180 	brightonBitmap *image;
181 	int x, y;
182 	int w, h;
183 	int d; /* Rotational point? */
184 	int scale;
185 } brightonLayerItem;
186 
187 typedef struct BrightonNRPcontrol {
188 	int nrp;
189 	struct brightonDevice *device;
190 } brightonNRPcontrol;
191 
192 #define BRIGHTON_NRP_COUNT 128
193 #define BRIGHTON_GANG_COUNT 8
194 
195 typedef struct BrightonWindow {
196 	unsigned int flags;
197 	struct BrightonWindow *next, *last;
198 	brightonDisplay *display;
199 	brightonBitmap *image;
200 	brightonBitmap *surface;
201 	brightonPanel *panels;
202 	brightonBitmap *bitmaps;
203 	brightonBitmap *canvas; /* surface overlaid with image, scaled. */
204 	brightonBitmap *dlayer; /* device rendering layer. */
205 	brightonBitmap *slayer; /* shadow rendering layer. */
206 	brightonBitmap *tlayer; /* patch rendering layer (should be a stack?). */
207 	brightonBitmap *mlayer; /* menu rendering layer (should be a stack?). */
208 	brightonBitmap *render; /* output bitmap to screen */
209 	brightonBitmap *renderalias; /* output alias bitmap to screen */
210 	brightonLayerItem items[BRIGHTON_ITEM_COUNT];
211 	float opacity;
212 	int quality;
213 	float antialias;
214 	int grayscale;
215 	int win;
216 	void *gc;
217 	int x, y;
218 	unsigned int width, height, depth, border;
219 	unsigned int minw, minh;
220 	unsigned int maxw, maxh;
221 	float aspect;
222 	int cmap_size;
223 	int id;
224 	char *window_name;
225 	int lightX, lightY, lightH;
226 	float lightI;
227 	brightonRoutine callbacks[BLASTEvent];
228 	brightonIApp *app;
229 	brightonApp *template;
230 	brightonIResource *activepanel;
231 	brightonILocations *activedev;
232 	int parentwin;
233 	/* These should not really be in this structure, but in the synth. */
234 	int midimap[128]; /* This could be u_char */
235 	/*
236 	 * Only build support for 128 controls. Supporting 16384 of them would be
237 	 * rather large on memory however a bigger value could be useful - FFS.
238 	 */
239 	int GM2values[128];
240 	/* These are for CC tracking */
241 	struct brightonDevice *midicontrol[128][BRIGHTON_GANG_COUNT];
242 	float midicontrolval[128][BRIGHTON_GANG_COUNT];
243 	float midicontrolscaler[128];
244 	/* These are for NRP tracking */
245 	int nrpcount;
246 	brightonNRPcontrol *nrpcontrol; //[BRIGHTON_NRP_COUNT];
247 	/* CC value mapping tables */
248 	u_char valuemap[128][128];
249 	int kbdmap[256][2];
250 	int dcTimeout;
251 } brightonWindow;
252 
253 typedef int (*brightonDeviceAlgo)();
254 
255 /*
256  * Global structure for any given renderable object.
257  */
258 #define BRIGHTON_DEV_INITED 0x01
259 typedef struct BrightonDevice {
260 	unsigned int flags;
261 	struct BrightonDevice *next, *last;
262 	int device; /* device type. 0=rotary, etc. */
263 	int index; /* index of this instance */
264 	int panel; /* parent panel of this instance */
265 	brightonWindow *bwin;
266 	brightonPanel *parent;
267 	int originx, originy;
268 	int x, y; /* Location onto parent window. */
269 	int width, height; /* Target width and height */
270 	brightonBitmap *imagebg; /* background image, not rotated */
271 	brightonBitmap *image; /* Generic rotatatable */
272 	brightonBitmap *image0; /* Generic rotatatable */
273 	brightonBitmap *image1; /* Not rotated. If null, render circle of fg */
274 	brightonBitmap *image2; /* Not rotated. If null, render circle of fg */
275 	brightonBitmap *image3; /* Not rotated. If null, render circle of fg */
276 	brightonBitmap *image4; /* Not rotated. If null, render circle of fg */
277 	brightonBitmap *image5; /* Not rotated. If null, render circle of fg */
278 	brightonBitmap *image6; /* Not rotated. If null, render circle of fg */
279 	brightonBitmap *image7; /* Not rotated. If null, render circle of fg */
280 	brightonBitmap *image8; /* Not rotated. If null, render circle of fg */
281 	brightonBitmap *image9; /* Not rotated. If null, render circle of fg */
282 	brightonBitmap *imagec; /* Not rotated. If null, render circle of fg */
283 	brightonBitmap *imagee; /* Not rotated. If null, render circle of fg */
284 	int bg, fg; /* background palette - usual not used. FG for top of pot. */
285 	float value;
286 	float lastvalue;
287 	float position;
288 	float lastposition;
289 	float value2;
290 	float lastvalue2;
291 	float position2;
292 	float lastposition2;
293 	char text[64]; /* displayable name for device. */
294 	int varindex; /* index into global variable table - device's tracking var. */
295 	brightonDeviceAlgo destroy;
296 	brightonDeviceAlgo configure;
297 	brightonShadow shadow;
298 } brightonDevice;
299 
300 #define BRIGHTON_DEFAULT_ICON 1
301 
302 extern void brightonStretchAlias(brightonWindow *, brightonBitmap *, brightonBitmap *, int, int, int, int, float);
303 extern void brightonStretch(brightonWindow *, brightonBitmap *, brightonBitmap *, int, int, int, int, int);
304 extern brightonDisplay *brightonOpenDisplay(char *);
305 extern brightonDisplay *brightonFindDisplay(brightonDisplay *, brightonDisplay *);
306 extern brightonWindow *brightonCreateWindow(brightonDisplay *, brightonApp *, int, int, int, int, int, int);
307 extern void brightonDestroyWindow(brightonWindow *);
308 extern void brightonDestroyPanel(brightonPanel *);
309 extern int brightonEventLoop(brightonDisplay **);
310 extern void brightonInitDefHandlers(brightonWindow *);
311 extern int brightonFillBase(brightonWindow *, char *, char *);
312 extern void *brightonmalloc(size_t);
313 extern FILE *brightonfopen(char *, char *);
314 extern char *brightonfgets(char *, int, FILE *);
315 extern int brightonfclose(FILE *);
316 extern brightonPalette *brightonInitColormap(brightonWindow *, int);
317 extern int brightonFindColor(brightonPalette *, int, unsigned short, unsigned short, unsigned short, int);
318 extern int brightonFindFreeColor(brightonPalette *, int);
319 extern int brightonGetGC(brightonWindow *, unsigned short, unsigned short, unsigned short);
320 extern int brightonGetGCByName(brightonWindow *, char *);
321 extern int brightonFreeGC(brightonWindow *, int);
322 extern brightonBitmap *brightonFreeBitmap(brightonWindow *, brightonBitmap *);
323 extern brightonBitmap *brightonCreateNamedBitmap(brightonWindow *, int, int, char *);
324 extern brightonBitmap *brightonCreateBitmap(brightonWindow *, int, int);
325 extern brightonBitmap *brightonReadImage(brightonWindow *, char *);
326 extern int brightonDestroyImage(brightonWindow *, brightonBitmap *);
327 extern int brightonRender(brightonWindow *, brightonBitmap *, brightonBitmap *, int, int, int, int, int);
328 extern int brightonTesselate(brightonWindow *, brightonBitmap *, brightonBitmap *, int, int, int, int, int);
329 extern int brightonRotate(brightonWindow *, brightonBitmap *, brightonBitmap *, int, int, int, int, double);
330 extern int brightonWorldChanged(brightonWindow *, int, int);
331 extern brightonDevice *brightonCreateDevice(brightonWindow *, int, int, int, char *);
332 extern void brightonDestroyDevice(brightonDevice *);
333 extern void brightonConfigureDevice(brightonDevice *, brightonEvent *);
334 extern void brightonDeviceEvent(brightonDevice *, brightonEvent *);
335 extern int brightonForwardEvent(brightonWindow *);
336 extern int brightonLocation(brightonWindow *, int, int, int, int, int);
337 extern int brightonXpmWrite(brightonWindow *, char *);
338 
339 extern int brightonRequestResize(brightonWindow *, int, int);
340 
341 extern brightonILocations *brightonLocator(brightonWindow *, int, int);
342 extern brightonIResource *brightonPanelLocator(brightonWindow *, int, int);
343 extern brightonILocations *brightonDeviceLocator(brightonIResource *, int, int);
344 
345 extern int brightonCreateInterface(brightonWindow *, brightonApp *);
346 extern int brightonDestroyInterface(brightonWindow *);
347 
348 extern int brightonRenderShadow(brightonDevice *, int);
349 extern int brightonFinalRender(brightonWindow *, int, int, int, int);
350 extern int brightonDevUndraw(brightonWindow *, brightonBitmap *, int, int, int, int);
351 extern int brightonRePlace(brightonWindow *);
352 extern int brightonPlace(brightonWindow *, char *, int, int, int, int);
353 extern int brightonPut(brightonWindow *, char *, int, int, int, int);
354 extern int brightonRemove(brightonWindow *, int);
355 
356 extern int brightonSlowTimer(brightonWindow *, brightonDevice *, int);
357 extern int brightonFastTimer(brightonWindow *, int, int, int, int);
358 
359 extern void brightonAlphaLayer(brightonWindow *, brightonBitmap *, brightonBitmap *, int, int, int, int, double);
360 
361 extern int brightonInitBitmap(brightonBitmap *, int);
362 extern int brightonDoFinalRender(brightonWindow *, int, int, int, int);
363 
364 extern int BAutoRepeat(brightonDisplay *, int);
365 
366 extern int brightonGetDCTimer();
367 extern int brightonDoubleClick();
368 extern void brightonfree(void *);
369 
370 extern void brightonRegisterController(brightonDevice *);
371 
372 #endif /* BRIGHTONINTERNALS_H */
373 
374