Loading...
Searching...
No Matches
juce::universal_midi_packets::Input Class Reference

Detailed Description

An input (from the JUCE project's perspective) that receives messages sent by an endpoint.

An Input is conceptually similar to a unique_ptr, in that it's a nullable move-only type. You can check the null state of an instance by calling isAlive(). isAlive() will return true for an Input that's currently connected, or false otherwise. In particular, isAlive() will return false for a default-constructed Input. If isAlive() returns false, you should avoid calling other member functions: although this won't result in undefined behaviour, none of the functions will produce useful results in this state.

In the case that the device connected to the Input becomes unavailable (e.g. it is unplugged or the bluetooth connection is dropped), the Input will null itself, and calls to isAlive() will return false. You can register a callback to handle this event by calling addDisconnectionListener().

A particular pitfall to watch out for is calling addConsumer(), removeConsumer(), addDisconnectionListener(), and removeDisconnectionListener() on a default-constructed Input or other Input for which isAlive() returns false. This will have no effect. Instead, if you want to attach listeners to an Input, you should use Session::connectInput() to create an Input, and ensure that isAlive() returns true on that Input before attaching listeners.


The documentation for this class was generated from the following file:

Public Member Functions

 Input ()
 Creates a disconnected input.
 ~Input ()
 Destructor.
 Input (Input &&) noexcept
Inputoperator= (Input &&) noexcept
 Input (const Input &)=delete
Inputoperator= (const Input &)=delete
EndpointId getEndpointId () const
 Returns this connection's endpoint.
PacketProtocol getProtocol () const
 Returns the protocol that was requested when creating this connection.
void addConsumer (Consumer &r)
 Attaches a receiver that will receive MIDI messages from this input.
void removeConsumer (Consumer &r)
 Detaches the receiver so that it will no longer receive MIDI messages from this Input.
void addDisconnectionListener (DisconnectionListener &r)
 Attaches a listener that will be notified when this endpoint is disconnected.
void removeDisconnectionListener (DisconnectionListener &r)
 Removes a disconnection listener.
bool isAlive () const
 True if this connection is currently active.
 operator bool () const

Constructors and Destructors

◆ Input() [1/3]

juce::universal_midi_packets::Input::Input ( )

Creates a disconnected input.

A default-constructed input will never receive any messages.

Instances should only be created on the main thread.

Referenced by Input(), Input(), operator=(), and operator=().

◆ ~Input()

juce::universal_midi_packets::Input::~Input ( )

Destructor.

Instances should only be destroyed on the main thread in order to avoid potential races with disconnection callbacks, which also happen on the main thread.

◆ Input() [2/3]

juce::universal_midi_packets::Input::Input ( Input && )
noexcept

References Input().

◆ Input() [3/3]

juce::universal_midi_packets::Input::Input ( const Input & )
delete

References Input().

Member Functions

◆ operator=() [1/2]

Input & juce::universal_midi_packets::Input::operator= ( Input && )
noexcept

References Input().

◆ operator=() [2/2]

Input & juce::universal_midi_packets::Input::operator= ( const Input & )
delete

References Input().

◆ getEndpointId()

EndpointId juce::universal_midi_packets::Input::getEndpointId ( ) const

Returns this connection's endpoint.

References getEndpointId().

Referenced by getEndpointId().

◆ getProtocol()

PacketProtocol juce::universal_midi_packets::Input::getProtocol ( ) const

Returns the protocol that was requested when creating this connection.

References getProtocol().

Referenced by getProtocol().

◆ addConsumer()

void juce::universal_midi_packets::Input::addConsumer ( Consumer & r)

Attaches a receiver that will receive MIDI messages from this input.

Incoming messages will be converted to the protocol that was requested when opening the Input.

If isAlive() returns false at the point where this function is called, this function will have no effect. This can commonly happen when attempting to add listeners to a default-constructed Input, or if the input device got disconnected.

It is an error to add or remove a consumer from within the consumer callback. This will cause deadlocks, so be careful!

You should only add and remove consumers from the main thread.

Calls to Consumer::consume() will happen on a separate thread, often with high or even realtime priority.

References addConsumer().

Referenced by addConsumer().

◆ removeConsumer()

void juce::universal_midi_packets::Input::removeConsumer ( Consumer & r)

Detaches the receiver so that it will no longer receive MIDI messages from this Input.

It is an error to add or remove a consumer from within the consumer callback. This will cause deadlocks, so be careful!

See also
addConsumer()

References removeConsumer().

Referenced by removeConsumer().

◆ addDisconnectionListener()

void juce::universal_midi_packets::Input::addDisconnectionListener ( DisconnectionListener & r)

Attaches a listener that will be notified when this endpoint is disconnected.

Disconnection notifications will be sent on the main thread, and listeners should only be added or removed on the main thread in order to avoid potential data races.

Calling this function on an instance for which isAlive() returns false has no effect.

References addDisconnectionListener().

Referenced by addDisconnectionListener().

◆ removeDisconnectionListener()

void juce::universal_midi_packets::Input::removeDisconnectionListener ( DisconnectionListener & r)

Removes a disconnection listener.

See also
addDisconnectionListener()

References removeDisconnectionListener().

Referenced by removeDisconnectionListener().

◆ isAlive()

bool juce::universal_midi_packets::Input::isAlive ( ) const

True if this connection is currently active.

This function returns false for a default-constructed instance.

References isAlive().

Referenced by isAlive(), and operator bool().

◆ operator bool()

juce::universal_midi_packets::Input::operator bool ( ) const
inlineexplicit

References isAlive().

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram