[Gridflow-cvs] [svn] commit: r3500 - in /trunk/base: flow_objects.c flow_objects.rb

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Mon Apr 14 20:42:20 EDT 2008


Author: matju
Date: Mon Apr 14 20:42:20 2008
New Revision: 3500

Log:
rewrote [shunt] in c++

Modified:
    trunk/base/flow_objects.c
    trunk/base/flow_objects.rb

Modified: trunk/base/flow_objects.c
==============================================================================
--- trunk/base/flow_objects.c (original)
+++ trunk/base/flow_objects.c Mon Apr 14 20:42:20 2008
@@ -2935,6 +2935,45 @@
 }
 \end class {install("route2",1,1);}
 
+template <class T> int sgn(T a, T b=0) {return a<b?-1:a>b;}
+
+\class Shunt : FObject {
+	int n;
+	\attr int index;
+	\attr int mode;
+	\attr int hi;
+	\attr int lo;
+	\decl void initialize(int n=2, int i=0);
+	\decl void initialize2();
+	\decl void method_missing(...);
+	\decl 1 float(int i);
+};
+\def void initialize(int n=2, int i=0) {
+	SUPER;
+	this->n=n;
+	this->hi=n-1;
+	this->lo=0;
+	this->mode=0;
+	this->index=i;
+}
+\def void initialize2() {bself->noutlets_set(n);}
+\def void method_missing(...) {
+	t_atom at[argc];
+	ruby2pd(argc,argv,at);
+	t_symbol *sel = gensym(at[0].a_w.w_symbol->s_name+3);
+	outlet_anything(bself->out[index],sel,argc-1,at+1);
+	if (mode) {
+		index += sgn(mode);
+		if (index<lo || index>hi) {
+			int k = max(hi-lo+1,0);
+			int m = gf_abs(mode);
+			if (m==1) index = mod(index-lo,k)+lo; else {mode=-mode; index+=mode;}
+		}
+	}
+}
+\def 1 float(int i) {index = mod(i,n);}
+\end class {install("shunt",2,0); add_creator("demux");}
+
 //****************************************************************
 
 #define OP(x) op_dict[string(#x)]

Modified: trunk/base/flow_objects.rb
==============================================================================
--- trunk/base/flow_objects.rb (original)
+++ trunk/base/flow_objects.rb Mon Apr 14 20:42:20 2008
@@ -178,30 +178,6 @@
 	install "pd_netsocket", 2, 2
 end
 
-FObject.subclass("shunt",2,0) {
-	gfattr :index
-	gfattr :mode
-	gfattr :hi
-	gfattr :lo
-	def initialize(n=2,i=0) super; @n=n; @hi=n-1; @lo=0; @mode=0; @index=i end
-	def initialize2; self.noutlets= @n end
-	def method_missing(sel,*args)
-		sel.to_s =~ /^_(\d)_(.*)$/ or super
-		send_out @index,$2.intern,*args
-		if @mode!=0 then
-			@index += @mode<=>0
-			if @index<@lo or @index>@hi then
-				k = @hi- at lo+1
-				m = @mode.abs
-				if m==1 then @index = ((@index- at lo) % k)+ at lo
-				else @mode=- at mode; @index+=@mode end
-			end
-		end
-	end
-	def _1_float i; @index=i.to_i % @n end
-	add_creator "demux"
-}
-
 FObject.subclass("printargs",1,0) {
   def initialize(*args)
     super



More information about the Gridflow-cvs mailing list