Base class for all MIDI endpoints. More...
Inherited by BMidiConsumer, and BMidiProducer.
Public Member Functions | |
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/. | |
Base class for all MIDI endpoints.
BMidiEndpoint is the abstract base class that represents either a producer or consumer endpoint. It may be used to obtain the state, name, properties, or system-wide ID of the object. BMidiEndpoint also provides the ability to change the name and properties of endpoints that were created locally.
Remember, you cannot call the destructor of BMidiEndpoint and its subclasses directly. Endpoint objects are destructed automatically when their reference count drops to zero. If necessary, the destructor of a local endpoint first breaks off any connections and Unregister()'s the endpoint before it is deleted. However, for good style and bonus points you should really Disconnect() and Unregister() the object yourself and not rely on the destructor to do this.
status_t BMidiEndpoint::Acquire | ( | ) |
Increments the endpoint's reference count.
Each BMidiEndpoint has a reference count associated with it, so that BMidiRoster can do proper bookkeeping. Acquire() increments this reference count, and Release() decrements it. Once the count reaches zero, the endpoint is deleted.
When you are done with the endpoint, whether local or remote, you should always Release() it!
Upon construction, local endpoints start with a reference count of 1. Any objects you obtain from BMidiRoster using the NextXXX() or FindXXX() functions have their reference counts incremented in the process. If you forget to call Release(), the objects won't be properly cleaned up and you'll make a fool out of yourself.
After you Release() an object, you are advised not to use it any further. If you do, your app will probably crash. That also happens if you Release() an object too many times.
Typically, you don't need to call Acquire(), unless you have two disparate parts of your application working with the same endpoint, and you don't want to have to keep track of who needs to Release() the endpoint. Now you simply have both of them release it.
Reads the properties of the endpoint.
Usage example:
Note that GetProperties() overwrites the contents of your BMessage.
int32 BMidiEndpoint::ID | ( | ) | const |
Returns the ID of the endpoint.
An ID uniquely identifies an endpoint in the system. The ID is a signed 32-bit number that is assigned by the Midi Server when the endpoint is created. (So even if a local endpoint is not published, it still has a unique ID.) Valid IDs range from 1 to 0x7FFFFFFF, the largest value an int32 can have. 0 and negative values are not valid IDs.
bool BMidiEndpoint::IsConsumer | ( | ) | const |
Determines whether this endpoint is a BMidiConsumer.
If it is, you can use a dynamic_cast to convert this object into a consumer:
bool BMidiEndpoint::IsLocal | ( | ) | const |
Determines whether this endpoint represents a local object.
An endpoint is "local" when it is created by this application; in other words, a BMidiLocalConsumer or BMidiLocalProducer.
bool BMidiEndpoint::IsPersistent | ( | ) | const |
Not used.
The purpose of this function is unclear, and as a result it doesn't do anything in the Haiku Midi Kit implementation.
false
always. bool BMidiEndpoint::IsProducer | ( | ) | const |
Determines whether this endpoint is a BMidiProducer.
If it is, you can use a dynamic_cast to convert this object into a producer:
bool BMidiEndpoint::IsRemote | ( | ) | const |
Determines whether this endpoint is a proxy for a remote object.
An endpoint is "remote" when it is created by another application. Obviously, the remote object is Register()'ed as well, otherwise you would not be able to see it.
bool BMidiEndpoint::IsValid | ( | ) | const |
Determines whether the endpoint still exists.
Suppose you obtained a proxy object for a remote endpoint by querying the BMidiRoster. What if the application that published this endpoint quits, or less drastically, Unregister()'s that endpoint? Even though you still have a BMidiEndpoint proxy object, the real endpoint no longer exists. You can use IsValid() to check for this.
Don't worry, operations on invalid objects, such as GetProperties(), will return an error code (typically B_ERROR), but not cause a crash. Local objects are always are considered to be valid, even if you did not Register() them. (The only time a local endpoint is not valid is when there was a problem constructing it.)
If the application that created the remote endpoint crashes, then there is no guarantee that the Midi Server immediately recognizes this. In that case, IsValid() may still return true. Eventually, the stale endpoint will be removed from the roster, though. From then on, IsValid() correctly returns false
.
const char * BMidiEndpoint::Name | ( | ) | const |
status_t BMidiEndpoint::Register | ( | ) |
Publishes the endpoint on the roster.
MIDI objects created by an application are invisible to other applications until they are published. To publish an object use the Register() method. The corresponding Unregister() method will cause an object to once again become invisible to remote applications.
BMidiRoster also has Register() and Unregister() methods. You may also use those methods to publish or hide your endpoints; both do the same thing.
Although it is considered bad style, calling Register() on local endpoints that are already registered won't mess things up. The Midi Server will simply ignore your request. Likewise for Unregister()'ing more than once. Attempts to Register() or Unregister() remote endpoints will fail, of course.
If you are watching , you will not receive notifications for any local endpoints you register or unregister. Of course, other applications will be notified about your endpoints.
Existing connections will not be broken when an object is unregistered, but future remote connections will be denied. When objects are destroyed, they automatically become unregistered.
B_ERROR
) if something went wrong.status_t BMidiEndpoint::Release | ( | ) |
void BMidiEndpoint::SetName | ( | const char * | name | ) |
Changes the name of the endpoint.
Names don't have to be unique, but it is recommended that you give any endpoints you publish meaningful and unique names, so users can easily recognize what each endpoint does. There is no limit to the size of endpoint names.
Even though you can call this function on both remote and local objects, you are only allowed to change the names of local endpoints; SetName() calls on remote endpoints are ignored.
name | The new name. If you pass NULL the name won't be changed. |
Changes the properties of the endpoint.
Endpoints can have properties, which is any kind of information that might be useful to associate with a MIDI object. The properties are stored in a BMessage.
Usage example:
You are only allowed to call SetProperties() on a local object.
Properties should follow a protocol, so different applications will know how to read each other's properties. The current protocol is very limited – it only allows you to associate icons with your endpoints. Be planned to publish a more complete protocol that included additional information, such as vendor/model names, copyright/version info, category, etc., but they never got around to it.
property | Vector icon (raw data) |
field name | "icon" |
field type | 'VICN' |
This vector icon is available under Haiku only, and comes as raw data, not a BBitmap. Before being able to display it, you first must render the vector icon in the size of your choice.
property | Large (32x32) icon |
field name | "be:large_icon" |
field type | 'ICON' |
property | Small (16x16) icon |
field name | "be:mini_icon" |
field type | 'MICN' |
The MidiUtil package (downloadable from the OpenBeOS website) contains a number of convenient functions to associate icons with endpoints, so you don't have to write that code all over again.
status_t BMidiEndpoint::Unregister | ( | ) |
Hides the endpoint from the roster/.