Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected states when parsing information for tally lights #81

Closed
lukas-runge opened this issue May 6, 2020 · 7 comments
Closed

unexpected states when parsing information for tally lights #81

lukas-runge opened this issue May 6, 2020 · 7 comments
Labels
question Further information is requested

Comments

@lukas-runge
Copy link

lukas-runge commented May 6, 2020

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [x] question about how to use this project

  • Summary
    I am building a dmx tally light solution for atem switchers. When I just cut between two cameras there is one state transmitted which has previous preview as program so preview and program are identical for one state. This results in the previous program tally switching off before switching to green again. (flickering)
    In this example I am only showing camera 1 tally information to make it easier to understand:
    image

Is there any way to catch this case or directly extract tally light information for example for one input with the atem-connection library?

Thank you all in advance for your help and this awesome open source library!
Kind regards
@lukas-runge

  • Other information
    To get the Tally light information I am parsing the state object to extract tally information out of it. (using listVisibleInputs() on the switcher object) and some ways to prevent weird states messing up my readout.

Here is my current code 🔽
parseForTally
image created with Polacode for Visual Studio Code

copy/paste code
this.switcher.on('stateChanged', (state: any) => {
    // State does not always contain ME video data; Return if necessary data is missing.
    if(!state || !state.video || !state.video.ME || !state.video.ME[0])
        return;
    
    // There is some weird state change after a transition that I am able to catch with my glitch variable here
    if (state.video.ME[0].inTransition) {
        state.video.ME[0].transitionPosition == 0 || state.video.ME[0].transitionPosition == 10000 ? glitch = true : null;
    } else {
        glitch = false;
    }
    
    // checking out current preview and program information
    let new_preview = this.switcher.listVisibleInputs("preview", 0)
    let new_program = this.switcher.listVisibleInputs("program", 0)

    // comparing to old preview information, updating if changed
    if (_.isEqual(this.preview, new_preview) == false && glitch == false) {
        console.log(`PREVIEW: ${new_preview}`)
        this.preview = new_preview
        update_now = true
    }

    // comparing to old program information, updating if changed
    if (_.isEqual(this.program, new_program) == false && glitch == false) {
        console.log(`PROGRAM: ${new_program}`)
        this.program = new_program
        update_now = true
    }

    // notifing tallys ("Inputs") if there are changes
    if (update_now == true) {
        this.notifyInputs();
        update_now = false
    } 
});
@Julusian
Copy link
Member

Julusian commented May 6, 2020

I think this is a known limitation of the v1 releases. The way we parse commands from the atem means that we emit a stateChanged for every single thing it sends, even thought they are batched. This will be better in v2, but there are some bugs there that are blocking its release (eg #76)

As a workaround, you could try adding a simple debounce to stateChanged, so that you wait for a gap in commands before doing this, but I dont know if that will play well with transitions..
I dont have any better ideas right now, not without modifying the library to expose some more data

@Julusian Julusian added the question Further information is requested label May 6, 2020
@lukas-runge
Copy link
Author

Hi @Julusian,

thank you for your ultra fast response.
Your idea sounds like a solution that would work for me. I should be able to catch the case in which i am dealing with a transition to only apply the function in the other cases. 👌 I am not that experienced in coding tho, so i'll have to first learn how to write a debounce function in typescript. But I'll try to do my best. Thank you very much for your assessment on my challenge.
Other than that: When do you think we can expect v2?

Kind regards
@lukas-runge

@Julusian
Copy link
Member

Julusian commented May 6, 2020

There is no concrete timescale on v2. It is waiting for either me to have the time and motivation to look into the issues which were reported, or for nrk to want to upgrade to it and provide the time needed.

It does mostly work, I think it is just some bugs in edge case conditions, or functionality used less often

@lukas-runge
Copy link
Author

Appreciate the work and time you guys are putting into this. Thank you very much! I would love to test v2 to see if it works without issues in my usecase. So I could just clone the current state of the master branch, build it and copy it into the node_modules folder to test v2 myself, right?

Kind regards
@lukas-runge

@Julusian
Copy link
Member

Julusian commented May 6, 2020

The easiest way to install it is via npm install atem-connection@nightly
There are some small api differences, but as you are using typescript, it should report anything

@lukas-runge
Copy link
Author

Awesome! Just tried it with the nightly build. Works like a charm in my usecase 😎 Even enabled me to make my code much simpler cuz' all of the weired in between states are gone now 😍👌
image

Thank you @Julusian your fast help on my challenge and huge thanks to all maintainers of this library for enabling me to do my project at all - thank you guys!

Kind regards
@lukas-runge

Here is my new code 🔽
nightly-test-2
image created with Polacode for Visual Studio Code

copy/paste code
constructor (ip: string) {
    this.ip = ip
    this.switcher = new AtemSwitcher()

    this.switcher.on('connected', (state: any) => {
        console.log(`Connected to ${this.ip}.`);

        let update_now: boolean = true;
        update_now = this.parseNewState(update_now)

        this.switcher.on('stateChanged', (state: any) => {
            update_now = this.parseNewState(update_now)
        });

    })

    this.switcher.on('disconnected', () => {
        console.log(`Disconnected from ${this.ip}.`);
        this.connect();
    })

}

parseNewState(update_now: boolean):boolean {
    
    // checking out current preview and program information
    let new_preview = this.switcher.listVisibleInputs("preview", 0)
    let new_program = this.switcher.listVisibleInputs("program", 0)
    
    // comparing to old preview information, updating if changed
    if (_.isEqual(this.preview, new_preview) == false) {
        console.log(`PREVIEW: ${new_preview}`)
        this.preview = new_preview
        update_now = true
    }

    // comparing to old program information, updating if changed
    if (_.isEqual(this.program, new_program) == false) {
        console.log(`PROGRAM: ${new_program}`)
        this.program = new_program
        update_now = true
    }

    // notifing tallys ("Inputs") if there are changes
    if (update_now == true) {
        this.notifyInputs();
        update_now = false
    }

    // return update_now: boolean to track if
    // information has changed compared to previous state
    return update_now
}

connect () {
    console.log(`Connecting to ${this.ip}...`);
    this.switcher.connect(this.ip)
}

@lukas-runge
Copy link
Author

Hi everyone,

finally finished & published my tally light tool 🎉

Thank you @Julusian for your fast help on during development and huge thanks to all maintainers of this library for enabling me to do my project at all - thank you guys!

Now I am very excited to see how people are going to use my new atem-tools library:
https://www.npmjs.com/package/atem-tools

Kind regards
@lukas-runge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants