diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drone.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/drone.c b/src/drone.c index e3748f1..47508f9 100644 --- a/src/drone.c +++ b/src/drone.c @@ -260,3 +260,55 @@ int xas_drone_chamber_event_seq(xas_drone_chamber *chamber, error_seq_add: return -1; } + +static void max_speech_duration(xas_drone_chamber *chamber, + struct timeval *max) { + size_t i; + + for (i=0; i<chamber->drone_count; i++) { + xas_drone *drone = chamber->drones[i]; + xas_bank_player *player = (xas_bank_player *)drone->obj->ctx; + + struct timeval duration; + + xas_bank_entry_duration(drone->bank, + player->entry, + &duration); + + if (timercmp(&duration, max, >)) { + duration.tv_sec = max->tv_sec; + duration.tv_usec = max->tv_usec; + } + } +} + +int xas_drone_chamber_chorus_seq(xas_drone_chamber *chamber, + xas_seq *seq, + int advance, + struct timeval *now) { + struct timeval duration, + tmp, + delay = { 0, 500000 }; + + size_t i; + + max_speech_duration(chamber, &duration); + + for (i=0; i<chamber->drone_count; i++) { + xas_drone *drone = chamber->drones[i]; + + if (xas_seq_add_event_on(seq, drone->obj, *now) < 0) { + goto error_seq_add; + } + } + + if (advance) { + timeradd(now, &duration, &tmp); + timeradd(&tmp, &delay, now); + } + + return 0; + +error_seq_add: + return -1; +} |