public LEDDomeFlashVisualizer(
            Configuration config,
            AudioInput audio,
            MidiInput midi,
            LEDDomeOutput dome
            )
        {
            this.config = config;
            this.audio  = audio;
            this.midi   = midi;
            this.dome   = dome;
            this.dome.RegisterVisualizer(this);

            this.shapes = new Dictionary <ShapeType, List <Shape> >()
            {
                { ShapeType.Triangle, new List <Shape>() },
                { ShapeType.Triforce, new List <Shape>() },
                { ShapeType.Polygon, new List <Shape>() },
                { ShapeType.LargePolygon, new List <Shape>() },
                { ShapeType.Everything, new List <Shape>() },
            };
            this.strutsToShapes      = new Dictionary <int, List <Shape> >();
            this.activeAnimations    = new List <Animation>();
            this.padsToLastAnimation = new Dictionary <int, Animation>();

            this.rand = new Random();
            this.lastUserAnimationCreated = 0;

            this.BuildShapes();
        }
Esempio n. 2
0
        public void Visualize()
        {
            //-----------------------------------------------------------------------
            // SETTING THE RACERS
            //-----------------------------------------------------------------------

            this.racer_spacing = this.config.domeRadialSize > 1 ? 1.0 : this.config.domeRadialSize;
            var curTicks = DateTime.Now.Ticks;

            if (this.lastTicks == -1)
            {
                this.lastTicks = curTicks;
            }
            else
            {
                double numSeconds = ((double)(curTicks - this.lastTicks)) / (1000 * 1000 * 10);
                foreach (Racer r in Racers)
                {
                    r.Move(numSeconds, audio, config);
                }
                this.lastTicks = curTicks;
            }

            //-----------------------------------------------------------------------
            // SETTING LEDS
            //-----------------------------------------------------------------------

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                Strut strut = Strut.FromIndex(this.config, i);
                var   leds  = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var pixel_p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);
                    // Vertical height
                    var y   = 1.0 - pixel_p.Item4;
                    var rad = pixel_p.Item3;
                    Tuple <Racer, double, double, Racer> loc = this.GetRacer(y, rad);
                    if (loc == null)
                    {
                        // color = 0 is off.
                        this.dome.SetPixel(i, j, 0);
                    }
                    else
                    {
                        // Let the racer choose its color
                        var color = loc.Item4.Color(dome, config, loc.Item2, loc.Item3);
                        this.dome.SetPixel(i, j, color);
                    }
                }
            }

            // No messages will be sent to the Beaglebone until Flush is called. This
            // makes it imperative that you call Flush at the end of Visualize, or
            // whenever you want to update the LEDs. The LEDs themselves are stateful,
            // and will maintain whatever color you set them to until they lose power.
            this.dome.Flush();
        }
Esempio n. 3
0
 public LEDDomeTVStaticVisualizer(
     Configuration config,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
 }
        public void Visualize()
        {
            if (this.stopwatch.ElapsedMilliseconds <= 250)
            {
                return;
            }
            this.stopwatch.Restart();
            this.state = (this.state + 1) % 2;

            if (this.state == 0)
            {
                for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
                {
                    Strut strut = Strut.FromIndex(this.config, i);
                    for (int j = 0; j < strut.Length; j++)
                    {
                        this.dome.SetPixel(i, j, 0x000000);
                    }
                }
                this.dome.Flush();
                return;
            }

            byte brightnessByte = (byte)(
                0xFF * this.config.domeMaxBrightness *
                this.config.domeBrightness
                );
            int color = brightnessByte << 16
                        | brightnessByte << 8
                        | brightnessByte;

            for (int teensy = 0; teensy < 5; teensy++)
            {
                for (int localIndex = 0; localIndex < 38; localIndex++)
                {
                    var   strutIndex = LEDDomeOutput.FindStrutIndex(teensy, localIndex);
                    Strut strut      = Strut.FromIndex(this.config, strutIndex);
                    if (this.state == 2)
                    {
                        for (int j = 1; j < strut.Length - 1; j++)
                        {
                            this.dome.SetPixel(strutIndex, j, 0x000000);
                        }
                        this.dome.SetPixel(strutIndex, 0, color);
                        this.dome.SetPixel(strutIndex, strut.Length - 1, color);
                    }
                    else
                    {
                        for (int j = 0; j < strut.Length; j++)
                        {
                            this.dome.SetPixel(strutIndex, j, color);
                        }
                    }
                }
            }
            this.dome.Flush();
        }
