Skip to content

Commit 87c8c65

Browse files
committed
Update to StreamDeckSharp 4.0-preview
1 parent 0867884 commit 87c8c65

File tree

4 files changed

+27
-68
lines changed

4 files changed

+27
-68
lines changed

NdiStreamDeck/NdiStreamDeck/MainWindow.xaml.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// as found in the LICENSE.txt file.
44

55
using NewTek.NDI;
6+
using OpenMacroBoard.SDK;
67
using StreamDeckSharp;
78
using System;
89
using System.Collections.Generic;
@@ -22,7 +23,7 @@ public partial class MainWindow : Window
2223
private Finder finder;
2324
private IReadOnlyList<NdiStreamDeckView> views = new List<NdiStreamDeckView>();
2425
private IReadOnlyList<CameraStatusProvider> statusProviders = new List<CameraStatusProvider>();
25-
private IReadOnlyList<IStreamDeckBoard> streamDecks;
26+
private IReadOnlyList<IMacroBoard> streamDecks;
2627
private DispatcherTimer timer;
2728

2829
public MainWindow()
@@ -44,9 +45,9 @@ private void InitializeStreamDecksAndFinder(object sender, RoutedEventArgs e)
4445
streamDecks = devices.Select(device => StreamDeck.OpenDevice(device.DevicePath)).ToList();
4546
streamDeckInfo.Text = string.Join("\r\n", devices.Zip(streamDecks, (device, deck) =>
4647
$"{device.DeviceName}: Firmware {deck.GetFirmwareVersion()}\r\n" +
47-
$" Keys: {deck.Keys.KeyCountX}x{deck.Keys.KeyCountY}\r\n" +
48-
$" Key size: {deck.Keys.KeyWidth}x{deck.Keys.KeyHeight}px\r\n" +
49-
$" Key gap: {deck.Keys.GetKeyDistanceXWorkaround()}x{deck.Keys.GetKeyDistanceYWorkaround()}px"));
48+
$" Keys: {deck.Keys.CountX}x{deck.Keys.CountY}\r\n" +
49+
$" Key size: {deck.Keys.KeySize}px\r\n" +
50+
$" Key gap: {deck.Keys.GapSize}px"));
5051

5152
// Start the NDI "finder" which discovers available sources
5253
finder = new Finder();

NdiStreamDeck/NdiStreamDeck/NdiStreamDeck.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<ItemGroup>
1010
<ProjectReference Include="..\..\..\Tools\Church\NDILibDotNet2\NDILibDotNet2.csproj" />
1111
<None Include="../../../Tools/Church/NdiRuntime/**" CopyToOutputDirectory="Always" Visible="False" />
12-
<PackageReference Include="StreamDeckSharp" Version="3.2.0" />
12+
<PackageReference Include="StreamDeckSharp" Version="4.0.0-preview" />
1313
</ItemGroup>
1414
</Project>

NdiStreamDeck/NdiStreamDeck/NdiStreamDeckView.cs

+21-26
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,24 @@ namespace NdiStreamDeck
1616
/// </summary>
1717
internal sealed class NdiStreamDeckView : IDisposable
1818
{
19-
private readonly IStreamDeckBoard deck;
19+
private readonly IMacroBoard deck;
2020
private readonly IList<VideoFrameReceiver> sources;
2121
private int activeSourceIndex;
2222

2323
// Just for convenience...
2424
private readonly int rows;
2525
private readonly int columns;
26-
private readonly int keyWidth;
27-
private readonly int keyHeight;
28-
private readonly int keyGapWidth;
29-
private readonly int keyGapHeight;
26+
private readonly int keySize;
27+
private readonly int gapSize;
3028

3129
// Note: not using IReadOnlyList as that doesn't have IndexOf :(
32-
internal NdiStreamDeckView(IStreamDeckBoard deck, IList<VideoFrameReceiver> sources)
30+
internal NdiStreamDeckView(IMacroBoard deck, IList<VideoFrameReceiver> sources)
3331
{
3432
this.deck = deck;
35-
rows = deck.Keys.KeyCountY;
36-
columns = deck.Keys.KeyCountX;
37-
keyWidth = deck.Keys.KeyWidth;
38-
keyHeight = deck.Keys.KeyHeight;
39-
40-
keyGapWidth = deck.Keys.GetKeyDistanceXWorkaround();
41-
keyGapHeight = deck.Keys.GetKeyDistanceYWorkaround();
33+
rows = deck.Keys.CountY;
34+
columns = deck.Keys.CountX;
35+
keySize = deck.Keys.KeySize;
36+
gapSize = deck.Keys.GapSize;
4237

4338
this.sources = sources.Take(rows).ToList();
4439
deck.KeyStateChanged += HandleStreamDeckKey;
@@ -86,8 +81,8 @@ private void HandleStreamDeckKey(object sender, KeyEventArgs e)
8681
/// </summary>
8782
private unsafe void DrawThumbnail(int row, VideoFrame frame)
8883
{
89-
var height = keyHeight;
90-
var width = keyWidth;
84+
var height = keySize;
85+
var width = keySize;
9186
var data = new byte[width * height * 3];
9287

9388
int scale = Math.Min(frame.Height / height, frame.Width / width);
@@ -111,7 +106,7 @@ private unsafe void DrawThumbnail(int row, VideoFrame frame)
111106
sourceIndex += (scale - 1) * 4;
112107
}
113108
}
114-
var bitmap = new KeyBitmap(width, height, data);
109+
var bitmap = KeyBitmap.FromBgr24Array(width, height, data);
115110
deck.SetKeyBitmap(row * columns, bitmap);
116111
}
117112

