4 \brief Defines the Baseclass of all MIDI consumers and producers.
11 \brief Base class for all MIDI endpoints.
13 BMidiEndpoint is the abstract base class that represents either a
14 producer or consumer endpoint. It may be used to obtain the state, name,
15 properties, or system-wide ID of the object. BMidiEndpoint also provides
16 the ability to change the name and properties of endpoints that were
19 Remember, you cannot call the destructor of BMidiEndpoint and its
20 subclasses directly. Endpoint objects are destructed automatically when
21 their reference count drops to zero. If necessary, the destructor of a
22 local endpoint first breaks off any connections and Unregister()'s the
23 endpoint before it is deleted. However, for good style and bonus points
24 you should really \link BMidiProducer::Disconnect() Disconnect() \endlink
25 and Unregister() the object yourself and not rely on the destructor to
30 \fn const char* BMidiEndpoint::Name() const
31 \brief Returns the name of the endpoint.
33 The function never returns NULL. If you created a local endpoint by
34 passing a \c NULL name into its constructor (or passing no name,
35 which is the same thing), then Name() will return an empty string,
42 \fn void BMidiEndpoint::SetName(const char* name)
43 \brief Changes the name of the endpoint.
45 Names don't have to be unique, but it is recommended that you give any
46 endpoints you publish meaningful and unique names, so users can easily
47 recognize what each endpoint does. There is no limit to the size of
50 Even though you can call this function on both remote and local objects,
51 you are only allowed to change the names of local endpoints; SetName()
52 calls on remote endpoints are ignored.
54 \param name The new name. If you pass \c NULL the name won't be changed.
60 \fn int32 BMidiEndpoint::ID() const
61 \brief Returns the ID of the endpoint
63 An ID uniquely identifies an endpoint in the system. The ID is a signed
64 32-bit number that is assigned by the Midi Server when the endpoint is
65 created. (So even if a local endpoint is not published, it still has a
66 unique ID.) Valid IDs range from 1 to 0x7FFFFFFF, the largest value an
67 int32 can have. 0 and negative values are <b>not</b> valid IDs.
72 \fn bool BMidiEndpoint::IsProducer() const
73 \brief Determines whether this endpoint is a BMidiProducer
75 If it is, you can use a dynamic_cast to convert this object into a
79 if (endp->IsProducer())
81 BMidiProducer* prod = dynamic_cast<BMidiProducer*>(endp);
92 \fn bool BMidiEndpoint::IsConsumer() const
93 \brief Determines whether this endpoint is a BMidiConsumer
95 If it is, you can use a dynamic_cast to convert this object into a consumer:
98 if (endp->IsConsumer())
100 BMidiConsumer* cons = dynamic_cast<BMidiConsumer*>(endp);
111 \fn bool BMidiEndpoint::IsRemote() const
112 \brief Determines whether this endpoint is a proxy for a remote object.
114 An endpoint is "remote" when it is created by another application.
115 Obviously, the remote object is Register()'ed as well, otherwise you would
116 not be able to see it.
121 \fn bool BMidiEndpoint::IsLocal() const
122 \brief Determines whether this endpoint represents a local object
124 An endpoint is "local" when it is created by this application; in other
125 words, a BMidiLocalConsumer or BMidiLocalProducer.
130 \fn bool BMidiEndpoint::IsPersistent() const
133 The purpose of this function is unclear, and as a result it doesn't do
134 anything in the Haiku Midi Kit implementation.
136 \return \c false always.
141 \fn bool BMidiEndpoint::IsValid() const
142 \brief Determines whether the endpoint still exists.
144 Suppose you obtained a proxy object for a remote endpoint by querying the
145 BMidiRoster. What if the application that published this endpoint quits,
146 or less drastically, Unregister()'s that endpoint? Even though you still
147 have a BMidiEndpoint proxy object, the real endpoint no longer exists.
148 You can use IsValid() to check for this.
150 Don't worry, operations on invalid objects, such as GetProperties(), will
151 return an error code (typically B_ERROR), but not cause a crash. Local
152 objects are always are considered to be valid, even if you did not
153 Register() them. (The only time a local endpoint is not valid is when there
154 was a problem constructing it.)
156 If the application that created the remote endpoint crashes, then there is
157 no guarantee that the Midi Server immediately recognizes this. In that
158 case, IsValid() may still return true. Eventually, the stale endpoint will
159 be removed from the roster, though. From then on, IsValid() correctly
165 \fn status_t BMidiEndpoint::Acquire()
166 \brief Increments the endpoint's reference count
168 Each BMidiEndpoint has a reference count associated with it, so that
169 BMidiRoster can do proper bookkeeping. Acquire() increments this reference
170 count, and Release() decrements it. Once the count reaches zero, the
173 When you are done with the endpoint, whether local or remote, you should
176 Upon construction, local endpoints start with a reference count of 1. Any
177 objects you obtain from BMidiRoster using the NextXXX() or FindXXX()
178 functions have their reference counts incremented in the process. If you
179 forget to call Release(), the objects won't be properly cleaned up and
180 you'll make a fool out of yourself.
182 After you Release() an object, you are advised not to use it any further.
183 If you do, your app will probably crash. That also happens if you Release()
184 an object too many times.
186 Typically, you don't need to call Acquire(), unless you have two disparate
187 parts of your application working with the same endpoint, and you don't
188 want to have to keep track of who needs to Release() the endpoint. Now you
189 simply have both of them release it.
191 \return Always returns B_OK
197 \fn status_t BMidiEndpoint::Release()
198 \brief Decrements the endpoint's reference count.
200 \return Always returns B_OK
206 \fn status_t BMidiEndpoint::Register()
207 \brief Publishes the endpoint on the roster
209 MIDI objects created by an application are invisible to other applications
210 until they are published. To publish an object use the Register() method.
211 The corresponding Unregister() method will cause an object to once again
212 become invisible to remote applications.
214 BMidiRoster also has Register() and Unregister() methods. You may also use
215 those methods to publish or hide your endpoints; both do the same thing.
217 Although it is considered bad style, calling Register() on local endpoints
218 that are already registered won't mess things up. The Midi Server will
219 simply ignore your request. Likewise for Unregister()'ing more than once.
220 Attempts to Register() or Unregister() remote endpoints will fail, of
223 If you are \link BMidiRoster::StartWatching() watching \endlink, you will
224 <b>not</b> receive notifications for any local endpoints you register or
225 unregister. Of course, other applications <I>will</I> be notified about
228 Existing connections will not be broken when an object is unregistered,
229 but future remote connections will be denied. When objects are destroyed,
230 they automatically become unregistered.
232 \returns B_OK on success, or an error code (typically \c B_ERROR) if
233 something went wrong.
239 \fn status_t BMidiEndpoint::Unregister()
240 \brief Hides the endpoint from the roster/
246 \fn status_t BMidiEndpoint::SetProperties(const BMessage* props)
247 \brief Changes the properties of the endpoint
249 Endpoints can have properties, which is any kind of information that
250 might be useful to associate with a MIDI object. The properties are
251 stored in a BMessage.
257 if (endpoint->GetProperties(&props) == B_OK)
259 ...add data to the message...
260 endpoint->SetProperties(&props);
264 You are only allowed to call SetProperties() on a local object.
266 Properties should follow a protocol, so different applications will know
267 how to read each other's properties. The current protocol is very limited
268 -- it only allows you to associate icons with your endpoints. Be planned
269 to publish a more complete protocol that included additional information,
270 such as vendor/model names, copyright/version info, category, etc., but
271 they never got around to it.
274 <TR><TD>property</TD><TD>Vector icon (raw data)</TD></TR>
275 <TR><TD>field name</TD><TD>"icon"</TD></TR>
276 <TR><TD>field type</TD><TD>'VICN'</TD></TR>
279 This vector icon is available under Haiku only, and comes as raw data,
280 not a BBitmap. Before being able to display it, you first must render
281 the vector icon in the size of your choice.
284 <TR><TD>property</TD><TD>Large (32x32) icon</TD></TR>
285 <TR><TD>field name</TD><TD>"be:large_icon"</TD></TR>
286 <TR><TD>field type</TD><TD>'ICON'</TD></TR>
290 <TR><TD>property</TD><TD>Small (16x16) icon</TD></TR>
291 <TR><TD>field name</TD><TD>"be:mini_icon"</TD></TR>
292 <TR><TD>field type</TD><TD>'MICN'</TD></TR>
295 The MidiUtil package (downloadable from the OpenBeOS website) contains a
296 number of convenient functions to associate icons with endpoints, so you
297 don't have to write that code all over again.
303 \fn status_t BMidiEndpoint::GetProperties(BMessage* props) const
304 \brief Reads the properties of the endpoint
310 if (endpoint->GetProperties(&props) == B_OK)
312 ...examine the contents of the message...
316 Note that GetProperties() overwrites the contents of your BMessage.