Skip to content

Commit

Permalink
Merge pull request #64 from BarRaider/stream-deck-plus-sdk
Browse files Browse the repository at this point in the history
Stream Deck+ SDK support
  • Loading branch information
BarRaider authored Dec 8, 2022
2 parents 69cb52a + 0622f5f commit 06a69df
Show file tree
Hide file tree
Showing 27 changed files with 1,710 additions and 253 deletions.
95 changes: 95 additions & 0 deletions barraider-sdtools/Backend/EncoderBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using BarRaider.SdTools.Payloads;
using System;
using System.Collections.Generic;
using System.Text;

namespace BarRaider.SdTools
{
/// <summary>
/// Main abstract class your plugin should derive from for dials (not keys)
/// For keys use the KeyBase or KeyAndEncoderBase
/// Holds implementation for all the basic functions
/// If you're missing an event, you can register to it from the Connection.StreamDeckConnection object
/// </summary>
public abstract class EncoderBase : IEncoderPlugin
{
/// <summary>
/// Called when the dial is rotated
/// </summary>
public abstract void DialRotate(DialRotatePayload payload);

/// <summary>
/// Called when the Dial is pressed or released
/// </summary>
public abstract void DialPress(DialPressPayload payload);

/// <summary>
/// Called when the touchpad (above the dials) is pressed
/// </summary>
public abstract void TouchPress(TouchpadPressPayload payload);

/// <summary>
/// Called when the PropertyInspector has new settings
/// </summary>
/// <param name="payload"></param>
public abstract void ReceivedSettings(ReceivedSettingsPayload payload);

/// <summary>
/// Called when GetGlobalSettings is called.
/// </summary>
/// <param name="payload"></param>
public abstract void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload);

/// <summary>
/// Called every second
/// Logic for displaying title/image can go here
/// </summary>
public abstract void OnTick();

/// <summary>
/// Abstract method Called when the plugin is disposed
/// </summary>
public abstract void Dispose();

/// <summary>
/// Main iDisposable Dispose function
/// </summary>
public void Destroy()
{
Dispose();
if (Connection != null)
{
Connection.Dispose();
}
}

/// <summary>
/// Connection object which handles your communication with the Stream Deck app
/// </summary>
protected ISDConnection Connection { get; private set; }

/// <summary>
/// Constructor for PluginBase. Receives the communication and plugin settings
/// Note that the settings object is not used by the base and should be consumed by the deriving class.
/// Usually, a private class inside the deriving class is created which stores the settings
/// Example for settings usage:
/// * if (payload.Settings == null || payload.Settings.Count == 0)
/// * {
/// * // Create default settings
/// * }
/// * else
/// * {
/// this.settings = payload.Settings.ToObject();
/// * }
///
/// </summary>
/// <param name="connection">Communication module with Stream Deck</param>
/// <param name="payload">Plugin settings - NOTE: Not used in base class, should be consumed by deriving class</param>
#pragma warning disable IDE0060 // Remove unused parameter
public EncoderBase(ISDConnection connection, InitialPayload payload)
#pragma warning restore IDE0060 // Remove unused parameter
{
Connection = connection;
}
}
}
32 changes: 32 additions & 0 deletions barraider-sdtools/Backend/ICommonPluginFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BarRaider.SdTools
{
public interface ICommonPluginFunctions : IDisposable
{
/// <summary>
/// Called when the PropertyInspector has new settings
/// </summary>
/// <param name="payload"></param>
void ReceivedSettings(ReceivedSettingsPayload payload);

/// <summary>
/// Called when GetGlobalSettings is called.
/// </summary>
/// <param name="payload"></param>
void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload);

/// <summary>
/// Called every second
/// Logic for displaying title/image can go here
/// </summary>
void OnTick();

/// <summary>
/// Internal function used by StreamDeckTools to prevent memory leaks
/// </summary>
void Destroy();
}
}
28 changes: 28 additions & 0 deletions barraider-sdtools/Backend/IEncoderPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using BarRaider.SdTools.Payloads;
using System;
using System.Collections.Generic;
using System.Text;

