github.com/256dpi/max-go@v0.7.0/lib/max/ext_time.h (about) 1 /* 2 * ext_time.h 3 * 4 * Copyright 2008 Cycling '74. All rights reserved. 5 * 6 */ 7 8 #ifndef __EXT_TIME_H__ 9 #define __EXT_TIME_H__ 10 11 #include "ext_itm.h" 12 13 BEGIN_USING_C_LINKAGE 14 15 16 17 /** 18 A high-level time object for tempo-based scheduling. 19 20 @ingroup time 21 @see #t_itm 22 @see @ref chapter_itm 23 */ 24 typedef t_object t_timeobject; 25 26 27 /*******************************************************************************/ 28 29 30 /** 31 Stop a currently scheduled time object. 32 33 @ingroup time 34 @param x The time object. 35 36 */ 37 void time_stop(t_timeobject *x); 38 39 40 /** 41 Execute a time object's task, then if it was already set to execute, reschedule for the current interval value of the object. 42 43 @ingroup time 44 @param x The time object. 45 46 */ 47 void time_tick(t_timeobject *x); 48 49 50 /** 51 Convert the value of a time object to milliseconds. 52 53 @ingroup time 54 @param x The time object. 55 @return The time object's value, converted to milliseconds. 56 */ 57 double time_getms(t_timeobject *x); 58 59 60 /** 61 Convert the value of a time object to ticks. 62 63 @ingroup time 64 @param x The time object. 65 @return The time object's value, converted to ticks. 66 */ 67 double time_getticks(t_timeobject *x); 68 69 70 /** 71 Return the phase of the ITM object (transport) associated with a time object. 72 73 @ingroup time 74 @param tx The time object. 75 @param phase Pointer to a double to receive the progress within the specified time value of the associated ITM object. 76 @param slope Pointer to a double to receive the slope (phase difference) within the specified time value of the associated ITM object. 77 @param ticks 78 */ 79 void time_getphase(t_timeobject *tx, double *phase, double *slope, double *ticks); 80 81 82 /** 83 Specify that a millisecond-based attribute to be updated automatically when the converted milliseconds of the time object's value changes. 84 85 @ingroup time 86 @param x The time object. 87 @param attr Name of the millisecond based attribute in the owning object that will be updated 88 @param flags If TIME_FLAGS_LISTENTICKS is passed here, updating will not happen if the time value is fixed (ms) based 89 */ 90 void time_listen(t_timeobject *x, t_symbol *attr, long flags); 91 92 93 /** 94 Set the current value of a time object (either an interval or a position) using a Max message. 95 96 @ingroup time 97 @param tx The time object. 98 @param s Message selector. 99 @param argc Count of arguments. 100 @param argv Message arguments. 101 */ 102 void time_setvalue(t_timeobject *tx, t_symbol *s, long argc, t_atom *argv); 103 104 /** 105 Create an attribute permitting a time object to be changed in a user-friendly way. 106 107 @ingroup time 108 @param c Class being initialized. 109 @param attrname Name of the attribute associated with the time object. 110 @param attrlabel Descriptive label for the attribute (appears in the inspector) 111 @param flags Options, see "Flags that determine time object behavior" above 112 */ 113 void class_time_addattr(t_class *c, const char *attrname, const char *attrlabel, long flags); 114 115 /** 116 Create a new time object. 117 118 @ingroup time 119 @param owner Object that will own this time object (task routine, if any, will pass owner as argument). 120 @param attrname Name of the attribute associated with the time object. 121 @param tick Task routine that will be executed (can be NULL) 122 @param flags Options, see "Flags that determine time object behavior" above 123 @return The newly created #t_timeobject. 124 */ 125 void *time_new(t_object *owner, t_symbol *attrname, method tick, long flags); 126 127 /** 128 Return a time object associated with an attribute of an owning object. 129 130 @ingroup time 131 @param owner Object that owns this time object (task routine, if any, will pass owner as argument). 132 @param attrname Name of the attribute associated with the time object. 133 @return The #t_timeobject associated with the named attribute. 134 */ 135 t_object *time_getnamed(t_object *owner, t_symbol *attrname); 136 137 138 void time_enable_attributes(t_object *x); 139 140 /** 141 Return whether this time object currently holds a fixed (millisecond-based) value. 142 143 @ingroup time 144 @param x Time object. 145 @return True if time object's current value is fixed, false if it is tempo-relative. 146 */ 147 long time_isfixedunit(t_timeobject *x); 148 149 150 /** 151 Schedule a task, with optional quantization. 152 153 @ingroup time 154 @param x The time object that schedules temporary events (must have been created with TIME_FLAGS_USECLOCK but not TIME_FLAGS_PERMANENT) 155 @param quantize A time object that holds a quantization interval, can be NULL for no quantization. 156 */ 157 void time_schedule(t_timeobject *x, t_timeobject *quantize); 158 159 160 /** 161 Schedule a task, with optional minimum interval, 162 163 @ingroup time 164 @param x The time object that schedules temporary events (must have been created with TIME_FLAGS_USECLOCK but not TIME_FLAGS_PERMANENT) 165 @param quantize The minimum interval into the future when the event can occur, can be NULL if there is no minimum interval. 166 */ 167 void time_schedule_limit(t_timeobject *x, t_timeobject *quantize); 168 169 /** 170 Schedule a task for right now, with optional quantization. 171 172 @ingroup time 173 @param x The time object that schedules temporary events. The time interval is ignored and 0 ticks is used instead. 174 @param quantize A time object that holds a quantization interval, can be NULL for no quantization. 175 */ 176 void time_now(t_timeobject *x, t_timeobject *quantize); 177 178 179 /** 180 Return the ITM object associated with this time object. 181 182 @ingroup time 183 @param ox Time object. 184 @return The associated #t_itm object. 185 */ 186 void *time_getitm(t_timeobject *ox); 187 188 189 /** 190 Calculate the quantized interval (in ticks) if this time object were to be scheduled at the current time. 191 192 @ingroup time 193 @param ox Time object. 194 @param vitm The associated ITM object (use time_getitm() to determine it). 195 @param oq A time object that holds a quantization interval, can be NULL. 196 @return Interval (in ticks) for scheduling this object. 197 */ 198 double time_calcquantize(t_timeobject *ox, t_itm *vitm, t_timeobject *oq); 199 200 201 /** 202 Associate a named setclock object with a time object (unsupported). 203 204 @ingroup time 205 @param tx Time object. 206 @param sc Name of an associated setclock object. 207 */ 208 void time_setclock(t_timeobject *tx, t_symbol *sc); 209 210 END_USING_C_LINKAGE 211 212 #endif // __EXT_TIME_H__ 213