Digital Music Programming II: gettime




This lab demonstrates how to get the current time in milliseconds which can be used for timing events coming in and going out of Max. Here is an example usage of the gettime object created in this lab:

The Max function gettime() is used to find the current time in milliseconds.

gettime.c

#include "ext.h"

typedef struct {
   t_object max_data;      
   void*    output;       
} MyObject;

void* object_data = NULL;

void*  create_object    (void);
void   InputBang        (MyObject* mo);

void main(void) {
   setup((t_messlist**)&object_data, (method)create_object, 
         NULL, sizeof(MyObject), NULL, A_NOTHING);
   addbang((method)InputBang);
}

void* create_object(void) {
   MyObject* mo = (MyObject*)newobject(object_data);
   mo->output   = intout(mo);
   return mo;
}

void InputBang(MyObject* mo) {
   outlet_int(mo->output, gettime());
}