commit e89b4c1ece1d7fa678e8ad54431e4429e16857f9 Author: BlubbFish Date: Mon Aug 3 13:55:20 2026 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..12e0f40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vs +StreamDeckBlubb/bin +StreamDeckBlubb/obj \ No newline at end of file diff --git a/StreamDeckBlubb.slnx b/StreamDeckBlubb.slnx new file mode 100644 index 0000000..21bb7d2 --- /dev/null +++ b/StreamDeckBlubb.slnx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/StreamDeckBlubb/Program.cs b/StreamDeckBlubb/Program.cs new file mode 100644 index 0000000..d1bf2fd --- /dev/null +++ b/StreamDeckBlubb/Program.cs @@ -0,0 +1,137 @@ +using OpenMacroBoard.SDK; +using SixLabors.Fonts; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Drawing.Processing; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using StreamDeckSharp; + +namespace StreamDeckBlubb { + internal class Program { + static void Main(String[] args) => _ = new Program(args); + + private IMacroBoard deck; + private readonly Font arial60 = SystemFonts.CreateFont("Arial", 60); + private readonly Font arial80 = SystemFonts.CreateFont("Arial", 80); + + private Byte brightness = 100; + + public Program(String[] _1) { + this.Open(); + + this.WriteKeys(); + + this.WriteBar(); + + this.deck.ButtonPressed += this.Deck_ButtonPressed; + this.deck.ButtonReleased += this.Deck_ButtonReleased; + + deck.TouchbarTouched += Deck_TouchbarTouched; + deck.TouchbarPressed += Deck_TouchbarPressed; + deck.TouchFlipEvent += Deck_TouchFlipEvent; + + deck.EncoderPressed += Deck_EncoderPressed; + deck.EncoderReleased += Deck_EncoderReleased; + deck.EncoderTurn += Deck_EncoderTurn; + + _ = Console.ReadKey(); + } + + private void WriteBar() { + Image imt = new(1200, 100, Color.Green.ToPixel()); + imt.Mutate(ctx => ctx.Paint( + canvas => canvas.DrawText(new(this.arial80) { + Origin = new(10, 10) + }, "Peter, Philip und Naomi", Brushes.Solid(Color.Black), null))); + this.deck.SetWindowImage(KeyBitmap.Create.FromImageSharpImage(imt)); + } + + private void WriteKeys() { + + for(Int32 i = 0; i < this.deck.Keys.Count; i++) { + (Int32 r, Int32 g, Int32 b) = ColorFromHSV(i * 10, 1, 0.5); + Image im = new(112, 112, Color.ParseHex("#" + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + "FF").ToPixel()); + im.Mutate(ctx => ctx.Paint( + canvas => canvas.DrawText(new(this.arial60) { + Origin = new(10, 10) + }, Convert.ToChar((i + 65)).ToString(), Brushes.Solid(Color.Black), null))); + + this.deck.SetButtonImage(i, KeyBitmap.Create.FromImageSharpImage(im)); + } + } + + private void Deck_ButtonPressed(Object? sender, KeyPressEvent e) { + (Int32 r, Int32 g, Int32 b) = ColorFromHSV(e.Key * 10, 1, 1); + Image im = new(112, 112, Color.ParseHex("#" + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + "FF").ToPixel()); + im.Mutate(ctx => ctx.Paint( + canvas => canvas.DrawText(new(this.arial60) { + Origin = new(10, 10) + }, Convert.ToChar((e.Key + 65)).ToString(), Brushes.Solid(Color.Black), null))); + this.deck.SetButtonImage(e.Key, KeyBitmap.Create.FromImageSharpImage(im)); + } + + private void Deck_ButtonReleased(Object? sender, KeyPressEvent e) { + (Int32 r, Int32 g, Int32 b) = ColorFromHSV(e.Key * 10, 1, 0.5); + Image im = new(112, 112, Color.ParseHex("#" + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + "FF").ToPixel()); + im.Mutate(ctx => ctx.Paint( + canvas => canvas.DrawText(new(this.arial60) { + Origin = new(10, 10) + }, Convert.ToChar((e.Key + 65)).ToString(), Brushes.Solid(Color.Black), null))); + this.deck.SetButtonImage(e.Key, KeyBitmap.Create.FromImageSharpImage(im)); + } + + private void Deck_EncoderTurn(Object? sender, KnobTurnEvent e) { + if(e.Encoder == 5) { + if(this.brightness + e.Steps > 100) { + this.brightness = 100; + } else if(this.brightness + e.Steps < 0) { + this.brightness = 0; + } else { + this.brightness = (Byte)(this.brightness + e.Steps); + } + this.deck.SetBrightness(this.brightness); + } else { + Console.WriteLine("Encoder Rotated " + e); + } + } + + + private void Open() { + //Open the Stream Deck device + this.deck = StreamDeck.OpenDevice(); + this.deck.SetBrightness(this.brightness); + } + + private static void Deck_EncoderReleased(Object? sender, KnobPressEvent e) => Console.WriteLine("Encoder Released " + e); + private static void Deck_EncoderPressed(Object? sender, KnobPressEvent e) => Console.WriteLine("Encoder Pressed " + e); + private static void Deck_TouchbarTouched(Object? sender, TouchTipEvent e) => Console.WriteLine("Touched " + e); + private static void Deck_TouchbarPressed(Object? sender, TouchTipEvent e) => Console.WriteLine("Pressed " + e); + private static void Deck_TouchFlipEvent(Object? sender, TouchFlipEvent e) => Console.WriteLine("Flipped " + e); + + + public static (Int32, Int32, Int32) ColorFromHSV(Double hue, Double saturation, Double value) { + Int32 hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6; + Double f = (hue / 60) - Math.Floor(hue / 60); + + value *= 255; + Int32 v = Convert.ToInt32(value); + Int32 p = Convert.ToInt32(value * (1 - saturation)); + Int32 q = Convert.ToInt32(value * (1 - (f * saturation))); + Int32 t = Convert.ToInt32(value * (1 - ((1 - f) * saturation))); + + if(hi == 0) { + return (v, t, p); + } else if(hi == 1) { + return (q, v, p); + } else if(hi == 2) { + return (p, v, t); + } else if(hi == 3) { + return (p, q, v); + } else if(hi == 4) { + return (t, p, v); + } else { + return (v, p, q); + } + } + } +} diff --git a/StreamDeckBlubb/StreamDeckBlubb.csproj b/StreamDeckBlubb/StreamDeckBlubb.csproj new file mode 100644 index 0000000..8ace6b6 --- /dev/null +++ b/StreamDeckBlubb/StreamDeckBlubb.csproj @@ -0,0 +1,20 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + + +