aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/lib/edje_multisense.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 17:29:19 +1000
committerDavid Walter Seikel2013-01-13 17:29:19 +1000
commit07274513e984f0b5544586c74508ccd16e7dcafa (patch)
treeb32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/edje/src/lib/edje_multisense.c
parentAdded Irrlicht 1.8, but without all the Windows binaries. (diff)
downloadSledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/edje/src/lib/edje_multisense.c')
-rw-r--r--libraries/edje/src/lib/edje_multisense.c407
1 files changed, 0 insertions, 407 deletions
diff --git a/libraries/edje/src/lib/edje_multisense.c b/libraries/edje/src/lib/edje_multisense.c
deleted file mode 100644
index a35b223..0000000
--- a/libraries/edje/src/lib/edje_multisense.c
+++ /dev/null
@@ -1,407 +0,0 @@
1#include "edje_private.h"
2
3typedef struct _Multisense_Data
4{
5 Edje_Multisense_Env *msenv;
6#ifdef HAVE_LIBREMIX
7 RemixDeck *deck;
8 RemixTrack *track;
9 RemixLayer *snd_layer, *player_layer;
10 RemixBase *player;
11 RemixBase *player_snd;
12 int remaining;
13 int offset;
14 Eina_List *snd_src_list;
15
16 MULTISENSE_SOUND_PLAYER_GET_FUNC multisense_sound_player_get;
17#endif
18}Multisense_Data;
19
20#define BUF_LEN 64
21#define SND_PROCESS_LENGTH 2048
22
23#ifdef HAVE_LIBREMIX
24static Ecore_Thread *player_thread = NULL;
25static int command_pipe[2];
26static Eina_Bool pipe_initialized = EINA_FALSE;
27#endif
28
29typedef enum _Edje_Sound_Action_Type
30{
31 EDJE_PLAY_SAMPLE = 0,
32 EDJE_PLAY_TONE,
33 /*
34 EDJE_PLAY_PATTERN,
35 EDJE_PLAY_INSTRUMENT,
36 EDJE_PLAY_SONG,
37 */
38 EDJE_SOUND_LAST
39} Edje_Sound_Action_Type;
40
41typedef struct _Edje_Sample_Action Edje_Sample_Action;
42typedef struct _Edje_Tone_Action Edje_Tone_Action;
43typedef struct _Edje_Multisense_Sound_Action Edje_Multisense_Sound_Action;
44
45struct _Edje_Sample_Action
46{
47 char sample_name[BUF_LEN];
48 double speed;
49};
50
51struct _Edje_Tone_Action
52{
53 char tone_name[BUF_LEN];
54 double duration;
55};
56
57struct _Edje_Multisense_Sound_Action
58{
59 Edje *ed;
60 Edje_Sound_Action_Type action;
61 union {
62 Edje_Sample_Action sample;
63 Edje_Tone_Action tone;
64 } type;
65};
66
67#ifdef HAVE_LIBREMIX
68static Multisense_Data *
69init_multisense_environment(void)
70{
71 Multisense_Data *msdata;
72 char ms_factory[BUF_LEN];
73 char *ms_factory_env;
74 Eina_Module *m = NULL;
75 MULTISENSE_FACTORY_INIT_FUNC multisense_factory_init;
76
77 msdata = calloc(1, sizeof(Multisense_Data));
78 if (!msdata) goto err;
79
80 msdata->msenv = calloc(1, sizeof(Edje_Multisense_Env));
81 if (!msdata->msenv) goto err;
82
83 ms_factory_env = getenv("MULTISENSE_FACTORY");
84 if (ms_factory_env)
85 strncpy(ms_factory, ms_factory_env, BUF_LEN);
86 else
87 strcpy(ms_factory, "multisense_factory");
88
89 m = _edje_module_handle_load(ms_factory);
90 if (!m) goto err;
91
92 msdata->msenv->remixenv = remix_init();
93
94 multisense_factory_init =
95 eina_module_symbol_get(m, "multisense_factory_init");
96 if (multisense_factory_init) multisense_factory_init(msdata->msenv);
97
98 msdata->multisense_sound_player_get =
99 eina_module_symbol_get(m, "multisense_sound_player_get");
100 if (!msdata->multisense_sound_player_get) goto err;
101
102 msdata->deck = remix_deck_new(msdata->msenv->remixenv);
103 msdata->track = remix_track_new(msdata->msenv->remixenv, msdata->deck);
104 msdata->snd_layer = remix_layer_new_ontop(msdata->msenv->remixenv,
105 msdata->track,
106 REMIX_TIME_SAMPLES);
107 msdata->player_layer = remix_layer_new_ontop(msdata->msenv->remixenv,
108 msdata->track,
109 REMIX_TIME_SAMPLES);
110 msdata->player = msdata->multisense_sound_player_get(msdata->msenv);
111 if (!msdata->player) goto err;
112 msdata->player_snd = remix_sound_new(msdata->msenv->remixenv,
113 msdata->player, msdata->player_layer,
114 REMIX_SAMPLES(0),
115 REMIX_SAMPLES(REMIX_COUNT_INFINITE));
116 return msdata;
117
118err:
119 if (msdata)
120 {
121 if (msdata->deck) remix_destroy(msdata->msenv->remixenv, msdata->deck);
122 if (msdata->msenv->remixenv) remix_purge(msdata->msenv->remixenv);
123 if (msdata->msenv) free(msdata->msenv);
124 free(msdata);
125 }
126 return NULL;
127}
128#endif
129
130#ifdef HAVE_LIBREMIX
131static RemixBase *
132eet_sound_reader_get(Edje_Multisense_Env *msenv, const char *path, const char *sound_id, const double speed)
133{
134 RemixPlugin *sf_plugin = NULL;
135 RemixBase * eet_snd_reader = NULL;
136 int sf_path_key = 0;
137 int sf_sound_id_key = 0;
138 int sf_speed_key = 0;
139 CDSet *sf_parms = NULL;
140 RemixEnv *env = msenv->remixenv;
141
142 if (sf_plugin == NULL)
143 {
144 sf_plugin = remix_find_plugin(env, "eet_sndfile_reader");
145 if (sf_plugin == NULL)
146 {
147 ERR ("Multisense EET Sound reader plugin NULL\n");
148 return NULL;
149 }
150
151 sf_path_key = remix_get_init_parameter_key(env, sf_plugin, "path");
152 sf_sound_id_key = remix_get_init_parameter_key(env, sf_plugin, "sound_id");
153 sf_speed_key = remix_get_init_parameter_key(env, sf_plugin, "speed");
154 }
155 sf_parms = cd_set_replace(env, sf_parms, sf_path_key, CD_STRING(path));
156 sf_parms = cd_set_replace(env, sf_parms, sf_sound_id_key, CD_STRING(sound_id));
157 sf_parms = cd_set_replace(env, sf_parms, sf_speed_key, CD_DOUBLE(speed));
158 eet_snd_reader = remix_new(env, sf_plugin, sf_parms);
159
160 return eet_snd_reader;
161}
162
163
164static RemixBase *
165edje_remix_sample_create(Multisense_Data *msdata, Edje*ed, Edje_Sample_Action *action)
166{
167 RemixBase *remix_snd = NULL;
168 Edje_Sound_Sample *sample;
169 int i;
170 char snd_id_str[16];
171
172 if ((!ed) || (!ed->file) || (!ed->file->sound_dir))
173 return NULL;
174
175 for (i = 0; i < (int)ed->file->sound_dir->samples_count; i++)
176 {
177 sample = &ed->file->sound_dir->samples[i];
178 if (!strcmp(sample->name, action->sample_name))
179 {
180 snprintf(snd_id_str, sizeof(snd_id_str), "edje/sounds/%i", sample->id);
181 remix_snd = eet_sound_reader_get(msdata->msenv, ed->file->path,
182 snd_id_str, action->speed);
183 break;
184 }
185 }
186 return remix_snd;
187}
188
189static RemixBase *
190edje_remix_tone_create(Multisense_Data *msdata, Edje*ed, Edje_Tone_Action *action)
191{
192 Edje_Sound_Tone *tone;
193 RemixSquareTone *square = NULL;
194 unsigned int i;
195
196 if ((!ed) || (!ed->file) || (!ed->file->sound_dir))
197 return NULL;
198
199 for (i = 0; i < ed->file->sound_dir->tones_count; i++)
200 {
201 tone = &ed->file->sound_dir->tones[i];
202 if (!strcmp(tone->name, action->tone_name))
203 {
204 square = remix_squaretone_new (msdata->msenv->remixenv, tone->value);
205 break;
206 }
207 }
208 return square;
209}
210
211static void
212sound_command_handler(Multisense_Data *msdata)
213{
214 RemixCount length;
215 Edje_Multisense_Sound_Action command;
216 RemixBase *base = NULL;
217 RemixBase *sound;
218
219 if (read(command_pipe[0], &command, sizeof(command)) <= 0) return;
220 switch (command.action)
221 {
222 case EDJE_PLAY_SAMPLE:
223 base = edje_remix_sample_create(msdata, command.ed,
224 &command.type.sample);
225 length = remix_length(msdata->msenv->remixenv, base);
226 break;
227 case EDJE_PLAY_TONE:
228 base = edje_remix_tone_create(msdata, command.ed, &command.type.tone);
229 length = (command.type.tone.duration *
230 remix_get_samplerate(msdata->msenv->remixenv));
231 break;
232 default:
233 ERR("Invalid Sound Play Command\n");
234 break;
235 }
236 if (base)
237 {
238 sound = remix_sound_new(msdata->msenv->remixenv, base, msdata->snd_layer,
239 REMIX_SAMPLES(msdata->offset),
240 REMIX_SAMPLES(length));
241 if (msdata->remaining < length) msdata->remaining = length;
242 msdata->snd_src_list = eina_list_append(msdata->snd_src_list, sound);
243 msdata->snd_src_list = eina_list_append(msdata->snd_src_list, base);
244 }
245}
246#endif
247
248#ifdef HAVE_LIBREMIX
249// msdata outside of thread due to thread issues in dlsym etc.
250static Multisense_Data *msdata = NULL;
251
252static void
253_msdata_free(void)
254{
255 // cleanup msdata outside of thread due to thread issues in dlsym etc.
256 if (!msdata) return;
257 //cleanup Remix stuffs
258 remix_destroy(msdata->msenv->remixenv, msdata->player);
259 remix_destroy(msdata->msenv->remixenv, msdata->deck);
260 remix_purge(msdata->msenv->remixenv);
261
262 free(msdata->msenv);
263 free(msdata);
264 msdata = NULL;
265}
266
267static void
268_player_job(void *data __UNUSED__, Ecore_Thread *th)
269{
270 fd_set wait_fds;
271 RemixBase *sound;
272 RemixCount process_len;
273// disable and move outside of thread due to dlsym etc. thread issues
274// Multisense_Data * msdata = init_multisense_environment();
275
276 if (!msdata) return;
277
278 fcntl(command_pipe[0], F_SETFL, O_NONBLOCK);
279 FD_ZERO(&wait_fds);
280 FD_SET(command_pipe[0], &wait_fds);
281
282 while (!ecore_thread_check(th))
283 {
284 if (!msdata->remaining)
285 {
286 //Cleanup already played sound sources
287 EINA_LIST_FREE(msdata->snd_src_list, sound)
288 {
289 remix_destroy(msdata->msenv->remixenv, sound);
290 }
291 //wait for new sound
292 select(command_pipe[0] + 1, &wait_fds, NULL, NULL, 0);
293 }
294 //read sound command , if any
295 sound_command_handler(msdata);
296 process_len = MIN(msdata->remaining, SND_PROCESS_LENGTH);
297 remix_process(msdata->msenv->remixenv, msdata->deck, process_len,
298 RemixNone, RemixNone);
299 msdata->offset += process_len;
300 msdata->remaining -= process_len;
301 }
302
303 //Cleanup last played sound sources
304 EINA_LIST_FREE(msdata->snd_src_list, sound)
305 {
306 remix_destroy(msdata->msenv->remixenv, sound);
307 }
308
309 close(command_pipe[0]);
310 close(command_pipe[1]);
311}
312#endif
313
314#ifdef HAVE_LIBREMIX
315static void
316_player_cancel(void *data __UNUSED__, Ecore_Thread *th __UNUSED__)
317{
318 // cleanup msdata outside of thread due to thread issues in dlsym etc.
319 _msdata_free();
320 player_thread = NULL;
321}
322#endif
323
324#ifdef HAVE_LIBREMIX
325static void
326_player_end(void *data __UNUSED__, Ecore_Thread *th __UNUSED__)
327{
328 // cleanup msdata outside of thread due to thread issues in dlsym etc.
329 _msdata_free();
330 player_thread = NULL;
331}
332#endif
333
334Eina_Bool
335_edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, const double speed)
336{
337 ssize_t size = 0;
338#ifdef ENABLE_MULTISENSE
339 Edje_Multisense_Sound_Action command;
340
341 if ((!pipe_initialized) && (!player_thread)) return EINA_FALSE;
342
343 command.action = EDJE_PLAY_SAMPLE;
344 command.ed = ed;
345 strncpy(command.type.sample.sample_name, sample_name, BUF_LEN);
346 command.type.sample.speed = speed;
347 size = write(command_pipe[1], &command, sizeof(command));
348#else
349 // warning shh
350 (void) ed;
351 (void) sample_name;
352 (void) speed;
353#endif
354 return (size == sizeof(Edje_Multisense_Sound_Action));
355}
356
357Eina_Bool
358_edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const double duration)
359{
360 ssize_t size = 0;
361#ifdef ENABLE_MULTISENSE
362 Edje_Multisense_Sound_Action command;
363
364 if ((!pipe_initialized) && (!player_thread)) return EINA_FALSE;
365 command.action = EDJE_PLAY_TONE;
366 command.ed = ed;
367 strncpy(command.type.tone.tone_name, tone_name, BUF_LEN);
368 command.type.tone.duration = duration;
369 size = write(command_pipe[1], &command, sizeof(command));
370#else
371 // warning shh
372 (void) ed;
373 (void) duration;
374 (void) tone_name;
375#endif
376 return (size == sizeof(Edje_Multisense_Sound_Action));
377
378}
379
380/* Initialize the modules in main thread. to avoid dlopen issue in the Threads */
381void
382_edje_multisense_init(void)
383{
384#ifdef ENABLE_MULTISENSE
385 if (!pipe_initialized && (pipe(command_pipe) != -1))
386 pipe_initialized = EINA_TRUE;
387
388 // init msdata outside of thread due to thread issues in dlsym etc.
389 if (!msdata) msdata = init_multisense_environment();
390
391 if (!player_thread)
392 player_thread = ecore_thread_run(_player_job, _player_end, _player_cancel, NULL);
393#endif
394}
395
396void
397_edje_multisense_shutdown(void)
398{
399#ifdef ENABLE_MULTISENSE
400 if (pipe_initialized)
401 {
402 close(command_pipe[1]);
403 close(command_pipe[0]);
404 }
405 if (player_thread) ecore_thread_cancel(player_thread);
406#endif
407}