Skip to content

UI: Can copy-paste filters to multiple sources#4334

Closed
bershanskiy wants to merge 1 commit into
obsproject:masterfrom
bershanskiy:4290
Closed

UI: Can copy-paste filters to multiple sources#4334
bershanskiy wants to merge 1 commit into
obsproject:masterfrom
bershanskiy:4290

Conversation

@bershanskiy

@bershanskiy bershanskiy commented Mar 11, 2021

Copy link
Copy Markdown
Contributor

Description

Fix #4290.
Add support for pasting copied filters to multiple selected sources, instead of only one which was selected first. Instead of calling GetCurrentSceneItem() which returns the index of the first selected source from the array returned by ui->sources->selectionModel()->selectedIndexes(), call ui->sources->selectionModel()->selectedIndexes() directly and iterate over all selected sources.

Adds confirmation prompt if filter is pasted to more than 4 sources:
image

Motivation and Context

Reporter of the original bug #4290, @AskMP, works with large numbers of sources. In one comment he mentioned having to copy-paste filters to 48 sources by hand.

How Has This Been Tested?

I a bunch of tests, here are a few:

  • Created many sources (images)
  • Added a filter to one source which is very obvious
  • Copied filter from source A, selected one other source B and pasted the filter to it (supported prior to the change)
  • Copied filter from source A and pasted it to the same source A, checked that filter was not duplicated (supported prior to the change)
  • Copied filter from source A, selected multiple other sources B,C,D and pasted the filter to them, checked that each got the filter
  • Copied filter from source A, selected multiple other sources, deselected some of them, pasted the filter, checked that deselected sources did not get the filter

Test env:
OS: Windows 10 Home 20H2
CPU: Intel(R) Core(TM) i7-10875H
GPU: Nvidia GeForce RTX 2060

