missing commit in generator.h
[galan.git] / plugins / libreverse.c
blob2a9db682b02363be578e6456228d06e0c11226e5
1 /* gAlan - Graphical Audio Language
2 * Copyright (C) 1999 Tony Garnock-Jones
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <stddef.h>
24 #include <gdk/gdk.h>
25 #include <gtk/gtk.h>
26 #include <gmodule.h>
28 #include "global.h"
29 #include "generator.h"
30 #include "comp.h"
31 #include "control.h"
32 #include "gencomp.h"
34 #define GENERATOR_CLASS_NAME "reverse"
35 #define GENERATOR_CLASS_PATH "Timebase/Reverse"
37 #define SIG_INPUT 0
38 #define SIG_OUTPUT 0
40 PRIVATE SAMPLETIME output_range(Generator *g, OutputSignalDescriptor *sig) {
41 return gen_get_randomaccess_input_range(g, SIG_INPUT, 0);
44 PRIVATE gboolean output_generator(Generator *g, OutputSignalDescriptor *sig,
45 SAMPLETIME offset, SAMPLE *buf, int buflen) {
46 SAMPLETIME inoffset;
47 SAMPLETIME len = gen_get_randomaccess_input_range(g, SIG_INPUT, 0);
48 int inbuflen = buflen;
49 SAMPLE *inbuf = buf;
50 int i, j;
52 inoffset = len - offset - buflen;
54 if (inoffset <= -buflen)
55 return FALSE;
57 if (inoffset < 0) {
58 memset(buf, 0, -inoffset * sizeof(SAMPLE));
59 inbuflen += inoffset; /* *decrease* inbuflen */
60 inbuf += (-inoffset); /* *advance* inbuf */
61 inoffset = 0;
64 if (!gen_read_randomaccess_input(g, SIG_INPUT, 0, inoffset, inbuf, inbuflen))
65 return FALSE;
67 for (i = 0, j = (buflen - 1); i < j; i++, j--) {
68 SAMPLE tmp = buf[i];
69 buf[i] = buf[j];
70 buf[j] = tmp;
73 return TRUE;
76 PRIVATE InputSignalDescriptor input_sigs[] = {
77 { "Input", SIG_FLAG_RANDOMACCESS },
78 { NULL, }
81 PRIVATE OutputSignalDescriptor output_sigs[] = {
82 { "Output", SIG_FLAG_RANDOMACCESS, { NULL, { output_range, output_generator } } },
83 { NULL, }
86 PRIVATE ControlDescriptor controls[] = {
87 /* { kind, name, min,max,step,page, size,editable, is_dst,queue_number,
88 init,destroy,refresh,refresh_data }, */
89 { CONTROL_KIND_NONE, }
92 PRIVATE void setup_class(void) {
93 GeneratorClass *k = gen_new_generatorclass(GENERATOR_CLASS_NAME, FALSE, 0, 0,
94 input_sigs, output_sigs, controls,
95 NULL, NULL, NULL, NULL);
97 gencomp_register_generatorclass(k, FALSE, GENERATOR_CLASS_PATH,
98 NULL,
99 NULL);
102 PUBLIC void init_plugin(void) {
103 setup_class();