Esempio n. 5
0
        public DomeSimulatorWindow(Configuration config)
        {
            this.InitializeComponent();
            this.config = config;

            this.rect   = new Int32Rect(0, 0, 750, 750);
            this.bitmap = new WriteableBitmap(
                this.rect.Width,
                this.rect.Height,
                96,
                96,
                PixelFormats.Bgra32,
                null
                );
            this.pixels = new byte[this.rect.Width * this.rect.Height * 4];
            for (int x = 0; x < this.rect.Width; x++)
            {
                for (int y = 0; y < this.rect.Height; y++)
                {
                    this.SetPixelColor(this.pixels, x, y, (uint)0xFF000000);
                }
            }
            RenderOptions.SetBitmapScalingMode(
                this.image,
                BitmapScalingMode.NearestNeighbor
                );
            RenderOptions.SetEdgeMode(
                this.image,
                EdgeMode.Aliased
                );

            this.strutLabels = new Label[LEDDomeOutput.GetNumStruts()];
            var brush = new SolidColorBrush(Colors.White);

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var   pt1     = GetPoint(i, 0);
                var   pt2     = GetPoint(i, 1);
                var   centerX = (pt1.Item1 + pt2.Item1) / 2;
                var   centerY = (pt1.Item2 + pt2.Item2) / 2;
                Label label   = new Label();
                label.Content    = i;
                label.FontSize   = 12;
                label.Visibility = Visibility.Collapsed;
                label.Foreground = brush;
                label.Margin     = new Thickness(
                    centerX - 10,
                    centerY - 10,
                    0,
                    0
                    );
                label.MouseDown    += StrutLabelClicked;
                this.strutLabels[i] = label;
                this.canvas.Children.Add(label);
            }
        }
Esempio n. 6
0
        public void ParametricTest()
        {
            double progress = this.config.beatBroadcaster.ProgressThroughBeat(
                this.config.domeVolumeRotationSpeed
                );

            double level = this.audio.LevelForChannel(0);

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                Strut strut = Strut.FromIndex(this.config, i);
                var   leds  = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var    p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);
                    double r = 0;
                    double g = 0;
                    double b = 0;

                    //radar effect
                    double a = (p.Item3 + Math.PI) / (Math.PI * 2);
                    r = progress - a;
                    if (r < 0)
                    {
                        r += 1;
                    }
                    if (r > 1)
                    {
                        r = 1;
                    }

                    //pulse effect
                    double dist = Math.Abs(progress - p.Item4);
                    r = 1 - dist;
                    if (r < 0.9)
                    {
                        r = 0;
                    }

                    //spiral effect
                    double m = p.Item4 - a;
                    if (m < 0)
                    {
                        m += 1;
                    }
                    double n = progress - m;
                    if (n < 0)
                    {
                        n += 1;
                    }
                    r = 1 - n;

                    this.dome.SetPixel(i, j, LEDColor.FromDoubles(r, g, b));
                }
            }
        }
Esempio n. 7
0
        private void ShowKey(object sender, RoutedEventArgs e)
        {
            this.keyMode = !this.keyMode;
            foreach (Label strutLabel in this.strutLabels)
            {
                strutLabel.Visibility = this.keyMode
          ? Visibility.Visible
          : Visibility.Collapsed;
            }
            this.showKey.Content = this.keyMode
        ? "Hide Key"
        : "Show Key";
            this.directionLabel.Visibility = this.keyMode
        ? Visibility.Visible
        : Visibility.Collapsed;
            this.previewBox.Visibility = this.keyMode
        ? Visibility.Visible
        : Visibility.Collapsed;

            if (!this.keyMode)
            {
                this.bitmap.WritePixels(this.rect, this.pixels, this.rect.Width * 4, 0);
                return;
            }

            var strutPixels = new byte[rect.Width * rect.Height * 4];

            for (int x = 0; x < rect.Width; x++)
            {
                for (int y = 0; y < rect.Height; y++)
                {
                    this.SetPixelColor(strutPixels, x, y, (uint)0xFF000000);
                }
            }

            uint color = (uint)SimulatorUtils.GetComputerColor(0xFFFFFF)
                         | (uint)0xFF000000;

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var    pt1     = GetPoint(i, 0);
                var    pt2     = GetPoint(i, 1);
                int    numLEDs = LEDDomeOutput.GetNumLEDs(i);
                double deltaX  = (pt1.Item1 - pt2.Item1) / (numLEDs + 2.0);
                double deltaY  = (pt1.Item2 - pt2.Item2) / (numLEDs + 2.0);
                for (int j = 0; j < numLEDs * 3 / 4; j++)
                {
                    int x = pt1.Item1 - (int)(deltaX * (j + 1));
                    int y = pt1.Item2 - (int)(deltaY * (j + 1));
                    this.SetPixelColor(strutPixels, x, y, color);
                }
            }

            this.bitmap.WritePixels(this.rect, strutPixels, this.rect.Width * 4, 0);
        }
 public LEDDomeRadialVisualizer(
     Configuration config,
     AudioInput audio,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.audio  = audio;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
 }
Esempio n. 9
0
 public void Static()
 {
     for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
     {
         Strut strut = Strut.FromIndex(this.config, i);
         for (int j = 0; j < strut.Length; j++)
         {
             this.dome.SetPixel(i, j, this.RandomColor());
         }
     }
 }
Esempio n. 10
0
 public LEDDomeFlashColorsDiagnosticVisualizer(
     Configuration config,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
     this.stopwatch = new Stopwatch();
     this.stopwatch.Start();
 }
        public override void Animate(LEDDomeOutput dome)
        {
            double intensity          = this.AnimationIntensity;
            double scaleColor         = Math.Min(intensity * 2 * this.velocity, 1.0);
            int    totalParts         = this.shape.layout.NumSegments;
            int    animationSplitInto = 2 * ((totalParts - 1) / 2 + 1);

            for (int part = 0; part < totalParts; part += 2)
            {
                double startRange = (double)part / animationSplitInto;
                double endRange   = (double)(part + 2) / animationSplitInto;
                double scaled     = (intensity - startRange) /
                                    (endRange - startRange);
                scaled     = Math.Max(Math.Min(scaled, 1.0), 0.0);
                startRange = Math.Min(startRange / intensity, 1.0);
                endRange   = Math.Min(endRange / intensity, 1.0);

                var spokeSegment = this.shape.layout.GetSegment(part);
                foreach (var strut in spokeSegment.GetStruts())
                {
                    for (int i = 0; i < strut.Length; i++)
                    {
                        double gradientPos =
                            strut.GetGradientPos(scaled, startRange, endRange, i);
                        int color1 = gradientPos != -1.0
              ? LEDColor.ScaleColor(
                            dome.GetGradientColor(this.pad, gradientPos, 0.0, false),
                            scaleColor
                            )
              : 0x000000;
                        dome.SetPixel(strut.Index, i, color1);
                    }
                }

                if (part + 1 == totalParts)
                {
                    break;
                }

                var circleSegment = this.shape.layout.GetSegment(part + 1);
                var color2        = scaled == 1.0
          ? LEDColor.ScaleColor(dome.GetSingleColor(this.pad), scaleColor)
          : 0x000000;
                foreach (var strut in circleSegment.GetStruts())
                {
                    for (int i = 0; i < strut.Length; i++)
                    {
                        dome.SetPixel(strut.Index, i, color2);
                    }
                }
            }
        }
 public Shape(LEDDomeOutput dome, ShapeType type, StrutLayout layout)
 {
     this.dome            = dome;
     this.type            = type;
     this.layout          = layout;
     this.activeAnimation = null;
     this.struts          = new HashSet <int>(
         Enumerable.Range(0, this.layout.NumSegments)
         .SelectMany(i =>
                     this.layout.GetSegment(i).GetStruts().Select(strut => strut.Index)
                     )
         );
 }
 public LEDDomeMidiTestVisualizer(
     Configuration config,
     MidiInput midi,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.midi   = midi;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
     this.strutStates = new Dictionary <int, int>();
     this.rand        = new Random();
 }
Esempio n. 14
0
 public LEDDomeJkmdTestVisualizer(
     Configuration config,
     AudioInput audio,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.audio  = audio;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
     this.animationSize = 0;
     this.centerOffset  = 0;
     this.ringsLayout   = this.BuildRingsLayout();
     //this.UpdateLayouts();
 }
 public LEDDomeVolumeVisualizer(
     Configuration config,
     AudioInput audio,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.audio  = audio;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
     this.animationSize = 0;
     this.centerOffset  = 0;
     this.spokeLayout   = this.BuildSpokeLayout();
     this.UpdateLayouts();
 }
