aboutsummaryrefslogtreecommitdiff
path: root/src/time.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
commit2b60d55c919e7588f5aff15936e83c300b3660bb (patch)
tree14d860de7f28083d3756ad91b627de70f26788f6 /src/time.c
parentc500bc542cb7cc78d6dac3f7da3bff626056b1aa (diff)
zexy-2.0:
- use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641
Diffstat (limited to 'src/time.c')
-rw-r--r--src/time.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/time.c b/src/time.c
new file mode 100644
index 0000000..4f54871
--- /dev/null
+++ b/src/time.c
@@ -0,0 +1,122 @@
+/******************************************************
+ *
+ * zexy - implementation file
+ *
+ * copyleft (c) IOhannes m zmölnig
+ *
+ * 1999:forum::für::umläute:2004
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+/*
+ (c) 1202:forum::für::umläute:2000
+ 1506:forum::für::umläute:2003: use timeb only if needed (like on windoze)
+
+ "time" gets the current time from the system
+ "date" gets the current date from the system
+
+*/
+
+#ifdef NT
+#define USE_TIMEB
+#endif
+
+#ifdef MACOSX
+#include <sys/types.h>
+/* typedef _BSD_TIME_T_ time_t; */
+#endif
+
+
+#include "zexy.h"
+#include <time.h>
+
+#ifdef USE_TIMEB
+#include <sys/timeb.h>
+#else
+#include <sys/time.h>
+#endif
+
+
+/* ----------------------- time --------------------- */
+
+static t_class *time_class;
+
+typedef struct _time
+{
+ t_object x_obj;
+
+ int GMT;
+
+ t_outlet *x_outlet1;
+ t_outlet *x_outlet2;
+ t_outlet *x_outlet3;
+ t_outlet *x_outlet4;
+} t_time;
+
+static void *time_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_time *x = (t_time *)pd_new(time_class);
+ char buf[5];
+
+ x->GMT=0;
+ if (argc) {
+ atom_string(argv, buf, 5);
+ if (buf[0]=='G' && buf[1]=='M' && buf[2]=='T')
+ x->GMT = 1;
+ }
+
+ x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
+ x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
+ x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
+ x->x_outlet4 = outlet_new(&x->x_obj, &s_float);
+
+ return (x);
+}
+
+static void time_bang(t_time *x)
+{
+ struct tm *resolvetime;
+ float ms = 0.f;
+#ifdef USE_TIMEB
+ struct timeb mytime;
+ ftime(&mytime);
+ resolvetime = (x->GMT)?gmtime(&mytime.time):localtime(&mytime.time);
+ ms=mytime.millitm;
+#else
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ resolvetime = (x->GMT)?gmtime(&tv.tv_sec):localtime(&tv.tv_sec);
+ ms = tv.tv_usec*0.001;
+#endif
+ // outlet_float(x->x_outlet4, (t_float)(mytime.millitm));
+ outlet_float(x->x_outlet4, (t_float)(ms));
+ outlet_float(x->x_outlet3, (t_float)resolvetime->tm_sec);
+ outlet_float(x->x_outlet2, (t_float)resolvetime->tm_min);
+ outlet_float(x->x_outlet1, (t_float)resolvetime->tm_hour);
+}
+
+static void help_time(t_time *x)
+{
+ post("\n%c time\t\t:: get the current system time", HEARTSYMBOL);
+ post("\noutputs are\t: hour / minute / sec / msec");
+ post("\ncreation\t:: 'time [GMT]': show local time or GMT");
+}
+
+void time_setup(void)
+{
+ time_class = class_new(gensym("time"),
+ (t_newmethod)time_new, 0,
+ sizeof(t_time), 0, A_GIMME, 0);
+
+ class_addbang(time_class, time_bang);
+
+ class_addmethod(time_class, (t_method)help_time, gensym("help"), 0);
+ class_sethelpsymbol(time_class, gensym("zexy/time"));
+ zexy_register("time");
+}