Skip to content
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

(Re)move identical calls to InstrumentTrack::processAudioBuffer #6867

Merged
merged 5 commits into from
Sep 21, 2023

Conversation

michaelgregorius
Copy link
Contributor

Remove identical calls to InstrumentTrack::processAudioBuffer which appear in the overridden implementations of Instrument::play and Instrument::playNotes. Instead the call to processAudioBuffer has been moved into InstrumentPlayHandle::play and InstrumentTrack::playNote. These two methods call the aforementioned methods of Instrument. Especially in the case of InstrumentTrack::playNote the previous implementation resulted in some unncessary "ping pong" where InstrumentTrack called a method on an Instrument which then in turn called a method on InstrumentTrack. And this was done in almost every instrument.

In InstrumentTrack::playNote an additional check was added which only calls processAudioBuffer if the buffer is not nullptr. The reason is that under certain circumstances PlayHandle::doProcessing calls the play method by explicitly passing a nullptr as the buffer. This behavior was added with commit 7bc97f5. Because it is unknown if this was done for some side effects the code was adjusted so that it behaves identical in this case.

Move the complex implementation for InstrumentPlayHandle::play and InstrumentPlayHandle::isFromTrack into the cpp file and optimize the includes.

Remove identical calls to `InstrumentTrack::processAudioBuffer` which appear in the overridden implementations of `Instrument::play` and `Instrument::playNotes`. Instead the call to `processAudioBuffer` has been moved into `InstrumentPlayHandle::play` and `InstrumentTrack::playNote`. These two methods call the aforementioned methods of `Instrument`. Especially in the case of `InstrumentTrack::playNote` the previous implementation resulted in some unncessary "ping pong" where `InstrumentTrack` called a method on an `Instrument` which then in turn called a method on `InstrumentTrack`. And this was done in almost every instrument.

In `InstrumentTrack::playNote` an additional check was added which only calls `processAudioBuffer` if the buffer is not `nullptr`. The reason is that under certain circumstances `PlayHandle::doProcessing` calls the `play` method by explicitly passing a `nullptr` as the buffer. This behavior was added with commit 7bc97f5. Because it is unknown if this was done for some side effects the code was adjusted so that it behaves identical in this case.

Move the complex implementation for `InstrumentPlayHandle::play` and `InstrumentPlayHandle::isFromTrack` into the cpp file and optimize the includes.
Remove the unused variable `frames` in `VestigeInstrument::play` to fix the stricter GitHub build.
include/InstrumentPlayHandle.h Outdated Show resolved Hide resolved
include/InstrumentPlayHandle.h Outdated Show resolved Hide resolved
src/tracks/InstrumentTrack.cpp Outdated Show resolved Hide resolved
src/core/InstrumentPlayHandle.cpp Outdated Show resolved Hide resolved
src/core/InstrumentPlayHandle.cpp Outdated Show resolved Hide resolved
src/core/InstrumentPlayHandle.cpp Outdated Show resolved Hide resolved
src/core/InstrumentPlayHandle.cpp Outdated Show resolved Hide resolved
src/core/InstrumentPlayHandle.cpp Outdated Show resolved Hide resolved
src/tracks/InstrumentTrack.cpp Outdated Show resolved Hide resolved
src/core/InstrumentPlayHandle.cpp Outdated Show resolved Hide resolved
@michaelgregorius
Copy link
Contributor Author

@LMMS/developers, can you please write some script that removes the unnecessary white spaces from the methods, etc.? It's a bit tiresome to discuss these in every pull request especially if the code was already there.

Remove whitespace in methods and add it to the parenthesis of some statements. Remove underscores from parameter names. Remove usage of `this` pointer.

Add `auto` keyword to shorten line length in `InstrumentPlayHandle::play`.

Move `const_cast` of `NotePlayHandle` closer to the `process` method as this method is the reason that the cast is needed in the first place. One might also add a version of `nphsOfInstrumentTrack` that returns a non-const result but it seems to be a general problem of a missing clear responsibility so I keep it as is.
Add some comments which describe why we need to guard agains nullptr.
Replace the check for a `nullptr` buffer with a check that checks if the NotePlayHandle uses a buffer. This is effectively the same condition that's used by `PlayHandle::doProcessing` to decide if it should call play with a `nullptr` in the first place. Hence it should be the most fitting check.
@michaelgregorius michaelgregorius merged commit 21fb430 into LMMS:master Sep 21, 2023
@michaelgregorius michaelgregorius deleted the RemoveIdenticalCalls branch September 21, 2023 18:12
@DomClark
Copy link
Member

can you please write some script that removes the unnecessary white spaces from the methods, etc.?

I believe our .clang-format file should take care of this. I'm not sure how easy it is to get it to format specific lines though, and formatting entire files makes reviewing really difficult. There may be some IDE support for it, but you'd have to do some research. (I know VS Code has a "format modified lines" option somewhere, but I've no idea whether it works with clang-format.)

I do agree though, that PR reviews asking for existing code to be reformatted (especially with the "request changes" option) can be tedious. I recall complaining about them too in the past. I imagine it's offputting to developers who want to contribute code to LMMS but find they're obligated to clean up somebody else's mess (and not even a mess necessarily - just outdated code style).

@sakertooth
Copy link
Contributor

can you please write some script that removes the unnecessary white spaces from the methods, etc.? It's a bit tiresome to discuss these in every pull request especially if the code was already there.

Since I have reason to believe you are using VSCode, you can use the Ctrl+K Ctrl+F keybind along with the Clang-Format extension to format specific selections of code at once that fits our style. That way, you don't have to make the changes one by one.

@michaelgregorius
Copy link
Contributor Author

I believe our .clang-format file should take care of this. I'm not sure how easy it is to get it to format specific lines though, and formatting entire files makes reviewing really difficult. There may be some IDE support for it, but you'd have to do some research. (I know VS Code has a "format modified lines" option somewhere, but I've no idea whether it works with clang-format.)

Ok, thanks! I will have to check. @sakertooth provided some good advice on how to integrate .clang-format with Visual Studio Code.

I do agree though, that PR reviews asking for existing code to be reformatted (especially with the "request changes" option) can be tedious. I recall complaining about them too in the past. I imagine it's offputting to developers who want to contribute code to LMMS but find they're obligated to clean up somebody else's mess (and not even a mess necessarily - just outdated code style).

Yes, exactly. It feels a bit like: "Oh, you provide us with some nice new feature into which you have invested lots of time? Please jump through these hoops so that it finally gets accepted and does not get to rot in the list of pull requests so that your time ultimately was wasted."

I also believe that clean and consistent code is important but it still makes me wonder sometimes what's more important to the project: features and bug fixes or the code formatting. And the fun thing is that the punctual fixes even make the code more inconsistent. However, I am also aware that fixing them all for good would lead to merge conflicts in almost all pull requests which would be even more offputting to the people who have provided them.

@curlymorphic
Copy link
Contributor

In my opinion code formatting, is an unrelated activity, to fixing any other bug or adding features, and should be treated as such and kept in a separate commit. Keeps the change logs easier to read, and when it comes to debugging in the future it's very hard to tell what was intended behavior changes, and what was just formatting.

If you do want to insist that any contributor that touches a file, reformats it, then maybe ask them to do so as a follow-up.

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.

4 participants