<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.ES30;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Batches;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.OpenGL.Vertices;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using System;

namespace osu.Game.Screens.Menu
{
    internal class LogoVisualisation : Drawable, IHasAccentColour
    {
        private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
        private Color4 barColour;

        private const int index_change = 5;
        private const float bar_length = 600;
        private const int bars_per_visualizer = 200;
        private const float visualizers = 5;

        /// <summary>
        /// How much should each bar go down each milisecond (based on a full bar)
        /// </summary>
        private const float decay_per_milisecond = 0.0024f;

        private int indexOffset;

        public Color4 AccentColour
        {
            get
            {
                return barColour;
            }
            set
            {
                barColour = value;
            }
        }

        private readonly float[] frequencyAmplitudes = new float[256];

        public override bool HandleInput => false;

        private Shader shader;
        private readonly Texture texture;

        public LogoVisualisation()
        {
            texture = Texture.WhitePixel;
            AccentColour = new Color4(1, 1, 1, 0.2f);
            BlendingMode = BlendingMode.Additive;
        }

        [BackgroundDependencyLoader(true)]
        private void load(ShaderManager shaders, OsuGame game)
        {
            if (game?.Beatmap != null)
                beatmap.BindTo(game.Beatmap);
            shader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED);
        }

        private void ensureAmplitudes()
        {
            float[] temporalAmplitudes = beatmap.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256];

            var effect = beatmap.Value?.Beatmap.ControlPointInfo.EffectPointAt(beatmap.Value.Track?.CurrentTime ?? Time.Current);

