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

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Mon Apr 14 15:43:57 EDT 2008


Author: matju
Date: Mon Apr 14 15:43:57 2008
New Revision: 3490

Log:
rewrote [unix_time] in c++ and fixed bug with seconds

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 15:43:57 2008
@@ -2731,6 +2731,39 @@
 
 //****************************************************************
 
+\class UnixTime : FObject {
+	\decl void initialize ();
+	\decl 0 bang ();
+};
+\def void initialize () {}
+\def 0 bang () {
+	timeval tv;
+	gettimeofday(&tv,0);
+	time_t t = time(0);
+	struct tm *tmp = localtime(&t);
+	if (!tmp) RAISE("localtime: %s",strerror(errno));
+	char tt[MAXPDSTRING];
+	strftime(tt,MAXPDSTRING,"%a %b %d %H:%M:%S %Z %Y",tmp);
+	t_atom a[6];
+	SETFLOAT(a+0,tmp->tm_year+1900);
+	SETFLOAT(a+1,tmp->tm_mon-1);
+	SETFLOAT(a+2,tmp->tm_mday);
+	SETFLOAT(a+3,tmp->tm_hour);
+	SETFLOAT(a+4,tmp->tm_min);
+	SETFLOAT(a+5,tmp->tm_sec);
+	t_atom b[3];
+	SETFLOAT(b+0,tv.tv_sec/86400);
+	SETFLOAT(b+1,mod(tv.tv_sec,86400));
+	SETFLOAT(b+2,tv.tv_usec);
+	outlet_anything(bself->out[2],&s_list,6,a);
+	outlet_anything(bself->out[1],&s_list,3,b);
+	send_out(0,strlen(tt),tt);
+}
+
+\end class UnixTime {install("unix_time",1,3);}
+
+//****************************************************************
+
 #define OP(x) op_dict[string(#x)]
 void startup_flow_objects () {
 	op_add = OP(+);

Modified: trunk/base/flow_objects.rb
==============================================================================
--- trunk/base/flow_objects.rb (original)
+++ trunk/base/flow_objects.rb Mon Apr 14 15:43:57 2008
@@ -76,18 +76,6 @@
 	end
 }
 
-FObject.subclass("unix_time",1,3) {
-  def _0_bang
-    t = Time.new
-    tt = t.to_s
-    send_out 2, t.year, t.month, t.day, t.hour, t.min, t.day
-    send_out 1, t.to_i/86400, t.to_i%86400,
-	((t.to_f-t.to_f.floor)*1000000).to_i
-    a=[]
-    for char in tt.split("") do a << char[0] end
-    send_out 0, :list, *a
-  end
-}
 FObject.subclass("exec",1,0) {def _0_shell(*a) system(a.map!{|x| x.to_s }.join(" ")) end}
 FObject.subclass("renamefile",1,0) {def initialize; end; def _0_list(a,b) File.rename(a.to_s,b.to_s) end}
 FObject.subclass("ls",1,1) {



More information about the Gridflow-cvs mailing list