lcd-m6sp.c: remove \r
[kugel-rb.git] / apps / plugins / pdbox / pdbox.h
blob2ee32a0dc861b874894275b517b6a79afef02a96
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009, 2010 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 /* Direct memory allocator functions to TLSF. */
40 #define malloc(size) tlsf_malloc(size)
41 #define free(ptr) tlsf_free(ptr)
42 #define realloc(ptr, size) tlsf_realloc(ptr, size)
43 #define calloc(elements, elem_size) tlsf_calloc(elements, elem_size)
45 /* Audio declarations. */
46 #define PD_SAMPLERATE 22050
47 #define PD_SAMPLES_PER_HZ ((PD_SAMPLERATE / HZ) + \
48 (PD_SAMPLERATE % HZ > 0 ? 1 : 0))
49 #define PD_OUT_CHANNELS 2
51 /* Audio buffer part. Contains data for one HZ period. */
52 #ifdef SIMULATOR
53 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS * 16)
54 #else
55 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS)
56 #endif
57 struct audio_buffer
59 int16_t data[AUDIOBUFSIZE];
60 unsigned int fill;
64 /* Additional functions. */
65 char *rb_strncat(char *s, const char *t, size_t n);
66 double rb_strtod(const char*, char**);
67 double rb_atof(const char*);
68 void rb_ftoan(float, char*, int);
69 float rb_floor(float);
70 long rb_atol(const char* s);
71 float rb_sin(float rad);
72 float rb_cos(float rad);
73 int rb_fscanf_f(int fd, float* f);
74 int rb_fprintf_f(int fd, float f);
75 float rb_log10(float);
76 float rb_log(float);
77 float rb_exp(float);
78 float rb_pow(float, float);
79 float rb_sqrt(float);
80 float rb_fabs(float);
81 float rb_atan(float);
82 float rb_atan2(float, float);
83 float rb_sinh(float);
84 float rb_tan(float);
85 #ifndef SIMULATOR
86 typedef struct
88 int quot;
89 int rem;
91 div_t;
92 div_t div(int x, int y);
93 #endif
94 union f2i
96 float f;
97 int32_t i;
99 void sys_findlibdir(const char* filename);
100 int sys_startgui(const char *guidir);
103 /* Network declarations. */
105 /* Maximal size of the datagram. */
106 #define MAX_DATAGRAM_SIZE 255
108 /* This structure replaces a UDP datagram. */
109 struct datagram
111 bool used;
112 uint8_t size;
113 char data[MAX_DATAGRAM_SIZE];
116 /* Prototypes of network functions. */
117 void net_init(void);
118 void net_destroy(void);
119 bool send_datagram(struct event_queue* route, int port,
120 char* data, size_t size);
121 bool receive_datagram(struct event_queue* route, int port,
122 struct datagram* buffer);
124 /* Network message queues. */
125 extern struct event_queue gui_to_core;
126 extern struct event_queue core_to_gui;
128 /* UDP ports of the original software. */
129 #define PD_CORE_PORT 3333
130 #define PD_GUI_PORT 3334
132 /* Convinience macros. */
133 #define SEND_TO_CORE(data) \
134 send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data))
135 #define RECEIVE_TO_CORE(buffer) \
136 receive_datagram(&gui_to_core, PD_CORE_PORT, buffer)
137 #define SEND_FROM_CORE(data) \
138 send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data))
139 #define RECEIVE_FROM_CORE(buffer) \
140 receive_datagram(&core_to_gui, PD_GUI_PORT, buffer)
142 /* PD core message callback. */
143 void rockbox_receive_callback(struct datagram* dg);
146 /* Pure Data declarations. */
148 /* Pure Data function prototypes. */
149 void pd_init(void);
152 /* Redefinitons of ANSI C functions. */
153 #include "lib/wrappers.h"
155 #define strncmp rb->strncmp
156 #define atoi rb->atoi
157 #define write rb->write
159 #define strncat rb_strncat
161 #ifndef SIMULATOR
162 #define floor rb_floor
163 #define atof rb_atof
164 #define atol rb_atol
165 #define sin rb_sin
166 #define cos rb_cos
167 #define log10 rb_log10
168 #define log rb_log
169 #define exp rb_exp
170 #define pow rb_pow
171 #define sqrt rb_sqrt
172 #define fabs rb_fabs
173 #define atan rb_atan
174 #define atan2 rb_atan2
175 #define sinh rb_sinh
176 #define tan rb_tan
177 #else
178 #include <math.h>
179 #endif
181 #define ftoan rb_ftoan
182 #define strtok_r rb->strtok_r
183 #define strstr rb->strcasestr
186 /* PdPod GUI declarations. */
188 enum pd_widget_id
190 PD_BANG,
191 PD_VSLIDER,
192 PD_HSLIDER,
193 PD_VRADIO,
194 PD_HRADIO,
195 PD_NUMBER,
196 PD_SYMBOL,
197 PD_TEXT
200 struct pd_widget
202 enum pd_widget_id id;
203 char name[128];
204 int x;
205 int y;
206 int w;
207 int h;
208 int min;
209 int max;
210 float value;
211 int timeout;
214 enum pd_key_id
216 KEY_PLAY,
217 KEY_REWIND,
218 KEY_FORWARD,
219 KEY_MENU,
220 KEY_ACTION,
221 KEY_WHEELLEFT,
222 KEY_WHEELRIGHT,
223 PD_KEYS
226 /* Map real keys to virtual ones.
227 Feel free to add your preferred keymap here. */
228 #if (CONFIG_KEYPAD == IRIVER_H300_PAD)
229 /* Added by wincent */
230 #define PDPOD_QUIT (BUTTON_OFF)
231 #define PDPOD_PLAY (BUTTON_ON)
232 #define PDPOD_PREVIOUS (BUTTON_LEFT)
233 #define PDPOD_NEXT (BUTTON_RIGHT)
234 #define PDPOD_MENU (BUTTON_SELECT)
235 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
236 #define PDPOD_WHEELRIGHT (BUTTON_UP)
237 #define PDPOD_ACTION (BUTTON_MODE)
238 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD)
239 /* Added by wincent */
240 #define PDPOD_QUIT (BUTTON_OFF)
241 #define PDPOD_PLAY (BUTTON_REC)
242 #define PDPOD_PREVIOUS (BUTTON_LEFT)
243 #define PDPOD_NEXT (BUTTON_RIGHT)
244 #define PDPOD_MENU (BUTTON_SELECT)
245 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
246 #define PDPOD_WHEELRIGHT (BUTTON_UP)
247 #define PDPOD_ACTION (BUTTON_ON)
248 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
249 /* Added by funman */
250 #define PDPOD_QUIT (BUTTON_HOME|BUTTON_REPEAT)
251 #define PDPOD_PLAY BUTTON_UP
252 #define PDPOD_PREVIOUS BUTTON_LEFT
253 #define PDPOD_NEXT BUTTON_RIGHT
254 #define PDPOD_MENU BUTTON_SELECT
255 #define PDPOD_WHEELLEFT BUTTON_SCROLL_BACK
256 #define PDPOD_WHEELRIGHT BUTTON_SCROLL_FWD
257 #define PDPOD_ACTION BUTTON_DOWN
258 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
259 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
260 /* Added by wincent */
261 #define PDPOD_QUIT (BUTTON_SELECT | BUTTON_MENU)
262 #define PDPOD_PLAY (BUTTON_PLAY)
263 #define PDPOD_PREVIOUS (BUTTON_LEFT)
264 #define PDPOD_NEXT (BUTTON_RIGHT)
265 #define PDPOD_MENU (BUTTON_MENU)
266 #define PDPOD_WHEELLEFT (BUTTON_SCROLL_BACK)
267 #define PDPOD_WHEELRIGHT (BUTTON_SCROLL_FWD)
268 #define PDPOD_ACTION (BUTTON_SELECT)
269 #else
270 #warning "No keys defined for this architecture!"
271 #endif
273 /* Prototype of GUI functions. */
274 void pd_gui_init(void);
275 unsigned int pd_gui_load_patch(struct pd_widget* wg, unsigned int max_widgets);
276 void pd_gui_draw(struct pd_widget* wg, unsigned int widgets);
277 bool pd_gui_parse_buttons(unsigned int widgets);
278 void pd_gui_parse_message(struct datagram* dg,
279 struct pd_widget* wg, unsigned int widgets);
280 bool pd_gui_apply_timeouts(struct pd_widget* wg, unsigned int widgets);
282 #endif