namespace BarRaider.SdTools
{
/// <summary>
/// Interface used to capture dial/encoder events
/// </summary>
public interface IEncoderPlugin : ICommonPluginFunctions
{
/// <summary>
/// Called when the dial is rotated
/// </summary>
void DialRotate(DialRotatePayload payload);

/// <summary>
/// Called when the Dial is pressed or released
/// </summary>
void DialPress(DialPressPayload payload);

/// <summary>
/// Called when the touchpad (above the dials) is pressed
/// </summary>
void TouchPress(TouchpadPressPayload payload);
}
}
19 changes: 19 additions & 0 deletions barraider-sdtools/Backend/IKeypadPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BarRaider.SdTools
{
/// <summary>
/// Interface used to capture key events
/// </summary>
public interface IKeypadPlugin : ICommonPluginFunctions
{
void KeyPressed(KeyPayload payload);

/// <summary>
/// Called when a Stream Deck key is released
/// </summary>
void KeyReleased(KeyPayload payload);
}
}
14 changes: 14 additions & 0 deletions barraider-sdtools/Backend/ISDConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ public interface ISDConnection : IDisposable
/// <returns></returns>
Task SetStateAsync(uint state);

/// <summary>
/// Sets the values of touchpad layouts items
/// </summary>
/// <param name="dictKeyValue">Dictionary holding the layout item keys and values you want to change</param>
/// <returns></returns>
Task SetFeedbackAsync(Dictionary<string, string> dictKeyValue);

/// <summary>
/// Sets the value of a single touchpad layout item
/// </summary>
/// <param name="dictKeyValues"></param>
/// <returns></returns>
Task SetFeedbackAsync(string layoutItemKey, string value);

#endregion

/// <summary>
Expand Down
109 changes: 109 additions & 0 deletions barraider-sdtools/Backend/KeyAndEncoderBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BarRaider.SdTools.Payloads;
using Newtonsoft.Json.Linq;

namespace BarRaider.SdTools
{

/// <summary>
/// Main abstract class your plugin should derive from for keys (not dials)
/// For dials use the EncoderBase or KeyAndEncoderBase
/// Holds implementation for all the basic functions
/// If you're missing an event, you can register to it from the Connection.StreamDeckConnection object
/// </summary>
public abstract class KeyAndEncoderBase : IKeypadPlugin, IEncoderPlugin
{
/// <summary>
/// Called when the dial is rotated
/// </summary>
public abstract void DialRotate(DialRotatePayload payload);

/// <summary>
/// Called when the Dial is pressed or released
/// </summary>
public abstract void DialPress(DialPressPayload payload);

/// <summary>
/// Called when the touchpad (above the dials) is pressed
/// </summary>
public abstract void TouchPress(TouchpadPressPayload payload);

/// <summary>
/// Called when a Stream Deck key is pressed
/// </summary>
public abstract void KeyPressed(KeyPayload payload);

/// <summary>
/// Called when a Stream Deck key is released
/// </summary>
public abstract void KeyReleased(KeyPayload payload);

/// <summary>
/// Called when the PropertyInspector has new settings
/// </summary>
/// <param name="payload"></param>
public abstract void ReceivedSettings(ReceivedSettingsPayload payload);

/// <summary>
/// Called when GetGlobalSettings is called.
/// </summary>
/// <param name="payload"></param>
public abstract void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload);

/// <summary>
/// Called every second
/// Logic for displaying title/image can go here
/// </summary>
public abstract void OnTick();

/// <summary>
/// Abstract method Called when the plugin is disposed
/// </summary>
public abstract void Dispose();

/// <summary>
/// Main iDisposable Dispose function
/// </summary>
public void Destroy()
{
Dispose();
if (Connection != null)
{
Connection.Dispose();
}
}

/// <summary>
/// Connection object which handles your communication with the Stream Deck app
/// </summary>
protected ISDConnection Connection { get; private set; }

/// <summary>
/// Constructor for PluginBase. Receives the communication and plugin settings
/// Note that the settings object is not used by the base and should be consumed by the deriving class.
/// Usually, a private class inside the deriving class is created which stores the settings
/// Example for settings usage:
/// * if (payload.Settings == null || payload.Settings.Count == 0)
/// * {
/// * // Create default settings
/// * }
/// * else
/// * {
/// this.settings = payload.Settings.ToObject();
/// * }
///
/// </summary>
/// <param name="connection">Communication module with Stream Deck</param>
/// <param name="payload">Plugin settings - NOTE: Not used in base class, should be consumed by deriving class</param>
#pragma warning disable IDE0060 // Remove unused parameter
public KeyAndEncoderBase(ISDConnection connection, InitialPayload payload)
#pragma warning restore IDE0060 // Remove unused parameter
{
Connection = connection;
}
}
}
Loading

0 comments on commit 06a69df

Please sign in to comment.