Esempio n. 16
0
        private void Update(object sender, EventArgs e)
        {
            int queueLength = this.config.domeCommandQueue.Count;

            if (queueLength == 0)
            {
                return;
            }

            //Stopwatch stopwatch = Stopwatch.StartNew();

            bool shouldRedraw = false;

            for (int k = 0; k < queueLength; k++)
            {
                DomeLEDCommand command;
                bool           result =
                    this.config.domeCommandQueue.TryDequeue(out command);
                if (!result)
                {
                    throw new Exception("Someone else is dequeueing!");
                }
                if (command.isFlush)
                {
                    shouldRedraw = true;
                    continue;
                }
                var    pt1     = GetPoint(command.strutIndex, 0);
                var    pt2     = GetPoint(command.strutIndex, 1);
                int    numLEDs = LEDDomeOutput.GetNumLEDs(command.strutIndex);
                double deltaX  = (pt1.Item1 - pt2.Item1) / (numLEDs + 2.0);
                double deltaY  = (pt1.Item2 - pt2.Item2) / (numLEDs + 2.0);
                int    x       = pt1.Item1 - (int)(deltaX * (command.ledIndex + 1));
                int    y       = pt1.Item2 - (int)(deltaY * (command.ledIndex + 1));
                uint   color   = (uint)SimulatorUtils.GetComputerColor(command.color)
                                 | (uint)0xFF000000;
                this.SetPixelColor(this.pixels, x, y, color);
            }

            if (shouldRedraw && !this.keyMode)
            {
                this.bitmap.WritePixels(this.rect, this.pixels, this.rect.Width * 4, 0);
            }

            //Debug.WriteLine("DomeSimulator took " + stopwatch.ElapsedMilliseconds + "ms to update");
        }
Esempio n. 17
0
 public int Color(LEDDomeOutput dome, Configuration config, double loc_y, double loc_ang)
 {
     if (conf.coloring == Coloring.Fade)
     {
         return(LEDColor.ScaleColor(dome.GetSingleColor(this.idx), loc_ang));
     }
     else if (conf.coloring == Coloring.FadeExp)
     {
         var s = 4 * loc_ang - 4;
         return(LEDColor.ScaleColor(
                    dome.GetSingleColor(this.idx),
                    1.0 / (1 + Math.Pow(Math.E, -s))
                    ));
     }
     else if (conf.coloring == Coloring.Multi)
     {
         var end_index = config.colorPalette.colors.Length - 1;
         return(dome.GetGradientBetweenColors(end_index - 4, end_index, loc_ang, 0.0, false));
     }
     return(dome.GetSingleColor(this.idx));
 }
Esempio n. 18
0
        public void Visualize()
        {
            if (this.wipeStrutsNextCycle)
            {
                for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
                {
                    Strut strut = Strut.FromIndex(this.config, i);
                    for (int j = 0; j < strut.Length; j++)
                    {
                        this.dome.SetPixel(i, j, 0x000000);
                    }
                }
                this.wipeStrutsNextCycle = false;
            }

            //this.StaticRingsAnimated();
            this.ParametricTest();

            //this.wipeStrutsNextCycle = true;
            this.dome.Flush();
        }
Esempio n. 19
0
        private void Draw()
        {
            uint color = (uint)SimulatorUtils.GetComputerColor(0x000000)
                         | (uint)0xFF000000;

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var    pt1     = GetPoint(i, 0);
                var    pt2     = GetPoint(i, 1);
                int    numLEDs = LEDDomeOutput.GetNumLEDs(i);
                double deltaX  = (pt1.Item1 - pt2.Item1) / (numLEDs + 2.0);
                double deltaY  = (pt1.Item2 - pt2.Item2) / (numLEDs + 2.0);
                for (int j = 0; j < numLEDs; j++)
                {
                    int x = pt1.Item1 - (int)(deltaX * (j + 1));
                    int y = pt1.Item2 - (int)(deltaY * (j + 1));
                    this.SetPixelColor(this.pixels, x, y, color);
                }
            }
            this.bitmap.WritePixels(this.rect, this.pixels, this.rect.Width * 4, 0);
            this.image.Source = this.bitmap;
        }
