Timer suggestion

mattgolsen's picture

I've got a composition that's going to be running 24 hours a day. Can anyone suggest a way to set up an alarm or timer to switch compositions at a specific time?

For example, say from 6am - 3pm, macro A plays, and at 3pm it switches/enables to macro B, and then on the following day it switches back?

I'm assuming the timeline patch would be best for something like this?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

DanieleCiabba's picture
this maybe help you

hi, MAttgolsen try this...

PreviewAttachmentSize
dateformatter.jpg
dateformatter.jpg141.79 KB
dateformatter.qtz5.33 KB
dateformatter1.png
dateformatter1.png1.22 MB

cwright's picture
JS Timeage

javascript has a bunch of time stuff built in to make this a snap.

// This doesn't actually use the input time, but the changing value causes it
// to update continually
 
var result = new Object();
 
function (__number day, __number hours, __number minutes, __number seconds) main (__number inputNumber)
{
   var now = new Date();
 
   result.day = now.getDay();
   result.hours = now.getHours();
   result.minutes = now.getMinutes();
   result.seconds = now.getSeconds();
 
   return result;
}

Then, plug in some always-changing value into the input (to keep the js patch evaluating every frame), like patch time or system time, and use the outputs as necessary. Use a Math Expression patch with something like "hours > 3" to output true when hours is greater than 3, or "hours > 6 && hours < 10" to output true when hours is between 6 and 10.

dwskau's picture
System Time

System time modulo 1036800 (the number of seconds in 2 days). Then just do a greater than or less than check for the period of time you want. If the switch time is midnight then you could just use x>518400 and x<=518400. Otherwise you might need to use x<## || x>#### and x>=## && x<=####.

cwright's picture
maths

24(hours/day) * 60(minutes/hour) * 60(seconds/minute) = 86400 (seconds/day). 86400 * 2 = 172800 -- not sure where 1036800 came from. (that's 12 days' worth of seconds).

modulo works too, as long as timezone stuff is sane (in my experience, timezone changes play hell on non-network-time-synced machines, and I hate dealing with those kinds of problems). sane = fixed/easily-derived offset you can add as an offset to keep stuff correct.

the JS above can also be extended to give you day-of-the-month, which is considerably trickier.

so, depends on what you need.

mattgolsen's picture
Ah, thanks

Thanks for the help, I set it up with an "Image with String" patch with a manually entered variable to indicate which timer is enabled. I'll attach it in case anyone else needs it.

Thanks again!

PreviewAttachmentSize
timer.qtz5.06 KB

mattgolsen's picture
Doh, more timing fun.

So, my composition has changed a little bit and I actually need to enable/disable patches by the minute on a 24 hour range. For example at 7:00am it starts showing Patch A (disabling C), at 7:06am it starts Patch B(disabling A), and then at 7:10am it shows Patch C(disabling B), after that the cycle would start over. So there are different time allotments for each patch. Not only that, but I also need to be able to add more patches down the road and change the timetable.

Also, if I use the above JS method using minutes instead of hours (minutes > 420 && minutes < 426, would be from 7am to 7:06am) I'd have to create like... 288 math patches to enable and disable everything by specific minute ranges.

I almost need a Javascript version of cron.

Any ideas? This is killing me.

cwright's picture
meet my blinky little friend

I think what you're looking for here is a boolean demultiplexer -- for the input, attach true, in the inspector panel, make sure the reset value thing is checked, and for the reset value, pick false, and you're in business -- you can now enable one of many patches by adjusting the index.

You'll still likely have to implement a lot of it in JS, but it'll be much neater than using a zillion math expression patches.

The JS patch can be modified from the above to use in-source tables to drive an index output, which can control which patch is active at a given time of day.

PreviewAttachmentSize
blinkyfriend-demux.qtz3.15 KB

toneburst's picture
Bools

The Boolean Demultiplexer trick is very handy. I've used it in the past for turning one of a groups GLSL Shaders on.

a|x http://machinesdontcare.wordpress.com

mattgolsen's picture
Y'know you kill me :D I see

Y'know you kill me :D

I see this stuff, file it away for later then I forget that I even saw it. Thanks for your help though, I need to send your a present or something for X-mas for all your awesome work.