mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-02-23 12:21:39 +00:00
Fixed a bug in the insertion of event in the queueLater list. When we looped
through the list, the prev variable was not updated. Also, the case when the event was last in the list was not handled. During the debugging I factorized some of the code. I kept it that way. Also, this file is indented using 8 spaces, as it is the Linux kernel coding style.
This commit is contained in:
parent
9444b03d43
commit
45ab6c3cf5
1 changed files with 340 additions and 258 deletions
|
@ -55,6 +55,7 @@ struct _fluid_sequencer_t {
|
|||
fluid_evt_entry* queue1[255][2];
|
||||
fluid_evt_entry* queueLater;
|
||||
fluid_evt_heap_t* heap;
|
||||
fluid_mutex_t mutex;
|
||||
#if FLUID_SEQ_WITH_TRACE
|
||||
char *tracebuf;
|
||||
char *traceptr;
|
||||
|
@ -143,7 +144,8 @@ delete_fluid_sequencer(fluid_sequencer_t* seq)
|
|||
}
|
||||
|
||||
#if FLUID_SEQ_WITH_TRACE
|
||||
if (seq->tracebuf != NULL) FLUID_FREE(seq->tracebuf);
|
||||
if (seq->tracebuf != NULL)
|
||||
FLUID_FREE(seq->tracebuf);
|
||||
seq->tracebuf = NULL;
|
||||
#endif
|
||||
|
||||
|
@ -238,7 +240,8 @@ void fluid_sequencer_unregister_client(fluid_sequencer_t* seq, short id)
|
|||
fluid_sequencer_client_t *client = (fluid_sequencer_client_t*)tmp->data;
|
||||
|
||||
if (client->id == id) {
|
||||
if (client->name) FLUID_FREE(client->name);
|
||||
if (client->name)
|
||||
FLUID_FREE(client->name);
|
||||
seq->clients = fluid_list_remove_link(seq->clients, tmp);
|
||||
delete1_fluid_list(tmp);
|
||||
return;
|
||||
|
@ -250,7 +253,8 @@ void fluid_sequencer_unregister_client(fluid_sequencer_t* seq, short id)
|
|||
|
||||
int fluid_sequencer_count_clients(fluid_sequencer_t* seq)
|
||||
{
|
||||
if (seq->clients == NULL) return 0;
|
||||
if (seq->clients == NULL)
|
||||
return 0;
|
||||
return fluid_list_size(seq->clients);
|
||||
}
|
||||
|
||||
|
@ -271,7 +275,8 @@ char* fluid_sequencer_get_client_name(fluid_sequencer_t* seq, int id)
|
|||
{
|
||||
fluid_list_t *tmp;
|
||||
|
||||
if (seq->clients == NULL) return NULL;
|
||||
if (seq->clients == NULL)
|
||||
return NULL;
|
||||
|
||||
tmp = seq->clients;
|
||||
while (tmp) {
|
||||
|
@ -315,7 +320,8 @@ void fluid_sequencer_send_now(fluid_sequencer_t* seq, fluid_event_t* evt)
|
|||
|
||||
if (dest->id == destID) {
|
||||
if (dest->callback)
|
||||
(dest->callback)(fluid_sequencer_get_tick(seq), evt, seq, dest->data);
|
||||
(dest->callback)(fluid_sequencer_get_tick(seq),
|
||||
evt, seq, dest->data);
|
||||
return;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
|
@ -357,9 +363,9 @@ fluid_sequencer_remove_events(fluid_sequencer_t* seq, short source, short dest,
|
|||
}
|
||||
|
||||
|
||||
/*******
|
||||
/*************************************
|
||||
time
|
||||
********/
|
||||
**************************************/
|
||||
unsigned int fluid_sequencer_get_tick(fluid_sequencer_t* seq)
|
||||
{
|
||||
unsigned int absMs = fluid_curtime();
|
||||
|
@ -425,53 +431,72 @@ double fluid_sequencer_get_time_scale(fluid_sequencer_t* seq)
|
|||
the queue
|
||||
|
||||
**********************/
|
||||
|
||||
/*
|
||||
The queue stores all future events to be processed.
|
||||
|
||||
Data structures
|
||||
|
||||
There is a heap, allocated at init time, for managing a pool of event entries,
|
||||
that is description of an event, its time, and whether it is a normal event
|
||||
or a removal command.
|
||||
There is a heap, allocated at init time, for managing a pool
|
||||
of event entries, that is description of an event, its time,
|
||||
and whether it is a normal event or a removal command.
|
||||
|
||||
The queue is separated in two arrays, and a list.
|
||||
The first array 'queue0' corresponds to the events to be sent in the next 256 ticks (0 to 255),
|
||||
the second array 'queue1' contains the events to be send from now+256 to now+65535. The list
|
||||
called 'queueLater' contains the events to be sent later than that. In each array, one cell contains
|
||||
a list of events having the same time (in the queue0 array), or the same time/256 (in the queue1 array),
|
||||
and a pointer to the last event in the list of the cell so as to be able to insert fast at the end of
|
||||
the list (i.e. a cell = 2 pointers).
|
||||
The 'queueLater' list is ordered by time and by post time.
|
||||
This way, inserting 'soon' events is fast (below 65535 ticks, that is about 1 minute if 1 tick=1ms).
|
||||
Inserting later events is more slow, but this is a realtime engine, isn't it ?
|
||||
The queue is separated in two arrays, and a list. The first
|
||||
array 'queue0' corresponds to the events to be sent in the
|
||||
next 256 ticks (0 to 255), the second array 'queue1' contains
|
||||
the events to be send from now+256 to now+65535. The list
|
||||
called 'queueLater' contains the events to be sent later than
|
||||
that. In each array, one cell contains a list of events having
|
||||
the same time (in the queue0 array), or the same time/256 (in
|
||||
the queue1 array), and a pointer to the last event in the list
|
||||
of the cell so as to be able to insert fast at the end of the
|
||||
list (i.e. a cell = 2 pointers). The 'queueLater' list is
|
||||
ordered by time and by post time. This way, inserting 'soon'
|
||||
events is fast (below 65535 ticks, that is about 1 minute if 1
|
||||
tick=1ms). Inserting later events is more slow, but this is a
|
||||
realtime engine, isn't it ?
|
||||
|
||||
The queue0 starts at queue0StartTime.
|
||||
When 256 ticks have elapsed, the queue0 array is emptied, and the
|
||||
first cell of the queue1 array is expanded in the queue0 array, according to the time of each event. The
|
||||
queue1 array is shifted to the left, and the first events of the queueLater list are inserte in the last
|
||||
cell of the queue1 array.
|
||||
The queue0 starts at queue0StartTime. When 256 ticks have
|
||||
elapsed, the queue0 array is emptied, and the first cell of
|
||||
the queue1 array is expanded in the queue0 array, according to
|
||||
the time of each event. The queue1 array is shifted to the
|
||||
left, and the first events of the queueLater list are inserte
|
||||
in the last cell of the queue1 array.
|
||||
|
||||
We remember the previously managed cell in queue0 in the prevCellNb variable. When processing the current
|
||||
cell, we process the events in between (late events).
|
||||
We remember the previously managed cell in queue0 in the
|
||||
prevCellNb variable. When processing the current cell, we
|
||||
process the events in between (late events).
|
||||
|
||||
Functions
|
||||
|
||||
The main thread functions first get an event entry from the heap, and copy the
|
||||
given event into it, then merely enqueue it in a preQueue. This is in order to protect the data
|
||||
structure : everything is managed in the callback (thread or interrupt, depending on the architecture).
|
||||
The main thread functions first get an event entry from the
|
||||
heap, and copy the given event into it, then merely enqueue it
|
||||
in a preQueue. This is in order to protect the data structure:
|
||||
everything is managed in the callback (thread or interrupt,
|
||||
depending on the architecture).
|
||||
|
||||
All queue data structure management is done in a timer callback: '_fluid_seq_queue_process'.
|
||||
The _fluid_seq_queue_process function first process the preQueue, inserting or removing
|
||||
event entrys from the queue, then processes the queue, by sending events ready to be sent
|
||||
at the current time.
|
||||
All queue data structure management is done in a timer
|
||||
callback: '_fluid_seq_queue_process'. The
|
||||
_fluid_seq_queue_process function first process the preQueue,
|
||||
inserting or removing event entrys from the queue, then
|
||||
processes the queue, by sending events ready to be sent at the
|
||||
current time.
|
||||
|
||||
Critical sections between the main thread (or app) and the sequencer thread (or interrupt) are:
|
||||
- the heap management (if two threads get a free event at the same time)
|
||||
Critical sections between the main thread (or app) and the
|
||||
sequencer thread (or interrupt) are:
|
||||
|
||||
- the heap management (if two threads get a free event at the
|
||||
same time)
|
||||
- the preQueue access.
|
||||
These are really small and fast sections (merely a pointer or two changing value). They are not protected
|
||||
by a mutex for now (August 2002). Waiting for crossplatform mutex solutions. When changing this code, beware
|
||||
that the _fluid_seq_queue_pre_insert function may be called by the callback of the queue thread (ex : a note event
|
||||
inserts a noteoff event).
|
||||
|
||||
These are really small and fast sections (merely a pointer or
|
||||
two changing value). They are not protected by a mutex for now
|
||||
(August 2002). Waiting for crossplatform mutex solutions. When
|
||||
changing this code, beware that the
|
||||
_fluid_seq_queue_pre_insert function may be called by the
|
||||
callback of the queue thread (ex : a note event inserts a
|
||||
noteoff event).
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
@ -488,6 +513,8 @@ void _fluid_seq_queue_send_queued_events(fluid_sequencer_t* seq);
|
|||
short
|
||||
_fluid_seq_queue_init(fluid_sequencer_t* seq, int maxEvents)
|
||||
{
|
||||
int i;
|
||||
|
||||
seq->heap = _fluid_evt_heap_init(maxEvents);
|
||||
if (seq->heap == NULL) {
|
||||
fluid_log(FLUID_PANIC, "sequencer: Out of memory\n");
|
||||
|
@ -499,12 +526,16 @@ _fluid_seq_queue_init(fluid_sequencer_t* seq, int maxEvents)
|
|||
|
||||
FLUID_MEMSET(seq->queue0, 0, 2*256*sizeof(fluid_evt_entry *));
|
||||
FLUID_MEMSET(seq->queue1, 0, 2*255*sizeof(fluid_evt_entry *));
|
||||
|
||||
seq->queueLater = NULL;
|
||||
seq->queue0StartTime = fluid_sequencer_get_tick(seq);
|
||||
seq->prevCellNb = -1;
|
||||
|
||||
fluid_mutex_init(seq->mutex);
|
||||
|
||||
/* start timer */
|
||||
seq->timer = new_fluid_timer((int)(1000/seq->scale), _fluid_seq_queue_process, (void *)seq, 1, 0);
|
||||
seq->timer = new_fluid_timer((int)(1000/seq->scale), _fluid_seq_queue_process,
|
||||
(void *)seq, 1, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -520,6 +551,7 @@ _fluid_seq_queue_end(fluid_sequencer_t* seq)
|
|||
_fluid_evt_heap_free(seq->heap);
|
||||
seq->heap = NULL;
|
||||
}
|
||||
fluid_mutex_destroy(seq->mutex);
|
||||
}
|
||||
|
||||
|
||||
|
@ -529,8 +561,8 @@ _fluid_seq_queue_end(fluid_sequencer_t* seq)
|
|||
/********************/
|
||||
|
||||
/* create event_entry and append to the preQueue */
|
||||
/* may be called from the main thread (usually) but also recursively from the queue thread, when a callback
|
||||
itself does an insert... */
|
||||
/* may be called from the main thread (usually) but also recursively
|
||||
from the queue thread, when a callback itself does an insert... */
|
||||
short
|
||||
_fluid_seq_queue_pre_insert(fluid_sequencer_t* seq, fluid_event_t * evt)
|
||||
{
|
||||
|
@ -545,7 +577,8 @@ _fluid_seq_queue_pre_insert(fluid_sequencer_t* seq, fluid_event_t * evt)
|
|||
evtentry->entryType = FLUID_EVT_ENTRY_INSERT;
|
||||
FLUID_MEMCPY(&(evtentry->evt), evt, sizeof(fluid_event_t));
|
||||
|
||||
/* critical - should threadlock ? */
|
||||
fluid_mutex_lock(seq->mutex);
|
||||
|
||||
/* append to preQueue */
|
||||
if (seq->preQueueLast) {
|
||||
seq->preQueueLast->next = evtentry;
|
||||
|
@ -554,12 +587,14 @@ _fluid_seq_queue_pre_insert(fluid_sequencer_t* seq, fluid_event_t * evt)
|
|||
}
|
||||
seq->preQueueLast = evtentry;
|
||||
|
||||
fluid_mutex_unlock(seq->mutex);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* create event_entry and append to the preQueue */
|
||||
/* may be called from the main thread (usually) but also recursively from the queue thread, when a callback
|
||||
itself does an insert... */
|
||||
/* may be called from the main thread (usually) but also recursively
|
||||
from the queue thread, when a callback itself does an insert... */
|
||||
void
|
||||
_fluid_seq_queue_pre_remove(fluid_sequencer_t* seq, short src, short dest, int type)
|
||||
{
|
||||
|
@ -580,7 +615,8 @@ _fluid_seq_queue_pre_remove(fluid_sequencer_t* seq, short src, short dest, int t
|
|||
evt->type = type;
|
||||
}
|
||||
|
||||
/* critical - should threadlock ? */
|
||||
fluid_mutex_lock(seq->mutex);
|
||||
|
||||
/* append to preQueue */
|
||||
if (seq->preQueueLast) {
|
||||
seq->preQueueLast->next = evtentry;
|
||||
|
@ -589,14 +625,15 @@ _fluid_seq_queue_pre_remove(fluid_sequencer_t* seq, short src, short dest, int t
|
|||
}
|
||||
seq->preQueueLast = evtentry;
|
||||
|
||||
fluid_mutex_unlock(seq->mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
/***********************/
|
||||
/* callback from timer
|
||||
/***********************
|
||||
* callback from timer
|
||||
* (may be in a different thread, or in an interrupt)
|
||||
*/
|
||||
/***********************/
|
||||
*
|
||||
***********************/
|
||||
int
|
||||
_fluid_seq_queue_process(void* data, unsigned int msec)
|
||||
{
|
||||
|
@ -606,12 +643,15 @@ _fluid_seq_queue_process(void* data, unsigned int msec)
|
|||
fluid_evt_entry* tmp;
|
||||
fluid_evt_entry* next;
|
||||
|
||||
/* critical - should threadlock ? */
|
||||
fluid_mutex_lock(seq->mutex);
|
||||
|
||||
/* get the preQueue */
|
||||
tmp = seq->preQueue;
|
||||
seq->preQueue = NULL;
|
||||
seq->preQueueLast = NULL;
|
||||
|
||||
fluid_mutex_unlock(seq->mutex);
|
||||
|
||||
/* walk all the preQueue and process them in order : inserts and removes */
|
||||
while (tmp) {
|
||||
next = tmp->next;
|
||||
|
@ -633,6 +673,88 @@ _fluid_seq_queue_process(void* data, unsigned int msec)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
_fluid_seq_queue_print_later(fluid_sequencer_t* seq)
|
||||
{
|
||||
int count = 0;
|
||||
fluid_evt_entry* tmp = seq->queueLater;
|
||||
|
||||
printf("queueLater:\n");
|
||||
|
||||
while (tmp) {
|
||||
unsigned int delay = tmp->evt.time - seq->queue0StartTime;
|
||||
printf("queueLater: Delay = %i\n", delay);
|
||||
tmp = tmp->next;
|
||||
count++;
|
||||
}
|
||||
printf("queueLater: Total of %i events\n", count);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_fluid_seq_queue_insert_queue0(fluid_sequencer_t* seq, fluid_evt_entry* tmp, int cell)
|
||||
{
|
||||
if (seq->queue0[cell][1] == NULL) {
|
||||
seq->queue0[cell][1] = seq->queue0[cell][0] = tmp;
|
||||
} else {
|
||||
seq->queue0[cell][1]->next = tmp;
|
||||
seq->queue0[cell][1] = tmp;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
_fluid_seq_queue_insert_queue1(fluid_sequencer_t* seq, fluid_evt_entry* tmp, int cell)
|
||||
{
|
||||
if (seq->queue1[cell][1] == NULL) {
|
||||
seq->queue1[cell][1] = seq->queue1[cell][0] = tmp;
|
||||
} else {
|
||||
seq->queue1[cell][1]->next = tmp;
|
||||
seq->queue1[cell][1] = tmp;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
_fluid_seq_queue_insert_queue_later(fluid_sequencer_t* seq, fluid_evt_entry* evtentry)
|
||||
{
|
||||
fluid_evt_entry* prev;
|
||||
fluid_evt_entry* tmp;
|
||||
unsigned int time = evtentry->evt.time;
|
||||
|
||||
/* insert in 'queueLater', after the ones that have the same
|
||||
* time */
|
||||
|
||||
/* first? */
|
||||
if ((seq->queueLater == NULL)
|
||||
|| (seq->queueLater->evt.time > time)) {
|
||||
evtentry->next = seq->queueLater;
|
||||
seq->queueLater = evtentry;
|
||||
return;
|
||||
}
|
||||
|
||||
/* walk queueLater */
|
||||
/* this is the only slow thing : if the event is more
|
||||
than 65535 ticks after the current time */
|
||||
|
||||
prev = seq->queueLater;
|
||||
tmp = prev->next;
|
||||
while (tmp) {
|
||||
if (tmp->evt.time > time) {
|
||||
/* insert before tmp */
|
||||
evtentry->next = tmp;
|
||||
prev->next = evtentry;
|
||||
return;
|
||||
}
|
||||
prev = tmp;
|
||||
tmp = prev->next;
|
||||
}
|
||||
|
||||
/* last */
|
||||
evtentry->next = NULL;
|
||||
prev->next = evtentry;
|
||||
}
|
||||
|
||||
void
|
||||
_fluid_seq_queue_insert_entry(fluid_sequencer_t* seq, fluid_evt_entry * evtentry)
|
||||
{
|
||||
|
@ -642,7 +764,9 @@ _fluid_seq_queue_insert_entry(fluid_sequencer_t* seq, fluid_evt_entry * evtentry
|
|||
unsigned int delay;
|
||||
|
||||
if (seq->queue0StartTime > 0) {
|
||||
/* queue0StartTime could be < 0 if the scale changed a lot early, breaking the following comparison */
|
||||
/* queue0StartTime could be < 0 if the scale changed a
|
||||
lot early, breaking the following comparison
|
||||
*/
|
||||
if (time < (unsigned int)seq->queue0StartTime) {
|
||||
/* we are late, send now */
|
||||
fluid_sequencer_send_now(seq, evt);
|
||||
|
@ -654,6 +778,8 @@ _fluid_seq_queue_insert_entry(fluid_sequencer_t* seq, fluid_evt_entry * evtentry
|
|||
|
||||
if (seq->prevCellNb >= 0) {
|
||||
/* prevCellNb could be -1 is seq was just started - unlikely */
|
||||
/* prevCellNb can also be -1 if cellNb was reset to 0 in
|
||||
_fluid_seq_queue_send_queued_events() */
|
||||
if (time <= (unsigned int)(seq->queue0StartTime + seq->prevCellNb)) {
|
||||
/* we are late, send now */
|
||||
fluid_sequencer_send_now(seq, evt);
|
||||
|
@ -666,58 +792,13 @@ _fluid_seq_queue_insert_entry(fluid_sequencer_t* seq, fluid_evt_entry * evtentry
|
|||
delay = time - seq->queue0StartTime;
|
||||
|
||||
if (delay > 65535) {
|
||||
/* insert in 'later', after the ones that have the same time */
|
||||
|
||||
if (seq->queueLater == NULL) {
|
||||
/* first one in later */
|
||||
seq->queueLater = evtentry;
|
||||
return;
|
||||
}
|
||||
|
||||
/* first one ?*/
|
||||
if (seq->queueLater->evt.time > time) {
|
||||
evtentry->next = seq->queueLater;
|
||||
seq->queueLater = evtentry;
|
||||
return;
|
||||
}
|
||||
|
||||
/* walk queueLater */
|
||||
/* this is the only slow thing : if the event is more
|
||||
than 65535 ticks after the current time */
|
||||
{
|
||||
fluid_evt_entry* prev = seq->queueLater;
|
||||
fluid_evt_entry* tmp = prev->next;
|
||||
while (tmp) {
|
||||
if (tmp->evt.time > time) {
|
||||
/* insert before tmp */
|
||||
evtentry->next = tmp;
|
||||
prev->next = evtentry;
|
||||
return;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
_fluid_seq_queue_insert_queue_later(seq, evtentry);
|
||||
|
||||
} else if (delay > 255) {
|
||||
/* append to the right cell in queue1 */
|
||||
unsigned int cellnb = delay/256;
|
||||
if (seq->queue1[cellnb-1][1] == NULL) {
|
||||
seq->queue1[cellnb-1][1] = seq->queue1[cellnb-1][0] = evtentry;
|
||||
} else {
|
||||
seq->queue1[cellnb-1][1]->next = evtentry;
|
||||
seq->queue1[cellnb-1][1] = evtentry;
|
||||
}
|
||||
evtentry->next = NULL;
|
||||
_fluid_seq_queue_insert_queue1(seq, evtentry, delay/256 - 1);
|
||||
|
||||
} else {
|
||||
/* insert in queue0 */
|
||||
if (seq->queue0[delay][1] == NULL) {
|
||||
seq->queue0[delay][1] = seq->queue0[delay][0] = evtentry;
|
||||
} else {
|
||||
seq->queue0[delay][1]->next = evtentry;
|
||||
seq->queue0[delay][1] = evtentry;
|
||||
}
|
||||
evtentry->next = NULL;
|
||||
_fluid_seq_queue_insert_queue0(seq, evtentry, delay);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,8 +829,7 @@ _fluid_seq_queue_matchevent(fluid_event_t* evt, int templType, short templSrc, s
|
|||
eventType == FLUID_SEQ_VOLUME ||
|
||||
eventType == FLUID_SEQ_REVERBSEND ||
|
||||
eventType == FLUID_SEQ_CONTROLCHANGE ||
|
||||
eventType == FLUID_SEQ_CHORUSSEND
|
||||
)
|
||||
eventType == FLUID_SEQ_CHORUSSEND)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -856,24 +936,35 @@ _fluid_seq_queue_remove_entries_matching(fluid_sequencer_t* seq, fluid_evt_entry
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_fluid_seq_queue_send_queued_events(fluid_sequencer_t* seq)
|
||||
_fluid_seq_queue_send_cell_events(fluid_sequencer_t* seq, int cellNb)
|
||||
{
|
||||
unsigned int nowTicks = fluid_sequencer_get_tick(seq);
|
||||
short cellNb;
|
||||
fluid_evt_entry* next;
|
||||
fluid_evt_entry* tmp;
|
||||
|
||||
cellNb = seq->prevCellNb + 1;
|
||||
while (cellNb <= (int)(nowTicks - seq->queue0StartTime)) {
|
||||
if (cellNb == 256) {
|
||||
tmp = seq->queue0[cellNb][0];
|
||||
while (tmp) {
|
||||
fluid_sequencer_send_now(seq, &(tmp->evt));
|
||||
|
||||
next = tmp->next;
|
||||
|
||||
_fluid_seq_heap_set_free(seq->heap, tmp);
|
||||
tmp = next;
|
||||
}
|
||||
seq->queue0[cellNb][0] = NULL;
|
||||
seq->queue0[cellNb][1] = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
_fluid_seq_queue_slide(fluid_sequencer_t* seq)
|
||||
{
|
||||
short i;
|
||||
int more = 1;
|
||||
fluid_evt_entry* next;
|
||||
fluid_evt_entry* tmp;
|
||||
int count = 0;
|
||||
|
||||
/* do the slide */
|
||||
seq->queue0StartTime += 256;
|
||||
cellNb = 0;
|
||||
|
||||
/* sort all queue1[0] into queue0 according to new queue0StartTime */
|
||||
tmp = seq->queue1[0][0];
|
||||
|
@ -883,23 +974,12 @@ _fluid_seq_queue_send_queued_events(fluid_sequencer_t* seq)
|
|||
if (delay > 255) {
|
||||
/* should not happen !! */
|
||||
/* append it to queue1[1] */
|
||||
if (seq->queue1[1][1] == NULL) {
|
||||
seq->queue1[1][1] = seq->queue1[1][0] = tmp;
|
||||
_fluid_seq_queue_insert_queue1(seq, tmp, 1);
|
||||
} else {
|
||||
seq->queue1[1][1]->next = tmp;
|
||||
seq->queue1[1][1] = tmp;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
} else {
|
||||
if (seq->queue0[delay][1] == NULL) {
|
||||
seq->queue0[delay][1] = seq->queue0[delay][0] = tmp;
|
||||
} else {
|
||||
seq->queue0[delay][1]->next = tmp;
|
||||
seq->queue0[delay][1] = tmp;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
_fluid_seq_queue_insert_queue0(seq, tmp, delay);
|
||||
}
|
||||
tmp = next;
|
||||
count++;
|
||||
}
|
||||
|
||||
/* slide all queue1[i] into queue1[i-1] */
|
||||
|
@ -910,42 +990,44 @@ _fluid_seq_queue_send_queued_events(fluid_sequencer_t* seq)
|
|||
seq->queue1[254][0] = NULL;
|
||||
seq->queue1[254][1] = NULL;
|
||||
|
||||
/* append queueLater to queue1[254] */
|
||||
more = 1;
|
||||
tmp = seq->queueLater;
|
||||
while (tmp && more) {
|
||||
unsigned int delay = tmp->evt.time - seq->queue0StartTime;
|
||||
next = tmp->next;
|
||||
if (delay <= 65535) {
|
||||
/* append it */
|
||||
if (seq->queue1[254][1] == NULL) {
|
||||
seq->queue1[254][1] = seq->queue1[254][0] = tmp;
|
||||
} else {
|
||||
seq->queue1[254][1]->next = tmp;
|
||||
seq->queue1[254][1] = tmp;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
tmp = next;
|
||||
} else more = 0;
|
||||
}
|
||||
seq->queueLater = tmp;
|
||||
|
||||
/* append queueLater to queue1[254] */
|
||||
count = 0;
|
||||
tmp = seq->queueLater;
|
||||
while (tmp) {
|
||||
unsigned int delay = tmp->evt.time - seq->queue0StartTime;
|
||||
|
||||
if (delay > 65535) {
|
||||
break;
|
||||
}
|
||||
|
||||
next = tmp->next;
|
||||
|
||||
/* append it */
|
||||
_fluid_seq_queue_insert_queue1(seq, tmp, 254);
|
||||
tmp = next;
|
||||
count++;
|
||||
}
|
||||
|
||||
seq->queueLater = tmp;
|
||||
}
|
||||
|
||||
void
|
||||
_fluid_seq_queue_send_queued_events(fluid_sequencer_t* seq)
|
||||
{
|
||||
unsigned int nowTicks = fluid_sequencer_get_tick(seq);
|
||||
short cellNb;
|
||||
|
||||
cellNb = seq->prevCellNb + 1;
|
||||
while (cellNb <= (int)(nowTicks - seq->queue0StartTime)) {
|
||||
if (cellNb == 256) {
|
||||
cellNb = 0;
|
||||
_fluid_seq_queue_slide(seq);
|
||||
} /* slide */
|
||||
|
||||
|
||||
/* process queue0[cellNb] */
|
||||
tmp = seq->queue0[cellNb][0];
|
||||
while (tmp) {
|
||||
|
||||
fluid_sequencer_send_now(seq, &(tmp->evt));
|
||||
|
||||
next = tmp->next;
|
||||
|
||||
_fluid_seq_heap_set_free(seq->heap, tmp);
|
||||
tmp = next;
|
||||
}
|
||||
seq->queue0[cellNb][0] = NULL;
|
||||
seq->queue0[cellNb][1] = NULL;
|
||||
_fluid_seq_queue_send_cell_events(seq, cellNb);
|
||||
|
||||
/* next cell */
|
||||
cellNb++;
|
||||
|
|
Loading…
Reference in a new issue