Skip to content

Use deep copy for realtime effect states when cloning a ReatimeEffectList - #7873

Merged
embarc-gabriel merged 3 commits into
audacity:release-3.7.2from
embarc-gabriel:4169-use-deepcopies-when-cloning-realtime-effect-state
Jan 8, 2025
Merged

embarc-gabriel merged 3 commits into
audacity:release-3.7.2from
embarc-gabriel:4169-use-deepcopies-when-cloning-realtime-effect-state

Conversation

@embarc-gabriel

Copy link
Copy Markdown
Contributor

Resolves: #4169

By cloning a RealtimeEffectList a shallow copy of the effect state is created.
In the current implementation if the user copy and paste a track the effect list state for both tracks will point to the same memory location.

This PR modifies the code to use a deep copy instead.
We should also add the effect settings change to the history to avoid just losing the modification after undoing some other action.

  • I signed CLA
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

@embarc-gabriel
embarc-gabriel changed the base branch from release-3.7.1 to release-3.7.2 December 10, 2024 09:44
@embarc-gabriel embarc-gabriel self-assigned this Dec 10, 2024
Comment thread src/RealtimeEffectPanel.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we have to add the name of the track it belongs to. If we don't,

  1. I tweak my reverb effect on track 1,
  2. I tweak my compressor effect on track 2,
  3. I undo

would undo my tweaking of the reverb effect of track 1, too.
@LWinterberg please 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.

I mean, it should undo the last effect, shouldn't it? I don't understand why the name of the track matters here. Does the code as-is effect all instances of an effect? so if:

  1. I tweak the reverb on track 1
  2. I tweak the reverb on track 2
  3. I tweak a second reverb on track 2
  4. I undo

would all changes across all tracks and effects be undone?

@saintmatthieu saintmatthieu Dec 22, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes.
Why track name matters: this is what the history mechanism bases its logic to consolidate actions. If you change a reverb setting on track one and tell the history "Change reverb param", and then change a reverb setting on track 2 and tell the history "Change reverb param", it'll get consolidated.
So without the track name, it's as you described. With the track name:

  1. tweak effect on track 1: state is modified (meaning if I close the project, I'm asked if I want to save).
  2. tweak effect with same name on track 1 again: nothing new happens.
  3. tweak effect with same name on track 2: new history item is created.

which I think is better, but please confirm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another note: a new history item will only get added when I close an effect's UI. Testing this on @embarc-gabriel 's branch, not sure it's the same on master. Seems strange to me. Maybe we should polish this, too, before totally freezing audacity 3.

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.

sounds good to me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added the track name as well as discussed here. This totally make sense.
But I don´t know exactly what is the best place to add the item to the history.
IMO to apply it only when the UI is closed is fine but for sure I appreciate any feedback on this.
@LWinterberg @saintmatthieu

Comment thread src/RealtimeEffectPanel.cpp Resolved
@embarc-gabriel
embarc-gabriel force-pushed the 4169-use-deepcopies-when-cloning-realtime-effect-state branch from ddb9572 to be94bd5 Compare January 7, 2025 11:40
@embarc-gabriel
embarc-gabriel merged commit 1dadfd0 into audacity:release-3.7.2 Jan 8, 2025
@kryksyh kryksyh mentioned this pull request Aug 17, 2026
5 of 7 tasks
kryksyh added a commit that referenced this pull request Aug 18, 2026
Resolves: #10141
Resolves: #8686
Resolves: #11708
Resolves: #11712

Fixes:

- Crash when a realtime effect dialog saves settings on close. In some
situations (applying destructive effect, undo/redo, etc) the dialog
closes when the effect state is destroyed. Regression from #7873.
- Master effect settings were not restored with undo/redo, because
master effect state is a project-wide singleton, and the state saved in
the undo system is the same state being edited by the dialog.
- Memory corruption on closing AudioUnit dialog
 

<!-- Use "x" to fill the checkboxes below like [x] -->

- [x] I signed [CLA](https://www.audacityteam.org/cla/)
- [x] The title of the pull request describes an issue it addresses
- [x] If changes are extensive, then there is a sequence of easily
reviewable commits
- [x] Each commit's message describes its purpose and effects
- [x] There are no behavior changes unnecessary for the stated purpose
of the PR

Recommended:
- [ ] Each commit compiles and runs on my machine without known
undesirable changes of behavior

QA:

- [ ] Testflow test cases have been run
@embarc-gabriel
embarc-gabriel deleted the 4169-use-deepcopies-when-cloning-realtime-effect-state branch August 28, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The realtime effect settings of a duplicated track are not independent

3 participants