Max 5 API Reference
00001 // ext_itm.h copyright 2008 cycling '74 all rights reserved 00002 00003 #ifndef __EXT_ITM_H__ 00004 #define __EXT_ITM_H__ 00005 00006 BEGIN_USING_C_LINKAGE 00007 00008 00009 /** A low-level object for tempo-based scheduling. 00010 @ingroup time 00011 @see #t_timeobject 00012 @see @ref chapter_itm */ 00013 typedef t_object t_itm; 00014 00015 00016 // private -- internal use only 00017 typedef struct _clocksource 00018 { 00019 t_object c_ob; 00020 method c_getticks; // returns the current tick count 00021 method c_getstate; // returns 0 if transport not going, 1 if going 00022 t_symbol *c_name; // name 00023 long c_usedcount; // number of transports using this clock source 00024 method c_gettempo; // get current tempo 00025 method c_gettimesig; // get current timesig 00026 } t_clocksource; 00027 00028 // used by clocksource to report time sig change to ITM 00029 00030 typedef struct _tschange { 00031 long c_num; 00032 long c_denom; 00033 double c_tsbaseticks; // ticks at last ts change (use -1 for "unknown") 00034 long c_tsbasebars; // bars at last ts change (use -1 for "unknown") 00035 } t_tschange; 00036 00037 /** Flags that determine attribute and time object behavior 00038 @ingroup time */ 00039 enum { 00040 TIME_FLAGS_LOCATION = 1, ///< 1 1 0 location-based bar/beat/unit values (as opposed to interval values, which are 0 0 0 relative) 00041 TIME_FLAGS_TICKSONLY = 2, ///< only ticks-based values (not ms) are acceptable 00042 TIME_FLAGS_FIXEDONLY = 4, ///< only fixed values (ms, hz, samples) are acceptable 00043 TIME_FLAGS_LOOKAHEAD = 8, ///< add lookahead attribute (unsupported) 00044 TIME_FLAGS_USECLOCK = 16, ///< this time object will schedule events, not just hold a value 00045 TIME_FLAGS_USEQELEM = 32, ///< this time object will defer execution of scheduled events to low priority thread 00046 TIME_FLAGS_FIXED = 64, ///< will only use normal clock (i.e., will never execute out of ITM) 00047 TIME_FLAGS_PERMANENT = 128, ///< event will be scheduled in the permanent list (tied to a specific time) 00048 TIME_FLAGS_TRANSPORT = 256, ///< add a transport attribute 00049 TIME_FLAGS_EVENTLIST = 512, ///< add an eventlist attribute (unsupported) 00050 TIME_FLAGS_CHECKSCHEDULE = 1024, ///< internal use only 00051 TIME_FLAGS_LISTENTICKS = 2048, ///< flag for time_listen: only get notifications if the time object holds tempo-relative values 00052 TIME_FLAGS_NOUNITS = 4096, ///< internal use only 00053 TIME_FLAGS_BBUSOURCE = 8192, ///< source time was in bar/beat/unit values, need to recalculate when time sig changes 00054 TIME_FLAGS_POSITIVE = 16384 ///< constrain any values < 0 to 0 00055 }; 00056 00057 00058 /*******************************************************************************/ 00059 00060 /** Return the global (default / unnamed) itm object. 00061 @ingroup time 00062 @return The global #t_itm object. */ 00063 void *itm_getglobal(void); 00064 00065 /** Return a named itm object. 00066 @ingroup time 00067 @param s The name of the itm to return. 00068 @param scheduler 00069 @param defaultclocksourcename 00070 @param create If non-zero, then create this named itm should it not already exist. 00071 @return The global #t_itm object. */ 00072 void *itm_getnamed(t_symbol *s, void *scheduler, t_symbol *defaultclocksourcename, long create); 00073 00074 // currently the same as itm_getnamed(s,true); 00075 void *itm_getfromarg(t_object *o, t_symbol *s); 00076 00077 /** Reference an itm object. 00078 When you are using an itm object, you must call this function to increment its reference count. 00079 @ingroup time 00080 @param x The itm object. */ 00081 void itm_reference(t_itm *x); 00082 00083 /** Stop referencing an itm object. 00084 When you are done using an itm object, you must call this function to decrement its reference count. 00085 @ingroup time 00086 @param x The itm object. */ 00087 void itm_dereference(t_itm *x); 00088 00089 00090 // event list support is limited to use in javascript for the time being. 00091 void itm_deleteeventlist(t_itm *x, t_symbol *eventlist); 00092 void itm_eventlistseek(t_itm *x); 00093 void itm_geteventlistnames(t_itm *x, long *count, t_symbol ***names); 00094 void itm_switcheventlist(t_itm *x, t_symbol *eventlist, double offset); 00095 00096 00097 /** Report the current internal time. 00098 This is the same as calling clock_getftime(); 00099 @ingroup time 00100 @param x The itm object. 00101 @return The current internal time. */ 00102 double itm_gettime(t_itm *x); 00103 00104 /** Report the current time of the itm in ticks. 00105 You can use functions such as itm_tickstobarbeatunits() or itm_tickstoms() to convert to a different representation of the time. 00106 @ingroup time 00107 @param x The itm object. 00108 @return The current time in ticks. */ 00109 double itm_getticks(t_itm *x); 00110 00111 /** Print diagnostic information about an itm object to the Max window. 00112 @ingroup time 00113 @param x The itm object. */ 00114 void itm_dump(t_itm *x); 00115 00116 00117 // private -- internal use only 00118 void itm_sync(t_itm *x); 00119 00120 00121 00122 /** Set an itm object's current time signature. 00123 @ingroup time 00124 @param x The itm object. 00125 @param num The top number of the time signature. 00126 @param denom The bottom number of the time signature. 00127 @param flags Currently unused -- pass zero. */ 00128 void itm_settimesignature(t_itm *x, long num, long denom, long flags); 00129 00130 /** Query an itm object for its current time signature. 00131 @ingroup time 00132 @param x The itm object. 00133 @param num The address of a variable to hold the top number of the time signature upon return. 00134 @param denom The address of a variable to hold the bottom number of the time signature upon return. */ 00135 void itm_gettimesignature(t_itm *x, long *num, long *denom); 00136 00137 void itm_seek(t_itm *x, double oldticks, double newticks, long chase); 00138 00139 /** Pause the passage of time for an itm object. 00140 This is the equivalent to setting the state of a transport object to 0 with a toggle. 00141 @ingroup time 00142 @param x The itm object. */ 00143 void itm_pause(t_itm *x); 00144 00145 /** Start the passage of time for an itm object, from it's current location. 00146 This is the equivalent to setting the state of a transport object to 0 with a toggle. 00147 @ingroup time 00148 @param x The itm object. */ 00149 void itm_resume(t_itm *x); 00150 00151 /** Find out if time is currently progressing for a given itm object. 00152 @ingroup time 00153 @param x The itm object. 00154 @return Returns non-zero if the time is running, or zero if it is paused. 00155 @see itm_pause() 00156 @see itm_resume() */ 00157 long itm_getstate(t_itm *x); 00158 00159 00160 /** Set the number of ticks-per-quarter-note globally for the itm system. 00161 The default is 480. 00162 @ingroup time 00163 @param res The number of ticks-per-quarter-note. 00164 @see itm_getresolution() */ 00165 void itm_setresolution(double res); 00166 00167 /** Get the number of ticks-per-quarter-note globally from the itm system. 00168 @ingroup time 00169 @return The number of ticks-per-quarter-note. 00170 @see itm_setresolution() */ 00171 double itm_getresolution(void); 00172 00173 00174 /** Given an itm object, return its name. 00175 @ingroup time 00176 @param x The itm object. 00177 @return The name of the itm. */ 00178 t_symbol *itm_getname(t_itm *x); 00179 00180 00181 00182 t_max_err itm_parse(t_itm *x, long argc, t_atom *argv, long flags, double *ticks, double *fixed, t_symbol **unit, long *bbu, char *bbusource); 00183 00184 00185 /** Convert a time value in ticks to the equivalent value in milliseconds, given the context of a specified itm object. 00186 @ingroup time 00187 @param x An itm object. 00188 @param ticks A time specified in ticks. 00189 @return The time specified in ms. */ 00190 double itm_tickstoms(t_itm *x, double ticks); 00191 00192 /** Convert a time value in milliseconds to the equivalent value in ticks, given the context of a specified itm object. 00193 @ingroup time 00194 @param x An itm object. 00195 @param ms A time specified in ms. 00196 @return The time specified in ticks. */ 00197 double itm_mstoticks(t_itm *x, double ms); 00198 00199 /** Convert a time value in milliseconds to the equivalent value in samples, given the context of a specified itm object. 00200 @ingroup time 00201 @param x An itm object. 00202 @param ms A time specified in ms. 00203 @return The time specified in samples. */ 00204 double itm_mstosamps(t_itm *x, double ms); 00205 00206 /** Convert a time value in samples to the equivalent value in milliseconds, given the context of a specified itm object. 00207 @ingroup time 00208 @param x An itm object. 00209 @param samps A time specified in samples. 00210 @return The time specified in ms. */ 00211 double itm_sampstoms(t_itm *x, double samps); 00212 00213 00214 /** Convert a time value in bbu to the equivalent value in ticks, given the context of a specified itm object. 00215 @ingroup time 00216 @param x An itm object. 00217 @param bars The measure number of the location/position. 00218 @param beats The beat number of the location/position. 00219 @param units The number of ticks past the beat of the location/position. 00220 @param ticks The address of a variable to hold the number of ticks upon return. 00221 @param position Set this parameter to #TIME_FLAGS_LOCATION or to zero (for position mode). */ 00222 void itm_barbeatunitstoticks(t_itm *x, long bars, long beats, double units, double *ticks, char position); 00223 00224 /** Convert a time value in bbu to the equivalent value in ticks, given the context of a specified itm object. 00225 @ingroup time 00226 @param x An itm object. 00227 @param ticks The number of ticks to translate into a time represented as bars, beats, and ticks. 00228 @param bars The address of a variable to hold the measure number of the location/position upon return. 00229 @param beats The address of a variable to hold the beat number of the location/position upon return. 00230 @param units The address of a variable to hold the number of ticks past the beat of the location/position upon return. 00231 @param position Set this parameter to #TIME_FLAGS_LOCATION or to zero (for position mode). */ 00232 void itm_tickstobarbeatunits(t_itm *x, double ticks, long *bars, long *beats, double *units, char position); 00233 00234 00235 void itm_format(t_itm *x, double ms, double ticks, long flags, t_symbol *unit, long *argc, t_atom **argv); 00236 00237 00238 /** Given the name of a time unit (e.g. 'ms', 'ticks', 'bbu', 'samples', etc.), determine whether the unit is fixed 00239 (doesn't change with tempo, time-signature, etc.) or whether it is flexible. 00240 @ingroup time 00241 @param u The name of the time unit. 00242 @return Zero if the unit is fixed (milliseconds, for example) or non-zero if it is flexible (ticks, for example). */ 00243 long itm_isunitfixed(t_symbol *u); 00244 00245 00246 00247 void itmclock_delay(t_object *x, t_itm *m, t_symbol *eventlist, double delay, long quantization); 00248 void *itmclock_new(t_object *owner, t_object *timeobj, method task, method killer, long permanent); 00249 void itmclock_set(t_object *x, t_itm *m, t_symbol *eventlist, double time); 00250 void itmclock_unset(t_object *x); 00251 00252 00253 // private -- internal use only 00254 void *itm_clocksource_getnamed(t_symbol *name, long create); 00255 void itm_getclocksources(long *count, t_symbol ***sources); 00256 00257 00258 END_USING_C_LINKAGE 00259 00260 #endif // __EXT_ITM_H__
Copyright © 2008, Cycling '74