示例#1
0
 private static void FillLights_Brightness(LED_Queue QueueToModify, byte Brightness)
 {
     FillLights_Brightness (QueueToModify, Brightness, true);
 }
示例#2
0
 private static void FillLights_Brightness(LED_Queue QueueToModify, byte Brightness, bool ApplyNow)
 {
     FillLights_Brightness (QueueToModify, Brightness, ApplyNow, false);
 }
示例#3
0
 private static void SetLight_Color(LED_Queue QueueToModify, int Index, byte R, byte G, byte B, bool ApplyNow)
 {
     SetLight_Color (QueueToModify, Index, R, G, B, ApplyNow, false);
 }
示例#4
0
 /// <summary>
 /// Recreates the light queues with the specified number of lights, halting animations if changes are needed.
 /// </summary>
 /// <param name="LightCount">Light count.  If specified number of lights differs from before, halts animations and recreates queues; otherwise, nothing happens.</param>
 private static void CreateLightQueues(int LightCount)
 {
     if (Actinic_Lights_Queue != null && Actinic_Lights_Queue.LightCount == LightCount) {
         // No update needed
         // Note: other queues cannot become de-synced as this queue always exists and will need updates if inaccurate.
         return;
     } else {
         if (Actinic_Lights_Queue != null) {
             Console.WriteLine ("Detected {0} lights, stopping animations and updating configuration...", LightCount);
         } else {
             Console.WriteLine ("Detected {0} lights", LightCount);
         }
         HaltActivity (true);
         lock (Actinic_Lights_Overlay_Queues) {
             Actinic_Lights_Overlay_Queues.Clear ();
         }
         Actinic_Lights_Queue = new LED_Queue (LightCount);
     }
 }
示例#5
0
 private static void FillLights_Color(LED_Queue QueueToModify, byte R, byte G, byte B)
 {
     FillLights_Color (QueueToModify, R, G, B, true);
 }
示例#6
0
 private static void FillLights_Color(LED_Queue QueueToModify, byte R, byte G, byte B, bool ApplyNow, bool SkipAnimationQueue)
 {
     for (int i = 0; i < QueueToModify.LightCount; i++) {
         QueueToModify.Lights [i].R = R;
         QueueToModify.Lights [i].G = G;
         QueueToModify.Lights [i].B = B;
     }
     if (ApplyNow) {
         if (SkipAnimationQueue) {
             QueueToModify.PushToQueue ();
         } else {
             AddToAnimQueue (QueueToModify);
         }
     }
 }
示例#7
0
 /// <summary>
 /// Add the current Lights collection of LEDs to the queue, automatically smoothly transitioning into it.
 /// </summary>
 /// <param name="QueueToModify">Queue to add animation to</param>
 private static void AddToAnimQueue(LED_Queue QueueToModify)
 {
     AddToAnimQueue (QueueToModify, QueueToModify.Lights);
 }
示例#8
0
 private static void FillLights_Color(LED_Queue QueueToModify, Actinic.Color SelectedColor, bool ApplyNow)
 {
     FillLights_Color (QueueToModify, SelectedColor, ApplyNow, false);
 }
示例#9
0
 private static void WaitForQueue(LED_Queue QueueToModify, int MaximumRemainingEvents)
 {
     if (Actinic_Light_Queue_Thread != null) {
         if (Actinic_Light_Queue_Thread.IsAlive == true) {
     #if DEBUG_PERFORMANCE
             if (QueueToModify.QueueCount > MaximumRemainingEvents)
                 Console.WriteLine ("-- {0} events in queue, waiting until {1}...", QueueToModify.QueueCount, MaximumRemainingEvents);
     #endif
             while (QueueToModify.QueueCount > MaximumRemainingEvents) {
                 System.Threading.Thread.Sleep (5);
             }
         }
     }
 }
示例#10
0
 private static void WarnQueueLossIfEmpty(LED_Queue QueueToModify)
 {
     if (QueueToModify.LightsHaveNoEffect) {
         Console.WriteLine ("(Warning: queue has no effect and will be automatically deleted!  Set a color, brightness, or animation to avoid this.)");
     }
 }
