Created
September 26, 2022 03:30
-
-
Save CaiB/024c00671446edaa6908610345796ead to your computer and use it in GitHub Desktop.
ColorChord.NET Visualizer Concatenator for IngoDingo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ColorChord.NET.API; | |
using ColorChord.NET.API.Extensions; | |
namespace IngoDingosInsanity; | |
public class Extension : IExtension | |
{ | |
public string Name => "IngoDingo's Insanity"; | |
public string Description => "Because who needs a normal system when you can have 3"; | |
public uint APIVersion => ColorChordAPI.APIVersion; | |
public void Initialize() { Log.Info("βπ«π€π¬ππ¦π«π€π¬ insanity mode activated"); } | |
public void PostInitialize() { } | |
public void Shutdown() { } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ColorChord.NET.API.Outputs; | |
using ColorChord.NET.API.Visualizers; | |
using ColorChord.NET.API.Visualizers.Formats; | |
using ColorChord.NET.Config; | |
using System; | |
namespace IngoDingosInsanity; | |
public class VisualizerConcatenator : IVisualizer, IDiscrete1D, IOutput | |
{ | |
public string Name { get; private init; } | |
private readonly IDiscrete1D MainViz; | |
private readonly IDiscrete1D[] ConcatViz; | |
/// <summary> All outputs that need to be notified when new data is available. </summary> | |
private readonly List<IOutput> Outputs = new(); | |
public VisualizerConcatenator(string name, Dictionary<string, object> config) | |
{ | |
this.Name = name; | |
if (!config.TryGetValue("MainVisualizer", out object? MainVizName)) { throw new Exception("Config needs to define MainVisualizer entry"); } | |
IVisualizer? MainVizFound = Configurer.FindVisualizer(this, new() { { "VisualizerName", MainVizName } }); | |
if (MainVizFound is not IDiscrete1D MainViz) { throw new Exception($"Main visualizer \"{MainVizName}\" could not be found."); } | |
this.MainViz = MainViz; | |
if (!config.TryGetValue("AddedVisualizers", out object? SubVizList)) { throw new Exception("Config needs to define AddedVisualizers entry"); } | |
if (SubVizList is not string[] SubVizNames) { throw new Exception("AddedVisualizers needs to be a string list"); } | |
this.ConcatViz = new IDiscrete1D[SubVizNames.Length]; | |
for (int i = 0; i < SubVizNames.Length; i++) | |
{ | |
IVisualizer ThisSubViz = Configurer.FindVisualizer(this, new() { { "VisualizerName", SubVizNames[i] } }) ?? throw new Exception($"Sub visualizer [{i}] \"{SubVizNames[i]}\" could not be found"); | |
this.ConcatViz[i] = (IDiscrete1D)ThisSubViz; | |
} | |
MainVizFound.AttachOutput(this); | |
} | |
public void AttachOutput(IOutput output) { if (output != null) { this.Outputs.Add(output); } } | |
public void Start() { } | |
public void Stop() { } | |
public int GetCountDiscrete() | |
{ | |
int Length = this.MainViz.GetCountDiscrete(); | |
foreach (IDiscrete1D AddViz in this.ConcatViz) { Length += AddViz.GetCountDiscrete(); } | |
return Length; | |
} | |
public uint[] GetDataDiscrete() | |
{ | |
List<uint> Data = this.MainViz.GetDataDiscrete().ToList(); | |
foreach (IDiscrete1D AddViz in this.ConcatViz) { Data.AddRange(AddViz.GetDataDiscrete()); } | |
return Data.ToArray(); | |
} | |
// Data from visualizers | |
public void Dispatch() | |
{ | |
foreach (IOutput Output in this.Outputs) { Output.Dispatch(); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment