All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Public Member Functions | List of all members
BMidiProducer Class Reference

Streams MIDI events to connected consumers. More...

#include <MidiProducer.h>

Inherits BMidiEndpoint.

Inherited by BMidiLocalProducer.

Public Member Functions

status_t Connect (BMidiConsumer *cons)
 Connects a consumer to this producer.
 
BListConnections () const
 Returns a list with all connected consumers.
 
status_t Disconnect (BMidiConsumer *cons)
 Disconnects a consumer from this producer.
 
bool IsConnected (BMidiConsumer *cons) const
 Determines whether a consumer is connected to this producer.
 
- Public Member Functions inherited from BMidiEndpoint
status_t Acquire ()
 Increments the endpoint's reference count.
 
status_t GetProperties (BMessage *properties) const
 Reads the properties of the endpoint.
 
int32 ID () const
 Returns the ID of the endpoint.
 
bool IsConsumer () const
 Determines whether this endpoint is a BMidiConsumer.
 
bool IsLocal () const
 Determines whether this endpoint represents a local object.
 
bool IsPersistent () const
 Not used.
 
bool IsProducer () const
 Determines whether this endpoint is a BMidiProducer.
 
bool IsRemote () const
 Determines whether this endpoint is a proxy for a remote object.
 
bool IsValid () const
 Determines whether the endpoint still exists.
 
const char * Name () const
 Returns the name of the endpoint.
 
status_t Register ()
 Publishes the endpoint on the roster.
 
status_t Release ()
 Decrements the endpoint's reference count.
 
void SetName (const char *name)
 Changes the name of the endpoint.
 
status_t SetProperties (const BMessage *properties)
 Changes the properties of the endpoint.
 
status_t Unregister ()
 Hides the endpoint from the roster/.
 

Detailed Description

Streams MIDI events to connected consumers.

A producer is an object that generate a stream of MIDI events. Each producer has a list of BMidiConsumer objects to which it is connected, and may be asked to connect to or disconnect from a BMidiConsumer. A producer can spray its events to multiple consumers at the same time. A BMidiProducer either represents a local producer, i.e. a class extending from BMidiLocalProducer, or is a proxy for a remote object published by another app.

Member Function Documentation

◆ Connect()

status_t BMidiProducer::Connect ( BMidiConsumer cons)

Connects a consumer to this producer.

Establishes a connection between this producer and the specified consumer endpoint. From now on, any events that this producer sprays will be sent to that consumer. You may connect multiple consumers to a producer.

Returns
B_OK on success, or an error code when the connection could not be established. If the consumer is a proxy for a remote object and that object no longer exists, Connect() returns B_ERROR. It also returns B_ERROR if you try to connect the same producer and consumer more than once.
See also
Disconnect()

◆ Connections()

BList * BMidiProducer::Connections ( ) const

Returns a list with all connected consumers.

Returns a BList with pointers to BMidiEndpoint objects for all consumers that are connected to this producer. You can examine the contents of the list as follows:

BList* list = prod->Connections();
for (int32 t = 0; t < list->CountItems(); ++t)
{
BMidiEndpoint* endp = (BMidiEndpoint*) list->ItemAt(t);
...do stuff...
endp->Release(); // yes, here too!
}
delete list;
__haiku_int32 int32
4-bytes signed integer.
Definition: SupportDefs.h:24
An ordered container that is designed to hold generic void* objects.
Definition: List.h:12
void * ItemAt(int32 index) const
Return a pointer to the item at the given index.
int32 CountItems() const
Returns the number of items in the list.
Base class for all MIDI endpoints.
Definition: MidiEndpoint.h:17
status_t Release()
Decrements the endpoint's reference count.

Every time you call this function, a new BList is allocated. The caller (that is you) is responsible for freeing this list. The BMidiEndpoint objects in the list have their reference counts bumped, so you need to Release() them before you delete the list or they will go all leaky on you.

◆ Disconnect()

status_t BMidiProducer::Disconnect ( BMidiConsumer cons)

Disconnects a consumer from this producer.

Terminates the connection between this producer and the specified consumer endpoint. From now on, any events that this producer sprays no longer go to that consumer.

Returns
B_OK on success, or an error code if there was no connection to break
See also
Connect()

◆ IsConnected()

bool BMidiProducer::IsConnected ( BMidiConsumer cons) const

Determines whether a consumer is connected to this producer.

See also
Connect()
Disconnect()