2016-08-23 12:50:54 -04:00
|
|
|
/* FluidSynth - A Software Synthesizer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Peter Hanappe and others.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2018-10-17 18:41:02 -04:00
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1 of
|
2016-08-23 12:50:54 -04:00
|
|
|
* 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
|
2018-10-17 18:41:02 -04:00
|
|
|
* Lesser General Public License for more details.
|
2016-08-23 12:50:54 -04:00
|
|
|
*
|
2018-10-17 18:41:02 -04:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2016-08-23 12:50:54 -04:00
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
2002 : API design by Peter Hanappe and Antoine Schmitt
|
|
|
|
August 2002 : Implementation by Antoine Schmitt as@gratin.org
|
|
|
|
as part of the infiniteCD author project
|
|
|
|
http://www.infiniteCD.org/
|
|
|
|
Oct4.2002 : AS : corrected bug in heap allocation, that caused a crash during sequencer free.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
#include "fluid_event.h"
|
2016-08-23 12:50:54 -04:00
|
|
|
#include "fluidsynth_priv.h"
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
*
|
|
|
|
* SEQUENCER EVENTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Event alloc/free */
|
|
|
|
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_clear(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
FLUID_MEMSET(evt, 0, sizeof(fluid_event_t));
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
// by default, no type
|
|
|
|
evt->dest = -1;
|
|
|
|
evt->src = -1;
|
|
|
|
evt->type = -1;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new sequencer event structure.
|
|
|
|
* @return New sequencer event structure or NULL if out of memory
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_t *
|
2016-08-23 12:50:54 -04:00
|
|
|
new_fluid_event()
|
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_t *evt;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
evt = FLUID_NEW(fluid_event_t);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
if(evt == NULL)
|
|
|
|
{
|
|
|
|
FLUID_LOG(FLUID_PANIC, "event: Out of memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fluid_event_clear(evt);
|
|
|
|
|
|
|
|
return(evt);
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure created by new_fluid_event().
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
delete_fluid_event(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_return_if_fail(evt != NULL);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
FLUID_FREE(evt);
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time field of a sequencer event.
|
|
|
|
* @internal
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param time Time value to assign
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_set_time(fluid_event_t *evt, unsigned int time)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->time = time;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 18:41:02 -04:00
|
|
|
* Set source of a sequencer event. \c src must be a unique sequencer ID or -1 if not set.
|
2016-08-23 12:50:54 -04:00
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @param src Unique sequencer ID
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_set_source(fluid_event_t *evt, fluid_seq_id_t src)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->src = src;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 18:41:02 -04:00
|
|
|
* 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.
|
2016-08-23 12:50:54 -04:00
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @param dest The destination unique sequencer ID
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_set_dest(fluid_event_t *evt, fluid_seq_id_t dest)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->dest = dest;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a timer event.
|
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @param data User supplied data pointer
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_timer(fluid_event_t *evt, void *data)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_TIMER;
|
|
|
|
evt->data = data;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a note on event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param key MIDI note number (0-127)
|
|
|
|
* @param vel MIDI velocity value (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_noteon(fluid_event_t *evt, int channel, short key, short vel)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_NOTEON;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->key = key;
|
|
|
|
evt->vel = vel;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a note off event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param key MIDI note number (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_noteoff(fluid_event_t *evt, int channel, short key)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_NOTEOFF;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->key = key;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a note duration event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param key MIDI note number (0-127)
|
|
|
|
* @param vel MIDI velocity value (0-127)
|
2018-10-17 18:41:02 -04:00
|
|
|
* @param duration Duration of note in the time scale used by the sequencer (by default milliseconds)
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_note(fluid_event_t *evt, int channel, short key, short vel, unsigned int duration)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_NOTE;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->key = key;
|
|
|
|
evt->vel = vel;
|
|
|
|
evt->duration = duration;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be an all sounds off event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_all_sounds_off(fluid_event_t *evt, int channel)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_ALLSOUNDSOFF;
|
|
|
|
evt->channel = channel;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a all notes off event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_all_notes_off(fluid_event_t *evt, int channel)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_ALLNOTESOFF;
|
|
|
|
evt->channel = channel;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a bank select event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param bank_num MIDI bank number (0-16383)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_bank_select(fluid_event_t *evt, int channel, short bank_num)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_BANKSELECT;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->control = bank_num;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a program change event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val MIDI program number (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_program_change(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_PROGRAMCHANGE;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a program select event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param sfont_id SoundFont ID number
|
|
|
|
* @param bank_num MIDI bank number (0-16383)
|
|
|
|
* @param preset_num MIDI preset number (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_program_select(fluid_event_t *evt, int channel,
|
|
|
|
unsigned int sfont_id, short bank_num, short preset_num)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_PROGRAMSELECT;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->duration = sfont_id;
|
|
|
|
evt->value = preset_num;
|
|
|
|
evt->control = bank_num;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 18:41:02 -04:00
|
|
|
* Set a sequencer event to be an any control change event (for internal use).
|
2016-08-23 12:50:54 -04:00
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_any_control_change(fluid_event_t *evt, int channel)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_ANYCONTROLCHANGE;
|
|
|
|
evt->channel = channel;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a pitch bend event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param pitch MIDI pitch bend value (0-16383, 8192 = no bend)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_pitch_bend(fluid_event_t *evt, int channel, int pitch)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_PITCHBEND;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(pitch < 0)
|
|
|
|
{
|
|
|
|
pitch = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pitch > 16383)
|
|
|
|
{
|
|
|
|
pitch = 16383;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->pitch = pitch;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a pitch wheel sensitivity event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
2018-10-17 18:41:02 -04:00
|
|
|
* @param value MIDI pitch wheel sensitivity value in semitones
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_pitch_wheelsens(fluid_event_t *evt, int channel, short value)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_PITCHWHEELSENS;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->value = value;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a modulation event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val MIDI modulation value (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_modulation(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_MODULATION;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val > 127)
|
|
|
|
{
|
|
|
|
val = 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a MIDI sustain event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val MIDI sustain value (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_sustain(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_SUSTAIN;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val > 127)
|
|
|
|
{
|
|
|
|
val = 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a MIDI control change event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param control MIDI control number (0-127)
|
2018-10-17 18:41:02 -04:00
|
|
|
* @param val MIDI control value (0-127)
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_control_change(fluid_event_t *evt, int channel, short control, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_CONTROLCHANGE;
|
|
|
|
evt->channel = channel;
|
|
|
|
evt->control = control;
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a stereo pan event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val MIDI panning value (0-127, 0=left, 64 = middle, 127 = right)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_pan(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_PAN;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val > 127)
|
|
|
|
{
|
|
|
|
val = 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a volume event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val Volume value (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_volume(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_VOLUME;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val > 127)
|
|
|
|
{
|
|
|
|
val = 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a reverb send event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val Reverb amount (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_reverb_send(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_REVERBSEND;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val > 127)
|
|
|
|
{
|
|
|
|
val = 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a chorus send event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val Chorus amount (0-127)
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_chorus_send(fluid_event_t *evt, int channel, short val)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_CHORUSSEND;
|
|
|
|
evt->channel = channel;
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val > 127)
|
|
|
|
{
|
|
|
|
val = 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt->value = val;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be an unregistering event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @since 1.1.0
|
|
|
|
*/
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_unregistering(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_UNREGISTERING;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a channel-wide aftertouch event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @param channel MIDI channel number
|
|
|
|
* @param val Aftertouch amount (0-127)
|
|
|
|
* @since 1.1.0
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
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)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
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;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a sequencer event to be a midi system reset event.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @since 1.1.0
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
void
|
|
|
|
fluid_event_system_reset(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->type = FLUID_SEQ_SYSTEMRESET;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Accessing event data
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event type (#fluid_seq_event_type) field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return Event type (#fluid_seq_event_type).
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
int fluid_event_get_type(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->type;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 18:41:02 -04:00
|
|
|
* @internal
|
2016-08-23 12:50:54 -04:00
|
|
|
* Get the time field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @return Time value
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
unsigned int fluid_event_get_time(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->time;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 18:41:02 -04:00
|
|
|
* Get the source sequencer client from a sequencer event structure.
|
2016-08-23 12:50:54 -04:00
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @return source field of the sequencer event
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_seq_id_t fluid_event_get_source(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->src;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-17 18:41:02 -04:00
|
|
|
* Get the dest sequencer client from a sequencer event structure.
|
2016-08-23 12:50:54 -04:00
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @return dest field of the sequencer event
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_seq_id_t fluid_event_get_dest(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->dest;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the MIDI channel field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @return MIDI zero-based channel number
|
2016-08-23 12:50:54 -04:00
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
int fluid_event_get_channel(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->channel;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the MIDI note field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return MIDI note number (0-127)
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
short fluid_event_get_key(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->key;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the MIDI velocity field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return MIDI velocity value (0-127)
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
short fluid_event_get_velocity(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
|
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->vel;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the MIDI control number field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return MIDI control number (0-127)
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
short fluid_event_get_control(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->control;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return Value field of event.
|
|
|
|
*
|
|
|
|
* The Value field is used by the following event types:
|
|
|
|
* #FLUID_SEQ_PROGRAMCHANGE, #FLUID_SEQ_PROGRAMSELECT (preset_num),
|
2018-10-17 18:41:02 -04:00
|
|
|
* #FLUID_SEQ_PITCHWHEELSENS, #FLUID_SEQ_MODULATION, #FLUID_SEQ_SUSTAIN,
|
2016-08-23 12:50:54 -04:00
|
|
|
* #FLUID_SEQ_CONTROLCHANGE, #FLUID_SEQ_PAN, #FLUID_SEQ_VOLUME,
|
|
|
|
* #FLUID_SEQ_REVERBSEND, #FLUID_SEQ_CHORUSSEND.
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
short fluid_event_get_value(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->value;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return Data field of event.
|
|
|
|
*
|
|
|
|
* Used by the #FLUID_SEQ_TIMER event type.
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
void *fluid_event_get_data(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->data;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the duration field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
2018-10-17 18:41:02 -04:00
|
|
|
* @return Note duration value in the time scale used by the sequencer (by default milliseconds)
|
2016-08-23 12:50:54 -04:00
|
|
|
*
|
|
|
|
* Used by the #FLUID_SEQ_NOTE event type.
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
unsigned int fluid_event_get_duration(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->duration;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the MIDI bank field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return MIDI bank number (0-16383)
|
|
|
|
*
|
|
|
|
* Used by the #FLUID_SEQ_BANKSELECT and #FLUID_SEQ_PROGRAMSELECT
|
|
|
|
* event types.
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
short fluid_event_get_bank(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->control;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the pitch field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return MIDI pitch bend pitch value (0-16383, 8192 = no bend)
|
|
|
|
*
|
|
|
|
* Used by the #FLUID_SEQ_PITCHBEND event type.
|
|
|
|
*/
|
2018-10-17 18:41:02 -04:00
|
|
|
int fluid_event_get_pitch(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->pitch;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the MIDI program field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return MIDI program number (0-127)
|
|
|
|
*
|
|
|
|
* Used by the #FLUID_SEQ_PROGRAMCHANGE and #FLUID_SEQ_PROGRAMSELECT
|
|
|
|
* event types.
|
|
|
|
*/
|
|
|
|
short
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_get_program(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->value;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the SoundFont ID field from a sequencer event structure.
|
|
|
|
* @param evt Sequencer event structure
|
|
|
|
* @return SoundFont identifier value.
|
|
|
|
*
|
|
|
|
* Used by the #FLUID_SEQ_PROGRAMSELECT event type.
|
|
|
|
*/
|
|
|
|
unsigned int
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_event_get_sfont_id(fluid_event_t *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt->duration;
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
/* heap management */
|
|
|
|
/********************/
|
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_evt_heap_t *
|
2016-08-23 12:50:54 -04:00
|
|
|
_fluid_evt_heap_init(int nbEvents)
|
|
|
|
{
|
|
|
|
#ifdef HEAP_WITH_DYNALLOC
|
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
int i;
|
|
|
|
fluid_evt_heap_t *heap;
|
|
|
|
fluid_evt_entry *tmp;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
heap = FLUID_NEW(fluid_evt_heap_t);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
if(heap == NULL)
|
|
|
|
{
|
|
|
|
FLUID_LOG(FLUID_PANIC, "sequencer: Out of memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap->freelist = NULL;
|
|
|
|
fluid_mutex_init(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* LOCK */
|
|
|
|
fluid_mutex_lock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* Allocate the event entries */
|
|
|
|
for(i = 0; i < nbEvents; i++)
|
|
|
|
{
|
|
|
|
tmp = FLUID_NEW(fluid_evt_entry);
|
|
|
|
tmp->next = heap->freelist;
|
|
|
|
heap->freelist = tmp;
|
|
|
|
}
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* UNLOCK */
|
|
|
|
fluid_mutex_unlock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
#else
|
2018-10-17 18:41:02 -04:00
|
|
|
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);
|
|
|
|
}
|
2016-08-23 12:50:54 -04:00
|
|
|
#endif
|
2018-10-17 18:41:02 -04:00
|
|
|
return (heap);
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
_fluid_evt_heap_free(fluid_evt_heap_t *heap)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
|
|
|
#ifdef HEAP_WITH_DYNALLOC
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_evt_entry *tmp, *next;
|
|
|
|
|
|
|
|
/* LOCK */
|
|
|
|
fluid_mutex_lock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
tmp = heap->freelist;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
while(tmp)
|
|
|
|
{
|
|
|
|
next = tmp->next;
|
|
|
|
FLUID_FREE(tmp);
|
|
|
|
tmp = next;
|
|
|
|
}
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* UNLOCK */
|
|
|
|
fluid_mutex_unlock(heap->mutex);
|
|
|
|
fluid_mutex_destroy(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
FLUID_FREE(heap);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
|
|
|
#else
|
2018-10-17 18:41:02 -04:00
|
|
|
FLUID_FREE(heap);
|
2016-08-23 12:50:54 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_evt_entry *
|
|
|
|
_fluid_seq_heap_get_free(fluid_evt_heap_t *heap)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
|
|
|
#ifdef HEAP_WITH_DYNALLOC
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_evt_entry *evt = NULL;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* LOCK */
|
|
|
|
fluid_mutex_lock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
|
|
|
#if !defined(MACOS9)
|
2018-10-17 18:41:02 -04:00
|
|
|
|
|
|
|
if(heap->freelist == NULL)
|
|
|
|
{
|
|
|
|
heap->freelist = FLUID_NEW(fluid_evt_entry);
|
|
|
|
|
|
|
|
if(heap->freelist != NULL)
|
|
|
|
{
|
|
|
|
heap->freelist->next = NULL;
|
|
|
|
}
|
2016-08-23 12:50:54 -04:00
|
|
|
}
|
2018-10-17 18:41:02 -04:00
|
|
|
|
2016-08-23 12:50:54 -04:00
|
|
|
#endif
|
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
evt = heap->freelist;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
if(evt != NULL)
|
|
|
|
{
|
|
|
|
heap->freelist = heap->freelist->next;
|
|
|
|
evt->next = NULL;
|
|
|
|
}
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* UNLOCK */
|
|
|
|
fluid_mutex_unlock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
return evt;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
|
|
|
#else
|
2018-10-17 18:41:02 -04:00
|
|
|
fluid_evt_entry *evt;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
if(heap->head == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* take from head of the heap */
|
|
|
|
/* critical - should threadlock ? */
|
|
|
|
evt = heap->head;
|
|
|
|
heap->head = heap->head->next;
|
|
|
|
|
|
|
|
return evt;
|
2016-08-23 12:50:54 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-17 18:41:02 -04:00
|
|
|
_fluid_seq_heap_set_free(fluid_evt_heap_t *heap, fluid_evt_entry *evt)
|
2016-08-23 12:50:54 -04:00
|
|
|
{
|
|
|
|
#ifdef HEAP_WITH_DYNALLOC
|
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* LOCK */
|
|
|
|
fluid_mutex_lock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
evt->next = heap->freelist;
|
|
|
|
heap->freelist = evt;
|
2016-08-23 12:50:54 -04:00
|
|
|
|
2018-10-17 18:41:02 -04:00
|
|
|
/* UNLOCK */
|
|
|
|
fluid_mutex_unlock(heap->mutex);
|
2016-08-23 12:50:54 -04:00
|
|
|
|
|
|
|
#else
|
2018-10-17 18:41:02 -04:00
|
|
|
/* append to the end of the heap */
|
|
|
|
/* critical - should threadlock ? */
|
|
|
|
heap->tail->next = evt;
|
|
|
|
heap->tail = evt;
|
|
|
|
evt->next = NULL;
|
2016-08-23 12:50:54 -04:00
|
|
|
#endif
|
|
|
|
}
|