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 * This will be a VU meter set, 16 LED sets for different tracks.
23 *
24 * We are probably going to cheat on the implementation: The backdrop will be
25 * an array of LEDs. We will produce a "blueprint" bitmap that will mask in/out
26 * the backdrop.
27 *
28 * This was written with internal brighton bitmaps, but to improve efficiency
29 * of these rather slow access routines (XDrawPixmap, etc), am going to build
30 * another extrapolated access to the X11 PixMap structures. These will use
31 * native sizes rather than scaling the results.
32 */
33
34 #include "brightoninternals.h"
35
36 int
destroyVu(brightonDevice * dev)37 destroyVu(brightonDevice *dev)
38 {
39 printf("destroyVu()\n");
40
41 if (dev->image)
42 brightonFreeBitmap(dev->bwin, dev->image);
43 if (dev->image2)
44 brightonFreeBitmap(dev->bwin, dev->image2);
45
46 dev->image = NULL;
47 dev->image2 = NULL;
48
49 return(0);
50 }
51
52 static int
displayvu(brightonDevice * dev)53 displayvu(brightonDevice *dev)
54 {
55 brightonIResource *panel;
56
57 /* printf("displayvu()\n"); */
58
59 if (dev->bwin->app->resources[dev->panel].flags & BRIGHTON_WITHDRAWN)
60 return(0);
61
62 panel = &dev->bwin->app->resources[dev->panel];
63
64 /*
65 * Only draw fixed number of steps.
66 */
67 brightonStretch(dev->bwin, dev->image2,
68 dev->bwin->dlayer,
69 dev->x + dev->bwin->app->resources[dev->panel].sx,
70 (int)(dev->y + dev->bwin->app->resources[dev->panel].sy),
71 dev->width, dev->height, 0);
72
73 brightonFinalRender(dev->bwin,
74 dev->x + dev->bwin->app->resources[dev->panel].sx,
75 dev->y + dev->bwin->app->resources[dev->panel].sy,
76 dev->width * 2,
77 (dev->height >> 2) + 1 + (dev->width >> 1));
78
79 return(0);
80 }
81
82 static void
pbm(brightonDevice * dev,register int o,register int c)83 pbm(brightonDevice *dev, register int o, register int c)
84 {
85 register int *pixels2 = dev->image2->pixels;
86 /*
87 dev->image2->pixels[o + 0] = dev->image->pixels[o + 0];
88 dev->image2->pixels[o + 1] = dev->image->pixels[o + 1];
89 dev->image2->pixels[o + 2] = dev->image->pixels[o + 2];
90 dev->image2->pixels[o + 3] = dev->image->pixels[o + 3];
91 dev->image2->pixels[o + 4] = dev->image->pixels[o + 4];
92 dev->image2->pixels[o + 5] = dev->image->pixels[o + 5];
93 dev->image2->pixels[o + 6] = dev->image->pixels[o + 6];
94 dev->image2->pixels[o + 7] = dev->image->pixels[o + 7];
95 dev->image2->pixels[o + 8] = dev->image->pixels[o + 8];
96 dev->image2->pixels[o + 9] = dev->image->pixels[o + 9];
97 */
98 pixels2[o + 0] = c;
99 pixels2[o + 1] = c;
100 pixels2[o + 2] = c;
101 pixels2[o + 3] = c;
102 pixels2[o + 4] = c;
103 pixels2[o + 5] = c;
104 pixels2[o + 6] = c;
105 pixels2[o + 7] = c;
106 pixels2[o + 8] = c;
107 pixels2[o + 9] = c;
108 }
109
110 static void
fbm(brightonDevice * dev)111 fbm(brightonDevice *dev)
112 {
113 register int i, j;
114 register int *pixels2 = dev->image2->pixels;
115
116 /*
117 * Param indicates the values on the points. Just deal with one for now
118 *
119 * Bitmap image 2 is all black. We are going to cut a few holes in it.
120 */
121 for (i = 63; i > 0; --i)
122 {
123 j = i * 160;
124
125 pixels2[j + 0] = dev->image->pixels[j + 0];
126 pixels2[j + 1] = dev->image->pixels[j + 1];
127 pixels2[j + 2] = dev->image->pixels[j + 2];
128 pixels2[j + 3] = dev->image->pixels[j + 3];
129 pixels2[j + 4] = dev->image->pixels[j + 4];
130 pixels2[j + 5] = dev->image->pixels[j + 5];
131 pixels2[j + 6] = dev->image->pixels[j + 6];
132 pixels2[j + 7] = dev->image->pixels[j + 7];
133 pixels2[j + 8] = dev->image->pixels[j + 8];
134 pixels2[j + 9] = dev->image->pixels[j + 9];
135
136 pixels2[j + 20] = dev->image->pixels[j + 0];
137 pixels2[j + 21] = dev->image->pixels[j + 1];
138 pixels2[j + 22] = dev->image->pixels[j + 2];
139 pixels2[j + 23] = dev->image->pixels[j + 3];
140 pixels2[j + 24] = dev->image->pixels[j + 4];
141 pixels2[j + 25] = dev->image->pixels[j + 5];
142 pixels2[j + 26] = dev->image->pixels[j + 6];
143 pixels2[j + 27] = dev->image->pixels[j + 7];
144 pixels2[j + 28] = dev->image->pixels[j + 8];
145 pixels2[j + 29] = dev->image->pixels[j + 9];
146
147 pixels2[j + 40] = dev->image->pixels[j + 0];
148 pixels2[j + 41] = dev->image->pixels[j + 1];
149 pixels2[j + 42] = dev->image->pixels[j + 2];
150 pixels2[j + 43] = dev->image->pixels[j + 3];
151 pixels2[j + 44] = dev->image->pixels[j + 4];
152 pixels2[j + 45] = dev->image->pixels[j + 5];
153 pixels2[j + 46] = dev->image->pixels[j + 6];
154 pixels2[j + 47] = dev->image->pixels[j + 7];
155 pixels2[j + 48] = dev->image->pixels[j + 8];
156 pixels2[j + 49] = dev->image->pixels[j + 9];
157
158 pixels2[j + 90] = dev->image->pixels[j + 0];
159 pixels2[j + 91] = dev->image->pixels[j + 1];
160 pixels2[j + 92] = dev->image->pixels[j + 2];
161 pixels2[j + 93] = dev->image->pixels[j + 3];
162 pixels2[j + 94] = dev->image->pixels[j + 4];
163 pixels2[j + 95] = dev->image->pixels[j + 5];
164 pixels2[j + 96] = dev->image->pixels[j + 6];
165 pixels2[j + 97] = dev->image->pixels[j + 7];
166 pixels2[j + 98] = dev->image->pixels[j + 8];
167 pixels2[j + 99] = dev->image->pixels[j + 9];
168 }
169 }
170
171 static void
cbm(brightonDevice * dev)172 cbm(brightonDevice *dev)
173 {
174 int i, j, c;
175
176 /*
177 * Param indicates the values on the points. Just deal with one for now
178 *
179 * Bitmap image 2 is all black. We are going to cut a few holes in it.
180 */
181 for (i = 64 - dev->value--; i > 0; i--)
182 {
183 j = i * 160;
184 c = dev->image2->colormap[0];
185
186 /* pbm(dev, j, c); */
187 pbm(dev, j + 20, c);
188 /* pbm(dev, j + 20, c); */
189 /* pbm(dev, j + 40, c); */
190 /* pbm(dev, j + 90, c); */
191 }
192 }
193
194 static int
configure(brightonDevice * dev,brightonEvent * event)195 configure(brightonDevice *dev, brightonEvent *event)
196 {
197 printf("configureVu()\n");
198
199 if (event->command == -1)
200 return(-1);
201
202 if (event->command == BRIGHTON_RESIZE)
203 {
204 dev->originx = event->x;
205 dev->originy = event->y;
206
207 dev->x = event->x;
208 dev->y = event->y;
209 dev->width = event->w;
210 dev->height = event->h;
211 printf("vuMeter width = %i, height = %i\n", dev->width, dev->height);
212 /*
213 * We should now delete our existing bitmap and create a new one for
214 * the size of this window.
215 */
216
217 /*
218 * We should now rework our parent understanding of our window, since
219 * it will have altered. NOT NECESSARY FOR SCALE.
220 brightonPanelLocation(dev->bwin,
221 dev->panel, dev->index, dev->x, dev->y, dev->width, dev->height);
222 */
223
224 displayvu(dev);
225
226 return(0);
227 }
228
229 if (event->command == BRIGHTON_KEYRELEASE)
230 {
231 }
232
233 if (event->command == BRIGHTON_BUTTONRELEASE)
234 {
235 }
236
237 if (event->command == BRIGHTON_KEYPRESS)
238 {
239 }
240
241 if (event->command == BRIGHTON_MOTION)
242 {
243 }
244
245 if ((event->command == BRIGHTON_PARAMCHANGE) ||
246 (event->command == BRIGHTON_KEYPRESS))
247 {
248 cbm(dev);
249 cbm(dev);
250 cbm(dev);
251 cbm(dev);
252
253 if (dev->value <= 1)
254 {
255 dev->value = 64;
256 fbm(dev);
257 }
258
259 displayvu(dev);
260
261 return(0);
262 }
263 return(0);
264 }
265
266 int *
createVu(brightonWindow * bwin,brightonDevice * dev,int index,char * bitmap)267 createVu(brightonWindow *bwin, brightonDevice *dev, int index, char *bitmap)
268 {
269 printf("createVu(%s)\n", bitmap);
270
271 dev->destroy = destroyVu;
272 dev->configure = configure;
273 dev->index = index;
274
275 dev->bwin = bwin;
276
277 if (bitmap == 0)
278 {
279 if (dev->image)
280 brightonFreeBitmap(bwin, dev->image);
281 if (dev->image2)
282 brightonFreeBitmap(bwin, dev->image2);
283 /*
284 * Open the default bitmap
285 */
286 if (bwin->app->resources[dev->panel].devlocn[dev->index].image != 0)
287 dev->image =
288 bwin->app->resources[dev->panel].devlocn[dev->index].image;
289
290 if (bwin->app->resources[dev->panel].devlocn[dev->index].image2 != 0)
291 dev->image2 =
292 bwin->app->resources[dev->panel].devlocn[dev->index].image2;
293 } else {
294 if (dev->image)
295 brightonFreeBitmap(bwin, dev->image);
296 dev->image = brightonReadImage(bwin, bitmap);
297
298 if (bwin->app->resources[dev->panel].devlocn[dev->index].image2 != 0)
299 dev->image2 =
300 bwin->app->resources[dev->panel].devlocn[dev->index].image2;
301 }
302
303 /*
304 * These will force an update when we first display ourselves.
305 */
306 dev->value = 64;
307
308 fbm(dev);
309
310 return(0);
311 }
312
313