Fix remaining reds/yellows.
[kugel-rb.git] / apps / plugins / pdbox / pdbox.h
blobce29c1e800ed536c9709d6c5ea82681afd26831d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Wincent Balin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef PDBOX_H
23 #define PDBOX_H
26 #if 1
27 /* Use TLSF. */
28 #include "codecs/lib/tlsf/src/tlsf.h"
29 #endif
31 /* Pure Data */
32 #include "PDa/src/m_pd.h"
34 /* Minimal memory size. */
35 #define MIN_MEM_SIZE (4 * 1024 * 1024)
37 /* Memory prototypes. */
39 #if 1
40 /* Direct memory allocator functions to TLSF. */
41 #define malloc(size) tlsf_malloc(size)
42 #define free(ptr) tlsf_free(ptr)
43 #define realloc(ptr, size) tlsf_realloc(ptr, size)
44 #define calloc(elements, elem_size) tlsf_calloc(elements, elem_size)
45 #endif
47 #if 0
48 extern void set_memory_pool(void* memory_pool, size_t memory_size);
49 extern void clear_memory_pool(void);
50 extern void* mcalloc(size_t nmemb, size_t size);
51 extern void* mmalloc(size_t size);
52 extern void mfree(void* ptr);
53 extern void* mrealloc(void* ptr, size_t size);
54 extern void print_memory_pool(void);
56 #define malloc mmalloc
57 #define free mfree
58 #define realloc mrealloc
59 #define calloc mcalloc
60 #endif
62 #if 0
63 #include <stdlib.h>
64 #define malloc malloc
65 #define free free
66 #define realloc realloc
67 #define calloc calloc
68 #endif
70 /* Audio declarations. */
71 #define PD_SAMPLERATE 22050
72 #define PD_SAMPLES_PER_HZ ((PD_SAMPLERATE / HZ) + \
73 (PD_SAMPLERATE % HZ > 0 ? 1 : 0))
74 #define PD_OUT_CHANNELS 2
76 /* Audio buffer part. Contains data for one HZ period. */
77 #ifdef SIMULATOR
78 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS * 32)
79 #else
80 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS)
81 #endif
82 struct audio_buffer
84 int16_t data[AUDIOBUFSIZE];
85 unsigned int fill;
89 /* Additional functions. */
90 char *rb_strncat(char *s, const char *t, size_t n);
91 double rb_strtod(const char*, char**);
92 double rb_atof(const char*);
93 void rb_ftoan(float, char*, int);
94 float rb_floor(float);
95 long rb_atol(const char* s);
96 float rb_sin(float rad);
97 float rb_cos(float rad);
98 int rb_fscanf_f(int fd, float* f);
99 int rb_fprintf_f(int fd, float f);
100 float rb_log10(float);
101 float rb_log(float);
102 float rb_exp(float);
103 float rb_pow(float, float);
104 float rb_sqrt(float);
105 float rb_fabs(float);
106 float rb_atan(float);
107 float rb_atan2(float, float);
108 float rb_sinh(float);
109 float rb_tan(float);
110 #ifndef SIMULATOR
111 typedef struct
113 int quot;
114 int rem;
116 div_t;
117 div_t div(int x, int y);
118 #endif
119 union f2i
121 float f;
122 int32_t i;
124 void sys_findlibdir(const char* filename);
125 int sys_startgui(const char *guidir);
128 /* Network declarations. */
130 /* Maximal size of the datagram. */
131 #define MAX_DATAGRAM_SIZE 255
133 /* This structure replaces a UDP datagram. */
134 struct datagram
136 bool used;
137 uint8_t size;
138 char data[MAX_DATAGRAM_SIZE];
141 /* Prototypes of network functions. */
142 void net_init(void);
143 void net_destroy(void);
144 bool send_datagram(struct event_queue* route, int port,
145 char* data, size_t size);
146 bool receive_datagram(struct event_queue* route, int port,
147 struct datagram* buffer);
149 /* Network message queues. */
150 extern struct event_queue gui_to_core;
151 extern struct event_queue core_to_gui;
153 /* UDP ports of the original software. */
154 #define PD_CORE_PORT 3333
155 #define PD_GUI_PORT 3334
157 /* Convinience macros. */
158 #define SEND_TO_CORE(data) \
159 send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data))
160 #define RECEIVE_TO_CORE(buffer) \
161 receive_datagram(&gui_to_core, PD_CORE_PORT, buffer)
162 #define SEND_FROM_CORE(data) \
163 send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data))
164 #define RECEIVE_FROM_CORE(buffer) \
165 receive_datagram(&core_to_gui, PD_GUI_PORT, buffer)
167 /* PD core message callback. */
168 void rockbox_receive_callback(struct datagram* dg);
171 /* Pure Data declarations. */
173 /* Pure Data function prototypes. */
174 void pd_init(void);
177 /* Redefinitons of ANSI C functions. */
178 #include "lib/wrappers.h"
180 #define strncmp rb->strncmp
181 #define atoi rb->atoi
182 #define write rb->write
184 #define strncat rb_strncat
186 #ifndef SIMULATOR
187 #define floor rb_floor
188 #define atof rb_atof
189 #define atol rb_atol
190 #define sin rb_sin
191 #define cos rb_cos
192 #define log10 rb_log10
193 #define log rb_log
194 #define exp rb_exp
195 #define pow rb_pow
196 #define sqrt rb_sqrt
197 #define fabs rb_fabs
198 #define atan rb_atan
199 #define atan2 rb_atan2
200 #define sinh rb_sinh
201 #define tan rb_tan
202 #else
203 #include <math.h>
204 #endif
206 #define ftoan rb_ftoan
207 #define strtok_r rb->strtok_r
208 #define strstr rb->strcasestr
211 /* PdPod GUI declarations. */
213 enum pd_widget_id
215 PD_BANG,
216 PD_VSLIDER,
217 PD_HSLIDER,
218 PD_VRADIO,
219 PD_HRADIO,
220 PD_NUMBER,
221 PD_SYMBOL,
222 PD_TEXT
225 struct pd_widget
227 enum pd_widget_id id;
228 char name[128];
229 int x;
230 int y;
231 int w;
232 int h;
233 int min;
234 int max;
235 float value;
236 int timeout;
239 enum pd_key_id
241 KEY_PLAY,
242 KEY_REWIND,
243 KEY_FORWARD,
244 KEY_MENU,
245 KEY_ACTION,
246 KEY_WHEELLEFT,
247 KEY_WHEELRIGHT,
248 PD_KEYS
251 /* Map real keys to virtual ones.
252 Feel free to add your preferred keymap here. */
253 #if defined(IRIVER_H300_SERIES)
254 /* Added by wincent */
255 #define PDPOD_QUIT (BUTTON_OFF)
256 #define PDPOD_PLAY (BUTTON_ON)
257 #define PDPOD_PREVIOUS (BUTTON_LEFT)
258 #define PDPOD_NEXT (BUTTON_RIGHT)
259 #define PDPOD_MENU (BUTTON_SELECT)
260 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
261 #define PDPOD_WHEELRIGHT (BUTTON_UP)
262 #define PDPOD_ACTION (BUTTON_MODE)
263 #elif defined(IRIVER_H100_SERIES)
264 /* Added by wincent */
265 #define PDPOD_QUIT (BUTTON_OFF)
266 #define PDPOD_PLAY (BUTTON_REC)
267 #define PDPOD_PREVIOUS (BUTTON_LEFT)
268 #define PDPOD_NEXT (BUTTON_RIGHT)
269 #define PDPOD_MENU (BUTTON_SELECT)
270 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
271 #define PDPOD_WHEELRIGHT (BUTTON_UP)
272 #define PDPOD_ACTION (BUTTON_ON)
273 #else
274 #warning "No keys defined for this architecture!"
275 #endif
277 /* Prototype of GUI functions. */
278 void pd_gui_init(void);
279 unsigned int pd_gui_load_patch(struct pd_widget* wg, unsigned int max_widgets);
280 void pd_gui_draw(struct pd_widget* wg, unsigned int widgets);
281 bool pd_gui_parse_buttons(unsigned int widgets);
282 void pd_gui_parse_message(struct datagram* dg,
283 struct pd_widget* wg, unsigned int widgets);
284 bool pd_gui_apply_timeouts(struct pd_widget* wg, unsigned int widgets);
286 #endif