Giter Site home page Giter Site logo

Comments (4)

GeekyEggo avatar GeekyEggo commented on June 3, 2024 1

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:

  1. Record - This uses state as a "toggle", i.e. the recording starts and stops based on the state.
  2. 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.

GeekyEggo avatar GeekyEggo commented on June 3, 2024 1

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.

oddbear avatar oddbear commented on June 3, 2024

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.

oddbear avatar oddbear commented on June 3, 2024

Closing this one, as it doesn't seem to be a issue with the SDK. Thanks for the help.

from sharpdeck.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.