Index: media/midi/midi_manager_mac.cc |
diff --git a/media/midi/midi_manager_mac.cc b/media/midi/midi_manager_mac.cc |
index e9d56fb13add478a8c79e963981b485cabbc8174..84b9e709bff098694f1592ce587a93a839f7dfdb 100644 |
--- a/media/midi/midi_manager_mac.cc |
+++ b/media/midi/midi_manager_mac.cc |
@@ -25,8 +25,7 @@ namespace media { |
namespace { |
-MidiPortInfo GetPortInfoFromEndpoint( |
- MIDIEndpointRef endpoint) { |
+MidiPortInfo GetPortInfoFromEndpoint(const MIDIEndpointRef endpoint) { |
yhirano
2014/10/24 03:30:08
What does this const mean?
Takashi Toyoshima
2015/02/17 17:10:38
reverted
|
SInt32 id_number = 0; |
MIDIObjectGetIntegerProperty(endpoint, kMIDIPropertyUniqueID, &id_number); |
string id = IntToString(id_number); |
@@ -65,7 +64,8 @@ MidiPortInfo GetPortInfoFromEndpoint( |
<< result; |
} |
- return MidiPortInfo(id, manufacturer, name, version); |
+ const bool connected = true; |
+ return MidiPortInfo(id, manufacturer, name, version, connected); |
} |
double MIDITimeStampToSeconds(MIDITimeStamp timestamp) { |
@@ -140,7 +140,8 @@ void MidiManagerMac::InitializeCoreMIDI() { |
// TODO(toyoshim): Set MIDINotifyProc to receive CoreMIDI event notifications. |
midi_client_ = 0; |
OSStatus result = |
- MIDIClientCreate(CFSTR("Chrome"), NULL, NULL, &midi_client_); |
+ MIDIClientCreate(CFSTR("Chrome"), ReceiveMidiNotifyDispatch, this, |
+ &midi_client_); |
if (result != noErr) |
return CompleteInitialization(MIDI_INITIALIZATION_ERROR); |
@@ -200,6 +201,69 @@ void MidiManagerMac::InitializeCoreMIDI() { |
} |
// static |
+void MidiManagerMac::ReceiveMidiNotifyDispatch(const MIDINotification* message, |
+ void* refcon) { |
+ MidiManagerMac* manager = static_cast<MidiManagerMac*>(refcon); |
+ manager->ReceiveMidiNotify(message); |
+} |
+ |
+void MidiManagerMac::ReceiveMidiNotify(const MIDINotification* message) { |
+ DCHECK(client_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
+ |
+ if (kMIDIMsgObjectAdded == message->messageID) { |
+ const MIDIObjectAddRemoveNotification* notification = |
+ reinterpret_cast<const MIDIObjectAddRemoveNotification*>(message); |
+ MIDIEndpointRef endpoint = |
+ static_cast<MIDIEndpointRef>(notification->child); |
+ if (notification->childType == kMIDIObjectType_Source) { |
+ SourceMap::iterator it = source_map_.find(endpoint); |
+ if (it == source_map_.end()) { |
+ uint32 index = source_map_.size(); |
+ source_map_[endpoint] = index; |
+ MidiPortInfo info = GetPortInfoFromEndpoint(endpoint); |
+ AddInputPort(info); |
+ } else { |
+ uint32 index = source_map_[endpoint]; |
+ SetInputPortState(index, true); |
+ } |
+ } else if (notification->childType == kMIDIObjectType_Destination) { |
+ bool found = false; |
+ for (uint32 i = 0; i < destinations_.size(); ++i) { |
yhirano
2014/10/24 03:30:08
You can use std::find.
palmer
2014/10/24 19:07:14
Yes, std::find.
Takashi Toyoshima
2015/02/17 17:10:37
But, I need to use the index i for SetOutputPortSt
yhirano
2015/02/18 03:21:25
Year, and you can use it:
auto i = std::find(...)
Takashi Toyoshima
2015/02/18 04:43:13
Oh, great. Sorry, I did't know this usage. thanks!
|
+ if (destinations_[i] != endpoint) |
+ continue; |
+ found = true; |
+ SetOutputPortState(i, true); |
+ break; |
+ } |
+ if (!found) { |
+ destinations_.push_back(endpoint); |
+ MidiPortInfo info = GetPortInfoFromEndpoint(endpoint); |
+ AddOutputPort(info); |
+ } |
+ } |
+ } else if (kMIDIMsgObjectRemoved == message->messageID) { |
+ const MIDIObjectAddRemoveNotification* notification = |
+ reinterpret_cast<const MIDIObjectAddRemoveNotification*>(message); |
+ MIDIEndpointRef endpoint = |
+ static_cast<MIDIEndpointRef>(notification->child); |
+ if (notification->childType == kMIDIObjectType_Source) { |
+ SourceMap::iterator it = source_map_.find(endpoint); |
+ if (it != source_map_.end()) { |
+ uint32 index = source_map_[endpoint]; |
+ SetInputPortState(index, false); |
+ } |
+ } else if (notification->childType == kMIDIObjectType_Destination) { |
+ for (uint32 i = 0; i < destinations_.size(); ++i) { |
yhirano
2014/10/24 03:30:08
ditto
Takashi Toyoshima
2015/02/17 17:10:38
same reason
|
+ if (destinations_[i] != endpoint) |
+ continue; |
+ SetOutputPortState(i, false); |
+ break; |
+ } |
+ } |
+ } |
+} |
+ |
+// static |
void MidiManagerMac::ReadMidiDispatch(const MIDIPacketList* packet_list, |
void* read_proc_refcon, |
void* src_conn_refcon) { |