Esempio n. 20
0
 public LEDDomeRaceVisualizer(
     Configuration config,
     AudioInput audio,
     MidiInput midi,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.audio  = audio;
     this.midi   = midi;
     this.dome   = dome;
     // Create new racers.
     this.Racers = new Racer[racerConfig.Length];
     for (int i = 0; i < racerConfig.Length; i++)
     {
         var rconf = racerConfig[i];
         this.Racers[i] = new Racer(i, racerConfig.Length, rconf);
     }
     this.lastTicks = -1;
     // This call is necessary to make sure the Operator considers this
     // Visualizer when comparing priorities for LEDDomeOutput. If you skip it
     // your Visualizer will never run
     this.dome.RegisterVisualizer(this);
 }
        public void Visualize()
        {
            if (this.stopwatch.ElapsedMilliseconds <= 1000)
            {
                return;
            }
            this.stopwatch.Restart();
            this.state = (this.state + 1) % 4;

            if (this.state == 0)
            {
                for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
                {
                    Strut strut = Strut.FromIndex(this.config, i);
                    for (int j = 0; j < strut.Length; j++)
                    {
                        this.dome.SetPixel(i, j, 0x000000);
                    }
                }
                this.dome.Flush();
                return;
            }

            byte brightnessByte = (byte)(
                0xFF * this.config.domeMaxBrightness *
                this.config.domeBrightness
                );
            int whiteColor = brightnessByte << 16
                             | brightnessByte << 8
                             | brightnessByte;

            int[] colors =
            {
                whiteColor& 0xFF0000,
                  whiteColor& 0x00FF00,
                  whiteColor& 0x0000FF,
                  whiteColor& 0xFFFF00,
                  whiteColor& 0xFF00FF,
                  whiteColor& 0x00FFFF,
            };

            for (int controlBox = 0; controlBox < 5; controlBox++)
            {
                int colorIndex = 0;
                for (int localIndex = 0; localIndex < 38; localIndex++)
                {
                    var   strutIndex = LEDDomeOutput.FindStrutIndex(controlBox, localIndex);
                    Strut strut      = Strut.FromIndex(this.config, strutIndex);
                    if (this.state == 2)
                    {
                        for (int j = 1; j < strut.Length - 1; j++)
                        {
                            this.dome.SetPixel(strutIndex, j, 0x000000);
                        }
                        this.dome.SetPixel(strutIndex, 0, colors[colorIndex]);
                        this.dome.SetPixel(strutIndex, strut.Length - 1, colors[colorIndex]);
                    }
                    else
                    {
                        for (int j = 0; j < strut.Length; j++)
                        {
                            this.dome.SetPixel(strutIndex, j, colors[colorIndex]);
                        }
                    }
                    colorIndex = (colorIndex + 1) % colors.Length;
                }
            }
            this.dome.Flush();
        }
Esempio n. 22
0
 public Shape(LEDDomeOutput dome, ShapeType type, StrutLayout layout)
 {
     this.dome = dome;
       this.type = type;
       this.layout = layout;
       this.activeAnimation = null;
       this.struts = new HashSet<int>(
     Enumerable.Range(0, this.layout.NumSegments)
       .SelectMany(i =>
     this.layout.GetSegment(i).GetStruts().Select(strut => strut.Index)
       )
       );
 }
        public void Visualize()
        {
            if (this.wipeStrutsNextCycle)
            {
                for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
                {
                    Strut strut = Strut.FromIndex(this.config, i);
                    for (int j = 0; j < strut.Length; j++)
                    {
                        this.dome.SetPixel(i, j, 0x000000);
                    }
                }
                this.wipeStrutsNextCycle = false;
            }

            this.UpdateCenter();
            this.UpdateAnimationSize(this.config.domeVolumeAnimationSize);

            int subdivisions    = this.partLayout.NumSegments / 2;
            int totalParts      = this.config.domeVolumeAnimationSize;
            int volumeSplitInto = 2 * ((totalParts - 1) / 2 + 1);

            for (int part = 0; part < totalParts; part += 2)
            {
                var    outwardSegment = this.partLayout.GetSegment(part);
                double startRange     = (double)part / volumeSplitInto;
                double endRange       = (double)(part + 2) / volumeSplitInto;
                double level          = this.audio.LevelForChannel(0);
                double scaled         = (level - startRange) /
                                        (endRange - startRange);
                scaled     = Math.Max(Math.Min(scaled, 1.0), 0.0);
                startRange = Math.Min(startRange / level, 1.0);
                endRange   = Math.Min(endRange / level, 1.0);

                foreach (Strut strut in outwardSegment.GetStruts())
                {
                    this.UpdateStrut(strut, scaled, startRange, endRange);
                }

                if (part + 1 == totalParts)
                {
                    break;
                }

                for (int i = 0; i < 6; i++)
                {
                    StrutLayoutSegment segment =
                        this.sectionLayout.GetSegment(i + part * 3);
                    double gradientStartPos = 0.0;
                    double gradientStep     = 1.0 / segment.GetStruts().Count;
                    foreach (Strut strut in segment.GetStruts())
                    {
                        double gradientEndPos = gradientStartPos + gradientStep;
                        this.UpdateStrut(
                            strut,
                            scaled == 1.0 ? 1.0 : 0.0,
                            gradientStartPos,
                            gradientEndPos
                            );
                        gradientStartPos = gradientEndPos;
                    }
                }
            }
            this.dome.Flush();
        }
Esempio n. 24
0
        public void Visualize()
        {
            if (this.stopwatch.ElapsedMilliseconds <= 1000)
            {
                return;
            }
            this.stopwatch.Restart();
            this.lastIndex++;
            byte brightnessByte = (byte)(
                0xFF * this.config.domeMaxBrightness *
                this.config.domeBrightness
                );
            int whiteColor = brightnessByte << 16
                             | brightnessByte << 8
                             | brightnessByte;

            if (this.lastIndex == 38)
            {
                this.lastIndex  = 0;
                this.lastTeensy = (this.lastTeensy + 1) % 5;

                // Reset every LED to blue
                for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
                {
                    Strut blueStrut = Strut.FromIndex(this.config, i);
                    for (int j = 0; j < blueStrut.Length; j++)
                    {
                        this.dome.SetPixel(i, j, 0x0000FF);
                    }
                }

                if (this.lastTeensy == 0)
                {
                    if (this.color == 0xFF0000)
                    {
                        this.color = 0x00FF00;
                    }
                    else if (this.color == 0x00FF00)
                    {
                        this.color = 0x0000FF;
                    }
                    else if (this.color == 0x0000FF)
                    {
                        this.color = 0xFFFFFF;
                    }
                    else if (this.color == 0xFFFFFF)
                    {
                        this.color = 0xFF0000;
                    }
                }
            }
            var strutIndex = LEDDomeOutput.FindStrutIndex(
                this.lastTeensy,
                this.lastIndex
                );
            Strut strut = Strut.FromIndex(this.config, strutIndex);

            for (int i = 0; i < strut.Length; i++)
            {
                this.dome.SetPixel(strutIndex, i, this.color & whiteColor);
            }
            this.dome.Flush();
        }
        public void Visualize()
        {
            var  commands = this.midi.GetCommandsSinceLastTick();
            bool valueSet = false;

            foreach (MidiCommand command in commands)
            {
                if (command.type != MidiCommandType.Note)
                {
                    continue;
                }
                if (command.index < 48 || command.index > 51)
                {
                    continue;
                }

                valueSet = true;
                if (this.strutStates.ContainsKey(command.index))
                {
                    var   existingStrutIndex = this.strutStates[command.index];
                    Strut existingStrut      = Strut.FromIndex(this.config, existingStrutIndex);
                    for (int i = 0; i < existingStrut.Length; i++)
                    {
                        this.dome.SetPixel(existingStrutIndex, i, 0x000000);
                    }
                    this.strutStates.Remove(command.index);
                    if (command.value == 0.0)
                    {
                        continue;
                    }
                }

                int color          = 0;
                int brightnessByte = (int)(
                    0xFF * this.config.domeMaxBrightness *
                    this.config.domeBrightness * command.value
                    );
                if (command.index == 48)
                {
                    color = brightnessByte << 16;
                }
                else if (command.index == 49)
                {
                    color = brightnessByte << 8;
                }
                else if (command.index == 50)
                {
                    color = brightnessByte;
                }
                else if (command.index == 51)
                {
                    color = brightnessByte | brightnessByte << 8 | brightnessByte << 16;
                }

                int strutIndex = -1;
                while (strutIndex == -1)
                {
                    int candidateStrutIndex = (int)(this.rand.NextDouble() * LEDDomeOutput.GetNumStruts());
                    if (this.strutStates.ContainsValue(candidateStrutIndex))
                    {
                        continue;
                    }
                    strutIndex = candidateStrutIndex;
                }

                Strut strut = Strut.FromIndex(this.config, strutIndex);
                for (int i = 0; i < strut.Length; i++)
                {
                    this.dome.SetPixel(strutIndex, i, color);
                }
                this.strutStates[command.index] = strutIndex;
            }

            if (valueSet)
            {
                this.dome.Flush();
            }
        }
