Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
osc_channel.hpp
Go to the documentation of this file.
1#pragma once
2
3// OscChannel — adapts pulp::osc Sender/Receiver to the runtime
4// MessageChannel contract.
5//
6// Each incoming UDP packet is delivered as a `Message{Binary, bytes}`.
7// The bytes are the raw OSC-encoded packet; callers can decode with
8// `pulp::osc::decode()` if they want the structured form. Outgoing
9// messages are treated the same way — `send(bytes)` transmits the
10// bytes verbatim, or the overload `send(const osc::Message&)` encodes
11// first.
12//
13// This wrapper is not a replacement for `osc::Sender` / `osc::Receiver`
14// — it lets higher-level code (JSON-RPC transport, remote-control,
15// MCP bridges) treat OSC as "just another MessageChannel" so a single
16// consumer can swap transports without branching.
17
18#include <pulp/osc/osc.hpp>
20
21#include <atomic>
22#include <cstdint>
23#include <memory>
24#include <mutex>
25#include <string>
26#include <string_view>
27
28namespace pulp::osc {
29
38
39class OscChannel : public pulp::runtime::MessageChannel {
40public:
44 static std::unique_ptr<OscChannel> open(
45 std::string_view host, std::uint16_t remote_port,
46 std::uint16_t local_port,
47 OscChannelOptions options = {});
48
49 ~OscChannel() override;
50
51 // MessageChannel
52 bool send(const std::uint8_t* data, std::size_t size) override;
56 void close() override;
57 bool is_open() const override { return open_.load(); }
58
60 bool send(const Message& msg);
61
63 std::string local_address() const {
64 return receiver_.local_address();
65 }
66 std::uint16_t local_port() const {
67 return receiver_.local_port();
68 }
69
70private:
72
73 void dispatch_message(const Message& msg);
74 void dispatch(std::function<void()> fn);
75
76 OscChannelOptions options_;
77 Sender sender_;
78 Receiver receiver_;
79 std::atomic<bool> open_{false};
80 std::atomic<bool> closed_fired_{false};
81
82 std::mutex mutex_;
86};
87
88} // namespace pulp::osc
Definition osc_channel.hpp:39
void on_error(pulp::runtime::ChannelErrorCallback callback) override
bool is_open() const override
Whether the channel is currently usable.
Definition osc_channel.hpp:57
void on_closed(pulp::runtime::ChannelClosedCallback callback) override
void close() override
Close the channel. Idempotent. Fires the closed callback.
std::uint16_t local_port() const
Definition osc_channel.hpp:66
bool send(const std::uint8_t *data, std::size_t size) override
Send a message.
void on_message(pulp::runtime::MessageCallback callback) override
Install / replace callbacks.
static std::unique_ptr< OscChannel > open(std::string_view host, std::uint16_t remote_port, std::uint16_t local_port, OscChannelOptions options={})
Construct a bidirectional channel: sender targets (host, remote_port) and the receiver listens on loc...
bool send(const Message &msg)
Convenience — encode and send a structured OSC message.
std::string local_address() const
Address and port the receiving side is bound to; empty / 0 when closed.
Definition osc_channel.hpp:63
Definition osc.hpp:131
Definition osc.hpp:74
Abstract base for message-oriented channels.
Definition message_channel.hpp:70
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
Definition bundle.hpp:13
constexpr std::string_view kBindLoopback
Definition osc.hpp:118
std::function< void()> ChannelClosedCallback
Called once when the channel transitions to a closed state — either the peer closed,...
Definition message_channel.hpp:55
std::function< void(const Message &message)> MessageCallback
Called when the channel receives a complete message.
Definition message_channel.hpp:51
std::function< void(std::string_view reason)> ChannelErrorCallback
Called when a transport-level error occurs.
Definition message_channel.hpp:60
std::function< void(std::function< void()>)> MessageExecutor
Executor used to dispatch callbacks off whichever worker thread the channel runs internally.
Definition message_channel.hpp:64
Definition osc.hpp:39
Definition osc_channel.hpp:30
pulp::runtime::MessageExecutor executor
Dispatch executor (same semantics as other channels).
Definition osc_channel.hpp:33
std::string bind_address
IPv4 literal the receiving side binds.
Definition osc_channel.hpp:36