public Task TransitionToAsync(PlaybackEnvironment environment, TimeSpan overTime) { var tasks = new List <Task> (); foreach (PlaybackEnvironmentElement element in this.elements) { Transition transition = new Transition { Length = overTime, StartingIntensity = element.Intensity }; tasks.Add(transition.Task); bool fadeOut = true; // TODO: Keep same elements playing as-is if (fadeOut) { transition.EndingIntensity = 0; } this.transitions[element] = transition; } return(Task.WhenAll(tasks)); }
private void TimelineRunner(object state) { this.loadedServices.Wait(); ActiveServices services = null; while (true) { PlaybackEnvironment environment = this.currentEnvironment; PlaybackEnvironment previous = this.previousEnvironment; if (this.servicesUpdated) { this.lck.Wait(); var enabled = this.enabledServices.ToArray(); services = new ActiveServices { Audio = enabled.OfType <IAudioService>().FirstOrDefault(), Lighting = enabled.OfType <ILightingService>().FirstOrDefault(), Storage = this.storage }; this.lck.Release(); } environment?.Tick(services); previous?.Tick(services); Thread.Sleep(1); } }
/// <summary> /// Stops the <paramref name="environment"/> if it is the currently playing environment. /// </summary> public void StopEnvironment(PlaybackEnvironment environment, bool transition = true) { if (this.currentEnvironment != environment) { return; } PlaybackEnvironment previous; this.lck.Wait(); try { if (this.currentEnvironment != environment) { return; } previous = Interlocked.Exchange(ref this.currentEnvironment, null); var originalPrevious = Interlocked.Exchange(ref this.previousEnvironment, previous); originalPrevious?.Stop(); } finally { this.lck.Release(); } if (previous == null) { return; } if (transition) { previous.FadeOutAsync(TransitionTime); } else { previous.Stop(); } EnvironmentChanged?.Invoke(this, new PlaybackEnvironmentChangedEventArgs(previous, null)); }
public void PlayEnvironment(PlaybackEnvironment environment, bool transition = true) { if (environment is null) { throw new ArgumentNullException(nameof(environment)); } PlaybackEnvironment previous; this.lck.Wait(); try { previous = Interlocked.Exchange(ref this.currentEnvironment, environment); if (previous != null) { var originalPrevious = Interlocked.Exchange(ref this.previousEnvironment, previous); originalPrevious?.Stop(); if (transition) { previous.TransitionToAsync(environment, TransitionTime); } else { previous.Stop(); } } else if (transition) { environment.FadeInAsync(TransitionTime); } } finally { this.lck.Release(); } EnvironmentChanged?.Invoke(this, new PlaybackEnvironmentChangedEventArgs(previous, environment)); }
public PlaybackEnvironmentChangedEventArgs(PlaybackEnvironment previousEnvironment, PlaybackEnvironment newEnvironment) { PreviousEnvironment = previousEnvironment; NewEnvironment = newEnvironment; }