{"id":1396,"date":"2018-10-09T14:39:34","date_gmt":"2018-10-09T21:39:34","guid":{"rendered":"http:\/\/tre.ucsd.edu\/wordpress\/?p=1396"},"modified":"2018-10-09T14:39:49","modified_gmt":"2018-10-09T21:39:49","slug":"mus177206-seconds-c","status":"publish","type":"post","link":"https:\/\/tre.ucsd.edu\/wp7\/?p=1396","title":{"rendered":"MUS177\/206 &#8211; seconds.c"},"content":{"rendered":"<p>Here is seconds.c, which uses &lt;time.h&gt; functions to send the day and time out as a list (out of a single list outlet).<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<pre><i>\/* seconds.c -<span class=\"Apple-converted-space\">\u00a0\r\n<\/span><\/i><i> this object has 1 inlets and 6 outlets\r\n<\/i><i> it responds the 'bang' message in the left inlet\r\n<\/i><i> it responds to the 'assistance' message sent by Max when the mouse is positioned over an inlet or outlet\r\n<\/i><i> (including an assistance method is optional, but strongly sugggested)\r\n<\/i><i>*\/\r\n<\/i>#include &lt;time.h&gt;\r\n#include \"m_pd.h\"\r\n\r\n<b>typedef<\/b> <b>struct<\/b> _seconds <i>\/\/ defines our object's internal variables for each instance in a patch\r\n<\/i>{\r\n    t_object x_ob;\r\n    t_outlet *x_outlist;\r\n    t_atom date[6];\r\n} t_seconds;\r\n\r\nt_class *seconds_class; <i>\/\/ global pointer to the object class - so max can reference the object<span class=\"Apple-converted-space\">\u00a0\r\n<\/span><\/i><i>\/\/ these are prototypes for the methods that are defined below\r\n<\/i><b>void<\/b> seconds_bang(t_seconds *x);\r\n<b>void<\/b> *seconds_new(<b>void<\/b>);\r\n<b>void<\/b> seconds_setup(<b>void<\/b>);\r\n\r\n<i>\/\/--------------------------------------------------------------------------\r\n<\/i><b>void<\/b> seconds_setup(<b>void<\/b>)\r\n{\r\n    seconds_class = class_new(gensym(\"seconds\"), (t_newmethod)seconds_new, 0, <b>sizeof<\/b>(t_seconds), 0, 0);\r\n    class_addbang(seconds_class, seconds_bang);<i>\/\/ the method it uses when it gets a bang in the left inlet<span class=\"Apple-converted-space\">\u00a0\r\n<\/span><\/i>}\r\n\r\n<i>\/\/--------------------------------------------------------------------------\r\n<\/i><b>void<\/b> seconds_bang(t_seconds *x) <i>\/\/ x = reference to this instance of the object<span class=\"Apple-converted-space\">\u00a0\r\n<\/span><\/i>{\r\n    time_t rawTime;\r\n<b>        float<\/b> year, month, date, hour, min, sec;\r\n<b>        struct<\/b> tm *now;\r\n\r\n    time(&amp;rawTime);\r\n    now = gmtime(&amp;rawTime);\r\n    year = (now-&gt;tm_year + 1900);\r\n    month = (now-&gt;tm_mon + 1);\r\n    date = (now-&gt;tm_mday);\r\n    hour = now-&gt;tm_hour;\r\n    min = now-&gt;tm_min;\r\n    sec = now-&gt;tm_sec;\r\n    SETFLOAT(x-&gt;date+0, year);\r\n    SETFLOAT(x-&gt;date+1, month);\r\n    SETFLOAT(x-&gt;date+2, date);\r\n    SETFLOAT(x-&gt;date+3, hour);\r\n    SETFLOAT(x-&gt;date+4, min);\r\n    SETFLOAT(x-&gt;date+5, sec);\r\n    outlet_list(x-&gt;x_outlist, gensym(\"list\"), 6, (x-&gt;date));\r\n}\r\n\r\n\/\/--------------------------------------------------------------------------\r\n<b>void<\/b> *seconds_new(<b>void<\/b>) <i>\/\/ n = int argument typed into object box (A_DEFLONG) -- defaults to 0 if no args are typed\r\n<\/i>{\r\n    t_seconds *x;<i>\/\/ local variable (pointer to a t_seconds data structure        <\/i>x = (t_seconds *)pd_new(seconds_class); <i>\/\/ create a new instance of this object\r\n<\/i>       x-&gt;x_outlist = outlet_new(&amp;x-&gt;x_ob, gensym(\"list\"));\r\n<b>      return<\/b>(x); <i>\/\/ return a reference to the object instance<span class=\"Apple-converted-space\">\u00a0\r\n<\/span><\/i>}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is seconds.c, which uses &lt;time.h&gt; functions to send the day and time out as a list (out of a single list outlet). &nbsp; \/* seconds.c &#8211;\u00a0 this object has 1 inlets and 6 outlets it responds the &#8216;bang&#8217; message &hellip; <a href=\"https:\/\/tre.ucsd.edu\/wp7\/?p=1396\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"class_list":["post-1396","post","type-post","status-publish","format-standard","hentry","category-music-177","category-music-206"],"_links":{"self":[{"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=\/wp\/v2\/posts\/1396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1396"}],"version-history":[{"count":1,"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=\/wp\/v2\/posts\/1396\/revisions"}],"predecessor-version":[{"id":1397,"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=\/wp\/v2\/posts\/1396\/revisions\/1397"}],"wp:attachment":[{"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wp7\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}