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

Use layouts for the instrument sound shaping tab / Extract classes for Envelope and LFO graphs #7193

Conversation

michaelgregorius
Copy link
Contributor

@michaelgregorius michaelgregorius commented Apr 4, 2024

Layouts for instrument sound shaping

Use layouts to align the elements of the instrument sound shaping page and its children. Here's a comparison before/after:

InstrumentSoundShaping-01-Before-NoLayoutsInstrumentSoundShaping-02-After-WithLayouts

This can also be considered as further preparation for a later adjustment of the instrument window to make it more scalable and to give the elements more "breathing space" (see this comment). Most of the other tabs already use layouts.

New widgets to render the envelope and LFO graphs

This pull requests also extracts the rendering of the envelope and the LFO graphs into their own widget classes. This needed to be done to get rid of the individual mouse handling and painting code in EnvelopeAndLfoView. Both events only worked with hard-coded layouts which are removed by this PR.

This also prepares both graphs to be implemented in a scalable and potentially more interactive way, e.g. the envelope graph could be used to directly manipulate the AHDSR curve. For now both graphs are set to the fixed size of their background pixmap so that they have the exact same appearance as before.

Adjusted rendering of the LFO info text

As can be seen in the screenshot the rendering of the LFO's info text has also been improved. It now displays "2000 ms/LFO" instead of "ms/LFO: 2000". The text is now always rendered at 20% of the widget height in preparation to make the widget resizable.

TODOs (for later PRs)

  • Separate EnvelopeAndLfoParameters into two classes EnvelopeParameters and LfoParameters so that each graph will only operate on the data that's it concerned with.

Move the rendering of the envelope graph into it's own class.

This is a preparation step to use layouts in `EnvelopeAndLfoView`. It does not work with the mixed in painting in the paint event.
Move the LFO graph into its own class. This finally enables the removal of the mouse event and paint event code in `EnvelopeAndLfoView`.

Make the enum `LfoShape` in `EnvelopeAndLfoParameters` public so that it can be used without friend declarations. Add accessor methods for the model of the LFO.
Use layouts to align the elements of the `EnvelopeAndLfoView`. This removes lots of hard-coded values.

Add helper lambdas for the repeated creation of `Knob` and `PixmapButton` instances.

The spacing between the envelope and LFO should be removed once there is a more open layout.
Use layouts to align the elements of the `InstrumentSoundShapingView`.
Draw the info text at around 20% of the LFO graph's height. This prepares the dialog to be scaled later.

Write "1000 ms/LFO" instead of "ms/LFO: 1000" with a larger gap.
@Veratil
Copy link
Contributor

Veratil commented Apr 4, 2024

image
This looks like the knob row isn't aligned exactly to the top row. The right margin is like 10px where the left is 3px (not exact numbers just giving context).

@michaelgregorius
Copy link
Contributor Author

@Veratil, I think this is an optical illusion. If I remove three of the knobs you can see that the layout is centered by default:

InstrumentSoundShaping-CenteredLayout

So with six knobs it should also be centered.

Once the dialog is more scalable we should give the layouts more breathing space anyway and also consider to give a new layout to some of the elements, e.g. by putting all the DAHDSR knobs right under the envelope graph, making the envelope graph larger, etc. I am currently working on adjusting the rendering of the envelope graph so that it becomes scalable and is not tied to the size of the background pixmap anymore.

However, we have to get started somewhere and one of the first step is to use layouts wherever possible. So moving step by step into the right direction, improving things step by step even if they are not "perfect" yet. Once this is merged I would merge it into my feature branch with the instrument redesign (see here) and adjust the layouts accordingly.

Currently the TabWidget seems to impose this small crammed size on all its children. In my redesign branch I am using a QTabWidget which does not have these problems and which scales with the size of the child widgets.

@Veratil
Copy link
Contributor

Veratil commented Apr 4, 2024

image
No, it's not an optical illusion. The margins are definitely off a bit. Surprisingly I was at least right in the difference of 7 pixels though. 😁

However, we have to get started somewhere and one of the first step is to use layouts wherever possible. So moving step by step into the right direction, improving things step by step even if they are not "perfect" yet. Once this is merged I would merge it into my feature branch with the instrument redesign (see here) and adjust the layouts accordingly.

I can agree with this though. If possible to get a better alignment without much extra work, we should. Otherwise it can be left to a future PR.

@michaelgregorius
Copy link
Contributor Author

No, it's not an optical illusion. The margins are definitely off a bit. Surprisingly I was at least right in the difference of 7 pixels though. 😁

Looks like you've got a golden eye. 😄

However, we have to get started somewhere and one of the first step is to use layouts wherever possible. So moving step by step into the right direction, improving things step by step even if they are not "perfect" yet. Once this is merged I would merge it into my feature branch with the instrument redesign (see here) and adjust the layouts accordingly.

I can agree with this though. If possible to get a better alignment without much extra work, we should. Otherwise it can be left to a future PR.

