-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Don't copy DetuningHelper in Note copy constructor #7888
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
Conversation
|
I just realized I forgot about deleting the DetuningHelper and who owns the pointer, now that notes can be shallow-copied and detuning clips be shared. So, I decided to make the |
|
At the request of @Rossmaxx, I have removed |
|
Thanks for applying my suggestion. The code looks good. Not approving as I didn't test. I feel like you missed something while removing shared object usage. You need to delete the inheritance of |
That was already done for |
|
Didn't check the other PR. Now that you did, I checked it. Good job |
|
Why are you using shared pointers again rather than unique pointers? Would that reintroduce the bug where copying clips doesn't do a deep copy of per-note automations? |
|
Normally yes, but I have added a new Honestly I could have done it either way, either making the constructor by default do a deep copy while having another function do a shallow copy, or how I have it right now, where the constructor does a shallow copy, while the The main thing is that |
|
I really don't like the use of A refactor should probably try to remove the dynamic allocations altogether. |
|
Would it be better if |
Co-authored-by: Dalton Messmer <[email protected]>
I think it would be better as a data member of The exception is |
Maybe if we store it as a |
No that wouldn't work because |
|
Tested with the included project from #7884, works fine. Gonna keep it on loop for a while, but before the PR, it would crash at the EXACT same position, and it's been about 20 loops now. |
messmerd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested it, but it looks good to me code-wise. Further refactoring could be done in a later PR.
Co-authored-by: Dalton Messmer <[email protected]>
Reworks how note detuning copying works so as not to perform a clip duplication and allocation by default in the constructors --------- Co-authored-by: Dalton Messmer <[email protected]>
TLDR This PR reverts some changes in #7477 and reworks how note detuning copying works so as not to perform a clip duplication and allocation by default in the constructors.
In #7477, I reworked how
Notes are copied to make their detuning automation clip be deep-copied. This fixed some issues where copying a detuned note or splitting a clip with detuned notes would cause the notes to be linked to each other, where editing the detuning of one would edit the detuning of another.However, this meant that
Note's constructors now always performed an allocation and interacted withProjectJournal::allocID, as @PhysSong pointed out in #7884. Normally, this might be okay if it were only called for gui operations. However, it turns out that it's also called inNotePlayHandle's constructor, which is problematic, as that is (afaik?) on the audio thread.Ideally, we could maybe have two kinds of constructors, one which deep copies the automation clip, and one which just takes in the pointer. The former would be used for gui operations which need to actually make a new note, and the latter would be for temporary note copies which are not going to be modified, like in NotePlayHandle.
My current implementation simply makes
Note's constructors take in a pointer for theDetuningHelper, and they don't do any kind of deep copy. Then, I added aNote::clonefunction which, analogous toClip::clone, makes a full copy of the note and detuning. Then, I replaced all necessary occurrences ofNote(*note)which needed to make deep copies to usenote->clone()instead. This way the allocation only occurs when explicitly necessary.I'm not 100% satisfied with my implementation. The way there are two ways to copy a note seems odd, and I removed the
unique_ptrfunctionality, which might not be great. I would love to hear your opinions. But, I've tested it for about an hour on the project from #7884, and it hasn't crashed yet, so I think it works.