Esempio n. 26
0
        void Render()
        {
            double level = this.audio.LevelForChannel(0);
            // Sqrt makes values larger and gives more resolution for lower values
            double adjustedLevel = Clamp(Math.Sqrt(level), 0.1, 1);

            double progress = this.config.beatBroadcaster.ProgressThroughMeasure;

            // rotation is scaled by 1/4 - otherwise it is way too fast and will make people vomit
            currentAngle     += this.config.domeVolumeRotationSpeed * Wrap(progress - this.lastProgress, 0, 1) * 0.25;
            currentAngle      = Wrap(currentAngle, 0, 1);
            currentGradient  += this.config.domeGradientSpeed * Wrap(progress - this.lastProgress, 0, 1);
            currentGradient   = Wrap(currentGradient, 0, 1);
            this.lastProgress = progress;

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var leds = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);

                    // map angle to 0-1
                    var angle = MapWrap(p.Item3, -Math.PI, Math.PI, 0.0, 1.0);
                    var dist  = p.Item4;

                    double val         = 0;
                    double gradientVal = 0;

                    switch (this.config.domeRadialEffect)
                    {
                    case 0:
                        // radar mapping
                        val = MapWrap(angle, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        val = Math.Abs(Map(val, 0, 1, -1, 1));

                        gradientVal = dist;
                        break;

                    case 1:
                        // pulse mapping
                        val = MapWrap(dist, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        val = Math.Abs(Map(val, 0, 1, -1, 1));

                        gradientVal = Math.Abs(Map(angle, 0, 1, -1, 1));
                        break;

                    case 2:
                        // spiral mapping
                        val = MapWrap(angle + dist / this.config.domeRadialFrequency, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        val = Math.Abs(Map(val, 0, 1, -1, 1));

                        gradientVal = dist;
                        break;

                    case 3:
                        // bubble mapping
                        var a = MapWrap(angle, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        a = Wrap(a * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        a   = Math.Abs(Map(a, 0, 1, -1, 1));
                        val = Clamp(dist - a, 0, 1);

                        gradientVal = dist;
                        break;
                    }

                    // size limit is scaled according the size slider and the current level
                    var  sizeLimit = this.config.domeRadialSize * adjustedLevel;
                    bool on        = val <= sizeLimit;

                    // use level to determine which colors to use
                    int whichGradient = (int)(level * 8);

                    var color = on ? this.dome.GetGradientColor(whichGradient, gradientVal, currentGradient, true) : 0;

                    this.dome.SetPixel(i, j, color);
                }
            }
        }
        void Render()
        {
            double progress = this.config.beatBroadcaster.ProgressThroughMeasure;

            currentAngle     += this.config.domeVolumeRotationSpeed * Wrap(progress - this.lastProgress, 0, 1);
            currentAngle      = Wrap(currentAngle, 0, 1);
            currentGradient  += this.config.domeGradientSpeed * Wrap(progress - this.lastProgress, 0, 1);
            currentGradient   = Wrap(currentGradient, 0, 1);
            this.lastProgress = progress;

            double level         = this.audio.LevelForChannel(0);
            double adjustedLevel = Map(level, 0, 1, 0.02, 1);

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                Strut strut = Strut.FromIndex(this.config, i);
                var   leds  = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);

                    // map angle to 0-1
                    var angle = MapWrap(p.Item3, -Math.PI, Math.PI, 0.0, 1.0);
                    var dist  = p.Item4;

                    double val         = 0;
                    double gradientVal = 0;

                    switch (this.config.domeRadialEffect)
                    {
                    case 0:
                        // radar mapping
                        val         = MapWrap(angle, currentAngle, 1 + currentAngle, 0, 1);
                        gradientVal = dist;
                        break;

                    case 1:
                        // pulse mapping
                        val         = MapWrap(dist, currentAngle, 1 + currentAngle, 0, 1);
                        gradientVal = Math.Abs(Map(angle, 0, 1, -1, 1));
                        break;

                    case 2:
                        // spiral mapping
                        val         = MapWrap(angle + dist / this.config.domeRadialFrequency, currentAngle, 1 + currentAngle, 0, 1);
                        gradientVal = dist;
                        break;
                    }

                    // scale val according to radial frequency
                    val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                    // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                    var centeredVal = Math.Abs(Map(val, 0, 1, -1, 1));

                    // size limit is scaled according the size slider and the current level
                    var  sizeLimit = this.config.domeRadialSize * adjustedLevel;
                    bool on        = centeredVal <= sizeLimit;

                    var color = on ? this.dome.GetGradientColor(0, gradientVal, currentGradient, true) : 0;

                    this.dome.SetPixel(i, j, color);
                }
            }
        }
 abstract public void Animate(LEDDomeOutput dome);
