fix red.
[kugel-rb/myfork.git] / apps / plugins / pdbox / pdbox.h
bloba8ae466675807574619a66e9cb9bc54a3aec9367
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 "tlsf.h"
29 #endif
31 /* Pure Data */
32 #include "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 typedef struct
112 int quot;
113 int rem;
115 div_t;
116 div_t div(int x, int y);
117 union f2i
119 float f;
120 int32_t i;
122 void sys_findlibdir(const char* filename);
123 int sys_startgui(const char *guidir);
126 /* Network declarations. */
128 /* Maximal size of the datagram. */
129 #define MAX_DATAGRAM_SIZE 255
131 /* This structure replaces a UDP datagram. */
132 struct datagram
134 bool used;
135 uint8_t size;
136 char data[MAX_DATAGRAM_SIZE];
139 /* Prototypes of network functions. */
140 void net_init(void);
141 void net_destroy(void);
142 bool send_datagram(struct event_queue* route, int port,
143 char* data, size_t size);
144 bool receive_datagram(struct event_queue* route, int port,
145 struct datagram* buffer);
147 /* Network message queues. */
148 extern struct event_queue gui_to_core;
149 extern struct event_queue core_to_gui;
151 /* UDP ports of the original software. */
152 #define PD_CORE_PORT 3333
153 #define PD_GUI_PORT 3334
155 /* Convinience macros. */
156 #define SEND_TO_CORE(data) \
157 send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data))
158 #define RECEIVE_TO_CORE(buffer) \
159 receive_datagram(&gui_to_core, PD_CORE_PORT, buffer)
160 #define SEND_FROM_CORE(data) \
161 send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data))
162 #define RECEIVE_FROM_CORE(buffer) \
163 receive_datagram(&core_to_gui, PD_GUI_PORT, buffer)
165 /* PD core message callback. */
166 void rockbox_receive_callback(struct datagram* dg);
169 /* Pure Data declarations. */
171 /* Pure Data function prototypes. */
172 void pd_init(void);
175 /* Redefinitons of ANSI C functions. */
176 #include "lib/wrappers.h"
178 #define strncmp rb->strncmp
179 #define atoi rb->atoi
180 #define write rb->write
182 #define strncat rb_strncat
183 #define floor rb_floor
184 #define atof rb_atof
185 #define atol rb_atol
186 #define ftoan rb_ftoan
187 #define sin rb_sin
188 #define cos rb_cos
189 #define log10 rb_log10
190 #define log rb_log
191 #define exp rb_exp
192 #define pow rb_pow
193 #define sqrt rb_sqrt
194 #define fabs rb_fabs
195 #define atan rb_atan
196 #define atan2 rb_atan2
197 #define sinh rb_sinh
198 #define tan rb_tan
200 #define strtok_r rb->strtok_r
201 #define strstr rb->strcasestr
204 /* PdPod GUI declarations. */
206 enum pd_widget_id
208 PD_BANG,
209 PD_VSLIDER,
210 PD_HSLIDER,
211 PD_VRADIO,
212 PD_HRADIO,
213 PD_NUMBER,
214 PD_SYMBOL,
215 PD_TEXT
218 struct pd_widget
220 enum pd_widget_id id;
221 char name[128];
222 int x;
223 int y;
224 int w;
225 int h;
226 int min;
227 int max;
228 float value;
229 int timeout;
232 enum pd_key_id
234 KEY_PLAY,
235 KEY_REWIND,
236 KEY_FORWARD,
237 KEY_MENU,
238 KEY_ACTION,
239 KEY_WHEELLEFT,
240 KEY_WHEELRIGHT,
241 PD_KEYS
244 /* Map real keys to virtual ones.
245 Feel free to add your preferred keymap here. */
246 #if defined(IRIVER_H300_SERIES)
247 /* Added by wincent */
248 #define PDPOD_QUIT (BUTTON_OFF)
249 #define PDPOD_PLAY (BUTTON_ON)
250 #define PDPOD_PREVIOUS (BUTTON_LEFT)
251 #define PDPOD_NEXT (BUTTON_RIGHT)
252 #define PDPOD_MENU (BUTTON_SELECT)
253 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
254 #define PDPOD_WHEELRIGHT (BUTTON_UP)
255 #define PDPOD_ACTION (BUTTON_MODE)
256 #elif defined(IRIVER_H100_SERIES)
257 /* Added by wincent */
258 #define PDPOD_QUIT (BUTTON_OFF)
259 #define PDPOD_PLAY (BUTTON_REC)
260 #define PDPOD_PREVIOUS (BUTTON_LEFT)
261 #define PDPOD_NEXT (BUTTON_RIGHT)
262 #define PDPOD_MENU (BUTTON_SELECT)
263 #define PDPOD_WHEELLEFT (BUTTON_DOWN)
264 #define PDPOD_WHEELRIGHT (BUTTON_UP)
265 #define PDPOD_ACTION (BUTTON_ON)
266 #else
267 #warning "No keys defined for this architecture!"
268 #endif
270 /* Prototype of GUI functions. */
271 void pd_gui_init(void);
272 unsigned int pd_gui_load_patch(struct pd_widget* wg, unsigned int max_widgets);
273 void pd_gui_draw(struct pd_widget* wg, unsigned int widgets);
274 bool pd_gui_parse_buttons(unsigned int widgets);
275 void pd_gui_parse_message(struct datagram* dg,
276 struct pd_widget* wg, unsigned int widgets);
277 bool pd_gui_apply_timeouts(struct pd_widget* wg, unsigned int widgets);
279 #endif