Skip to content

frontend: Update scene collection support for relative positioning - #11824

Merged
RytoEX merged 2 commits into
obsproject:masterfrom
PatTheMav:remigration-fix
Apr 21, 2025
Merged

RytoEX merged 2 commits into
obsproject:masterfrom
PatTheMav:remigration-fix

Conversation

@PatTheMav

Copy link
Copy Markdown
Member

Description

Updates the implementation of relative positioning code for scene collections by making the scene collection version and migration resolution part of the scene collection data model and removing it from the global OBSBasic application state.

Also implements #11630 within this updated implementation.

Additionally the following safeguards have been added:

  • When initialising the application, the default scene collection and profile are set not only when the value is not set in the user.ini file, but also if the value is an empty string
  • The frontend API call to get the name of the current scene collection handles a possible exception gracefully

Motivation and Context

This is a first iterative step to move from global application states into an encapsulated data class. To that end the following new data models have been added in the OBS namespace:

  • SceneCollection - a simple scene collection class that contains name, file path, version, and migration resolution of a scene collection found on disk
  • Rect - a generic rectangle class that stores width and height as double values and provides comparison operators as well as safe conversions from other types when constructing or updating an instance of a rectangle (using static_assert, using an incompatible type - namely a type that cannot be cast to double - will result in a compile error).

The new OBS::Rect allows for simpler comparisons between resolutions and ensures that "width" and "height" are always considered and combination even in code and not just logically or by convention.

Instead of storing a migration resolution in the global state of the OBSBasic instance, it is now a value on a SceneCollection instance and can be updated/changed accordingly.

Suggested Next Steps

Because scene collection objects were immutable before, use of std::optional and simpler value semantics were sufficient. With scene collections now becoming mutable objects, the copies provided by std::optional lead to unintuitive API behaviour.

Thus the SceneCollections container itself should become a proper class by itself with common container semantics (mainly iterator-based access) which will make working with actual scene collection references more straight-forward (while retaining value semantics).

How Has This Been Tested?

Tested with several scene collections:

  • Scene collection without version, resolution, or migration resolution
    • Will use "absolute" positioning until base resolution is set
  • Scene collection with version 1, resolution, but no migration resolution
    • Will use "absolute" positioning and will use the video reset detour when base resolution is set
  • Scene collection with version 2, resolution, and migration resolution set
    • Will use "relative" positioning and will allow resetting base resolution when output resolution is changed
  • Scene collection with version 2, but no resolution and migration resolution set
    • Will use "relative" positioning, menu item to set or reset base resolution is never available

Call To Action

I'd appreciate if a Windows-based maintainer could check:

  • Whether all the above still works correctly on Windows
  • Particularly if all the file paths are still correctly converted to/from Windows' wchar_t

Types of changes

  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Comment thread frontend/models/Rect.cpp Resolved
Comment thread frontend/OBSStudioAPI.cpp Resolved
@RytoEX
RytoEX requested review from Warchamp7 and derrod February 7, 2025 20:24
@Warchamp7 Warchamp7 self-assigned this Feb 10, 2025
@WizardCM WizardCM added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. kind/cleanup Non-breaking change which makes code smaller or more readable labels Feb 12, 2025

@RytoEX RytoEX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits/Questions. Will wait on testing, or will test if I can make time.

@RytoEX

RytoEX commented Mar 11, 2025

Copy link
Copy Markdown
Member

From a visual review, this looks okay. Would appreciate a second glance or testing from others.

@RytoEX RytoEX self-assigned this Mar 13, 2025
@RytoEX

RytoEX commented Apr 16, 2025 •

Copy link
Copy Markdown
Member

Are either of these scenarios covered?

  1. scene collection is version 1, has no resolution or migration_resolution
  2. scene collection is version 2, has resolution, but has no migration_resolution

@PatTheMav

Copy link
Copy Markdown
Member Author

Are either of these scenarios covered?

  1. scene collection is version 1, has no resolution or migration_resolution
  2. scene collection is version 2, has resolution, but has no migration_resolution

In scenario 1 nothing happens - the scene collection is loaded as-is and the app will use "absolute positioning" and the migration menu item should become enabled. Migration resolution is ignored for scene collections that are not of the v2 variant, it is expected not to be "there".

In scenario 2 nothing happens as well - a v2 variant without a migration_resolution is effectively a "native" relative variant.

The "rules" as they appeared to me from the original implementation were:

  • A resolution is only saved if a lastOutputResolution is set when the collection is saved
    • lastOutputResolution is only set if the "Set/Reset base resolution" menu item was used OR if a scene collection with resolution data is loaded
  • migration_resolution is only saved if the scene collection has already been loaded with a resolution set and thus was migrated, which will set the migration resolution
  • To remigrate an already migrated resolution, the new output resolution needs to be stored as resolution and the collection needs to be downgraded to v1 again. The migration will then happen automatically when the collection is reloaded.
  • A migration is only available if the collection has no resolution set
  • A remigration is only available if the current output resolution is different from the migration resolution

@RytoEX

RytoEX commented Apr 16, 2025

Copy link
Copy Markdown
Member

In scenario 1 nothing happens - the scene collection is loaded as-is and the app will use "absolute positioning" and the migration menu item should become enabled. Migration resolution is ignored for scene collections that are not of the v2 variant, it is expected not to be "there".

In scenario 1, I am not getting the "Set/Reset Base Resolution" menu item enabled.

@RytoEX RytoEX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am on a 1080p Scene Collection and profile, and I switch to a 4K SC that is version 1, no resolution, no migration_resolution, then updateRemigrationMenuItem is called with 0x02 (Relative). So isAbsoluteCoordinateMode is false, and the menu item remains disabled. This differs from current behavior on master.

@RytoEX RytoEX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine with the latest pushes.

@RytoEX
RytoEX merged commit cce1890 into obsproject:master Apr 21, 2025
@PatTheMav
PatTheMav deleted the remigration-fix branch April 21, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Non-breaking change which makes code smaller or more readable kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants