first commit

This commit is contained in:
BlubbFish 2026-08-03 13:55:20 +02:00
commit e89b4c1ece
4 changed files with 167 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vs
StreamDeckBlubb/bin
StreamDeckBlubb/obj

7
StreamDeckBlubb.slnx Normal file
View File

@ -0,0 +1,7 @@
<Solution>
<Project Path="../Librarys/ImageSharp/ImageSharp.Drawing/ImageSharp.Drawing.csproj" />
<Project Path="../Librarys/ImageSharp/ImageSharp/ImageSharp.csproj" />
<Project Path="../Librarys/StreamDeckSharp/OpenMacroBoard.SDK/OpenMacroBoard.SDK.csproj" />
<Project Path="../Librarys/StreamDeckSharp/StreamDeckSharp/StreamDeckSharp.csproj" />
<Project Path="StreamDeckBlubb/StreamDeckBlubb.csproj" />
</Solution>

137
StreamDeckBlubb/Program.cs Normal file
View File

@ -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<Rgb24> imt = new(1200, 100, Color.Green.ToPixel<Rgb24>());
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<Rgb24> im = new(112, 112, Color.ParseHex("#" + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + "FF").ToPixel<Rgb24>());
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<Rgb24> im = new(112, 112, Color.ParseHex("#" + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + "FF").ToPixel<Rgb24>());
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<Rgb24> im = new(112, 112, Color.ParseHex("#" + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + "FF").ToPixel<Rgb24>());
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);
}
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="10.0.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Librarys\ImageSharp\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />
<ProjectReference Include="..\..\Librarys\ImageSharp\ImageSharp\ImageSharp.csproj" />
<ProjectReference Include="..\..\Librarys\StreamDeckSharp\StreamDeckSharp\StreamDeckSharp.csproj" />
</ItemGroup>
</Project>