4 \brief Defines the heart of the MIDI Kit: the MIDI Roster.
11 \brief Defines the status codes for MIDI Server notification messages.
13 These codes are used when you request notification as in
14 BMidiRoster::StartWatching(). Check against these codes to determine what
15 is happening. See the StartWatching() method for a more complete
16 description of the codes and their meaning.
22 \brief BMessage identifier of MIDI messages.
27 \class BMidiRoster MidiRoster.h
29 \brief Interface to the system-wide Midi Roster.
31 BMidiRoster allows you to find available MIDI consumer and producer
32 objects. You can locate these objects using the iterative NextEndpoint(),
33 NextProducer(), and NextConsumer() methods or by requesting notification
34 messages to be sent with StartWatching(). Notification messages may
35 contain object IDs which can be resolved using the FindEndpoint(),
36 FindProducer(), and FindConsumer() methods.
38 The constructor and destructor of BMidiRoster are private, which means
39 that you cannot create or delete your own BMidiRoster objects. Every
40 application can have only one instance of BMidiRoster, which is
41 automatically created the very first time you use a Midi Kit function.
42 You can call BMidiRoster's functions like this:
44 producer = BMidiRoster::FindProducer(someID);
46 Or using the slightly more annoying:
48 BMidiRoster* roster = BMidiRoster::MidiRoster();
51 producer = roster->FindProducer(someID);
58 \fn BMidiEndpoint* BMidiRoster::NextEndpoint(int32* id)
59 \brief Returns the next endpoint from the roster
61 The "next endpoint" means: the endpoint with the ID that follows \a id.
62 So if you set id to 3, the first possible endpoint it returns is
63 endpoint 4. No endpoint can have ID 0, so passing 0 gives you the first
64 endpoint. If you pass \c NULL instead of an ID, NextEndpoint() always
65 returns \c NULL. When the function returns, it sets \a id to the ID of the
66 endpoint that was found. If no more endpoints exist, NextEndpoint()
67 returns \c NULL and id is not changed. NextEndpoint() does <b>not</b>
68 return locally created endpoints, even if they are Register()'ed.
74 while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL)
76 ... do something with endpoint ...
77 endp->Release(); // don't forget!
80 Remember that NextEndpoint() bumps the endpoint's reference count, so you
81 should always \link BMidiEndpoint::Release() Release() \endlink it when
87 \fn BMidiProducer* BMidiRoster::NextProducer(int32* id)
88 \brief Returns the next producer from the roster.
90 Like NextEndpoint(), but only returns producer endpoints.
98 \fn BMidiConsumer* BMidiRoster::NextConsumer(int32* id)
99 \brief Returns the next consumer from the roster.
101 Like NextEndpoint(), but only returns consumer endpoints.
109 \fn BMidiEndpoint* BMidiRoster::FindEndpoint(int32 id,
110 bool localOnly = false)
111 \brief Returns the endpoint with the specified \a id.
113 FindEndpoint() will always find <b>any</b> local endpoints created by this
114 application; they do not have to be published with Register() first. If
115 localOnly is false, FindEndpoint() also looks at remote endpoints,
116 otherwise only local endpoints will be resolved. Returns NULL if no such
117 endpoint could be found.
119 You should use a dynamic_cast to convert the BMidiEndpoint into a producer
122 BMidiEndpoint* endp = ...;
123 BMidiProducer* prod = NULL;
124 BMidiConsumer* cons = NULL;
125 if (endp->IsProducer())
127 prod = dynamic_cast<BMidiProducer*>(endp);
129 else if (endp->IsConsumer())
131 cons = dynamic_cast<BMidiConsumer*>(endp);
135 Remember that FindEndpoint() increments the endpoint's reference count,
136 so you should always \link BMidiEndpoint::Release() Release() \endlink
137 an endpoint when you are done with it:
139 BMidiEndpoint* endp = BMidiRoster::FindEndpoint(someID);
142 ...do stuff with the endpoint...
150 \fn BMidiProducer* BMidiRoster::FindProducer(int32 id,
151 bool localOnly = false)
152 \brief Finds the producer with the specified \a id.
154 Like FindEndpoint(), but only looks for producer endpoints. Returns
155 \c NULL if no endpoint with that ID exists, or if that endpoint is not
164 \fn BMidiConsumer* BMidiRoster::FindConsumer(int32 id,
165 bool localOnly = false)
166 \brief Finds the consumer with the specified \a id.
168 Like FindEndpoint(), but only looks for consumer endpoints. Returns
169 \c NULL if no endpoint with that ID exists, or if that endpoint is not
178 \fn void BMidiRoster::StartWatching(const BMessenger* msngr)
179 \brief Start receiving notifications from the Midi Roster
181 When you start watching, BMidiRoster sends you notifications for all
182 currently \b published \c remote endpoints, and all the current
183 connections between them. (At this point, BMidiRoster does not let you
184 know about connections between unpublished endpoints, nor does it tell
185 you anything about your local endpoints, even though they may be
188 Thereafter, you'll receive notifications any time something important
189 happens to an object. The application that performs these operations is
190 itself not notified. The assumption here is that you already know about
191 these changes, because you are the one that is performing them.
193 The notifications are BMessages with code B_MIDI_EVENT. You specify the
194 BMessenger that will be used to send these messages. Each message contains
195 a field called be:op that describes the type of notification.
197 The "registered" and "unregistered" notifications are sent when a remote
198 endpoint Register()'s or Unregister()'s, respectively. You don't receive
199 these notifications when you register or unregister your local endpoints,
200 but the other apps will.
206 <td>\c B_MIDI_REGISTERED</td>
211 <td>id of the endpoint</td>
216 <td>"producer" or "consumer"</td>
223 <td>\c B_MIDI_UNREGISTERED</td>
228 <td>id of the endpoint</td>
233 <td>"producer" or "consumer"</td>
237 The "connected" and "disconnected" notifications are sent when a consumer
238 \link BMidiProducer::Connect() Connect()\endlink's to a producer, or when
239 they \link BMidiProducer::Disconnect() Disconnect() \endlink. You will
240 receive these notifications when \b any two endpoints connect or
241 disconnect, even if they are not published. (The purpose of which is
242 debatable.) You won't receive the notifications if you are the one making
243 the connection, even if both endpoints are remote. You \b will be notified
244 when another app connects one of your published endpoints.
249 <td>\c B_MIDI_CONNECTED</td>
254 <td>id of the connector</td>
259 <td>id of the connectee</td>
267 <td>\c B_MIDI_DISCONNECTED</td>
272 <td>id of the connector</td>
277 <td>id of the connectee</td>
281 the following notifications are sent when an endpoint's attributes are
282 changed. you receive these notifications only if another application is
283 changing one of its published endpoints.
289 <td>\c B_MIDI_CHANGED_NAME</td>
294 <td>id of the endpoint</td>
299 <td>"producer" or "consumer"</td>
304 <td>the endpoint's new name</td>
312 <td>\c B_MIDI_CHANGED_LATENCY</td>
317 <td>id of the endpoint</td>
322 <td>"producer" or "consumer"</td>
327 <td>the new latency (microseconds)</td>
335 <td>\c B_MIDI_CHANGED_PROPERTIES</td>
340 <td>id of the endpoint</td>
345 <td>"producer" or "consumer"</td>
348 <td>be:properties</td>
350 <td>the new properties</td>
354 Typical usage example:
357 void MyView::AttachedToWindow()
359 BMessenger msgr(this);
360 BMidiRoster::StartWatching(&msgr);
362 void MyView::MessageReceived(BMessage* msg)
367 HandleMidiEvent(msg);
370 super::MessageReceived(msg);
376 For the possible midi options, see #BMidiOp
381 \fn void BMidiRoster::StopWatching()
382 \brief Stop receiving notifications from the Midi Roster.
389 \fn status_t BMidiRoster::Register(BMidiEndpoint* object)
390 \brief Publishes an endpoint to other applications.
392 Calls BMidiEndpoint's \link BMidiEndpoint::Register() Register() \endlink
393 method to publish an endpoint, which makes it visible to other
399 \fn status_t BMidiRoster::Unregister(BMidiEndpoint* object)
400 \brief Hides an endpoint from other applications.
402 Calls BMidiEndpoint's
403 \link BMidiEndpoint::Unregister() Unregister() \endlink method to hide
404 a previously published endpoint from other applications.
409 \fn BMidiRoster* BMidiRoster::MidiRoster()
410 \brief Returns a pointer to the only instance of BMidiRoster.
412 There is no real reason use this function, since all BMidiRoster's public