Skip to content

Commit

Permalink
Added gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
BackTrak committed Dec 18, 2023
1 parent 6b3dc5c commit d8e80a8
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2023 Nick Pirocanac

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
153 changes: 153 additions & 0 deletions PropertyInspector/PluginActionPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<select class="sdProperty sdpi-item-value select" id="visualizer_mode" oninput="setSettings()" onchange="onSelectionChange()">
<option value="GreenBars">Green Bars</option>
<option value="CustomColor">Custom Color</option>
<option value="Gradient">Gradient</option>
</select>
</div>

Expand Down Expand Up @@ -169,6 +170,152 @@
</select>
</div>

<div class="sdpi-item" id="gradient_color_select">
<div class="sdpi-item-label">Custom Color</div>
<select class="sdProperty sdpi-item-value select" id="gradient_color" oninput="setSettings()">
<option value="AliceBlue">AliceBlue</option>
<option value="AntiqueWhite">AntiqueWhite</option>
<option value="Aqua">Aqua</option>
<option value="Aquamarine">Aquamarine</option>
<option value="Azure">Azure</option>
<option value="Beige">Beige</option>
<option value="Bisque">Bisque</option>
<option value="Black">Black</option>
<option value="BlanchedAlmond">BlanchedAlmond</option>
<option value="Blue">Blue</option>
<option value="BlueViolet">BlueViolet</option>
<option value="Brown">Brown</option>
<option value="BurlyWood">BurlyWood</option>
<option value="CadetBlue">CadetBlue</option>
<option value="Chartreuse">Chartreuse</option>
<option value="Chocolate">Chocolate</option>
<option value="Coral">Coral</option>
<option value="CornflowerBlue">CornflowerBlue</option>
<option value="Cornsilk">Cornsilk</option>
<option value="Crimson">Crimson</option>
<option value="Cyan">Cyan</option>
<option value="DarkBlue">DarkBlue</option>
<option value="DarkCyan">DarkCyan</option>
<option value="DarkGoldenrod">DarkGoldenrod</option>
<option value="DarkGray">DarkGray</option>
<option value="DarkGreen">DarkGreen</option>
<option value="DarkKhaki">DarkKhaki</option>
<option value="DarkMagenta">DarkMagenta</option>
<option value="DarkOliveGreen">DarkOliveGreen</option>
<option value="DarkOrange">DarkOrange</option>
<option value="DarkOrchid">DarkOrchid</option>
<option value="DarkRed">DarkRed</option>
<option value="DarkSalmon">DarkSalmon</option>
<option value="DarkSeaGreen">DarkSeaGreen</option>
<option value="DarkSlateBlue">DarkSlateBlue</option>
<option value="DarkSlateGray">DarkSlateGray</option>
<option value="DarkTurquoise">DarkTurquoise</option>
<option value="DarkViolet">DarkViolet</option>
<option value="DeepPink">DeepPink</option>
<option value="DeepSkyBlue">DeepSkyBlue</option>
<option value="DimGray">DimGray</option>
<option value="DodgerBlue">DodgerBlue</option>
<option value="Firebrick">Firebrick</option>
<option value="FloralWhite">FloralWhite</option>
<option value="ForestGreen">ForestGreen</option>
<option value="Fuchsia">Fuchsia</option>
<option value="Gainsboro">Gainsboro</option>
<option value="GhostWhite">GhostWhite</option>
<option value="Gold">Gold</option>
<option value="Goldenrod">Goldenrod</option>
<option value="Gray">Gray</option>
<option value="Green">Green</option>
<option value="GreenYellow">GreenYellow</option>
<option value="Honeydew">Honeydew</option>
<option value="HotPink">HotPink</option>
<option value="IndianRed">IndianRed</option>
<option value="Indigo">Indigo</option>
<option value="Ivory">Ivory</option>
<option value="Khaki">Khaki</option>
<option value="Lavender">Lavender</option>
<option value="LavenderBlush">LavenderBlush</option>
<option value="LawnGreen">LawnGreen</option>
<option value="LemonChiffon">LemonChiffon</option>
<option value="LightBlue">LightBlue</option>
<option value="LightCoral">LightCoral</option>
<option value="LightCyan">LightCyan</option>
<option value="LightGoldenrodYellow">LightGoldenrodYellow</option>
<option value="LightGray">LightGray</option>
<option value="LightGreen">LightGreen</option>
<option value="LightPink">LightPink</option>
<option value="LightSalmon">LightSalmon</option>
<option value="LightSeaGreen">LightSeaGreen</option>
<option value="LightSkyBlue">LightSkyBlue</option>
<option value="LightSlateGray">LightSlateGray</option>
<option value="LightSteelBlue">LightSteelBlue</option>
<option value="LightYellow">LightYellow</option>
<option value="Lime">Lime</option>
<option value="LimeGreen">LimeGreen</option>
<option value="Linen">Linen</option>
<option value="Magenta">Magenta</option>
<option value="Maroon">Maroon</option>
<option value="MediumAquamarine">MediumAquamarine</option>
<option value="MediumBlue">MediumBlue</option>
<option value="MediumOrchid">MediumOrchid</option>
<option value="MediumPurple">MediumPurple</option>
<option value="MediumSeaGreen">MediumSeaGreen</option>
<option value="MediumSlateBlue">MediumSlateBlue</option>
<option value="MediumSpringGreen">MediumSpringGreen</option>
<option value="MediumTurquoise">MediumTurquoise</option>
<option value="MediumVioletRed">MediumVioletRed</option>
<option value="MidnightBlue">MidnightBlue</option>
<option value="MintCream">MintCream</option>
<option value="MistyRose">MistyRose</option>
<option value="Moccasin">Moccasin</option>
<option value="NavajoWhite">NavajoWhite</option>
<option value="Navy">Navy</option>
<option value="OldLace">OldLace</option>
<option value="Olive">Olive</option>
<option value="OliveDrab">OliveDrab</option>
<option value="Orange">Orange</option>
<option value="OrangeRed">OrangeRed</option>
<option value="Orchid">Orchid</option>
<option value="PaleGoldenrod">PaleGoldenrod</option>
<option value="PaleGreen">PaleGreen</option>
<option value="PaleTurquoise">PaleTurquoise</option>
<option value="PaleVioletRed">PaleVioletRed</option>
<option value="PapayaWhip">PapayaWhip</option>
<option value="PeachPuff">PeachPuff</option>
<option value="Peru">Peru</option>
<option value="Pink">Pink</option>
<option value="Plum">Plum</option>
<option value="PowderBlue">PowderBlue</option>
<option value="Purple">Purple</option>
<option value="Red">Red</option>
<option value="RosyBrown">RosyBrown</option>
<option value="RoyalBlue">RoyalBlue</option>
<option value="SaddleBrown">SaddleBrown</option>
<option value="Salmon">Salmon</option>
<option value="SandyBrown">SandyBrown</option>
<option value="SeaGreen">SeaGreen</option>
<option value="SeaShell">SeaShell</option>
<option value="Sienna">Sienna</option>
<option value="Silver">Silver</option>
<option value="SkyBlue">SkyBlue</option>
<option value="SlateBlue">SlateBlue</option>
<option value="SlateGray">SlateGray</option>
<option value="Snow">Snow</option>
<option value="SpringGreen">SpringGreen</option>
<option value="SteelBlue">SteelBlue</option>
<option value="Tan">Tan</option>
<option value="Teal">Teal</option>
<option value="Thistle">Thistle</option>
<option value="Tomato">Tomato</option>
<option value="Turquoise">Turquoise</option>
<option value="Violet">Violet</option>
<option value="Wheat">Wheat</option>
<option value="White">White</option>
<option value="WhiteSmoke">WhiteSmoke</option>
<option value="Yellow">Yellow</option>
<option value="YellowGreen">YellowGreen</option>
</select>
</div>

