Comments (4)
Hey @oddbear, action states are an odd one. Depending on how they're used, I often find they can produce unexpected behaviour, with that said however the behaviour should always be consistent, i.e. with a little trial and error in code they'll work.
One thing to note is; payload.state
is the current state of the action, whereas payload.userDesiredState
is the state the action is becoming. The latter of the two might simplify things.
The plugin "Sound Deck" uses Sharp Deck, and consumes states in two different ways:
- Record - This uses state as a "toggle", i.e. the recording starts and stops based on the state.
- Sampler - Controls the state based on whether an audio file is associated with an action.
Do you have a code snippet available? I'd be happy to take a look.
from sharpdeck.
Learning from pain points I encountered with Sound Deck, my only suggestion would be to resist the urge to persist things in memory (unless absolutely necessary). Originally I was persisting things like settings in memory against the action instance, and quickly found it became difficult to synchronize. Other than that, it looks like you're certainly on the right path.
Consider removing:
private FatChannelToggleSettings _settings;
private int? _lastState = null;
Which would also allow you to remove:
protected override async Task OnDidReceiveSettings(ActionEventArgs<ActionPayload> args)
You can then access the settings directly from the payload, which makes the OnKeyDown
look like this:
protected override async Task OnKeyDown(ActionEventArgs<KeyPayload> args)
{
await base.OnKeyDown(args);
var settings = args.Payload.GetSettings<FatChannelToggleSettings>();
var action = Action();
_updateService.SetRouteValue(_settings.Route, action);
}
Calling SetStateAsync
is minimal, so I think it should also be safe to remove the guard in UpdateState
:
private async Task StateUpdated()
{
var state = GetCurrentState() ? 0 : 1;
Trace.WriteLine($"Fat state: {state}, count: {_count}, context: {base.Context}");
await SetStateAsync(state);
}
from sharpdeck.
I will look into it. This is my first Stream Deck plugin (only made Touch Portal and Loupedeck before), so there might be a couple of things I have misunderstood. The code can be found at: https://github.com/oddbear/Revelator.io24.Api/blob/master/Revelator.io24.StreamDeck/Actions/FatChannelToggleAction.cs
from sharpdeck.
Closing this one, as it doesn't seem to be a issue with the SDK. Thanks for the help.
from sharpdeck.
Related Issues (14)
- Add unit tests HOT 1
- Incorrect Example HOT 1
- Update examples to 6.0.0 HOT 3
- Fast short keypresses trigger OnKeyLongPress HOT 2
- Update examples so they hold at least one PropertyInspector entry. HOT 2
- Improve support for settings to `StreamDeckAction`
- SD+ dial press does not work since Stream Deck v6.5
- Automatically publish to NuGet on release HOT 1
- Deadlocking prevention
- Action method decorators, for Property Inspector controllers
- Update example to demonstrate Property Inspector decorators HOT 1
- Add support for 4.1 endpoints
- Action instances contain incorrect settings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpdeck.