github.com/256dpi/max-go@v0.7.0/lib/max/ext_itm.h (about)

     1  // ext_itm.h copyright 2008 cycling '74 all rights reserved
     2  
     3  #ifndef __EXT_ITM_H__
     4  #define __EXT_ITM_H__
     5  
     6  #include "ext_prefix.h"
     7  #include "ext_mess.h"
     8  
     9  BEGIN_USING_C_LINKAGE
    10  
    11  
    12  /**	A low-level object for tempo-based scheduling.
    13  	@ingroup	time
    14  	@see		#t_timeobject
    15  	@see		@ref chapter_itm	*/
    16  typedef struct _itm t_itm;
    17  
    18  // private -- internal use only
    19  typedef struct _itmclock t_itmclock;
    20  
    21  typedef struct _clocksource
    22  {
    23  	t_object c_ob;
    24  	method c_getticks;		// returns the current tick count
    25  	method c_getstate;		// returns 0 if transport not going, 1 if going
    26  	t_symbol *c_name;		// name
    27  	long c_usedcount;		// number of transports using this clock source
    28  	method c_gettempo;		// get current tempo
    29  	method c_gettimesig;	// get current timesig
    30  	method c_getsr;			// get current samplerate 
    31  } t_clocksource;
    32  
    33  // used by clocksource to report time sig change to ITM
    34  
    35  typedef struct _tschange {
    36  	long c_num;
    37  	long c_denom;
    38  	double c_tsbaseticks;	// ticks at last ts change (use -1 for "unknown")
    39  	long c_tsbasebars;		// bars at last ts change (use -1 for "unknown")
    40  } t_tschange;
    41  
    42  // private, used for the "notifymult" notification (to notify multiple values at once)
    43  
    44  typedef enum _itm_notification_flags
    45  {
    46  	ITM_NOTIFY_NONE			= 0x00,
    47  	ITM_NOTIFY_TEMPO		= 0x01,
    48  	ITM_NOTIFY_UPDATESTATE	= 0x02,
    49  	ITM_NOTIFY_SEEK			= 0x04,
    50  	ITM_NOTIFY_TIMESIG		= 0x08
    51  } t_itm_notification_flags;
    52  
    53  typedef struct _itm_notification_info
    54  {
    55  	long		flags;
    56  	double		tempo;			// ITM_NOTIFICATION_TEMP
    57  	double		location[2];	// ITM_NOTIFICATION_SEEK
    58  	long		transport;		// ITM_NOTIFICATION_UPDATESTATE
    59  	t_tschange	*timesig;		// ITM_NOTIFICATION_TIMESIG
    60  } t_itm_notification_info;
    61  
    62  
    63  /**	Flags that determine attribute and time object behavior
    64  	@ingroup time	*/
    65  enum {
    66  	TIME_FLAGS_LOCATION			= 0x0001,	///< 1 1 0 location-based bar/beat/unit values (as opposed to interval values, which are 0 0 0 relative)
    67  	TIME_FLAGS_TICKSONLY		= 0x0002,	///< only ticks-based values (not ms) are acceptable
    68  	TIME_FLAGS_FIXEDONLY		= 0x0004,	///< only fixed values (ms, hz, samples) are acceptable
    69  	TIME_FLAGS_LOOKAHEAD 		= 0x0008,	///< add lookahead attribute (unsupported)
    70  	TIME_FLAGS_USECLOCK			= 0x0010,	///< this time object will schedule events, not just hold a value
    71  	TIME_FLAGS_USEQELEM			= 0x0020,	///< this time object will defer execution of scheduled events to low priority thread
    72  	TIME_FLAGS_FIXED			= 0x0040,	///< will only use normal clock (i.e., will never execute out of ITM)
    73  	TIME_FLAGS_PERMANENT		= 0x0080,	///< event will be scheduled in the permanent list (tied to a specific time)
    74  	TIME_FLAGS_TRANSPORT		= 0x0100,	///< add a transport attribute
    75  	TIME_FLAGS_EVENTLIST		= 0x0200,	///< add an eventlist attribute (unsupported)
    76  	TIME_FLAGS_CHECKSCHEDULE	= 0x0400,	///< internal use only
    77  	TIME_FLAGS_LISTENTICKS		= 0x0800,	///< flag for time_listen: only get notifications if the time object holds tempo-relative values
    78  	TIME_FLAGS_NOUNITS			= 0x1000,	///< internal use only
    79  	TIME_FLAGS_BBUSOURCE		= 0x2000,	///< source time was in bar/beat/unit values, need to recalculate when time sig changes
    80  	TIME_FLAGS_POSITIVE			= 0x4000	///< constrain any values <= 0 to a minimum value (default: 0)
    81  };
    82  
    83  /*******************************************************************************/
    84  
    85  /**	Return the global (default / unnamed) itm object.
    86  	@ingroup	time
    87  	@return		The global #t_itm object.	*/
    88  void *itm_getglobal(void);
    89  
    90  /**	Return a named itm object.
    91  	@ingroup		time
    92  	@param	s		The name of the itm to return.
    93  	@param	scheduler	
    94  	@param	defaultclocksourcename	
    95  	@param	create	If non-zero, then create this named itm should it not already exist.
    96  	@return			The global #t_itm object.	*/
    97  void *itm_getnamed(t_symbol *s, void *scheduler, t_symbol *defaultclocksourcename, long create);
    98  
    99  // currently the same as itm_getnamed(s,true);
   100  void *itm_getfromarg(t_object *o, t_symbol *s);
   101  
   102  /**	Reference an itm object.
   103  	When you are using an itm object, you must call this function to increment its reference count.
   104  	@ingroup	time
   105  	@param	x	The itm object.	*/
   106  void itm_reference(t_itm *x);
   107  
   108  /**	Stop referencing an itm object.
   109  	When you are done using an itm object, you must call this function to decrement its reference count.
   110  	@ingroup	time
   111  	@param	x	The itm object.	*/
   112  void itm_dereference(t_itm *x);
   113  
   114  
   115  // event list support is limited to use in javascript for the time being.
   116  void itm_deleteeventlist(t_itm *x, t_symbol *eventlist);
   117  void itm_eventlistseek(t_itm *x);
   118  void itm_geteventlistnames(t_itm *x, long *count, t_symbol ***names);
   119  void itm_switcheventlist(t_itm *x, t_symbol *eventlist, double offset);
   120  
   121  
   122  /**	Report the current internal time.
   123  	This is the same as calling clock_getftime();
   124  	@ingroup	time
   125  	@param	x	The itm object.	
   126  	@return		The current internal time.	*/
   127  double itm_gettime(t_itm *x);
   128  
   129  /**	Report the current time of the itm in ticks.
   130  	You can use functions such as itm_tickstobarbeatunits() or itm_tickstoms() to convert to a different representation of the time.
   131  	@ingroup	time
   132  	@param	x	The itm object.	
   133  	@return		The current time in ticks.	*/
   134  double itm_getticks(t_itm *x);
   135  
   136  /**	Print diagnostic information about an itm object to the Max window.
   137  	@ingroup	time
   138  	@param	x	The itm object.		*/
   139  void itm_dump(t_itm *x);
   140  
   141  
   142  // private -- internal use only
   143  void itm_sync(t_itm *x);
   144  
   145  
   146  
   147  /**	Set an itm object's current time signature.
   148  	@ingroup		time
   149  	@param	x		The itm object.	
   150  	@param	num		The top number of the time signature.
   151  	@param	denom	The bottom number of the time signature.
   152  	@param	flags	Currently unused -- pass zero.	*/
   153  void itm_settimesignature(t_itm *x, long num, long denom, long flags);
   154  
   155  /**	Query an itm object for its current time signature.
   156  	@ingroup		time
   157  	@param	x		The itm object.	
   158  	@param	num		The address of a variable to hold the top number of the time signature upon return.
   159  	@param	denom	The address of a variable to hold the bottom number of the time signature upon return.	*/
   160  void itm_gettimesignature(t_itm *x, long *num, long *denom);
   161  
   162  void itm_seek(t_itm *x, double oldticks, double newticks, long chase);
   163  
   164  /**	Pause the passage of time for an itm object.
   165  	This is the equivalent to setting the state of a transport object to 0 with a toggle.
   166  	@ingroup		time
   167  	@param	x		The itm object.		*/
   168  void itm_pause(t_itm *x);
   169  
   170  /**	Start the passage of time for an itm object, from it's current location.
   171  	This is the equivalent to setting the state of a transport object to 0 with a toggle.
   172  	@ingroup		time
   173  	@param	x		The itm object.		*/
   174  void itm_resume(t_itm *x);
   175  
   176  /**	Find out if time is currently progressing for a given itm object.
   177  	@ingroup		time
   178  	@param	x		The itm object.	
   179  	@return			Returns non-zero if the time is running, or zero if it is paused.
   180  	@see			itm_pause()
   181  	@see			itm_resume()	*/
   182  long itm_getstate(t_itm *x);
   183  
   184  
   185  /**	Set the number of ticks-per-quarter-note globally for the itm system.
   186  	The default is 480.
   187  	@ingroup		time
   188  	@param	res		The number of ticks-per-quarter-note.
   189  	@see			itm_getresolution()	*/
   190  void itm_setresolution(double res);
   191  
   192  /**	Get the number of ticks-per-quarter-note globally from the itm system.
   193  	@ingroup		time
   194  	@return			The number of ticks-per-quarter-note.
   195  	@see			itm_setresolution()	*/
   196  double itm_getresolution(void);
   197  
   198  
   199  /**	Given an itm object, return its name.
   200  	@ingroup	time
   201  	@param	x	The itm object.	
   202  	@return		The name of the itm.	*/
   203  t_symbol *itm_getname(t_itm *x);
   204  
   205  
   206  
   207  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);
   208  
   209  
   210  /**	Convert a time value in ticks to the equivalent value in milliseconds, given the context of a specified itm object.
   211  	@ingroup		time
   212  	@param	x		An itm object.
   213  	@param	ticks	A time specified in ticks.
   214  	@return			The time specified in ms.	*/
   215  double itm_tickstoms(t_itm *x, double ticks);
   216  
   217  /**	Convert a time value in milliseconds to the equivalent value in ticks, given the context of a specified itm object.
   218  	@ingroup		time
   219  	@param	x		An itm object.
   220  	@param	ms		A time specified in ms.
   221  	@return			The time specified in ticks.	*/
   222  double itm_mstoticks(t_itm *x, double ms);
   223  
   224  /**	Convert a time value in milliseconds to the equivalent value in samples, given the context of a specified itm object.
   225  	@ingroup		time
   226  	@param	x		An itm object.
   227  	@param	ms		A time specified in ms.
   228  	@return			The time specified in samples.	*/
   229  double itm_mstosamps(t_itm *x, double ms);
   230  
   231  /**	Convert a time value in samples to the equivalent value in milliseconds, given the context of a specified itm object.
   232  	@ingroup		time
   233  	@param	x		An itm object.
   234  	@param	samps	A time specified in samples.
   235  	@return			The time specified in ms.	*/
   236  double itm_sampstoms(t_itm *x, double samps);
   237  
   238  
   239  /**	Convert a time value in bbu to the equivalent value in ticks, given the context of a specified itm object.
   240  	@ingroup			time
   241  	@param	x			An itm object.
   242  	@param	bars		The measure number of the location/position.
   243  	@param	beats		The beat number of the location/position.
   244  	@param	units		The number of ticks past the beat of the location/position.
   245  	@param	ticks		The address of a variable to hold the number of ticks upon return.
   246  	@param	position	Set this parameter to #TIME_FLAGS_LOCATION or to zero (for position mode).	*/
   247  void itm_barbeatunitstoticks(t_itm *x, long bars, long beats, double units, double *ticks, char position);
   248  
   249  /**	Convert a time value in bbu to the equivalent value in ticks, given the context of a specified itm object.
   250  	@ingroup			time
   251  	@param	x			An itm object.
   252  	@param	ticks		The number of ticks to translate into a time represented as bars, beats, and ticks.
   253  	@param	bars		The address of a variable to hold the measure number of the location/position upon return.
   254  	@param	beats		The address of a variable to hold the beat number of the location/position upon return.
   255  	@param	units		The address of a variable to hold the number of ticks past the beat of the location/position upon return.
   256  	@param	position	Set this parameter to #TIME_FLAGS_LOCATION or to zero (for position mode).	*/
   257  void itm_tickstobarbeatunits(t_itm *x, double ticks, long *bars, long *beats, double *units, char position);
   258  
   259  
   260  void itm_format(t_itm *x, double ms, double ticks, long flags, t_symbol *unit, long *argc, t_atom **argv);
   261  
   262  
   263  /**	Given the name of a time unit (e.g. 'ms', 'ticks', 'bbu', 'samples', etc.), determine whether the unit is fixed
   264  	(doesn't change with tempo, time-signature, etc.) or whether it is flexible.
   265  	@ingroup		time
   266  	@param	u		The name of the time unit.
   267  	@return			Zero if the unit is fixed (milliseconds, for example) or non-zero if it is flexible (ticks, for example).	*/
   268  long itm_isunitfixed(t_symbol *u);
   269  
   270  void itmclock_delay(t_itmclock *x, t_itm *m, t_symbol *eventlist, double delay, long quantization);
   271  void *itmclock_new(t_object *owner, t_object *timeobj, method task, method killer, long permanent);
   272  void itmclock_set(t_itmclock *x, t_itm *m, t_symbol *eventlist, double time);
   273  void itmclock_unset(t_itmclock *x);
   274  
   275  // private -- internal use only
   276  void *itm_clocksource_getnamed(t_symbol *name, long create);
   277  void itm_getclocksources(long *count, t_symbol ***sources);
   278  double itm_getsr(t_itm *x);
   279  double itm_gettempo(t_itm *x);
   280  
   281  
   282  END_USING_C_LINKAGE
   283  
   284  #endif // __EXT_ITM_H__