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

Refactor Elements #154

Merged
merged 75 commits into from
Nov 15, 2023
Merged

Refactor Elements #154

merged 75 commits into from
Nov 15, 2023

Conversation

danngreen
Copy link
Member

@danngreen danngreen commented Nov 9, 2023

This PR refactors the MetaModule::Elements variant, with a few benefits:

Previously, each widget type needed a corresponding variant alternative type in the ever-growing Elements std::variant type.
Now, the Element variant alternatives are reduced to a small set of general types (like Knob, Slider, DualLight). Each one is parameterized by non-static member vars (e.g. image, color). This makes it easier to add new types.

Other changes (besides refactoring Elements):

  • Switches and slide pots can have a bg image (body) and a fg image (handle), so the rendering is closer to VCV Rack
  • More Rack widget images are ported (all of them used in the current set of modules, I think)
  • The new features in fix-switches-gui that make manually controlling switches/buttons "more natural" are present in this branch too
  • VCV_Adaptor automatically extracts strings for switch positions from ported VCV modules, and displays them when you manually adjust a switch. This was convenient to do with the new Elements system.
  • Images can be accessed by filename strings, rather than needing a pointer to the LVGL image struct. A mock read-only filesystem (image_fs.hh) translates the filename to raw data. In the future, we may use a real filesystem, so this paves the way for that.

There's almost no changes needed to 4ms modules (one very subtle difference, I'll document).

Performance-wise, I've noticed no change. I expect it to change very little, since this almost exclusively effects the GUI thread (which is bottlenecked by hardware) and pre-main startup (when Rack modules are converted to MetaModule-native structures). The binary is ~64k smaller, also.

TODO:

  • Document widget porting in the Porting Guide readme.
  • Fix pixel alignment issue with sliders and switches
  • Allow SlideSwitches to select which direction corresponds to an increasing value
  • Move std::string_view image from the derived classes to BaseElement
  • Check for conflicts with other open PRs

-added to Elements variant
Use SlideSwitch for hetrickcv CKSSRot
Fix missing brackets in tests. Fix button ranges
@danngreen danngreen marked this pull request as ready for review November 14, 2023 21:41
@danngreen
Copy link
Member Author

I fixed the pixel alignment issue with sliders. The cause was that VCV_adaptor just used the xy position specified in the ModuleWidget constructor calls to createParam(). Some widgets change their xy position by adding a margin, but this was not being picked up by MetaModule.

I also tested merging all the open PRs together, and it's not going to be a problem to merge.

So I'm going ahead with this!

@danngreen danngreen merged commit 307610a into main Nov 15, 2023
4 checks passed
@danngreen danngreen deleted the refactor-elements branch November 15, 2023 18:07
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.

1 participant