bitfocus / companion-module-obs-studio

OBS Studio Module for Companion
MIT License
41 stars 28 forks source link

current_text variable not updating correctly #237

Closed slords closed 5 months ago

slords commented 11 months ago

Describe the bug I'm trying to use the current text from a label and it isn't updating correctly. If the scene isn't visible the variable value never updates despite it updating in OBS and verified using obs-raw to query the value. If the scene is in preview or program then the variable updates some of the time but isn't consistent. I'm using this functionality to display the number of a song that prepared before switching to that scene. The values in OBS are being updated by lyrics+ script.

To Reproduce Steps to reproduce the behavior:

  1. Setup lyrics+ obs plugin with Text Source = lyrics, Title Source = song title, Static Source = song number
  2. Prepare multiple songs in lyrics+
  3. Switch songs using hotkeys so lyrics, title, number are updated
  4. Verify variables in companion aren't updated if scene isn't visible and will only update about 3/5 times when it is visible

Version Information:

bryce-seifert commented 11 months ago

@slords It seems like when the text is in program, we don't receive update events from websocket so that might be part of it. (See demo below)

https://github.com/bitfocus/companion-module-obs-studio/assets/50299051/f6df11cf-84f4-4b2f-b59b-e2961d5daca8

However, when I nest the Lyrics within their own scene, and add that scene to another scene it seems to update consistently. Could that possibly be a workaround?

slords commented 11 months ago

What window is on the bottom left of your demo? I'd love to be able to follow and see similar output when testing.

I've created a simple example where setting the text using OBS calls from companion don't get updated either. I've got a but raised upstream with the websocket component. If we can show the issue is with that hopefully we can get it fixed upstream.

test.zip

slords commented 11 months ago

Reference to websocket bug: https://github.com/obsproject/obs-websocket/issues/1157

bryce-seifert commented 11 months ago

Thanks for the test project, I am able to replicate.

I can work around the "setting the text using OBS calls from companion don't get updated either" issue by having Companion poll for the value after using the Set Text action. So I can work on fixing that, but I don't have a solution for the lyrics+ issue. I think best bet there would be trying a nested scene and seeing if that helps.

slords commented 11 months ago

The song lyrics are already in a nested scene. The interesting thing is I can change songs 2-3 times and then it fails. This works in both directions. So if I have 10 songs and scroll through them forward I get song 1-3 that update correctly and then fail for 4-10. If I start backwards then I get 1, 10, 9 and the rest from 8-2 fail. Doesn't make any sense.

Is there an event or trigger that OBS is sending to you indicating the source has been updated or changed? How do you observe or test that in a way that can be measured?

slords commented 11 months ago

The updating of the text from companion was just an example. That isn't what I'm doing and the proposed fix won't help me at all. It might for others but I think the true fix is to get it identified upstream and fixed there.

bryce-seifert commented 11 months ago

I'm using the SceneItemTransformChanged event to know when the source has been updated. So if that doesn't fire when the text is changed, Companion has no way of knowing to update the variable

slords commented 11 months ago

That might be why we aren't getting updates when just the text is changing. That event only reports New transform/crop info of the scene item. As the transform isn't changing we aren't getting any updates. I wonder if I can tweak the code to do a minor transform change during the switching of songs.

bryce-seifert commented 11 months ago

Yeah, it seems unfortunately that's the best-fit event I can see. There's no event subscription for text changes or source property changes that I found. So if your text length is equal between the old and new text it likely won't fire.

I supposed the real solution would be for obs-websocket to have an InputSettingsChanged event that fires, then we could change to that which would be far more reliable since it's actually the text property being changed

slords commented 11 months ago

The length never occured to me as to why things would change or not. That totally makes sense now. Looking at the code for lyrics it would be very easy to make it wiggle the size by a pixel to make it trigger the event. I'll give that a try and see if it solves my issue.

slords commented 11 months ago

I've submitted a pull request to work around the issue with obs lyrics. It isn't ideal but solves the issue for me. The best solution would be for OBS to implement an event for text changes so you could subscribe to that.

https://github.com/amirchev/OBS-Lyrics/pull/46

bryce-seifert commented 11 months ago

After some digging, it looks like OBS should be emitting an "update" event when source settings change as of 29.0.0. https://docs.obsproject.com/reference-sources#source-signals

Screenshot 2023-08-01 at 9 13 11 PM

So obs-websocket would need to add handling for that event, and that should solve this.

Maxildan commented 6 months ago

When I ask to OBS, they say is a companion problem ^^' please help https://github.com/obsproject/obs-studio/issues/10051

Maxildan commented 6 months ago

A websocket dev said :

"However, this doesn't appear to be a bug with obs-websocket at all, and is most likely an issue with bitfocus companion. I see no GetInputSettings requests in the message log of your session, which is the only way that bitfocus would be able to know the current value of the input. obs-websocket does not emit updates when an input's settings data changes."

tt2468 commented 6 months ago

I'm using the SceneItemTransformChanged event to know when the source has been updated. So if that doesn't fire when the text is changed, Companion has no way of knowing to update the variable

That event is only to alert clients that the transform for a scene item has changed. It's quite literally just that, and nothing more. Not related to changes for a source.

After some digging, it looks like OBS should be emitting an "update" event when source settings change as of 29.0.0.

What you are looking at in your screenshot is the API documentation for libobs, and not the obs-websocket API documentation. The obs-websocket docs are here: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md

obs-websocket does not, and has never had an event which broadcasts source/input settings data changes. We may add one in the future, though.

Maxildan commented 6 months ago

Cool to see that things are progressing! Thank you for your time!

That means Bitfocus could add the ability to check the value with each button press

bryce-seifert commented 5 months ago

@Maxildan @slords obs-websocket 5.4.0, which is currently in the OBS 30.1 beta, adds an event for input changes so we can do this properly now.

I have this event implemented, and it will be in the next release of the module.