diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/seq.c | 81 |
1 files changed, 34 insertions, 47 deletions
@@ -26,45 +26,32 @@ error_malloc_seq: } void xas_seq_destroy(xas_seq *seq) { - xas_seq_event_list_item *item = seq->first; + xas_seq_event *ev = seq->first; - while (item) { - xas_seq_event_list_item *next = item->next; + while (ev) { + xas_seq_event *next = ev->next; - free(item->ev); - free(item); + free(ev); - item = next; + ev = next; } free(seq); } static int event_add(xas_seq *seq, xas_seq_event *ev) { - xas_seq_event_list_item *item; - - if ((item = malloc(sizeof(*item))) == NULL) { - goto error_malloc_item; - } - - item->ev = ev; - item->next = NULL; - if (seq->first == NULL) { - seq->first = item; - seq->last = item; + seq->first = ev; + seq->last = ev; } else { - seq->last->next = item; - seq->last = item; + seq->last->next = ev; + seq->last = ev; } return 0; - -error_malloc_item: - return -1; } -static xas_seq_event_list_item *event_list_tail(xas_seq_event_list_item *head) { +static xas_seq_event *event_tail(xas_seq_event *head) { if (head == NULL) { return NULL; } @@ -76,17 +63,17 @@ static xas_seq_event_list_item *event_list_tail(xas_seq_event_list_item *head) { return head; } -static xas_seq_event_list_item *event_list_partition(xas_seq_event_list_item *head, - xas_seq_event_list_item *end, - xas_seq_event_list_item **head_new, - xas_seq_event_list_item **end_new) { - xas_seq_event_list_item *pivot = end, - *prev = NULL, - *cur = head, - *tail = pivot; +static xas_seq_event *event_list_partition(xas_seq_event *head, + xas_seq_event *end, + xas_seq_event **head_new, + xas_seq_event **end_new) { + xas_seq_event *pivot = end, + *prev = NULL, + *cur = head, + *tail = pivot; while (cur != pivot) { - if (timercmp(&cur->ev->timestamp, &pivot->ev->timestamp, <)) { + if (timercmp(&cur->timestamp, &pivot->timestamp, <)) { if (*head_new == NULL) { *head_new = cur; } @@ -94,7 +81,7 @@ static xas_seq_event_list_item *event_list_partition(xas_seq_event_list_item *he prev = cur; cur = cur->next; } else { - xas_seq_event_list_item *tmp; + xas_seq_event *tmp; if (prev) { prev->next = cur->next; @@ -118,11 +105,11 @@ static xas_seq_event_list_item *event_list_partition(xas_seq_event_list_item *he return pivot; } -static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *head, - xas_seq_event_list_item *end) { - xas_seq_event_list_item *head_new = NULL, - *end_new = NULL, - *pivot; +static xas_seq_event *event_list_sort_recur(xas_seq_event *head, + xas_seq_event *end) { + xas_seq_event *head_new = NULL, + *end_new = NULL, + *pivot; if (head == NULL || head == end) { return head; @@ -131,7 +118,7 @@ static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *h pivot = event_list_partition(head, end, &head_new, &end_new); if (head_new != pivot) { - xas_seq_event_list_item *tmp = head_new; + xas_seq_event *tmp = head_new; while (tmp->next != pivot) { tmp = tmp->next; @@ -141,7 +128,7 @@ static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *h head_new = event_list_sort_recur(head_new, tmp); - tmp = event_list_tail(head_new); + tmp = event_tail(head_new); tmp->next = pivot; } @@ -152,7 +139,7 @@ static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *h static void event_sort(xas_seq *seq) { seq->first = event_list_sort_recur(seq->first, seq->last); - seq->last = event_list_tail(seq->first); + seq->last = event_tail(seq->first); } int xas_seq_add_event_off(xas_seq *seq, @@ -563,7 +550,7 @@ static inline void timerupdate(struct timeval *tv, } int xas_seq_play(xas_seq *seq, xas_audio_stream *sink) { - xas_seq_event_list_item *item; + xas_seq_event *ev; xas_audio_stream *source; size_t frame = 0, @@ -581,21 +568,21 @@ int xas_seq_play(xas_seq *seq, xas_audio_stream *sink) { event_sort(seq); - item = seq->first; + ev = seq->first; - while (item) { + while (ev) { struct timeval tv; ssize_t readlen; timerupdate(&tv, interval, frame); - while (item && !timercmp(&tv, &item->ev->timestamp, <)) { - if (event_trigger(seq->scene, item->ev) < 0) { + while (ev && !timercmp(&tv, &ev->timestamp, <)) { + if (event_trigger(seq->scene, ev) < 0) { goto error_event_trigger; } - item = item->next; + ev = ev->next; } if ((readlen = xas_audio_stream_read(source, |