diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2007-01-01 02:17:27 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2007-01-01 02:17:27 +0000 |
commit | f39bb01ba3c81af91b76ea6b36bd318845cd77de (patch) | |
tree | 94e96ba7a745a9a05b7216553e096c9e3b46aa26 | |
parent | 5e357ed1cc0c85e950d6ab5fc27d249df7fae2bf (diff) |
The output message is pre-generated by hidio_build_element_list() and stored
in t_hid_element->output_message. Then just the value is updated. This saves
a bit of CPU time since this is run for every event that is output.
Previously, for each event outputted, it had to allocate a t_atom[3] and run a
SETSYMBOL for the name and a SETFLOAT for the instance.
svn path=/trunk/externals/io/hidio/; revision=7117
-rw-r--r-- | hidio.c | 33 | ||||
-rw-r--r-- | hidio.h | 3 | ||||
-rw-r--r-- | hidio_darwin.c | 7 | ||||
-rw-r--r-- | hidio_linux.c | 2 |
4 files changed, 23 insertions, 22 deletions
@@ -286,31 +286,21 @@ static short get_device_number_from_arguments(int argc, t_atom *argv) } -void hidio_output_event(t_hidio *x, t_hid_element *output_data) +/* output_message[3] is pre-generated by hidio_build_element_list() and + * stored in t_hid_element, then just the value is updated. This saves a bit + * of CPU time since this is run for every event that is output. */ +void hidio_output_event(t_hidio *x, t_hid_element *output_element) { - if( (output_data->relative) || // relative data should always be output - (output_data->value != output_data->previous_value) ) - { /* debug_post(LOG_DEBUG,"hidio_output_event: instance %d/%d last: %llu", x->x_instance+1, hidio_instance_count, last_execute_time[x->x_device_number]);*/ - t_atom event_data[3]; - /* TODO: this output message should be stored in t_hid_element, then just - * the value updated. That would save a bit of CPU time since this is - * run for every event that is output. */ #ifdef PD - SETSYMBOL(event_data, output_data->name); - SETFLOAT(event_data + 1, output_data->instance); - SETFLOAT(event_data + 2, output_data->value); + SETFLOAT(output_element->output_message + 2, output_element->value); #else /* Max */ - atom_setsym(event_data, output_data->name); - //TODO: why is this line repeated? - atom_setsym(event_data, output_data->name); - atom_setlong(event_data + 1, (long)output_data->instance); - atom_setlong(event_data + 2, (long)output_data->value); + atom_setlong(output_element->output_message + 2, (long)output_element->value); #endif /* PD */ - outlet_anything(x->x_data_outlet, output_data->type, 3, event_data); - } + outlet_anything(x->x_data_outlet, output_element->type, 3, + output_element->output_message); } @@ -454,10 +444,11 @@ static void hidio_tick(t_hidio *x) // debug_post(LOG_DEBUG,"hidio_tick"); t_hid_element *current_element; unsigned int i; -#ifdef PD - double right_now = clock_getlogicaltime(); -#else double right_now; + +#ifdef PD + right_now = clock_getlogicaltime(); +#else /* Max */ clock_getftime(&right_now); #endif /* PD */ @@ -42,7 +42,7 @@ typedef void t_clock; #define HIDIO_MAJOR_VERSION 0 #define HIDIO_MINOR_VERSION 0 -/* static char *version = "$Revision: 1.13 $"; */ +/* static char *version = "$Revision: 1.14 $"; */ /*------------------------------------------------------------------------------ * MACRO DEFINES @@ -151,6 +151,7 @@ typedef struct _hid_element t_int min; // from device report t_int max; // from device report t_float instance; // usage page/usage instance # (e.g. [absolute x 2 163( ) + t_atom output_message[3]; // pre-generated message for hidio_output_event() t_int value; // output the sum of events in a poll for relative axes t_int previous_value; //only output on change on abs and buttons } t_hid_element; diff --git a/hidio_darwin.c b/hidio_darwin.c index d9ae055..16a9fd1 100644 --- a/hidio_darwin.c +++ b/hidio_darwin.c @@ -417,6 +417,13 @@ static void hidio_build_element_list(t_hidio *x) new_element = (t_hid_element *)getbytes(sizeof(t_hid_element)); new_element->pHIDElement = (void *) pCurrentHIDElement; get_usage_symbols(pCurrentHIDElement, new_element); +#ifdef PD + SETSYMBOL(new_element->output_message, new_element->name); + SETFLOAT(new_element->output_message + 1, new_element->instance); +#else /* Max */ + atom_setsym(new_element->output_message, new_element->name); + atom_setlong(new_element->output_message + 1, (long)new_element->instance); +#endif /* PD */ new_element->relative = pCurrentHIDElement->relative; new_element->instance = get_type_name_instance(new_element->type, new_element->name, diff --git a/hidio_linux.c b/hidio_linux.c index 2436b32..5949c40 100644 --- a/hidio_linux.c +++ b/hidio_linux.c @@ -359,6 +359,8 @@ static void hidio_build_element_list(t_hidio *x) new_element->relative = 1; else new_element->relative = 0; + SETSYMBOL(new_element->output_message, new_element->name); + SETFLOAT(new_element->output_message + 1, new_element->instance); // fill in the t_hid_element struct here post("x->x_device_number: %d element_count[]: %d", x->x_device_number, element_count[x->x_device_number]); |