            for (int i = 0; i < bars_per_visualizer; i++)
            {
                int index = (i + indexOffset) % bars_per_visualizer;
                if (beatmap?.Value?.Track?.IsRunning ?? false)
                {
                    if (temporalAmplitudes[index] > frequencyAmplitudes[i])
                        frequencyAmplitudes[i] = temporalAmplitudes[index] * (effect?.KiaiMode == true ? 1 : 0.5f);
                }
                else
                {
                    if (frequencyAmplitudes[(i + index_change) % bars_per_visualizer] > frequencyAmplitudes[i])
                        frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualizer];
                }
            }
            indexOffset = (indexOffset + index_change) % bars_per_visualizer;
            Scheduler.AddDelayed(ensureAmplitudes, 50);
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();
            ensureAmplitudes();
        }

        protected override void Update()
        {
            base.Update();

            float decayFactor = (float)Time.Elapsed * decay_per_milisecond;
            for (int i = 0; i < bars_per_visualizer; i++)
            {
                //0.03% of extra bar length to make it a little faster when bar is almost at it's minimum
                frequencyAmplitudes[i] -= decayFactor * (frequencyAmplitudes[i] + 0.03f);
                if (frequencyAmplitudes[i] < 0)
                    frequencyAmplitudes[i] = 0;
            }

            Invalidate(Invalidation.DrawNode, shallPropagate: false);
        }

        protected override DrawNode CreateDrawNode() => new VisualisationDrawNode();

        private readonly VisualizerSharedData sharedData = new VisualizerSharedData();
        protected override void ApplyDrawNode(DrawNode node)
        {
            base.ApplyDrawNode(node);

            var visNode = (VisualisationDrawNode)node;

            visNode.Shader = shader;
            visNode.Texture = texture;
            visNode.Size = DrawSize.X;
            visNode.Shared = sharedData;
            visNode.Colour = barColour;
            visNode.AudioData = frequencyAmplitudes;
        }

        private class VisualizerSharedData
        {
            public readonly LinearBatch<TexturedVertex2D> VertexBatch = new LinearBatch<TexturedVertex2D>(100 * 4, 10, PrimitiveType.Quads);
        }

        private class VisualisationDrawNode : DrawNode
        {
            public Shader Shader;
            public Texture Texture;
            public VisualizerSharedData Shared;
            //Asuming the logo is a circle, we don't need a second dimension.
            public float Size;

            public Color4 Colour;
            public float[] AudioData;

            public override void Draw(Action<TexturedVertex2D> vertexAction)<commit_msg>Simplify AccentColour property for now<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.ES30;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Batches;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.OpenGL.Vertices;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using System;

namespace osu.Game.Screens.Menu
{
    internal class LogoVisualisation : Drawable, IHasAccentColour
    {
        private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();

        private const int index_change = 5;
        private const float bar_length = 600;
        private const int bars_per_visualizer = 200;
        private const float visualizers = 5;

        /// <summary>
        /// How much should each bar go down each milisecond (based on a full bar)
        /// </summary>
        private const float decay_per_milisecond = 0.0024f;

        private int indexOffset;

        public Color4 AccentColour { get; set; }

        private readonly float[] frequencyAmplitudes = new float[256];

        public override bool HandleInput => false;

        private Shader shader;
        private readonly Texture texture;

        public LogoVisualisation()
        {
            texture = Texture.WhitePixel;
            AccentColour = new Color4(1, 1, 1, 0.2f);
            BlendingMode = BlendingMode.Additive;
        }

        [BackgroundDependencyLoader(true)]
        private void load(ShaderManager shaders, OsuGame game)
        {
            if (game?.Beatmap != null)
                beatmap.BindTo(game.Beatmap);
            shader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED);
        }

        private void ensureAmplitudes()
        {
            float[] temporalAmplitudes = beatmap.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256];

            var effect = beatmap.Value?.Beatmap.ControlPointInfo.EffectPointAt(beatmap.Value.Track?.CurrentTime ?? Time.Current);

            for (int i = 0; i < bars_per_visualizer; i++)
            {
                int index = (i + indexOffset) % bars_per_visualizer;
                if (beatmap?.Value?.Track?.IsRunning ?? false)
                {
                    if (temporalAmplitudes[index] > frequencyAmplitudes[i])
                        frequencyAmplitudes[i] = temporalAmplitudes[index] * (effect?.KiaiMode == true ? 1 : 0.5f);
                }
                else
                {
                    if (frequencyAmplitudes[(i + index_change) % bars_per_visualizer] > frequencyAmplitudes[i])
                        frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualizer];
                }
            }
            indexOffset = (indexOffset + index_change) % bars_per_visualizer;
            Scheduler.AddDelayed(ensureAmplitudes, 50);
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();
            ensureAmplitudes();
        }

        protected override void Update()
        {
            base.Update();

            float decayFactor = (float)Time.Elapsed * decay_per_milisecond;
            for (int i = 0; i < bars_per_visualizer; i++)
            {
                //0.03% of extra bar length to make it a little faster when bar is almost at it's minimum
                frequencyAmplitudes[i] -= decayFactor * (frequencyAmplitudes[i] + 0.03f);
                if (frequencyAmplitudes[i] < 0)
                    frequencyAmplitudes[i] = 0;
            }

            Invalidate(Invalidation.DrawNode, shallPropagate: false);
        }

        protected override DrawNode CreateDrawNode() => new VisualisationDrawNode();

        private readonly VisualizerSharedData sharedData = new VisualizerSharedData();
        protected override void ApplyDrawNode(DrawNode node)
        {
            base.ApplyDrawNode(node);

            var visNode = (VisualisationDrawNode)node;

            visNode.Shader = shader;
            visNode.Texture = texture;
            visNode.Size = DrawSize.X;
            visNode.Shared = sharedData;
            visNode.Colour = AccentColour;
            visNode.AudioData = frequencyAmplitudes;
        }

        private class VisualizerSharedData
        {
            public readonly LinearBatch<TexturedVertex2D> VertexBatch = new LinearBatch<TexturedVertex2D>(100 * 4, 10, PrimitiveType.Quads);
        }

        private class VisualisationDrawNode : DrawNode
        {
            public Shader Shader;
            public Texture Texture;
            public VisualizerSharedData Shared;
            //Asuming the logo is a circle, we don't need a second dimension.
            public float Size;

            public Color4 Colour;
            public float[] AudioData;

            public override void Draw(Action<TexturedVertex2D> vertexAction)
{'fraction_non_alphanumeric': 0.08334118978033374, 'fraction_numerical': 0.011784670500612804, 'mean_word_length': 2.1190826227580124, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1203354', 'n_tokens_mistral': 3003, 'n_tokens_neox': 2721, 'n_words': 686}