2010-06-28 20:03:12 +00:00
|
|
|
/* FluidSynth - A Software Synthesizer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Peter Hanappe and others.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2017-07-12 15:45:23 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
2017-07-12 15:53:03 +00:00
|
|
|
* as published by the Free Software Foundation; either version 2.1 of
|
2010-06-28 20:03:12 +00: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
|
2017-07-12 15:45:23 +00:00
|
|
|
* Lesser General Public License for more details.
|
2010-06-28 20:03:12 +00:00
|
|
|
*
|
2017-07-12 15:54:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-06-28 20:03:12 +00:00
|
|
|
* License along with this library; if not, write to the Free
|
2011-08-15 12:57:10 +00:00
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA
|
2010-06-28 20:03:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _FLUID_RVOICE_EVENT_H
|
|
|
|
#define _FLUID_RVOICE_EVENT_H
|
|
|
|
|
|
|
|
#include "fluidsynth_priv.h"
|
2010-06-30 16:39:20 +00:00
|
|
|
#include "fluid_rvoice_mixer.h"
|
2010-06-28 20:03:12 +00:00
|
|
|
#include "fluid_ringbuffer.h"
|
|
|
|
|
|
|
|
typedef struct _fluid_rvoice_event_t fluid_rvoice_event_t;
|
|
|
|
typedef struct _fluid_rvoice_eventhandler_t fluid_rvoice_eventhandler_t;
|
|
|
|
|
|
|
|
struct _fluid_rvoice_event_t {
|
2018-04-08 15:22:57 +00:00
|
|
|
fluid_rvoice_function_t method;
|
2010-06-28 20:03:12 +00:00
|
|
|
void* object;
|
2018-04-08 15:22:57 +00:00
|
|
|
fluid_rvoice_param_t param[EVENT_PARAMS];
|
2010-06-28 20:03:12 +00:00
|
|
|
};
|
|
|
|
|
2017-11-30 11:55:20 +00:00
|
|
|
/*
|
2010-06-28 20:03:12 +00:00
|
|
|
* Bridge between the renderer thread and the midi state thread.
|
2018-04-08 10:07:10 +00:00
|
|
|
* fluid_rvoice_eventhandler_fetch_all() can be called in parallell
|
|
|
|
* with fluid_rvoice_eventhandler_push/flush()
|
2010-06-28 20:03:12 +00:00
|
|
|
*/
|
|
|
|
struct _fluid_rvoice_eventhandler_t {
|
|
|
|
fluid_ringbuffer_t* queue; /**< List of fluid_rvoice_event_t */
|
2017-10-25 11:22:36 +00:00
|
|
|
fluid_atomic_int_t queue_stored; /**< Extras pushed but not flushed */
|
2010-06-28 20:03:12 +00:00
|
|
|
fluid_ringbuffer_t* finished_voices; /**< return queue from handler, list of fluid_rvoice_t* */
|
2010-06-30 16:39:20 +00:00
|
|
|
fluid_rvoice_mixer_t* mixer;
|
2010-06-28 20:03:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fluid_rvoice_eventhandler_t* new_fluid_rvoice_eventhandler(
|
2018-04-08 10:07:10 +00:00
|
|
|
int queuesize, int finished_voices_size, int bufs,
|
2010-10-17 10:43:48 +00:00
|
|
|
int fx_bufs, fluid_real_t sample_rate);
|
2010-06-28 20:03:12 +00:00
|
|
|
|
|
|
|
void delete_fluid_rvoice_eventhandler(fluid_rvoice_eventhandler_t*);
|
|
|
|
|
2010-07-03 12:25:43 +00:00
|
|
|
int fluid_rvoice_eventhandler_dispatch_all(fluid_rvoice_eventhandler_t*);
|
|
|
|
int fluid_rvoice_eventhandler_dispatch_count(fluid_rvoice_eventhandler_t*);
|
2010-06-28 20:03:12 +00:00
|
|
|
|
|
|
|
static FLUID_INLINE void
|
|
|
|
fluid_rvoice_eventhandler_flush(fluid_rvoice_eventhandler_t* handler)
|
|
|
|
{
|
2017-08-25 19:16:37 +00:00
|
|
|
int queue_stored = fluid_atomic_int_get(&handler->queue_stored);
|
|
|
|
|
|
|
|
if (queue_stored > 0) {
|
|
|
|
fluid_atomic_int_set(&handler->queue_stored, 0);
|
|
|
|
fluid_ringbuffer_next_inptr(handler->queue, queue_stored);
|
2010-06-28 20:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return next finished voice, or NULL if nothing in queue
|
|
|
|
*/
|
|
|
|
static FLUID_INLINE fluid_rvoice_t*
|
|
|
|
fluid_rvoice_eventhandler_get_finished_voice(fluid_rvoice_eventhandler_t* handler)
|
|
|
|
{
|
|
|
|
void* result = fluid_ringbuffer_get_outptr(handler->finished_voices);
|
|
|
|
if (result == NULL) return NULL;
|
|
|
|
result = * (fluid_rvoice_t**) result;
|
|
|
|
fluid_ringbuffer_next_outptr(handler->finished_voices);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int fluid_rvoice_eventhandler_push(fluid_rvoice_eventhandler_t* handler,
|
2018-04-08 15:22:57 +00:00
|
|
|
fluid_rvoice_function_t method, void* object, int intparam,
|
2010-06-28 20:03:12 +00:00
|
|
|
fluid_real_t realparam);
|
|
|
|
|
|
|
|
int fluid_rvoice_eventhandler_push_ptr(fluid_rvoice_eventhandler_t* handler,
|
2018-04-08 15:22:57 +00:00
|
|
|
fluid_rvoice_function_t method, void* object, void* ptr);
|
2010-06-28 20:03:12 +00:00
|
|
|
|
2018-04-08 15:22:57 +00:00
|
|
|
int fluid_rvoice_eventhandler_push_param(fluid_rvoice_eventhandler_t* handler,
|
|
|
|
fluid_rvoice_function_t method, void* object,
|
|
|
|
fluid_rvoice_param_t param[EVENT_PARAMS]);
|
|
|
|
|
2010-06-28 20:03:12 +00:00
|
|
|
static FLUID_INLINE void
|
|
|
|
fluid_rvoice_eventhandler_add_rvoice(fluid_rvoice_eventhandler_t* handler,
|
|
|
|
fluid_rvoice_t* rvoice)
|
|
|
|
{
|
2010-06-30 16:39:20 +00:00
|
|
|
fluid_rvoice_eventhandler_push_ptr(handler, fluid_rvoice_mixer_add_voice,
|
|
|
|
handler->mixer, rvoice);
|
2010-06-28 20:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|