Skip to content

Grid Abstraction - Vector Graph#8221

Open
szeli1 wants to merge 30 commits intoLMMS:masterfrom
szeli1:feature_better_grid
Open

Grid Abstraction - Vector Graph#8221
szeli1 wants to merge 30 commits intoLMMS:masterfrom
szeli1:feature_better_grid

Conversation

@szeli1
Copy link
Contributor

@szeli1 szeli1 commented Jan 19, 2026

closes #7158
closes #4367

Grid Abstraction

This PR addresses a common pattern in lmms: grids. A grid is has regularly spaced horizontal and vertical lines forming squares where usually data is displayed. From this abstraction at least 2 widgets can benefit from: AutomationEditor and PianoRoll
GridModel:
GridModel is used to manage positions and movement on the grid. It is designed for storing below 10000 objects. For storage it uses 2 vectors, the storage structure is optimized for random access (logarithmic), adding or removing has polynomial complexity (not counting vector reallocation). GridModel can't store custom data on its own, so GridModelTyped pairs custom data to GridModel.
GridView: it draws a grid and implements selection (a functionality all grids should have).

Vector Graph

An example widget is implemented using the grid abstraction, the same widget #7158 and #4367 implements.
Comparing this vector graph to #7158:

Comparing this vector graph to #4367:

How to test:

  1. open lmms
  2. add the waveshaper effect to an instrument
  3. the new VectorGraph should be there
  4. place points with LMB
  5. remove points with RMB
  6. hold ctrl and LMB to select
  7. use keyboard shortcuts Key_Up, Key_Down, Key_Right, Key_Left to move selection with the keyboard.
  8. use keyboard shortcuts shift + Key_Up, Key_Down, Key_Right, Key_Left to select.
  9. use keyboard shortcuts ctrl + Key_Up, Key_Down, Key_Right, Key_Left to move selected points.
  10. use keyboard shortcuts ctrl + Key_C, Key_V, Key_X, Key_A to copy, paste, cut and select all
  11. use keyboard shortcut Key_Delete to delete
  12. use keyboard shortcut ctrl + Key_T (or mouse wheel) to change the line type of the selected points. The line types are "bezier", "attribute", "sine", "peak" and "steps".
  13. "attribute" type points are displayed smaller. Use these points to configure all other line types. "attribute" points should have not "attribute" points before and after.
  14. test saving and loading
VectorGraphB6

{
Q_OBJECT
public:
using signedSize = signed long long;
Copy link
Contributor

@Veratil Veratil Jan 19, 2026

Choose a reason for hiding this comment

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

From what I can find it looks like we can do something like this instead of creating our own type here:

#if defined(_MSC_VER)
#include <BaseTsd.h>
using ssize_t = SSIZE_T;
#endif

You can see all the types defined in this header here: https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is fine to use signed long long in the code. Maybe I will remove this line and replace every 2 references of signedSize with long long.

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't include a Win32 header.

I'd recommend using either std::int64_t or this:

using ssize_t = std::make_signed_t<std::size_t>;

Comment on lines +37 to +38
VectorGraphView::VectorGraphView(QWidget* parent, size_t cubeWidth, size_t cubeHeight)
: GridView{parent, new VectorGraphModel{10, 10, GRID_MAX_STEPS, GRID_MAX_STEPS, 200, nullptr, QString(), true}, cubeWidth, cubeHeight}
Copy link
Member

Choose a reason for hiding this comment

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

The view shouldn't own the model. A non-owning pointer to the model should be passed to the view in the view's constructor.

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