diff options
Diffstat (limited to 'libs/fluidsynth/src/fluid_event.c')
-rw-r--r-- | libs/fluidsynth/src/fluid_event.c | 694 |
1 files changed, 413 insertions, 281 deletions
diff --git a/libs/fluidsynth/src/fluid_event.c b/libs/fluidsynth/src/fluid_event.c index b3b0608345..d7962eac98 100644 --- a/libs/fluidsynth/src/fluid_event.c +++ b/libs/fluidsynth/src/fluid_event.c @@ -3,16 +3,16 @@ * Copyright (C) 2003 Peter Hanappe and others. * * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA @@ -28,7 +28,7 @@ */ -#include "fluid_event_priv.h" +#include "fluid_event.h" #include "fluidsynth_priv.h" /*************************************************************** @@ -39,33 +39,36 @@ /* Event alloc/free */ void -fluid_event_clear(fluid_event_t* evt) +fluid_event_clear(fluid_event_t *evt) { - FLUID_MEMSET(evt, 0, sizeof(fluid_event_t)); + FLUID_MEMSET(evt, 0, sizeof(fluid_event_t)); - // by default, no type - evt->dest = -1; - evt->src = -1; - evt->type = -1; + // by default, no type + evt->dest = -1; + evt->src = -1; + evt->type = -1; } /** * Create a new sequencer event structure. * @return New sequencer event structure or NULL if out of memory */ -fluid_event_t* +fluid_event_t * new_fluid_event() { - fluid_event_t* evt; + fluid_event_t *evt; - evt = FLUID_NEW(fluid_event_t); - if (evt == NULL) { - fluid_log(FLUID_PANIC, "event: Out of memory\n"); - return NULL; - } - fluid_event_clear(evt); + evt = FLUID_NEW(fluid_event_t); - return(evt); + if(evt == NULL) + { + FLUID_LOG(FLUID_PANIC, "event: Out of memory\n"); + return NULL; + } + + fluid_event_clear(evt); + + return(evt); } /** @@ -73,14 +76,11 @@ new_fluid_event() * @param evt Sequencer event structure created by new_fluid_event(). */ void -delete_fluid_event(fluid_event_t* evt) +delete_fluid_event(fluid_event_t *evt) { + fluid_return_if_fail(evt != NULL); - if (evt == NULL) { - return; - } - - FLUID_FREE(evt); + FLUID_FREE(evt); } /** @@ -90,43 +90,43 @@ delete_fluid_event(fluid_event_t* evt) * @param time Time value to assign */ void -fluid_event_set_time(fluid_event_t* evt, unsigned int time) +fluid_event_set_time(fluid_event_t *evt, unsigned int time) { - evt->time = time; + evt->time = time; } /** - * Set source of a sequencer event (DOCME). + * Set source of a sequencer event. \c src must be a unique sequencer ID or -1 if not set. * @param evt Sequencer event structure - * @param src DOCME + * @param src Unique sequencer ID */ void -fluid_event_set_source(fluid_event_t* evt, short src) +fluid_event_set_source(fluid_event_t *evt, fluid_seq_id_t src) { - evt->src = src; + evt->src = src; } /** - * Set destination of a sequencer event (DOCME). + * Set destination of this sequencer event, i.e. the sequencer client this event will be sent to. \c dest must be a unique sequencer ID. * @param evt Sequencer event structure - * @param dest DOCME + * @param dest The destination unique sequencer ID */ void -fluid_event_set_dest(fluid_event_t* evt, short dest) +fluid_event_set_dest(fluid_event_t *evt, fluid_seq_id_t dest) { - evt->dest = dest; + evt->dest = dest; } /** * Set a sequencer event to be a timer event. * @param evt Sequencer event structure - * @param data DOCME + * @param data User supplied data pointer */ void -fluid_event_timer(fluid_event_t* evt, void* data) +fluid_event_timer(fluid_event_t *evt, void *data) { - evt->type = FLUID_SEQ_TIMER; - evt->data = data; + evt->type = FLUID_SEQ_TIMER; + evt->data = data; } /** @@ -137,12 +137,12 @@ fluid_event_timer(fluid_event_t* evt, void* data) * @param vel MIDI velocity value (0-127) */ void -fluid_event_noteon(fluid_event_t* evt, int channel, short key, short vel) +fluid_event_noteon(fluid_event_t *evt, int channel, short key, short vel) { - evt->type = FLUID_SEQ_NOTEON; - evt->channel = channel; - evt->key = key; - evt->vel = vel; + evt->type = FLUID_SEQ_NOTEON; + evt->channel = channel; + evt->key = key; + evt->vel = vel; } /** @@ -152,11 +152,11 @@ fluid_event_noteon(fluid_event_t* evt, int channel, short key, short vel) * @param key MIDI note number (0-127) */ void -fluid_event_noteoff(fluid_event_t* evt, int channel, short key) +fluid_event_noteoff(fluid_event_t *evt, int channel, short key) { - evt->type = FLUID_SEQ_NOTEOFF; - evt->channel = channel; - evt->key = key; + evt->type = FLUID_SEQ_NOTEOFF; + evt->channel = channel; + evt->key = key; } /** @@ -165,16 +165,16 @@ fluid_event_noteoff(fluid_event_t* evt, int channel, short key) * @param channel MIDI channel number * @param key MIDI note number (0-127) * @param vel MIDI velocity value (0-127) - * @param duration Duration of note (DOCME units?) + * @param duration Duration of note in the time scale used by the sequencer (by default milliseconds) */ void -fluid_event_note(fluid_event_t* evt, int channel, short key, short vel, unsigned int duration) +fluid_event_note(fluid_event_t *evt, int channel, short key, short vel, unsigned int duration) { - evt->type = FLUID_SEQ_NOTE; - evt->channel = channel; - evt->key = key; - evt->vel = vel; - evt->duration = duration; + evt->type = FLUID_SEQ_NOTE; + evt->channel = channel; + evt->key = key; + evt->vel = vel; + evt->duration = duration; } /** @@ -183,10 +183,10 @@ fluid_event_note(fluid_event_t* evt, int channel, short key, short vel, unsigned * @param channel MIDI channel number */ void -fluid_event_all_sounds_off(fluid_event_t* evt, int channel) +fluid_event_all_sounds_off(fluid_event_t *evt, int channel) { - evt->type = FLUID_SEQ_ALLSOUNDSOFF; - evt->channel = channel; + evt->type = FLUID_SEQ_ALLSOUNDSOFF; + evt->channel = channel; } /** @@ -195,10 +195,10 @@ fluid_event_all_sounds_off(fluid_event_t* evt, int channel) * @param channel MIDI channel number */ void -fluid_event_all_notes_off(fluid_event_t* evt, int channel) +fluid_event_all_notes_off(fluid_event_t *evt, int channel) { - evt->type = FLUID_SEQ_ALLNOTESOFF; - evt->channel = channel; + evt->type = FLUID_SEQ_ALLNOTESOFF; + evt->channel = channel; } /** @@ -208,11 +208,11 @@ fluid_event_all_notes_off(fluid_event_t* evt, int channel) * @param bank_num MIDI bank number (0-16383) */ void -fluid_event_bank_select(fluid_event_t* evt, int channel, short bank_num) +fluid_event_bank_select(fluid_event_t *evt, int channel, short bank_num) { - evt->type = FLUID_SEQ_BANKSELECT; - evt->channel = channel; - evt->control = bank_num; + evt->type = FLUID_SEQ_BANKSELECT; + evt->channel = channel; + evt->control = bank_num; } /** @@ -222,11 +222,11 @@ fluid_event_bank_select(fluid_event_t* evt, int channel, short bank_num) * @param val MIDI program number (0-127) */ void -fluid_event_program_change(fluid_event_t* evt, int channel, short val) +fluid_event_program_change(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_PROGRAMCHANGE; - evt->channel = channel; - evt->value = val; + evt->type = FLUID_SEQ_PROGRAMCHANGE; + evt->channel = channel; + evt->value = val; } /** @@ -238,27 +238,26 @@ fluid_event_program_change(fluid_event_t* evt, int channel, short val) * @param preset_num MIDI preset number (0-127) */ void -fluid_event_program_select(fluid_event_t* evt, int channel, - unsigned int sfont_id, short bank_num, short preset_num) +fluid_event_program_select(fluid_event_t *evt, int channel, + unsigned int sfont_id, short bank_num, short preset_num) { - evt->type = FLUID_SEQ_PROGRAMSELECT; - evt->channel = channel; - evt->duration = sfont_id; - evt->value = preset_num; - evt->control = bank_num; + evt->type = FLUID_SEQ_PROGRAMSELECT; + evt->channel = channel; + evt->duration = sfont_id; + evt->value = preset_num; + evt->control = bank_num; } /** - * Set a sequencer event to be an any control change event. + * Set a sequencer event to be an any control change event (for internal use). * @param evt Sequencer event structure * @param channel MIDI channel number - * DOCME */ void -fluid_event_any_control_change(fluid_event_t* evt, int channel) +fluid_event_any_control_change(fluid_event_t *evt, int channel) { - evt->type = FLUID_SEQ_ANYCONTROLCHANGE; - evt->channel = channel; + evt->type = FLUID_SEQ_ANYCONTROLCHANGE; + evt->channel = channel; } /** @@ -268,27 +267,36 @@ fluid_event_any_control_change(fluid_event_t* evt, int channel) * @param pitch MIDI pitch bend value (0-16383, 8192 = no bend) */ void -fluid_event_pitch_bend(fluid_event_t* evt, int channel, int pitch) +fluid_event_pitch_bend(fluid_event_t *evt, int channel, int pitch) { - evt->type = FLUID_SEQ_PITCHBEND; - evt->channel = channel; - if (pitch < 0) pitch = 0; - if (pitch > 16383) pitch = 16383; - evt->pitch = pitch; + evt->type = FLUID_SEQ_PITCHBEND; + evt->channel = channel; + + if(pitch < 0) + { + pitch = 0; + } + + if(pitch > 16383) + { + pitch = 16383; + } + + evt->pitch = pitch; } /** * Set a sequencer event to be a pitch wheel sensitivity event. * @param evt Sequencer event structure * @param channel MIDI channel number - * @param value MIDI pitch wheel sensitivity value (DOCME units?) + * @param value MIDI pitch wheel sensitivity value in semitones */ void -fluid_event_pitch_wheelsens(fluid_event_t* evt, int channel, short value) +fluid_event_pitch_wheelsens(fluid_event_t *evt, int channel, short value) { - evt->type = FLUID_SEQ_PITCHWHHELSENS; - evt->channel = channel; - evt->value = value; + evt->type = FLUID_SEQ_PITCHWHEELSENS; + evt->channel = channel; + evt->value = value; } /** @@ -298,13 +306,22 @@ fluid_event_pitch_wheelsens(fluid_event_t* evt, int channel, short value) * @param val MIDI modulation value (0-127) */ void -fluid_event_modulation(fluid_event_t* evt, int channel, short val) +fluid_event_modulation(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_MODULATION; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_MODULATION; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; } /** @@ -314,13 +331,22 @@ fluid_event_modulation(fluid_event_t* evt, int channel, short val) * @param val MIDI sustain value (0-127) */ void -fluid_event_sustain(fluid_event_t* evt, int channel, short val) +fluid_event_sustain(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_SUSTAIN; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_SUSTAIN; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; } /** @@ -328,15 +354,15 @@ fluid_event_sustain(fluid_event_t* evt, int channel, short val) * @param evt Sequencer event structure * @param channel MIDI channel number * @param control MIDI control number (0-127) - * @param val MIDI control value (0-16383 DOCME is that true?) + * @param val MIDI control value (0-127) */ void -fluid_event_control_change(fluid_event_t* evt, int channel, short control, short val) +fluid_event_control_change(fluid_event_t *evt, int channel, short control, short val) { - evt->type = FLUID_SEQ_CONTROLCHANGE; - evt->channel = channel; - evt->control = control; - evt->value = val; + evt->type = FLUID_SEQ_CONTROLCHANGE; + evt->channel = channel; + evt->control = control; + evt->value = val; } /** @@ -346,13 +372,22 @@ fluid_event_control_change(fluid_event_t* evt, int channel, short control, short * @param val MIDI panning value (0-127, 0=left, 64 = middle, 127 = right) */ void -fluid_event_pan(fluid_event_t* evt, int channel, short val) +fluid_event_pan(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_PAN; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_PAN; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; } /** @@ -362,13 +397,22 @@ fluid_event_pan(fluid_event_t* evt, int channel, short val) * @param val Volume value (0-127) */ void -fluid_event_volume(fluid_event_t* evt, int channel, short val) +fluid_event_volume(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_VOLUME; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_VOLUME; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; } /** @@ -378,13 +422,22 @@ fluid_event_volume(fluid_event_t* evt, int channel, short val) * @param val Reverb amount (0-127) */ void -fluid_event_reverb_send(fluid_event_t* evt, int channel, short val) +fluid_event_reverb_send(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_REVERBSEND; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_REVERBSEND; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; } /** @@ -394,13 +447,22 @@ fluid_event_reverb_send(fluid_event_t* evt, int channel, short val) * @param val Chorus amount (0-127) */ void -fluid_event_chorus_send(fluid_event_t* evt, int channel, short val) +fluid_event_chorus_send(fluid_event_t *evt, int channel, short val) { - evt->type = FLUID_SEQ_CHORUSSEND; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_CHORUSSEND; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; } @@ -410,9 +472,9 @@ fluid_event_chorus_send(fluid_event_t* evt, int channel, short val) * @since 1.1.0 */ void -fluid_event_unregistering(fluid_event_t* evt) +fluid_event_unregistering(fluid_event_t *evt) { - evt->type = FLUID_SEQ_UNREGISTERING; + evt->type = FLUID_SEQ_UNREGISTERING; } /** @@ -422,14 +484,61 @@ fluid_event_unregistering(fluid_event_t* evt) * @param val Aftertouch amount (0-127) * @since 1.1.0 */ -void -fluid_event_channel_pressure(fluid_event_t* evt, int channel, short val) +void +fluid_event_channel_pressure(fluid_event_t *evt, int channel, short val) +{ + evt->type = FLUID_SEQ_CHANNELPRESSURE; + evt->channel = channel; + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->value = val; +} + +/** + * Set a sequencer event to be a polyphonic aftertouch event. + * @param evt Sequencer event structure + * @param channel MIDI channel number + * @param key MIDI note number (0-127) + * @param val Aftertouch amount (0-127) + * @since 2.0.0 + */ +void +fluid_event_key_pressure(fluid_event_t *evt, int channel, short key, short val) { - evt->type = FLUID_SEQ_CHANNELPRESSURE; - evt->channel = channel; - if (val < 0) val = 0; - if (val > 127) val = 127; - evt->value = val; + evt->type = FLUID_SEQ_KEYPRESSURE; + evt->channel = channel; + + if(key < 0) + { + key = 0; + } + + if(key > 127) + { + key = 127; + } + + if(val < 0) + { + val = 0; + } + + if(val > 127) + { + val = 127; + } + + evt->key = key; + evt->value = val; } /** @@ -437,10 +546,10 @@ fluid_event_channel_pressure(fluid_event_t* evt, int channel, short val) * @param evt Sequencer event structure * @since 1.1.0 */ -void -fluid_event_system_reset(fluid_event_t* evt) +void +fluid_event_system_reset(fluid_event_t *evt) { - evt->type = FLUID_SEQ_SYSTEMRESET; + evt->type = FLUID_SEQ_SYSTEMRESET; } @@ -454,49 +563,50 @@ fluid_event_system_reset(fluid_event_t* evt) * @param evt Sequencer event structure * @return Event type (#fluid_seq_event_type). */ -int fluid_event_get_type(fluid_event_t* evt) +int fluid_event_get_type(fluid_event_t *evt) { - return evt->type; + return evt->type; } /** + * @internal * Get the time field from a sequencer event structure. * @param evt Sequencer event structure - * @return Time value (DOCME units?) + * @return Time value */ -unsigned int fluid_event_get_time(fluid_event_t* evt) +unsigned int fluid_event_get_time(fluid_event_t *evt) { - return evt->time; + return evt->time; } /** - * Get the source field from a sequencer event structure. + * Get the source sequencer client from a sequencer event structure. * @param evt Sequencer event structure - * @return DOCME + * @return source field of the sequencer event */ -short fluid_event_get_source(fluid_event_t* evt) +fluid_seq_id_t fluid_event_get_source(fluid_event_t *evt) { - return evt->src; + return evt->src; } /** - * Get the dest field from a sequencer event structure. + * Get the dest sequencer client from a sequencer event structure. * @param evt Sequencer event structure - * @return DOCME + * @return dest field of the sequencer event */ -short fluid_event_get_dest(fluid_event_t* evt) +fluid_seq_id_t fluid_event_get_dest(fluid_event_t *evt) { - return evt->dest; + return evt->dest; } /** * Get the MIDI channel field from a sequencer event structure. * @param evt Sequencer event structure - * @return MIDI channel number (DOCME 0-15 or more?) + * @return MIDI zero-based channel number */ -int fluid_event_get_channel(fluid_event_t* evt) +int fluid_event_get_channel(fluid_event_t *evt) { - return evt->channel; + return evt->channel; } /** @@ -504,9 +614,9 @@ int fluid_event_get_channel(fluid_event_t* evt) * @param evt Sequencer event structure * @return MIDI note number (0-127) */ -short fluid_event_get_key(fluid_event_t* evt) +short fluid_event_get_key(fluid_event_t *evt) { - return evt->key; + return evt->key; } /** @@ -514,10 +624,10 @@ short fluid_event_get_key(fluid_event_t* evt) * @param evt Sequencer event structure * @return MIDI velocity value (0-127) */ -short fluid_event_get_velocity(fluid_event_t* evt) +short fluid_event_get_velocity(fluid_event_t *evt) { - return evt->vel; + return evt->vel; } /** @@ -525,9 +635,9 @@ short fluid_event_get_velocity(fluid_event_t* evt) * @param evt Sequencer event structure * @return MIDI control number (0-127) */ -short fluid_event_get_control(fluid_event_t* evt) +short fluid_event_get_control(fluid_event_t *evt) { - return evt->control; + return evt->control; } /** @@ -537,13 +647,13 @@ short fluid_event_get_control(fluid_event_t* evt) * * The Value field is used by the following event types: * #FLUID_SEQ_PROGRAMCHANGE, #FLUID_SEQ_PROGRAMSELECT (preset_num), - * #FLUID_SEQ_PITCHWHHELSENS, #FLUID_SEQ_MODULATION, #FLUID_SEQ_SUSTAIN, + * #FLUID_SEQ_PITCHWHEELSENS, #FLUID_SEQ_MODULATION, #FLUID_SEQ_SUSTAIN, * #FLUID_SEQ_CONTROLCHANGE, #FLUID_SEQ_PAN, #FLUID_SEQ_VOLUME, * #FLUID_SEQ_REVERBSEND, #FLUID_SEQ_CHORUSSEND. */ -short fluid_event_get_value(fluid_event_t* evt) +short fluid_event_get_value(fluid_event_t *evt) { - return evt->value; + return evt->value; } /** @@ -553,21 +663,21 @@ short fluid_event_get_value(fluid_event_t* evt) * * Used by the #FLUID_SEQ_TIMER event type. */ -void* fluid_event_get_data(fluid_event_t* evt) +void *fluid_event_get_data(fluid_event_t *evt) { - return evt->data; + return evt->data; } /** * Get the duration field from a sequencer event structure. * @param evt Sequencer event structure - * @return Note duration value (DOCME units?) + * @return Note duration value in the time scale used by the sequencer (by default milliseconds) * * Used by the #FLUID_SEQ_NOTE event type. */ -unsigned int fluid_event_get_duration(fluid_event_t* evt) +unsigned int fluid_event_get_duration(fluid_event_t *evt) { - return evt->duration; + return evt->duration; } /** @@ -578,9 +688,9 @@ unsigned int fluid_event_get_duration(fluid_event_t* evt) * Used by the #FLUID_SEQ_BANKSELECT and #FLUID_SEQ_PROGRAMSELECT * event types. */ -short fluid_event_get_bank(fluid_event_t* evt) +short fluid_event_get_bank(fluid_event_t *evt) { - return evt->control; + return evt->control; } /** @@ -590,9 +700,9 @@ short fluid_event_get_bank(fluid_event_t* evt) * * Used by the #FLUID_SEQ_PITCHBEND event type. */ -int fluid_event_get_pitch(fluid_event_t* evt) +int fluid_event_get_pitch(fluid_event_t *evt) { - return evt->pitch; + return evt->pitch; } /** @@ -604,9 +714,9 @@ int fluid_event_get_pitch(fluid_event_t* evt) * event types. */ short -fluid_event_get_program(fluid_event_t* evt) +fluid_event_get_program(fluid_event_t *evt) { - return evt->value; + return evt->value; } /** @@ -617,9 +727,9 @@ fluid_event_get_program(fluid_event_t* evt) * Used by the #FLUID_SEQ_PROGRAMSELECT event type. */ unsigned int -fluid_event_get_sfont_id(fluid_event_t* evt) +fluid_event_get_sfont_id(fluid_event_t *evt) { - return evt->duration; + return evt->duration; } @@ -628,154 +738,176 @@ fluid_event_get_sfont_id(fluid_event_t* evt) /* heap management */ /********************/ -fluid_evt_heap_t* +fluid_evt_heap_t * _fluid_evt_heap_init(int nbEvents) { #ifdef HEAP_WITH_DYNALLOC - int i; - fluid_evt_heap_t* heap; - fluid_evt_entry *tmp; + int i; + fluid_evt_heap_t *heap; + fluid_evt_entry *tmp; - heap = FLUID_NEW(fluid_evt_heap_t); - if (heap == NULL) { - fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); - return NULL; - } + heap = FLUID_NEW(fluid_evt_heap_t); - heap->freelist = NULL; - fluid_mutex_init(heap->mutex); + if(heap == NULL) + { + FLUID_LOG(FLUID_PANIC, "sequencer: Out of memory\n"); + return NULL; + } + + heap->freelist = NULL; + fluid_mutex_init(heap->mutex); - /* LOCK */ - fluid_mutex_lock(heap->mutex); + /* LOCK */ + fluid_mutex_lock(heap->mutex); - /* Allocate the event entries */ - for (i = 0; i < nbEvents; i++) { - tmp = FLUID_NEW(fluid_evt_entry); - tmp->next = heap->freelist; - heap->freelist = tmp; - } + /* Allocate the event entries */ + for(i = 0; i < nbEvents; i++) + { + tmp = FLUID_NEW(fluid_evt_entry); + tmp->next = heap->freelist; + heap->freelist = tmp; + } - /* UNLOCK */ - fluid_mutex_unlock(heap->mutex); + /* UNLOCK */ + fluid_mutex_unlock(heap->mutex); #else - int i; - fluid_evt_heap_t* heap; - int siz = 2*sizeof(fluid_evt_entry *) + sizeof(fluid_evt_entry)*nbEvents; - - heap = (fluid_evt_heap_t *)FLUID_MALLOC(siz); - if (heap == NULL) { - fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); - return NULL; - } - FLUID_MEMSET(heap, 0, siz); - - /* link all heap events */ - { - fluid_evt_entry *tmp = &(heap->pool); - for (i = 0 ; i < nbEvents - 1 ; i++) - tmp[i].next = &(tmp[i+1]); - tmp[nbEvents-1].next = NULL; - - /* set head & tail */ - heap->tail = &(tmp[nbEvents-1]); - heap->head = &(heap->pool); - } + int i; + fluid_evt_heap_t *heap; + int siz = 2 * sizeof(fluid_evt_entry *) + sizeof(fluid_evt_entry) * nbEvents; + + heap = (fluid_evt_heap_t *)FLUID_MALLOC(siz); + + if(heap == NULL) + { + FLUID_LOG(FLUID_PANIC, "sequencer: Out of memory\n"); + return NULL; + } + + FLUID_MEMSET(heap, 0, siz); + + /* link all heap events */ + { + fluid_evt_entry *tmp = &(heap->pool); + + for(i = 0 ; i < nbEvents - 1 ; i++) + { + tmp[i].next = &(tmp[i + 1]); + } + + tmp[nbEvents - 1].next = NULL; + + /* set head & tail */ + heap->tail = &(tmp[nbEvents - 1]); + heap->head = &(heap->pool); + } #endif - return (heap); + return (heap); } void -_fluid_evt_heap_free(fluid_evt_heap_t* heap) +_fluid_evt_heap_free(fluid_evt_heap_t *heap) { #ifdef HEAP_WITH_DYNALLOC - fluid_evt_entry *tmp, *next; + fluid_evt_entry *tmp, *next; + + /* LOCK */ + fluid_mutex_lock(heap->mutex); - /* LOCK */ - fluid_mutex_lock(heap->mutex); + tmp = heap->freelist; - tmp = heap->freelist; - while (tmp) { - next = tmp->next; - FLUID_FREE(tmp); - tmp = next; - } + while(tmp) + { + next = tmp->next; + FLUID_FREE(tmp); + tmp = next; + } - /* UNLOCK */ - fluid_mutex_unlock(heap->mutex); - fluid_mutex_destroy(heap->mutex); + /* UNLOCK */ + fluid_mutex_unlock(heap->mutex); + fluid_mutex_destroy(heap->mutex); - FLUID_FREE(heap); + FLUID_FREE(heap); #else - FLUID_FREE(heap); + FLUID_FREE(heap); #endif } -fluid_evt_entry* -_fluid_seq_heap_get_free(fluid_evt_heap_t* heap) +fluid_evt_entry * +_fluid_seq_heap_get_free(fluid_evt_heap_t *heap) { #ifdef HEAP_WITH_DYNALLOC - fluid_evt_entry* evt = NULL; + fluid_evt_entry *evt = NULL; - /* LOCK */ - fluid_mutex_lock(heap->mutex); + /* LOCK */ + fluid_mutex_lock(heap->mutex); #if !defined(MACOS9) - if (heap->freelist == NULL) { - heap->freelist = FLUID_NEW(fluid_evt_entry); - if (heap->freelist != NULL) { - heap->freelist->next = NULL; + + if(heap->freelist == NULL) + { + heap->freelist = FLUID_NEW(fluid_evt_entry); + + if(heap->freelist != NULL) + { + heap->freelist->next = NULL; + } } - } + #endif - evt = heap->freelist; + evt = heap->freelist; - if (evt != NULL) { - heap->freelist = heap->freelist->next; - evt->next = NULL; - } + if(evt != NULL) + { + heap->freelist = heap->freelist->next; + evt->next = NULL; + } - /* UNLOCK */ - fluid_mutex_unlock(heap->mutex); + /* UNLOCK */ + fluid_mutex_unlock(heap->mutex); - return evt; + return evt; #else - fluid_evt_entry* evt; - if (heap->head == NULL) return NULL; + fluid_evt_entry *evt; - /* take from head of the heap */ - /* critical - should threadlock ? */ - evt = heap->head; - heap->head = heap->head->next; + if(heap->head == NULL) + { + return NULL; + } - return evt; + /* take from head of the heap */ + /* critical - should threadlock ? */ + evt = heap->head; + heap->head = heap->head->next; + + return evt; #endif } void -_fluid_seq_heap_set_free(fluid_evt_heap_t* heap, fluid_evt_entry* evt) +_fluid_seq_heap_set_free(fluid_evt_heap_t *heap, fluid_evt_entry *evt) { #ifdef HEAP_WITH_DYNALLOC - /* LOCK */ - fluid_mutex_lock(heap->mutex); + /* LOCK */ + fluid_mutex_lock(heap->mutex); - evt->next = heap->freelist; - heap->freelist = evt; + evt->next = heap->freelist; + heap->freelist = evt; - /* UNLOCK */ - fluid_mutex_unlock(heap->mutex); + /* UNLOCK */ + fluid_mutex_unlock(heap->mutex); #else - /* append to the end of the heap */ - /* critical - should threadlock ? */ - heap->tail->next = evt; - heap->tail = evt; - evt->next = NULL; + /* append to the end of the heap */ + /* critical - should threadlock ? */ + heap->tail->next = evt; + heap->tail = evt; + evt->next = NULL; #endif } |