# HG changeset patch # User William Pitcock # Date 1190138270 18000 # Node ID d4f9e45c1e2724eb54485b08a4aff0345d78003c # Parent a5b1084e7f3822f69fc493b6932b442333bd9b93 Flow manager. diff -r a5b1084e7f38 -r d4f9e45c1e27 src/audacious/Makefile --- a/src/audacious/Makefile Tue Sep 18 11:58:09 2007 -0500 +++ b/src/audacious/Makefile Tue Sep 18 12:57:50 2007 -0500 @@ -51,6 +51,7 @@ effect.c \ eventqueue.c \ fft.c \ + flow.c \ formatter.c \ general.c \ glade.c \ diff -r a5b1084e7f38 -r d4f9e45c1e27 src/audacious/flow.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/flow.c Tue Sep 18 12:57:50 2007 -0500 @@ -0,0 +1,121 @@ +/* + * Audacious + * Copyright (c) 2007 William Pitcock + * + * flow.c: flow management API. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * The Audacious team does not consider modular code linking to + * Audacious or using our public API to be a derived work. + */ + +#include "flow.h" + +mowgli_object_class_t flow_klass; + +static void +flow_destructor(Flow *flow) +{ + FlowElement *element, *element2; + + g_return_if_fail(flow != NULL); + + MOWGLI_ITER_FOREACH_SAFE(element, element2, flow->head) + g_slice_free(FlowElement, element); + + g_slice_free(Flow, flow); +} + +void flow_execute(Flow *flow, gpointer data, gsize len, AFormat fmt, + gint srate, gint channels) +{ + FlowElement *element; + FlowContext context = {}; + + g_return_if_fail(flow != NULL); + g_return_if_fail(data != NULL); + + context.data = data; + context.len = len; + context.fmt = fmt; + context.srate = srate; + context.channels = channels; + context.error = FALSE; + + MOWGLI_ITER_FOREACH(element, flow->head) + { + element->func(&context); + + if (context.error) + break; + } +} + +Flow * +flow_new(void) +{ + static int init = 0; + Flow *out; + + if (!init) + { + mowgli_object_class_init(&flow_klass, "audacious.flow", + (mowgli_destructor_t) flow_destructor, FALSE); + ++init; + } + + out = g_slice_new0(Flow); + mowgli_object_init(mowgli_object(out), NULL, &flow_klass, NULL); + + return out; +} + +void +flow_link_element(Flow *flow, FlowFunction func) +{ + FlowElement *element; + + g_return_if_fail(flow != NULL); + g_return_if_fail(func != NULL); + + element = g_slice_new0(FlowElement); + element->func = func; + element->prev = flow->tail; + + if (flow->tail) + flow->tail->next = element; + + flow->tail = element; +} + +/* TBD: unlink all elements of func, or just the first --nenolod */ +void +flow_unlink_element(Flow *flow, FlowFunction func) +{ + FlowElement *iter, *iter2; + + g_return_if_fail(flow != NULL); + g_return_if_fail(func != NULL); + + MOWGLI_ITER_FOREACH_SAFE(iter, iter2, flow->head) + if (iter->func == func) + { + if (iter->next) + iter->next->prev = iter->prev; + + iter->prev->next = iter->next; + + g_slice_free(FlowElement, iter); + } +} diff -r a5b1084e7f38 -r d4f9e45c1e27 src/audacious/flow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/flow.h Tue Sep 18 12:57:50 2007 -0500 @@ -0,0 +1,61 @@ +/* + * Audacious + * Copyright (c) 2007 William Pitcock + * + * flow.h: Definition of flow context structure, flow management API. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * The Audacious team does not consider modular code linking to + * Audacious or using our public API to be a derived work. + */ + +#include +#include + +#include "output.h" + +#ifndef __AUDACIOUS_FLOW_H__ +#define __AUDACIOUS_FLOW_H__ + +typedef struct { + gpointer data; + gsize len; + AFormat fmt; + gint srate; + gint channels; + gboolean error; +} FlowContext; + +typedef void (*FlowFunction)(FlowContext *ctx); + +typedef struct _FlowElement { + struct _FlowElement *prev, *next; + FlowFunction func; +} FlowElement; + +typedef struct { + mowgli_object_t parent; + FlowElement *head, *tail; +} Flow; + +void flow_execute(Flow *flow, gpointer data, gsize len, AFormat fmt, + gint srate, gint channels); + +Flow *flow_new(void); +void flow_link_element(Flow *flow, FlowFunction func); +void flow_unlink_element(Flow *flow, FlowFunction func); + +#define flow_destroy(flow) mowgli_object_unref(flow) + +#endif