Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
command_registry.hpp File Reference

CommandRegistry + CommandHandler + CommandInfo + ShortcutMap — Pulp-native command dispatch and keyboard-shortcut routing. More...

#include <pulp/view/input_events.hpp>
#include <cstdint>
#include <functional>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

Go to the source code of this file.

Classes

struct  pulp::view::CommandInfo
 Metadata for one command. More...
class  pulp::view::CommandHandler
 Interface implemented by any object that can perform commands. More...
class  pulp::view::ShortcutMap
 (KeyCode, modifiers) → CommandID lookup table. More...
struct  pulp::view::ShortcutMap::Chord
 All chords currently bound to the given command. More...
class  pulp::view::CommandRegistry
 Central command dispatcher. More...

Namespaces

namespace  pulp
namespace  pulp::state
 SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the bulk, observable state a step sequencer / mod-matrix / pattern engine holds outside its automatable parameter set (e.g.
namespace  pulp::view
 Hover-cursor tracking for platform window hosts.

Functions

CommandInfo pulp::view::make_open_settings_command_info ()
 CommandInfo for kCommandOpenSettings with the platform-standard chord as its default binding.
void pulp::view::route_global_keys (View &root, CommandRegistry &registry)
 Install registry as the root view's single global-key dispatcher: assigns root.on_global_key to forward every key event into registry.dispatch_key_event().

Variables

constexpr CommandID pulp::view::kInvalidCommandID = 0
constexpr KeyCode pulp::view::kKeyComma = static_cast<KeyCode>(',')
 ASCII comma as a KeyCode.
constexpr CommandID pulp::view::kCommandOpenSettings = 0x504C5354
 Framework-reserved CommandID for "open the app's settings / preferences" (ASCII 'PLST').
constexpr std::uint16_t pulp::view::kOpenSettingsModifiers = kModCmd
 The platform-standard open-settings chord: Cmd+, on macOS, Ctrl+, elsewhere.

Detailed Description

CommandRegistry + CommandHandler + CommandInfo + ShortcutMap — Pulp-native command dispatch and keyboard-shortcut routing.

The primitives are named for Pulp's command model rather than mirroring any reference framework's class names. The behavior contract is "a key event finds the topmost focused handler that claims a command and dispatches to it".

Architecture

  • CommandID — opaque 32-bit ID. Apps define their own constants.
  • CommandInfo — metadata for one command (display name, category, default shortcut, enabled state). Used by the KeyMappingEditor.
  • CommandHandler — interface implemented by any object that knows how to perform commands. Typically a View subclass, but doesn't have to be — anything with command knowledge can register. The handler reports which commands it can perform and runs them on demand.
  • CommandRegistry — central per-app dispatcher. Owns:
    • the set of known CommandInfo records;
    • the chain of registered CommandHandler pointers (front of the chain = highest priority);
    • the ShortcutMap (key + modifier → command id). dispatch(id) walks the handler chain top-to-bottom and invokes the first handler that claims the command.
  • ShortcutMap — pure data: associates a (KeyCode, modifiers) pair with a CommandID. The registry uses it for routing; the editor UI uses it for rebinding. Persists via pulp::state::PropertiesFile.

Routing through the existing focus chain

The registry exposes dispatch_key_event(const KeyEvent&) which:

  1. Looks up the (key, modifiers) tuple in the ShortcutMap.
  2. If no command matches, returns false (host can fall through to its existing per-View on_key_event delivery).
  3. If a command matches, walks the registered handler chain and invokes the first one that claims the command. Returns true iff a handler ran.

The contract intentionally lets the host integrate two ways: (a) call dispatch_key_event BEFORE the normal on_key_event delivery — global shortcuts win; (b) call it AFTER — focused widget wins, with the registry as a fall-through after focused-widget handling.

Persistence

ShortcutMap::save_to(PropertiesFile&) and load_from(PropertiesFile&) round-trip the user's rebindings through Pulp's pulp::state::ApplicationProperties (user settings file). The editor UI calls save() on every commit so changes survive a restart.