<div class="sdpi-item" id="visualizer_device_select">
<div class="sdpi-item-label">Monitor Device</div>
<select class="sdProperty sdpi-item-value select" id="visualizer_device" oninput="setSettings()">
Expand All @@ -183,9 +330,15 @@

if (mode == 'CustomColor') {
$('#custom_color_select').show();
$('#gradient_color_select').hide();
}
else if (mode == 'Gradient') {
$('#custom_color_select').show();
$('#gradient_color_select').show();
}
else {
$('#custom_color_select').hide();
$('#gradient_color_select').hide();
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# StreamDeckNvidiaBroadcastPlugin
# Stream Deck Visualizer
3 changes: 2 additions & 1 deletion VisualizerMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Visualizer
internal enum VisualizerMode
{
GreenBars,
CustomColor
CustomColor,
Gradient
}
}
52 changes: 39 additions & 13 deletions VisualizerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Specialized;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
Expand All @@ -27,6 +28,7 @@ public class VisualizerPlugin : KeypadBase
{
private VisualizerMode _visualizerMode = VisualizerMode.GreenBars;
private KnownColor _customColor = KnownColor.AliceBlue;
private KnownColor _gradientColor = KnownColor.Coral;
private string _targetDeviceID = String.Empty;

private bool _wasEnabledOnLastTick = false;
Expand Down Expand Up @@ -54,6 +56,9 @@ private void UpdateSettings(JObject settings)
if (Enum.TryParse<KnownColor>(settings.Value<String>("custom_color"), out _customColor) == false)
_customColor = KnownColor.AliceBlue;

if (Enum.TryParse<KnownColor>(settings.Value<String>("gradient_color"), out _gradientColor) == false)
_gradientColor = KnownColor.Coral;

if (_targetDeviceID != settings.Value<String>("visualizer_device"))
{
_targetDeviceID = settings.Value<String>("visualizer_device");
Expand Down Expand Up @@ -276,19 +281,28 @@ private void RenderData()
Brush red = new SolidBrush(Color.FromKnownColor(KnownColor.Red));
Brush black = new SolidBrush(Color.FromKnownColor(KnownColor.Black));
Brush custom = new SolidBrush(Color.FromKnownColor(_customColor));
Brush gradient = new LinearGradientBrush(new RectangleF(0, 0, bitmap.Width, bitmap.Height), Color.FromKnownColor(_customColor), Color.FromKnownColor(_gradientColor), 90);

if (_visualizerMode == VisualizerMode.GreenBars)
switch (_visualizerMode)
{
graphics.FillRectangle(red, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
graphics.FillRectangle(yellow, new RectangleF(0, bitmap.Height - bitmap.Height * .9f, bitmap.Width, bitmap.Height));
graphics.FillRectangle(green, new RectangleF(0, bitmap.Height - bitmap.Height * .7f, bitmap.Width, bitmap.Height));
}
else
{
graphics.FillRectangle(custom, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
//graphics.FillRectangle(white, new RectangleF(0, bitmap.Height - bitmap.Height * .9f, bitmap.Width, bitmap.Height));
//graphics.FillRectangle(white, new RectangleF(0, bitmap.Height - bitmap.Height * .7f, bitmap.Width, bitmap.Height));
case VisualizerMode.GreenBars:
graphics.FillRectangle(red, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
graphics.FillRectangle(yellow, new RectangleF(0, bitmap.Height - bitmap.Height * .9f, bitmap.Width, bitmap.Height));
graphics.FillRectangle(green, new RectangleF(0, bitmap.Height - bitmap.Height * .7f, bitmap.Width, bitmap.Height));
break;

case VisualizerMode.CustomColor:
graphics.FillRectangle(custom, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
break;

case VisualizerMode.Gradient:
graphics.FillRectangle(gradient, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
break;

default:
throw new NotSupportedException(_visualizerMode.ToString());
}


for (int i = 0; i < 8; i++)
{
Expand All @@ -305,11 +319,23 @@ private void RenderData()
//float height = (float)(peakFreqs[i] / FftValues[peakIndex] * bitmap.Height);
float height = (float)(peaks[i] / max[i] * bitmap.Height);
float width = bitmap.Width / peaks.Length;
float radius = (width) / 2;
float midpoint = radius;


for (int j = 1; j < width; j++)
{
float x = j - midpoint;
var angle = Math.Acos(x / radius);
var curveHeight = (float) Math.Sin(angle) * radius;

graphics.DrawLine(new Pen(black), (i * bitmap.Width / 8) + j, 0, (i * bitmap.Width / 8) + j, bitmap.Height - height - curveHeight + bitmap.Height / 8 / 2);
}

graphics.FillRectangle(black, new RectangleF(i * width, 0, width, bitmap.Height - height + bitmap.Height / 8 / 2));
//graphics.FillRectangle(black, new RectangleF(i * width, 0, width, bitmap.Height - height + bitmap.Height / 8 / 2));

if (_visualizerMode == VisualizerMode.CustomColor)
graphics.FillEllipse(custom, new RectangleF(i * bitmap.Width / 8, bitmap.Height - height, bitmap.Width / 8, bitmap.Height / 8));
//if (_visualizerMode == VisualizerMode.CustomColor)
// graphics.FillEllipse(custom, new RectangleF(i * bitmap.Width / 8, bitmap.Height - height, bitmap.Width / 8, bitmap.Height / 8));

//if (_visualizerMode == VisualizerMode.NegativeBalls)
// graphics.FillEllipse(red, new RectangleF(i * bitmap.Width / 8, height, bitmap.Width / 8, bitmap.Height / 8));
Expand Down
2 changes: 2 additions & 0 deletions com.zaphop.visualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<Content Include="!!README!!.txt" />
Expand Down Expand Up @@ -223,6 +224,7 @@
<Content Include="Images\zhgold72.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="LICENSE.txt" />
<Content Include="PropertyInspector\PluginActionPI.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit d8e80a8

Please sign in to comment.