It's very likely an effect of the TabWidget which does not resize and which compresses everything. If you look at the layouts I have added you will find that most of them should use the default margins. However, looking at the screenshots they are obviously not applied. The reason is that something is constraining the layout.

So, I'd like to keep this for a later PR when everything will be "decompressed" anyway. Otherwise we might be hunting ghost or artifacts of Qt's layout algorithm under size constraints. And it's not like the previous hard-coded layout was perfect anyway.

By the way, I also have the changes ready to make the envelope graph resizable so that it renders the graph correctly at different sizes. Shall I put it on top of this PR or shall we first merge the layout changes and then do the envelope graph changes?

@Veratil
Copy link
Contributor

Veratil commented Apr 4, 2024

By the way, I also have the changes ready to make the envelope graph resizable so that it renders the graph correctly at different sizes. Shall I put it on top of this PR or shall we first merge the layout changes and then do the envelope graph changes?

If this PR affects the rendering of the envelope then we should fix it in this PR, otherwise we can do it in a separate.

So, I'd like to keep this for a later PR when everything will be "decompressed" anyway. Otherwise we might be hunting ghost or artifacts of Qt's layout algorithm under size constraints. And it's not like the previous hard-coded layout was perfect anyway.

Sounds good, we don't need chase the margins at this time. 👍

@michaelgregorius
Copy link
Contributor Author

If this PR affects the rendering of the envelope then we should fix it in this PR, otherwise we can do it in a separate.

In the current state the rendering of the envelope is not changed. It's rendered as a separate widget but the widget has a fixed size and renders everything in fixed coordinates with regards to that size. So everything like before.

I will therefore create a separate PR for the dynamic rendering once this is merged.

Sounds good, we don't need chase the margins at this time. 👍

Ok, great. Do you want to do an "official" review or did you already check the code and it's good to go?

…apingWithLayout

Conflicts:
* src/gui/instrument/EnvelopeAndLfoView.cpp
* src/gui/instrument/InstrumentSoundShapingView.cpp
include/EnvelopeGraph.h Outdated Show resolved Hide resolved
include/LfoGraph.h Outdated Show resolved Hide resolved
src/gui/instrument/EnvelopeAndLfoView.cpp Outdated Show resolved Hide resolved
src/gui/instrument/EnvelopeAndLfoView.cpp Outdated Show resolved Hide resolved
src/gui/instrument/EnvelopeAndLfoView.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
Whitespace and formatting.
Copy link
Member

@messmerd messmerd left a comment

Choose a reason for hiding this comment

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

Mostly a style review.
I didn't run into any issues while testing.

include/EnvelopeGraph.h Outdated Show resolved Hide resolved
include/LfoGraph.h Outdated Show resolved Hide resolved
include/LfoGraph.h Outdated Show resolved Hide resolved
src/gui/instrument/EnvelopeGraph.cpp Show resolved Hide resolved
src/gui/instrument/EnvelopeGraph.cpp Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
include/EnvelopeGraph.h Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Outdated Show resolved Hide resolved
src/gui/instrument/LfoGraph.cpp Show resolved Hide resolved
* Remove some "pragma once" for now
* Adjust include orders
* Variable initialization in headers
* Prevention of most vexing parses
@michaelgregorius michaelgregorius merged commit d447cb0 into LMMS:master Apr 5, 2024
9 checks passed
@michaelgregorius michaelgregorius deleted the InstrumentSoundShapingWithLayout branch April 5, 2024 09:35
enp2s0 pushed a commit to enp2s0/lmms that referenced this pull request Apr 12, 2024
…r Envelope and LFO graphs (LMMS#7193)

Move the envelope and LFO graphs into their own classes.

Besides the improved code organization this step had to be done to be able to use layouts in `EnvelopeAndLfoView`. The class previously had fixed layouts mixed with custom rendering in the paint event. Mouse events are now also handled in both new classes instead of in `EnvelopeAndLfoView`.

## Layouts in EnvelopeAndLfoView
Use layouts to align the elements of the `EnvelopeAndLfoView`. This removes lots of hard-coded values. Add helper lambdas for the repeated creation of `Knob` and `PixmapButton` instances.

The spacing that is explicitly introduced between the envelope and LFO should be removed once there is a more open layout.

## Layouts for InstrumentSoundShapingView
Use layouts to align the elements of the `InstrumentSoundShapingView`.

## Info text improvements in LFO graph
Draw the info text at around 20% of the LFO graph's height. This prepares the dialog to be scaled later.

Write "1000 ms/LFO" instead of "ms/LFO: 1000" with a larger gap.

## Accessors for EnvelopeAndLfoParameters
Make the enum `LfoShape` in `EnvelopeAndLfoParameters` public so that it can be used without friend declarations. Add accessor methods for the model of the LFO.

## Other improvements
* Adjust include orders
* Variable initialization in headers
* Prevention of most vexing parses
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.

3 participants