@@ -127,8 +122,8 @@ private unsafe void DrawFullFrame(VideoFrame frame)
127122
int keyOffsetX = 1;
128123
int keyOffsetY = 0;
129124

130-
int keyPixelsWidth = keyWidth * keyColumns + keyGapWidth * (keyColumns - 1);
131-
int keyPixelsHeight = keyHeight * keyRows + keyGapHeight * (keyRows - 1);
125+
int keyPixelsWidth = keySize * keyColumns + gapSize * (keyColumns - 1);
126+
int keyPixelsHeight = keySize * keyRows + gapSize * (keyRows - 1);
132127
int scale = Math.Min(frame.Height / keyPixelsHeight, frame.Width / keyPixelsWidth);
133128

134129
// Our simplistic scaling means we don't show absolutely everything,
@@ -140,16 +135,16 @@ private unsafe void DrawFullFrame(VideoFrame frame)
140135

141136
for (int row = 0; row < keyRows; row++)
142137
{
143-
int startY = row * (keyHeight + keyGapHeight) * scale + inputOffsetY;
138+
int startY = row * (keySize + gapSize) * scale + inputOffsetY;
144139
for (int col = 0; col < keyColumns; col++)
145140
{
146-
int startX = col * (keyWidth + keyGapWidth) * scale + inputOffsetX;
147-
var data = new byte[keyWidth * keyHeight * 3];
141+
int startX = col * (keySize + gapSize) * scale + inputOffsetX;
142+
var data = new byte[keySize * keySize * 3];
148143
int destIndex = 0;
149-
for (int y = 0; y < keyHeight; y++)
144+
for (int y = 0; y < keySize; y++)
150145
{
151146
int sourceIndex = (y * scale + startY) * frame.Stride + startX * 4;
152-
for (int x = 0; x < keyWidth; x++)
147+
for (int x = 0; x < keySize; x++)
153148
{
154149
data[destIndex++] = buffer[sourceIndex++];
155150
data[destIndex++] = buffer[sourceIndex++];
@@ -158,15 +153,15 @@ private unsafe void DrawFullFrame(VideoFrame frame)
158153
sourceIndex += (scale - 1) * 4;
159154
}
160155
}
161-
var bitmap = new KeyBitmap(keyWidth, keyHeight, data);
162-
deck.SetKeyBitmap((row + keyOffsetY) * deck.Keys.KeyCountX + col + keyOffsetX, bitmap);
156+
var bitmap = KeyBitmap.FromBgr24Array(keySize, keySize, data);
157+
deck.SetKeyBitmap((row + keyOffsetY) * columns + col + keyOffsetX, bitmap);
163158
}
164159
}
165160
}
166161

167162
public void Dispose()
168163
{
169-
deck.ClearKeysWithWorkaround();
164+
deck.ClearKeys();
170165
deck.KeyStateChanged -= HandleStreamDeckKey;
171166
foreach (var source in sources)
172167
{

NdiStreamDeck/NdiStreamDeck/StreamDeckWorkarounds.cs

-37
This file was deleted.

0 commit comments

Comments
 (0)