2 * libremix -- An audio mixing and sequencing library.
4 * Copyright (C) 2001 Commonwealth Scientific and Industrial Research
5 * Organisation (CSIRO), Australia.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library 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 GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * RemixContext: REMIX core context.
26 * Conrad Parker <conrad@metadecks.org>, August 2001
35 remix_plugin_destroy (RemixEnv * env, RemixPlugin * plugin)
37 if (plugin->destroy) {
38 plugin->destroy (env, plugin);
43 remix_context_destroy (RemixEnv * env)
45 RemixContext * ctx = env->context;
46 RemixWorld * world = env->world;
50 world->plugins = cd_list_destroy_with (env, world->plugins, remix_plugin_destroy);
51 remix_plugin_defaults_unload (env);
53 //world->bases = cd_list_destroy_with (env, world->bases, remix_destroy);
55 remix_channelset_defaults_destroy (env);
61 remix_add_thread_context (RemixContext * ctx, RemixWorld * world)
63 RemixEnv * env = remix_malloc (sizeof (struct _RemixThreadContext));
71 _remix_context_copy (RemixEnv * env, RemixContext * dest)
73 RemixContext * ctx = env->context;
75 if (dest == RemixNone) {
76 remix_set_error (env, REMIX_ERROR_NOENTITY);
80 dest->samplerate = ctx->samplerate;
81 dest->tempo = ctx->tempo;
82 dest->mixlength = ctx->mixlength;
83 dest->channels = cd_set_clone_keys (env, ctx->channels);
89 * _remix_context_merge (env, dest)
91 * Merges the context of env into context 'dest'. Copies over the samplerate
92 * and tempo, and expands the mixlength and channels if they are greater in
93 * 'env's context than in 'dest'.
96 _remix_context_merge (RemixEnv * env, RemixContext * dest)
98 RemixContext * ctx = env->context;
102 if (dest == RemixNone) {
103 remix_set_error (env, REMIX_ERROR_NOENTITY);
107 dest->samplerate = ctx->samplerate;
108 dest->tempo = ctx->tempo;
110 if (ctx->mixlength > dest->mixlength)
111 dest->mixlength = ctx->mixlength;
113 for (s = ctx->channels; s; s = s->next) {
114 k = cd_set_find (env, dest->channels, s->key);
115 if (k.s_pointer == NULL)
116 dest->channels = cd_set_insert (env, dest->channels, s->key,
131 (RemixWorld *) remix_malloc (sizeof (struct _RemixWorld));
133 (RemixContext *) remix_malloc (sizeof (struct _RemixContext));
136 world->plugins = cd_list_new (ctx);
137 world->bases = cd_list_new (ctx);
138 world->purging = FALSE;
140 ctx->mixlength = REMIX_DEFAULT_MIXLENGTH;
141 ctx->samplerate = REMIX_DEFAULT_SAMPLERATE;
142 ctx->tempo = REMIX_DEFAULT_TEMPO;
144 env = remix_add_thread_context (ctx, world);
145 remix_channelset_defaults_initialise (env);
146 ctx->channels = REMIX_MONO;
148 remix_plugin_defaults_initialise (env);
154 * remix_init_clone ()
157 remix_init_clone (RemixEnv * env)
159 RemixEnv * new_env = remix_add_thread_context (env->context, env->world);
164 remix_purge (RemixEnv * env)
166 RemixWorld * world = env->world;
168 if (world->refcount <= 0) {
169 remix_context_destroy (env);
175 remix_set_error (RemixEnv * env, RemixError error)
177 RemixError old = env->last_error;
178 env->last_error = error;
183 remix_last_error (RemixEnv * env)
185 return env->last_error;
189 remix_set_mixlength (RemixEnv * env, RemixCount mixlength)
191 RemixContext * ctx = env->context;
192 RemixCount old = ctx->mixlength;
193 ctx->mixlength = mixlength;
198 remix_get_mixlength (RemixEnv * env)
200 RemixContext * ctx = env->context;
201 return ctx->mixlength;
205 remix_set_samplerate (RemixEnv * env, RemixSamplerate samplerate)
207 RemixContext * ctx = env->context;
208 RemixSamplerate old = ctx->samplerate;
209 ctx->samplerate = samplerate;
214 remix_get_samplerate (RemixEnv * env)
216 RemixContext * ctx = env->context;
217 return ctx->samplerate;
221 remix_set_tempo (RemixEnv * env, RemixTempo tempo)
223 RemixContext * ctx = env->context;
224 RemixTempo old = ctx->tempo;
230 remix_get_tempo (RemixEnv * env)
232 RemixContext * ctx = env->context;
237 remix_set_channels (RemixEnv * env, CDSet * channels)
239 RemixContext * ctx = env->context;
240 CDSet * old = ctx->channels;
241 ctx->channels = cd_set_clone_keys (env, channels);
246 remix_get_channels (RemixEnv * env)
248 RemixContext * ctx = env->context;
249 return ctx->channels;
253 _remix_register_plugin (RemixEnv * env, RemixPlugin * plugin)
255 RemixWorld * world = env->world;
256 remix_dprintf ("[_remix_register_plugin] REGISTERING %s\n",
257 plugin->metatext ? plugin->metatext->identifier : "(\?\?\?)");
258 world->plugins = cd_list_append (env, world->plugins, CD_POINTER(plugin));
263 _remix_unregister_plugin (RemixEnv * env, RemixPlugin * plugin)
265 RemixWorld * world = env->world;
266 if (world->purging) return env;
268 world->plugins = cd_list_remove (env, world->plugins, CD_TYPE_POINTER,
274 _remix_register_base (RemixEnv * env, RemixBase * base)
276 RemixWorld * world = env->world;
277 world->bases = cd_list_append (env, world->bases, CD_POINTER(base));
282 _remix_unregister_base (RemixEnv * env, RemixBase * base)
284 RemixWorld * world = env->world;
285 if (world->purging) return env;
287 world->bases = cd_list_remove (env, world->bases, CD_TYPE_POINTER,
293 plugin_id_eq (RemixEnv * env, RemixPlugin * plugin, char * identifier)
295 if (plugin == RemixNone) return FALSE;
296 if (plugin->metatext == RemixNone) return FALSE;
297 return !(strcmp(plugin->metatext->identifier, identifier));
301 remix_find_plugin (RemixEnv * env, char * identifier)
303 RemixWorld * world = env->world;
304 CDList * l = cd_list_find_first (env, world->plugins, CD_TYPE_POINTER,
305 (CDCmpFunc)plugin_id_eq,
306 CD_POINTER(identifier));
308 if (l == RemixNone) return RemixNone;
309 return (RemixPlugin *)l->data.s_pointer;