Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
modulation_matrix_widget.hpp
Go to the documentation of this file.
1#pragma once
2
3// Modulation-matrix canvas widget.
4//
5// Thin View that visualises a ModulationMatrix: draws source nodes on
6// the left, destinations on the right, and one line per route with a
7// thickness/color proportional to depth. Clicking a source then a
8// destination adds a route. Clicking an existing route's line removes
9// it.
10//
11// The widget owns visualisation + hit-testing. It adds routes at
12// depth = 1.0 by default; selected route depth and curve are mutable
13// through the public setters so plugins can wire their own external
14// controls.
15
17#include <pulp/view/view.hpp>
18
19#include <string>
20#include <vector>
21
22namespace pulp::view {
23
25public:
29 struct Endpoint {
30 std::string label;
31 uint32_t id = 0;
32 };
33
35 void set_sources(std::vector<Endpoint> sources) { sources_ = std::move(sources); invalidate_layout(); }
36 void set_destinations(std::vector<Endpoint> dests) { destinations_ = std::move(dests); invalidate_layout(); }
37
38 ModulationMatrix* matrix() const { return matrix_; }
39 const std::vector<Endpoint>& sources() const { return sources_; }
40 const std::vector<Endpoint>& destinations() const { return destinations_; }
41
44 int pending_source() const { return pending_source_; }
45
49 int selected_route() const { return selected_route_; }
50
52 void set_selected_route(int idx) { selected_route_ = idx; }
53
57 float set_selected_route_depth(float depth);
58
61
65
66 void paint(canvas::Canvas& canvas) override;
67 void on_mouse_down(Point pos) override;
68 void on_mouse_cancel(Point pos) override { (void)pos; pending_source_ = -1; }
69 bool wants_mouse_input() const override { return true; }
70
71private:
72 ModulationMatrix* matrix_ = nullptr;
73 std::vector<Endpoint> sources_;
74 std::vector<Endpoint> destinations_;
75 int pending_source_ = -1;
76 int selected_route_ = -1;
77
78 // Layout helpers
79 float row_height_() const;
80 float source_column_x_() const;
81 float dest_column_x_() const;
82
85 int route_at_(Point pos) const;
86};
87
88} // namespace pulp::view
Definition canvas.hpp:240
Definition modulation_matrix_widget.hpp:24
ModulationMatrix * matrix() const
Definition modulation_matrix_widget.hpp:38
void set_sources(std::vector< Endpoint > sources)
Definition modulation_matrix_widget.hpp:35
void set_selected_route_curve(ModCurve curve)
Mutate the curve of the selected route. No-op if no route is selected.
void on_mouse_down(Point pos) override
void set_destinations(std::vector< Endpoint > dests)
Definition modulation_matrix_widget.hpp:36
void set_selected_route(int idx)
Set the selected route by index (into matrix_->routes()). -1 clears.
Definition modulation_matrix_widget.hpp:52
const std::vector< Endpoint > & sources() const
Definition modulation_matrix_widget.hpp:39
int selected_route() const
Currently-selected route index (the route the user is editing).
Definition modulation_matrix_widget.hpp:49
void on_mouse_cancel(Point pos) override
Pointer / touch cancellation (iOS touchesCancelled, etc.).
Definition modulation_matrix_widget.hpp:68
int pending_source() const
Currently-selected source (for the click-source-then-destination gesture).
Definition modulation_matrix_widget.hpp:44
void paint(canvas::Canvas &canvas) override
bool wants_mouse_input() const override
True if this widget handles mouse down/drag through virtual methods even when it does not expose JS p...
Definition modulation_matrix_widget.hpp:69
void set_matrix(ModulationMatrix *matrix)
Definition modulation_matrix_widget.hpp:34
const std::vector< Endpoint > & destinations() const
Definition modulation_matrix_widget.hpp:40
float set_selected_route_depth(float depth)
Mutate the depth of the selected route.
void remove_selected_route()
Remove the selected route.
Definition modulation_matrix.hpp:49
void invalidate_layout()
Mark layout as needing recalculation (auto-invalidation).
Definition view.hpp:898
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
ModCurve
Definition modulation_matrix.hpp:25
Populate the source + destination labels.
Definition modulation_matrix_widget.hpp:29
std::string label
Definition modulation_matrix_widget.hpp:30
Definition geometry.hpp:20