Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
ump_session.hpp
Go to the documentation of this file.
1#pragma once
2
3// UmpSession — Pulp's MIDI 2.0 UMP session handle.
4//
5// One `UmpSession` per app or plugin instance. On macOS it owns the
6// underlying `MIDIClientRef` (CoreMIDI 2.0). On platforms that don't yet
7// have a UMP backend the session degrades to virtual-endpoints-only, which
8// is enough for unit tests and for in-process loopback.
9//
10// Design notes:
11// - The session is the only entity that knows how to talk to the
12// OS MIDI subsystem; everything else hangs off it.
13// - Endpoint lifetime is tied to the session: dropping the session
14// drops every endpoint it minted.
15// - Discovery returns a snapshot. We deliberately don't expose a
16// push-style "endpoint added" stream from this surface — the
17// existing `MidiSystem::set_port_change_callback()` already
18// handles hotplug for the legacy MIDI 1.0 stream, and re-running
19// `enumerate()` is cheap.
20// - Virtual endpoints are returned as `std::shared_ptr` so a test can keep
21// a direct handle. The session holds its own `shared_ptr`s and closes /
22// drops them during teardown; a caller-retained handle keeps the endpoint
23// object alive after that.
24
27
28#include <memory>
29#include <string>
30#include <vector>
31
32namespace pulp::midi {
33
37 std::string name = "Pulp UMP Session";
41 bool enable_os_backend = true;
42};
43
53
55public:
59
60 UmpSession(const UmpSession&) = delete;
61 UmpSession& operator=(const UmpSession&) = delete;
62
65 bool os_backend_active() const noexcept;
66
71
76 UmpEndpoint* open_endpoint(const std::string& id,
77 UmpOpenStatus* status = nullptr);
78
85
88 bool unregister_virtual_endpoint(const std::string& id);
89
91 std::size_t virtual_endpoint_count() const;
92
97 bool wire_virtual_loopback(const std::string& from_id,
98 const std::string& to_id);
99
100private:
101 struct Impl;
102 std::unique_ptr<Impl> impl_;
103};
104
105} // namespace pulp::midi
Polymorphic endpoint handle.
Definition ump_endpoint.hpp:69
bool os_backend_active() const noexcept
Returns true if the OS-backed UMP backend is live (CoreMIDI client created etc).
UmpSession & operator=(const UmpSession &)=delete
std::vector< UmpEndpointInfo > enumerate_endpoints() const
Snapshot the OS endpoints known to the system, plus every virtual endpoint registered through this se...
UmpSession(const UmpSession &)=delete
std::size_t virtual_endpoint_count() const
Number of virtual endpoints currently registered.
UmpSession(UmpSessionConfig cfg)
bool unregister_virtual_endpoint(const std::string &id)
Drop a virtual endpoint.
UmpEndpoint * open_endpoint(const std::string &id, UmpOpenStatus *status=nullptr)
Open (or attach to) an endpoint by id.
std::shared_ptr< VirtualUmpEndpoint > register_virtual_endpoint(VirtualUmpEndpointConfig cfg)
Register a virtual endpoint with the session.
bool wire_virtual_loopback(const std::string &from_id, const std::string &to_id)
Connect two virtual endpoints in a loopback: every packet sent into from is delivered to to.
Definition ump_virtual_endpoint.hpp:57
Definition custom_node_events.hpp:26
UmpOpenStatus
Outcome of creating an endpoint connection through the session.
Definition ump_session.hpp:47
@ NotFound
Definition ump_session.hpp:49
@ OsError
Definition ump_session.hpp:51
@ Ok
Definition ump_session.hpp:48
@ OsBackendUnavailable
Definition ump_session.hpp:50
STL namespace.
Static description of an endpoint discovered on the system or registered virtually.
Definition ump_endpoint.hpp:47
Options for creating a session.
Definition ump_session.hpp:36
std::string name
Definition ump_session.hpp:37
bool enable_os_backend
If true, the session attempts to open the OS UMP backend (e.g.
Definition ump_session.hpp:41
Configuration for a newly-registered virtual endpoint.
Definition ump_virtual_endpoint.hpp:44