Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
key_mapping_editor.hpp
Go to the documentation of this file.
1#pragma once
2
17
19#include <pulp/view/view.hpp>
20
21#include <functional>
22#include <string>
23
24namespace pulp::state { class PropertiesFile; }
25
26namespace pulp::view {
27
28class KeyMappingEditor : public View {
29public:
32 explicit KeyMappingEditor(CommandRegistry& registry);
33
39 std::string auto_save_path = {});
40
44 void set_persistence_prefix(std::string prefix);
45
46 // ── Selection / capture state ───────────────────────────────────
47
52
55
57 bool is_capturing() const { return capture_id_ != kInvalidCommandID; }
58
61 CommandID capturing_command() const { return capture_id_; }
62
65 void rebind(CommandID id, KeyCode key, std::uint16_t modifiers);
66
67 // ── Optional callbacks ──────────────────────────────────────────
68
70 std::function<void(CommandID, KeyCode, std::uint16_t)> on_rebound;
71
72 // ── View overrides ──────────────────────────────────────────────
73
74 void paint(canvas::Canvas& canvas) override;
75 void on_mouse_down(Point pos) override;
76 bool on_key_event(const KeyEvent& event) override;
77 bool accepts_text_input() const override { return is_capturing(); }
78 bool wants_mouse_input() const override { return true; }
79
81 float row_height() const { return row_height_; }
82 void set_row_height(float h) { row_height_ = h > 4.0f ? h : 4.0f; }
83
85 float intrinsic_height() const override;
86
87private:
88 void commit(CommandID id, KeyCode key, std::uint16_t modifiers);
89 int row_at(float y) const;
90
91 CommandRegistry& registry_;
92 pulp::state::PropertiesFile* props_ = nullptr;
93 std::string auto_save_path_;
94 std::string persistence_prefix_ = "shortcuts";
95
96 CommandID capture_id_ = kInvalidCommandID;
97 float row_height_ = 28.0f;
98};
99
103std::string format_chord(KeyCode key, std::uint16_t modifiers);
104
105} // namespace pulp::view
Definition canvas.hpp:240
JSON-backed persistent settings file.
Definition properties_file.hpp:16
Central command dispatcher.
Definition command_registry.hpp:207
std::function< void(CommandID, KeyCode, std::uint16_t)> on_rebound
Fires after a successful commit (capture or rebind).
Definition key_mapping_editor.hpp:70
void rebind(CommandID id, KeyCode key, std::uint16_t modifiers)
Force-rebind a command's chord, bypassing capture.
CommandID capturing_command() const
The command id currently being captured (kInvalidCommandID when not capturing).
Definition key_mapping_editor.hpp:61
bool on_key_event(const KeyEvent &event) override
Key event with modifiers and up/down state.
void paint(canvas::Canvas &canvas) override
float intrinsic_height() const override
Total intrinsic height = row_height * (1 + registered command count).
bool is_capturing() const
True when waiting for the user to press a chord.
Definition key_mapping_editor.hpp:57
void set_persistence_prefix(std::string prefix)
Optional: prefix to use inside the PropertiesFile (defaults to "shortcuts").
void cancel_capture()
Cancel any in-progress chord capture.
void begin_capture(CommandID id)
Select a row (by command id) and begin chord capture.
void set_row_height(float h)
Definition key_mapping_editor.hpp:82
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 key_mapping_editor.hpp:78
KeyMappingEditor(CommandRegistry &registry)
Construct an editor bound to a CommandRegistry.
bool accepts_text_input() const override
Does this widget consume printable character keys for text entry?
Definition key_mapping_editor.hpp:77
float row_height() const
Row height in points. Public for parent-shell layout math.
Definition key_mapping_editor.hpp:81
void set_persistence(pulp::state::PropertiesFile *props, std::string auto_save_path={})
Optional: a PropertiesFile to persist rebindings to.
void on_mouse_down(Point pos) override
CommandRegistry + CommandHandler + CommandInfo + ShortcutMap — Pulp-native command dispatch and keybo...
Definition affine_transform.hpp:24
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
std::string format_chord(KeyCode key, std::uint16_t modifiers)
Render a (key + modifiers) chord as a user-facing string, e.g.
uint32_t CommandID
A unique command identifier.
Definition app_framework.hpp:20
KeyCode
Definition input_events.hpp:35
@ h
Definition input_events.hpp:39
@ y
Definition input_events.hpp:42
constexpr CommandID kInvalidCommandID
Definition command_registry.hpp:76
Rich key event with key code, modifiers, and repeat state.
Definition input_events.hpp:193
Definition geometry.hpp:20