It does not affect any other functions because I changed only OBSBasic::on_actionPasteFilters_triggered() (I considered making a helper function for getting all selected scene items analogous to GetCurrentSceneItem(), but did not find any other function that could benefit from this helper.

Types of changes

  • New feature (non-breaking change which adds functionality)

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.

@WizardCM WizardCM added the kind/bug Categorizes issue or PR as related to a bug. label Mar 11, 2021
@WizardCM

Copy link
Copy Markdown
Member

The code looks good, but I wonder if it'd be worth warning the user about what they're about to do, especially if they select more than 4 or 5 sources - especially as there currently isn't an Undo button.

Additionally, would it be worth making sure the source for the sceneitem is unique, so that the same filters aren't copied to the same source multiple times?

@RytoEX

RytoEX commented Mar 12, 2021

Copy link
Copy Markdown
Member

The code looks good, but I wonder if it'd be worth warning the user about what they're about to do, especially if they select more than 4 or 5 sources - especially as there currently isn't an Undo button.

Additionally, would it be worth making sure the source for the sceneitem is unique, so that the same filters aren't copied to the same source multiple times?

Is that not what this section does?
https://github.com/obsproject/obs-studio/pull/4334/files#diff-4c0a52244f264feca9c3031c90edcbbbd1087a3040c15f9df4ca9700c5154fa3R7883-R7884

@bershanskiy

Copy link
Copy Markdown
Contributor Author

The code looks good, but I wonder if it'd be worth warning the user about what they're about to do, especially if they select more than 4 or 5 sources - especially as there currently isn't an Undo button.
Additionally, would it be worth making sure the source for the sceneitem is unique, so that the same filters aren't copied to the same source multiple times?

Is that not what this section does?
https://github.com/obsproject/obs-studio/pull/4334/files#diff-4c0a52244f264feca9c3031c90edcbbbd1087a3040c15f9df4ca9700c5154fa3R7883-R7884

Not exactly. The check ensures that the filter is not pasted to the source it was copied from, but we also should ensure that if two "destination" scene items have the same source, we apply the filter only once. I'm writing the updated patch right now.

@RytoEX

RytoEX commented Mar 12, 2021

Copy link
Copy Markdown
Member

An OBS Source can be used to create more than one scene item ("Add Existing" or "Paste Reference"), so getting an OBS source from multiple scene items that use the same source should result in the same OBSSource. I've just tested the current code and I didn't end up with duplicate filters pasted onto another scene item that uses the same OBS Source. Unless I'm missing something?

@RytoEX

RytoEX commented Mar 12, 2021

Copy link
Copy Markdown
Member

It looks like remove_items in UI/window-basic-main.cpp has an implementation of getting selected items. It is only used as a callback for obs_scene_enum_items just below it in OBSBasic::on_actionRemoveSource_triggered() for removing multiple selected sources.

Should we rename it to something more appropriate and reuse that?

static bool remove_items(obs_scene_t *, obs_sceneitem_t *item, void *param)
{
vector<OBSSceneItem> &items =
*reinterpret_cast<vector<OBSSceneItem> *>(param);
if (obs_sceneitem_selected(item)) {
items.emplace_back(item);
} else if (obs_sceneitem_is_group(item)) {
obs_sceneitem_group_enum_items(item, remove_items, &items);
}
return true;
};

void OBSBasic::on_actionRemoveSource_triggered()
{
vector<OBSSceneItem> items;
obs_scene_enum_items(GetCurrentScene(), remove_items, &items);

@bershanskiy

Copy link
Copy Markdown
Contributor Author

I've just tested the current code and I didn't end up with duplicate filters pasted onto another scene item that uses the same OBS Source. Unless I'm missing something?

Yes, my initial approach duplicated the filter in the following situation:

  1. Create new empty scene
  2. Create two different sources A and B1
  3. Create a "reference" source B2 referring to B1
  4. Add a filter to A
  5. Copy filter from A
  6. Paste copied filter to B1 and B2 in one step
  7. Observe that B1 and B2 have two copies of the filter

@bershanskiy bershanskiy force-pushed the 4290 branch 2 times, most recently from 1ad30f2 to 64d2619 Compare March 12, 2021 22:38
@RytoEX

RytoEX commented Mar 12, 2021

Copy link
Copy Markdown
Member

I've just tested the current code and I didn't end up with duplicate filters pasted onto another scene item that uses the same OBS Source. Unless I'm missing something?

Yes, my initial approach duplicated the filter in the following situation:

1. Create new empty scene
2. Create two different sources A and B1
3. Create a "reference" source B2 referring to B1
4. Add a filter to A
5. Copy filter from A
6. Paste copied filter to B1 and B2 in one step
7. Observe that B1 and B2 have two copies of the filter

I see what you mean now, and I observe that behavior too. In that case, since there is a need for unique OBSSource items in the collection, using remove_items as I mentioned above would only work if you went to the trouble of converting it to a set or applying sort and unique.

@bershanskiy

Copy link
Copy Markdown
Contributor Author

I see what you mean now, and I observe that behavior too. In that case, since there is a need for unique OBSSource items in the collection, using remove_items as I mentioned above would only work if you went to the trouble of converting it to a set or applying sort and unique.

I recently pushed an updated commit which does two things:

  • it uses std::set<OBSSource> to de-duplicate sources
  • it adds a simple confirmation prompt

Comment thread UI/window-basic-main.cpp Outdated
Comment thread UI/window-basic-main.cpp Outdated
Comment thread UI/window-basic-main.cpp Outdated
@bershanskiy bershanskiy force-pushed the 4290 branch 2 times, most recently from 8bcb698 to 22e36be Compare March 12, 2021 23:37
Comment thread UI/data/locale/en-US.ini Outdated
@bershanskiy

Copy link
Copy Markdown
Contributor Author

May I do anything to advance this PR?

@bershanskiy bershanskiy marked this pull request as draft April 20, 2021 11:33
@bershanskiy

bershanskiy commented Apr 20, 2021

Copy link
Copy Markdown
Contributor Author

Converting this to draft because I think undo-redo system has a bug #4562 which affects this PR.

@WizardCM

Copy link
Copy Markdown
Member

As the linked issues are fixed, would you be able to rebase this PR, clang format it, and then verify if all concerns have been dealt with so that it can be undrafted? Thanks!

@bershanskiy bershanskiy marked this pull request as ready for review September 6, 2021 09:28
@bershanskiy

Copy link
Copy Markdown
Contributor Author

I rebased this PR and tested manually and it works as expected.

@bershanskiy

Copy link
Copy Markdown
Contributor Author

Should I do anything to advance this PR?

@WizardCM

Copy link
Copy Markdown
Member

Hi, there are merge conflicts. Once the conflicts are resolved, we will perform a final review and/or merge.

@PatTheMav

Copy link
Copy Markdown
Member

Closing as last call for rebasing this PR for proper review went unanswered for now over a year and a half.

Can be reopened if a rebase took place and code is ready to be reviewed.

@PatTheMav PatTheMav closed this Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pasting filters only applies to the last item selected.

4 participants