示例#11
0
 private static void WaitForQueue(LED_Queue QueueToModify)
 {
     WaitForQueue (QueueToModify, 0);
 }
示例#12
0
        private static void UpdateAnimationStackForQueue(LED_Queue QueueToModify, long PerfTracking_TimeElapsed, string PerfTracking_QueueName)
        {
            if (QueueToModify.AnimationActive && QueueToModify.QueueEmpty) {
                // Only add an animation frame if enabled, and the queue is empty
                if ((QueueToModify.SelectedAnimation.RequestedAnimationDelay <= Light_Animation_Latency) ||
                    (QueueToModify.QueueIdleTime >= QueueToModify.SelectedAnimation.RequestedAnimationDelay) ||
                    (QueueToModify.AnimationForceFrameRequest == true)) {
                    // Only add an animation frame if less than default delay is requested, or enough time elapsed in idle
            #if DEBUG_PERFORMANCE
                        Console.WriteLine ("{0} ms - queuing frame from active animation ({1})", PerfTracking_TimeElapsed, PerfTracking_QueueName);
            #endif
                    try {
                        // In all of the below, you must set QueueToModify to the new, intended output, otherwise
                        //  animation transitions will contain old values.
                        if (QueueToModify.SelectedAnimation.EnableSmoothing && Animation_Fading_Enabled) {
                            // Get the next frame, apply smoothing
                            ApplySmoothing (QueueToModify.SelectedAnimation.SmoothingAmount, true, QueueToModify.SelectedAnimation.GetNextFrame (), QueueToModify);
                            // ...and insert it into the queue.
                            QueueToModify.PushToQueue ();
                        } else if ((QueueToModify.AnimationForceFrameRequest == true) &&
                            (QueueToModify.SelectedAnimation.RequestSmoothCrossfade)) {
                            // Animation has a potentially-sharp change and requests a smooth cross-fade
                            // Get the next frame...
                            QueueToModify.Lights = QueueToModify.SelectedAnimation.GetNextFrame ();
                            // ...and insert it into the queue with an animated transition.
                            AddToAnimQueue (QueueToModify);
                        } else {
                            // Without smoothing, just directly add to the queue
                            QueueToModify.Lights = QueueToModify.SelectedAnimation.GetNextFrame ();
                            // But ensure that the local QueueToModify list is accurate
                            QueueToModify.PushToQueue ();
                        }
                    } catch (System.InvalidOperationException) {
                        Console.WriteLine ("(error playing animation, invalid operation encountered - setting queue to black)");
                        // System.InvalidOperationException: AudioPlayer not running, can not determine current track position.
                        // TODO: Better method of fixing this?
                        //  For now, just stop the animation, and let it do whatever it was going to do.
                        Animation_Stop (QueueToModify);
                        FillLights_Color (QueueToModify, LightSystem.Color_MIN, LightSystem.Color_MIN, LightSystem.Color_MIN, false, true);
                        FillLights_Brightness (QueueToModify, LightSystem.Brightness_MIN, false, true);
                    }

                    QueueToModify.AnimationForceFrameRequest = false;
                    // Frame has been sent, reset the ForceFrameRequest flag
                }
            }
        }
示例#13
0
 private static void SetLight_Color(LED_Queue QueueToModify, int Index, byte R, byte G, byte B, bool ApplyNow, bool SkipAnimationQueue)
 {
     if (Index >= 0 & Index < QueueToModify.LightCount) {
         QueueToModify.Lights [Index].R = R;
         QueueToModify.Lights [Index].G = G;
         QueueToModify.Lights [Index].B = B;
     }
     if (ApplyNow) {
         if (SkipAnimationQueue) {
             QueueToModify.PushToQueue ();
         } else {
             AddToAnimQueue (QueueToModify);
         }
     }
 }
