aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas O Fredericks <mrtof@users.sourceforge.net>2009-10-22 20:44:21 +0000
committerThomas O Fredericks <mrtof@users.sourceforge.net>2009-10-22 20:44:21 +0000
commit6f4d941dacfb9df57f55f601154d3528a5b5db28 (patch)
treef066b1b1c01e2ff43b416f6ca6284cf266399c29 /src
parentd82c79024b44f96d3c5f613cfb93cc9c9d917ff9 (diff)
Created common out of put~ and get~
svn path=/trunk/externals/tof/; revision=12646
Diffstat (limited to 'src')
-rw-r--r--src/common~.c247
-rw-r--r--src/get~.c95
-rw-r--r--src/putget~.h136
-rw-r--r--src/put~.c90
4 files changed, 247 insertions, 321 deletions
diff --git a/src/common~.c b/src/common~.c
new file mode 100644
index 0000000..573eaf1
--- /dev/null
+++ b/src/common~.c
@@ -0,0 +1,247 @@
+//#include "commonget~.h"
+#include "m_pd.h"
+
+
+typedef struct _common {
+ t_symbol* name;
+ t_sample a[64];
+ t_sample b[64];
+ t_sample* w;
+ t_sample* r;
+ //int writers;
+ //int written;
+ int users;
+ struct _common* next;
+ struct _common* previous;
+ t_clock* clock;
+ int armed;
+
+} t_common;
+
+
+static t_common* common;
+
+
+// This should be triggered by the clock
+static void common_swap(t_common* pg) {
+ //post("clock");
+
+ t_sample* temp = pg->r;
+ pg->r = pg->w;
+ pg->w = temp;
+
+ int i;
+ t_sample* samples = pg->w;
+ for (i=0;i<64;i++) {
+ *samples++ = 0;
+
+ }
+
+ pg->armed = 0;
+
+ //if (pg == NULL) post("ouc");
+ //pg->written = 0;
+
+}
+
+static t_common* common_register(t_symbol* name) {
+
+ t_common* new_common;
+
+ //is_writer = is_writer ? 1 : 0;
+
+ t_common* pg = common;
+
+ if ( pg != NULL) {
+
+ // Search for previous common
+ while( pg ) {
+ if ( pg->name == name) {
+ //#ifdef PARAMDEBUG
+ // post("Found put/get with same name");
+ //#endif
+ //pg->writers = pg->writers + is_writer;
+ pg->users = pg->users + 1;
+ return pg;
+ }
+ if ( pg->next == NULL ) break;
+ pg = pg->next;
+ }
+ }
+
+
+ //post("Appending new put/get");
+ // Append new common
+ new_common = getbytes(sizeof(*new_common));
+ new_common->name = name;
+ //new_common->writers = is_writer;
+ new_common->users = 1;
+ new_common->armed = 0;
+
+ new_common->clock = clock_new(new_common, (t_method)common_swap);
+
+ new_common->r = new_common->a;
+ new_common->w = new_common->b;
+
+ new_common->previous = pg;
+ if ( pg) {
+ pg->next = new_common;
+ } else {
+ common = new_common;
+ }
+
+ return new_common;
+
+}
+
+
+static void common_unregister(t_common* pg) {
+
+ //post("Trying to remove %s",pg->name->s_name);
+
+ //if ( is_writer) pg->writers = pg->writers - 1;
+ pg->users = pg->users - 1;
+ if ( pg->users <= 0) {
+ //post("Removing last put/get of this name");
+ if (pg->previous) {
+ pg->previous->next = pg->next;
+ if (pg->next) pg->next->previous = pg->previous;
+ } else {
+ common = pg->next;
+ if ( pg->next != NULL) pg->next->previous = NULL;
+ }
+ clock_free(pg->clock);
+ freebytes(pg, sizeof *(pg) );
+ }
+}
+
+
+static void common_arm(t_common* pg) {
+
+ if (!pg->armed) {
+ pg->armed = 1;
+ clock_delay(pg->clock, 0);
+ }
+
+}
+
+///////////////
+// The class //
+///////////////
+
+static t_class *common_tilde_class;
+
+typedef struct _common_tilde {
+ t_object x_obj;
+ //t_sample f_common;
+ t_common* pg;
+ t_sample f;
+} t_common_tilde;
+
+static t_int* common_tilde_perform(t_int *w)
+{
+
+ t_common_tilde *x = (t_common_tilde *)(w[1]);
+
+ t_sample *in = (t_sample *)(w[2]);
+ t_sample *out= (t_sample *)(w[3]);
+ int n = (int)(w[4]);
+ int m;
+ t_sample *samples;
+
+
+ if ( x->pg) {
+
+ // Do adding
+ //if (x->pg->users > x->pg->writers) {
+ samples = x->pg->w;
+ m = n;
+ while (m--) {
+ *samples = *samples + *in;
+ samples++; in++;
+ }
+
+ //}
+
+
+ // Do reading
+ samples = x->pg->r;
+ m = n;
+ while (m--) {
+ *out++ = *samples++;
+ }
+
+ // Arm for swaping
+ common_arm( x->pg);
+
+ } else {
+
+ while (n--) {
+ *out++ = 0;
+ }
+
+ }
+
+ return (w+5);
+}
+
+
+static void common_tilde_set(t_common_tilde *x, t_symbol* s) {
+
+ if (gensym("") != s ) {
+ if ( x->pg ) {
+ if ( x->pg->name != s) {
+ common_unregister(x->pg);
+ x->pg = common_register(s);
+ }
+ } else {
+ x->pg = common_register(s);
+ }
+ }
+
+}
+
+
+static void common_tilde_dsp(t_common_tilde *x, t_signal **sp)
+{
+
+ if ( (int) sp[0]->s_n == 64 ) {
+ dsp_add(common_tilde_perform, 4, x,sp[0]->s_vec,sp[1]->s_vec, sp[0]->s_n);
+
+ } else {
+ error("common~ only works with a block size of 64");
+ }
+
+}
+
+static void common_tilde_free( t_common_tilde *x) {
+
+ if (x->pg) common_unregister(x->pg);
+}
+
+
+static void *common_tilde_new(t_symbol* s)
+{
+ t_common_tilde *x = (t_common_tilde *)pd_new(common_tilde_class);
+
+ if (gensym("") != s ) x->pg = common_register(s);
+
+ outlet_new(&x->x_obj, &s_signal);
+
+ return (void *)x;
+}
+
+void common_tilde_setup(void) {
+ common_tilde_class = class_new(gensym("common~"),
+ (t_newmethod)common_tilde_new,
+ (t_method)common_tilde_free, sizeof(t_common_tilde),
+ 0, A_DEFSYM, 0);
+
+ class_addmethod(common_tilde_class,
+ (t_method)common_tilde_dsp, gensym("dsp"), 0);
+
+ class_addmethod(common_tilde_class,
+ (t_method)common_tilde_set, gensym("set"), A_SYMBOL, 0);
+
+ CLASS_MAINSIGNALIN(common_tilde_class, t_common_tilde, f);
+}
diff --git a/src/get~.c b/src/get~.c
deleted file mode 100644
index 33e761e..0000000
--- a/src/get~.c
+++ /dev/null
@@ -1,95 +0,0 @@
-#include "putget~.h"
-
-static t_class *get_tilde_class;
-
-typedef struct _get_tilde {
- t_object x_obj;
- t_sample f_put;
- struct putget* pg;
- t_sample f;
-} t_get_tilde;
-
-t_int *get_tilde_perform(t_int *w)
-{
- t_get_tilde *x = (t_get_tilde *)(w[1]);
- t_sample *out = (t_sample *)(w[2]);
- int n = (int)(w[3]);
-
- if ( x->pg) {
-
- putget_arm( x->pg);
-
-
- t_sample *samples = x->pg->r;
-
- while (n--) {
- *out++ = *samples++;
- }
- } else {
- while (n--) {
- *out++ = 0;
- }
- }
-
- return (w+4);
-}
-
-static void get_tilde_set(t_get_tilde *x, t_symbol* s) {
-
- if (gensym("") != s ) {
- if ( x->pg ) {
- if ( x->pg->name != s) {
- putget_unregister(x->pg,0);
- x->pg = putget_register(s,0);
- }
- } else {
- x->pg = putget_register(s,0);
- }
- }
-
-}
-
-void get_tilde_dsp(t_get_tilde *x, t_signal **sp)
-{
-
- if ( sp[0]->s_n == 64 ) {
- dsp_add(get_tilde_perform, 3, x,sp[0]->s_vec, sp[0]->s_n);
- } else {
- pd_error(x,"get~ only works with a block size of 64");
- }
-}
-
-static void get_tilde_free( t_get_tilde *x) {
-
- if (x->pg) putget_unregister(x->pg,0);
-}
-
-
-void *get_tilde_new(t_symbol* s)
-{
- t_get_tilde *x = (t_get_tilde *)pd_new(get_tilde_class);
-
-count = count + 1;
-post("c:%i",count);
-
- if (gensym("") != s ) x->pg = putget_register(s,0);
-
- outlet_new(&x->x_obj, &s_signal);
-
- return (void *)x;
-}
-
-void get_tilde_setup(void) {
- get_tilde_class = class_new(gensym("get~"),
- (t_newmethod)get_tilde_new,
- (t_method)get_tilde_free, sizeof(t_get_tilde),
- CLASS_DEFAULT,
- A_DEFSYMBOL, 0);
-
- class_addmethod(get_tilde_class,
- (t_method)get_tilde_set, gensym("set"), A_SYMBOL, 0);
-
- class_addmethod(get_tilde_class,
- (t_method)get_tilde_dsp, gensym("dsp"), 0);
- //CLASS_MAINSIGNALIN(get_tilde_class, t_get_tilde, f);
-}
diff --git a/src/putget~.h b/src/putget~.h
deleted file mode 100644
index a796653..0000000
--- a/src/putget~.h
+++ /dev/null
@@ -1,136 +0,0 @@
-#include "m_pd.h"
-
-/*
- typedef struct _param_inlet2
-{
- t_object x_obj;
- t_param *p_owner;
-} t_param_inlet2;
-
-*/
-
-struct putget {
- t_symbol* name;
- t_sample a[64];
- t_sample b[64];
- t_sample* w;
- t_sample* r;
- int writers;
- //int written;
- int users;
- struct putget* next;
- struct putget* previous;
- t_clock* clock;
- int armed;
-
-};
-
-
-struct putget* PUTGETS;
-
-int count = 42;
-
-// This should be triggered by the clock
-static void putget_swap(struct putget* pg) {
- //post("clock");
-
- t_sample* temp = pg->r;
- pg->r = pg->w;
- pg->w = temp;
-
- int i;
- t_sample* samples = pg->w;
- for (i=0;i<64;i++) {
- *samples++ = 0;
-
- }
-
- pg->armed = 0;
-
- //if (pg == NULL) post("ouc");
- //pg->written = 0;
-
-}
-
-static struct putget* putget_register(t_symbol* name, int is_writer) {
-
- struct putget* new_putget;
-
- is_writer = is_writer ? 1 : 0;
-
- struct putget* pg = PUTGETS;
-
- if ( pg != NULL) {
-
- // Search for previous putget
- while( pg ) {
- if ( pg->name == name) {
- //#ifdef PARAMDEBUG
- // post("Found put/get with same name");
- //#endif
- pg->writers = pg->writers + is_writer;
- pg->users = pg->users + 1;
- return pg;
- }
- if ( pg->next == NULL ) break;
- pg = pg->next;
- }
- }
-
-
- //post("Appending new put/get");
- // Append new putget
- new_putget = getbytes(sizeof(*new_putget));
- new_putget->name = name;
- new_putget->writers = is_writer;
- new_putget->users = 1;
- new_putget->armed = 0;
-
- new_putget->clock = clock_new(new_putget, (t_method)putget_swap);
-
- new_putget->r = new_putget->a;
- new_putget->w = new_putget->b;
-
- new_putget->previous = pg;
- if ( pg) {
- pg->next = new_putget;
- } else {
- PUTGETS = new_putget;
- }
-
- return new_putget;
-
-}
-
-
-static void putget_unregister(struct putget* pg, int is_writer) {
-
- //post("Trying to remove %s",pg->name->s_name);
-
- if ( is_writer) pg->writers = pg->writers - 1;
- pg->users = pg->users - 1;
- if ( pg->users <= 0) {
- //post("Removing last put/get of this name");
- if (pg->previous) {
- pg->previous->next = pg->next;
- if (pg->next) pg->next->previous = pg->previous;
- } else {
- PUTGETS = pg->next;
- if ( pg->next != NULL) pg->next->previous = NULL;
- }
- clock_free(pg->clock);
- freebytes(pg, sizeof *(pg) );
- }
-}
-
-
-static void putget_arm(struct putget* pg) {
-
- if (!pg->armed) {
- pg->armed = 1;
- clock_delay(pg->clock, 0);
- }
-
-}
-
-
diff --git a/src/put~.c b/src/put~.c
deleted file mode 100644
index 0eb5415..0000000
--- a/src/put~.c
+++ /dev/null
@@ -1,90 +0,0 @@
-#include "putget~.h"
-
-static t_class *put_tilde_class;
-
-typedef struct _put_tilde {
- t_object x_obj;
- //t_sample f_put;
- struct putget* pg;
- t_sample f;
-} t_put_tilde;
-
-static t_int* put_tilde_perform(t_int *w)
-{
-
- t_put_tilde *x = (t_put_tilde *)(w[1]);
-
- if (x->pg && (x->pg->users > x->pg->writers)) {
- t_sample *in = (t_sample *)(w[2]);
- int n = (int)(w[3]);
- t_sample *samples = x->pg->w;
-
- while (n--) {
- *samples = *samples + *in;
- samples++; in++;
- }
-
- }
- return (w+4);
-}
-
-
-static void put_tilde_set(t_put_tilde *x, t_symbol* s) {
-
- if (gensym("") != s ) {
- if ( x->pg ) {
- if ( x->pg->name != s) {
- putget_unregister(x->pg,1);
- x->pg = putget_register(s,1);
- }
- } else {
- x->pg = putget_register(s,1);
- }
- }
-
-}
-
-
-static void put_tilde_dsp(t_put_tilde *x, t_signal **sp)
-{
-
- if ( (int) sp[0]->s_n == 64 ) {
- dsp_add(put_tilde_perform, 3, x,sp[0]->s_vec, sp[0]->s_n);
-
- } else {
- error("put~ only works with a block size of 64");
- }
-
-}
-
-static void put_tilde_free( t_put_tilde *x) {
-
- if (x->pg) putget_unregister(x->pg,1);
-}
-
-
-static void *put_tilde_new(t_symbol* s)
-{
- t_put_tilde *x = (t_put_tilde *)pd_new(put_tilde_class);
-
- if (gensym("") != s ) x->pg = putget_register(s,1);
-
- count = count + 1;
-post("c:%i",count);
- return (void *)x;
-}
-
-void put_tilde_setup(void) {
- put_tilde_class = class_new(gensym("put~"),
- (t_newmethod)put_tilde_new,
- (t_method)put_tilde_free, sizeof(t_put_tilde),
- 0, A_DEFSYM, 0);
-
- class_addmethod(put_tilde_class,
- (t_method)put_tilde_dsp, gensym("dsp"), 0);
-
- class_addmethod(put_tilde_class,
- (t_method)put_tilde_set, gensym("set"), A_SYMBOL, 0);
-
- CLASS_MAINSIGNALIN(put_tilde_class, t_put_tilde, f);
-}