Esempio n. 29
0
        public Operator(Configuration config)
        {
            this.config = config;
            this.operatorThreadBlockingStopwatch = new Stopwatch();
            this.operatorThreadBlockingStopwatch.Start();

            this.frameRateStopwatch = new Stopwatch();
            this.frameRateStopwatch.Start();
            this.framesThisSecond = 0;

            this.inputs = new List <Input>();
            var audio = new AudioInput(config);

            this.inputs.Add(audio);
            var midi = new MidiInput(config);

            this.inputs.Add(midi);

            this.outputs = new List <Output>();
            var hue = new HueOutput(config);

            this.outputs.Add(hue);
            var board = new LEDBoardOutput(config);

            this.outputs.Add(board);
            var dome = new LEDDomeOutput(config);

            this.outputs.Add(dome);
            var bar = new LEDBarOutput(config, dome);

            this.outputs.Add(bar);
            var stage = new LEDStageOutput(config);

            this.outputs.Add(stage);

            this.visualizers = new List <Visualizer>();
            this.visualizers.Add(new HueAudioVisualizer(
                                     this.config,
                                     audio,
                                     hue
                                     ));
            this.visualizers.Add(new LEDPanelVolumeVisualizer(
                                     this.config,
                                     audio,
                                     board
                                     ));
            this.visualizers.Add(new HueSolidColorVisualizer(
                                     this.config,
                                     hue
                                     ));
            this.visualizers.Add(new HueSilentVisualizer(
                                     this.config,
                                     audio,
                                     hue
                                     ));
            this.visualizers.Add(new LEDPanelMidiVisualizer(
                                     this.config,
                                     midi,
                                     board
                                     ));
            this.visualizers.Add(new LEDDomeMidiTestVisualizer(
                                     this.config,
                                     midi,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeStrutIterationDiagnosticVisualizer(
                                     this.config,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeFlashColorsDiagnosticVisualizer(
                                     this.config,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeStrandTestDiagnosticVisualizer(
                                     this.config,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeVolumeVisualizer(
                                     this.config,
                                     audio,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeRadialVisualizer(
                                     this.config,
                                     audio,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeJkmdTestVisualizer(
                                     this.config,
                                     audio,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeTVStaticVisualizer(
                                     this.config,
                                     dome
                                     ));
            this.visualizers.Add(new LEDDomeFlashVisualizer(
                                     this.config,
                                     audio,
                                     midi,
                                     dome
                                     ));
            this.visualizers.Add(new LEDBarFlashColorsDiagnosticVisualizer(
                                     this.config,
                                     bar
                                     ));
            this.visualizers.Add(new LEDStageFlashColorsDiagnosticVisualizer(
                                     this.config,
                                     stage
                                     ));
            this.visualizers.Add(new LEDStageTracerVisualizer(
                                     this.config,
                                     stage
                                     ));
            this.visualizers.Add(new LEDStageDepthLevelVisualizer(
                                     this.config,
                                     audio,
                                     stage
                                     ));
        }
Esempio n. 30
0
        public override void Animate(LEDDomeOutput dome)
        {
            double intensity = this.AnimationIntensity;
              double scaleColor = Math.Min(intensity * 2 * this.velocity, 1.0);
              int totalParts = this.shape.layout.NumSegments;
              int animationSplitInto = 2 * ((totalParts - 1) / 2 + 1);
              for (int part = 0; part < totalParts; part += 2) {
            double startRange = (double)part / animationSplitInto;
            double endRange = (double)(part + 2) / animationSplitInto;
            double scaled = (intensity - startRange) /
              (endRange - startRange);
            scaled = Math.Max(Math.Min(scaled, 1.0), 0.0);
            startRange = Math.Min(startRange / intensity, 1.0);
            endRange = Math.Min(endRange / intensity, 1.0);

            var spokeSegment = this.shape.layout.GetSegment(part);
            foreach (var strut in spokeSegment.GetStruts()) {
              for (int i = 0; i < strut.Length; i++) {
            double gradientPos =
              strut.GetGradientPos(scaled, startRange, endRange, i);
            int color1 = gradientPos != -1.0
              ? LEDColor.ScaleColor(
                  dome.GetGradientColor(this.pad, gradientPos, 0.0, false),
                  scaleColor
                )
              : 0x000000;
            dome.SetPixel(strut.Index, i, color1);
              }
            }

            if (part + 1 == totalParts) {
              break;
            }

            var circleSegment = this.shape.layout.GetSegment(part + 1);
            var color2 = scaled == 1.0
              ? LEDColor.ScaleColor(dome.GetSingleColor(this.pad), scaleColor)
              : 0x000000;
            foreach (var strut in circleSegment.GetStruts()) {
              for (int i = 0; i < strut.Length; i++) {
            dome.SetPixel(strut.Index, i, color2);
              }
            }
              }
        }