示例#14
0
 private static void FillLights_Brightness(LED_Queue QueueToModify, byte Brightness, bool ApplyNow, bool SkipAnimationQueue)
 {
     for (int i = 0; i < QueueToModify.LightCount; i++) {
         QueueToModify.Lights [i].Brightness = Brightness;
     }
     if (ApplyNow) {
         if (SkipAnimationQueue) {
             QueueToModify.PushToQueue ();
         } else {
             AddToAnimQueue (QueueToModify);
         }
     }
 }
示例#15
0
        /// <summary>
        /// Add the collection of LEDs to the queue, automatically smoothly transitioning into it.
        /// </summary>
        /// <param name="QueueToModify">Queue to add animation to</param>
        /// <param name="LED_Collection">Desired LED appearance</param>
        private static void AddToAnimQueue(LED_Queue QueueToModify, List<LED> LED_Collection)
        {
            if (QueueToModify.QueueCount > 0 && Command_ConflictsExpected == false)
                Console.WriteLine ("(Warning: interrupting fade, appearance may vary.  If intended, prefix with '!')");
            // Don't warn about clearing the output queue if it's expected by running multiple commands at once

            QueueToModify.ClearQueue ();
            if (Animation_Fading_Enabled) {
                double Avg_OldPercent = Math.Min (Animation_Smoothing_Percentage_DEFAULT, 1);
                double Avg_NewPercent = Math.Max (1 - Animation_Smoothing_Percentage_DEFAULT, 0);
                List<LED> LED_Intermediate = new List<LED> ();
                lock (QueueToModify.LightsLastProcessed) {
                    for (int i = 0; i < LightSystem.LIGHT_COUNT; i++) {
                        LED_Intermediate.Add (new LED (QueueToModify.LightsLastProcessed [i].R, QueueToModify.LightsLastProcessed [i].G, QueueToModify.LightsLastProcessed [i].B, QueueToModify.LightsLastProcessed [i].Brightness));
                    }
                }
                for (int i_fades = 0; i_fades < Animation_Smoothing_Iterations_DEFAULT; i_fades++) {
                    for (int i = 0; i < LightSystem.LIGHT_COUNT; i++) {
                        LED_Intermediate [i].R = (byte)((LED_Collection [i].R * Avg_NewPercent) + (LED_Intermediate [i].R * Avg_OldPercent));
                        LED_Intermediate [i].G = (byte)((LED_Collection [i].G * Avg_NewPercent) + (LED_Intermediate [i].G * Avg_OldPercent));
                        LED_Intermediate [i].B = (byte)((LED_Collection [i].B * Avg_NewPercent) + (LED_Intermediate [i].B * Avg_OldPercent));
                        LED_Intermediate [i].Brightness = (byte)((LED_Collection [i].Brightness * Avg_NewPercent) + (LED_Intermediate [i].Brightness * Avg_OldPercent));
                    }
                    QueueToModify.PushToQueue (LED_Intermediate);
                }
                // Just in case the fade did not finish completely, ensure the desired state is sent, too
                QueueToModify.PushToQueue (LED_Collection);
            } else {
                QueueToModify.PushToQueue (LED_Collection);
            }
        }
示例#16
0
 private static void FillLights_Color(LED_Queue QueueToModify, Actinic.Color SelectedColor)
 {
     FillLights_Color (QueueToModify, SelectedColor, true);
 }
示例#17
0
        private static void Animation_Play(LED_Queue QueueToModify, AbstractAnimation DesiredAnimation)
        {
            if (DesiredAnimation == null)
                throw new System.ArgumentNullException ("DesiredAnimation", "You must specify a valid animation to play.");
            if (QueueToModify.AnimationActive)
                Animation_Stop (QueueToModify);

            QueueToModify.SelectedAnimation = DesiredAnimation;
            if ((QueueToModify.SelectedAnimation.RequestedAnimationDelay > Light_Animation_Latency) || (QueueToModify.SelectedAnimation.RequestSmoothCrossfade))
                QueueToModify.AnimationForceFrameRequest = true;
            // If animation requests a longer delay or a smooth cross-fade, force the first frame to happen now

            if (QueueToModify.SelectedAnimation is AbstractReactiveAnimation) {
                // If animation reacts to music, start up the VU system
                if (! ActiveAudioInputSystem.StartAudioCapture ()) {
                    Console.Error.WriteLine ("(Something went wrong while starting the audio capture system)");
                }
            }
        }
示例#18
0
 private static void FillLights_Color(LED_Queue QueueToModify, Actinic.Color SelectedColor, bool ApplyNow, bool SkipAnimationQueue)
 {
     FillLights_Color (QueueToModify, SelectedColor.R, SelectedColor.G, SelectedColor.B, ApplyNow, SkipAnimationQueue);
 }
示例#19
0
 private static void Animation_Stop(LED_Queue QueueToModify)
 {
     WaitForQueue (QueueToModify);
     if (QueueToModify.SelectedAnimation is AudioBitmapAnimation)
         (QueueToModify.SelectedAnimation as AudioBitmapAnimation).StopAudioSystem ();
     if (QueueToModify.SelectedAnimation is AbstractReactiveAnimation || ActiveAudioInputSystem.Running) {
         // If animation reacts to music, shut down the VU system
         if (! ActiveAudioInputSystem.StopAudioCapture ()) {
             Console.Error.WriteLine ("(Something went wrong while stopping the audio capture system)");
         }
     }
     QueueToModify.SelectedAnimation = null;
 }
示例#20
0
 private static void FillLights_Color(LED_Queue QueueToModify, byte R, byte G, byte B, bool ApplyNow)
 {
     FillLights_Color (QueueToModify, R, G, B, ApplyNow, false);
 }
示例#21
0
        /// <summary>
        /// Applies smoothing to the provided queue from colors specified.
        /// </summary>
        /// <param name='SmoothingAmount'>
        /// Smoothing amount, percentage from 0 to 1, higher numbers = longer fade.
        /// </param>
        /// <param name='OnlySmoothBrightnessDecrease'>
        /// Only smooth brightness when it is decreasing.
        /// </param>
        /// <param name='QueueToModify'>
        /// Queue to apply the smoothed results to.
        /// </param>
        private static void ApplySmoothing(double SmoothingAmount, bool OnlySmoothBrightnessDecrease, List<LED> Lights_Unsmoothed, LED_Queue QueueToModify)
        {
            double Avg_OldPercent = Math.Min (SmoothingAmount, 1);
            double Avg_NewPercent = Math.Max (1 - SmoothingAmount, 0);

            for (int i = 0; i < QueueToModify.LightCount; i++) {
                QueueToModify.Lights [i].R = (byte)((Lights_Unsmoothed [i].R * Avg_NewPercent) + (QueueToModify.Lights [i].R * Avg_OldPercent));
                QueueToModify.Lights [i].G = (byte)((Lights_Unsmoothed [i].G * Avg_NewPercent) + (QueueToModify.Lights [i].G * Avg_OldPercent));
                QueueToModify.Lights [i].B = (byte)((Lights_Unsmoothed [i].B * Avg_NewPercent) + (QueueToModify.Lights [i].B * Avg_OldPercent));
                QueueToModify.Lights [i].Brightness = (byte)((Lights_Unsmoothed [i].Brightness * Avg_NewPercent) + (QueueToModify.Lights [i].Brightness * Avg_OldPercent));
                if (OnlySmoothBrightnessDecrease) {
                    QueueToModify.Lights [i].Brightness = (byte)Math.Max (Lights_Unsmoothed [i].Brightness, QueueToModify.Lights [i].Brightness);
                }
            }
        }
示例#22
0
 private static void HaltActivity(LED_Queue QueueToModify, bool ForceQueueCleanup = false)
 {
     if (Actinic_Lights_Queue == null)
         return;
     if (ForceQueueCleanup) {
         QueueToModify.ClearQueue ();
     }
     if (QueueToModify.AnimationActive)
         Animation_Stop (QueueToModify);
 }
示例#23
0
 private static void SetLight_Color(LED_Queue QueueToModify, int Index, byte R, byte G, byte B)
 {
     SetLight_Color (QueueToModify, Index, R, G, B, true);
 }