1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_MAC_H_ 6 #define MEDIA_MIDI_MIDI_MANAGER_MAC_H_ 7 8 #include <CoreMIDI/MIDIServices.h> 9 #include <map> 10 #include <string> 11 #include <vector> 12 13 #include "base/basictypes.h" 14 #include "base/compiler_specific.h" 15 #include "base/threading/thread.h" 16 #include "media/midi/midi_manager.h" 17 #include "media/midi/midi_port_info.h" 18 19 namespace media { 20 21 class MEDIA_EXPORT MidiManagerMac : public MidiManager { 22 public: 23 MidiManagerMac(); 24 virtual ~MidiManagerMac(); 25 26 // MidiManager implementation. 27 virtual void StartInitialization() OVERRIDE; 28 virtual void DispatchSendMidiData(MidiManagerClient* client, 29 uint32 port_index, 30 const std::vector<uint8>& data, 31 double timestamp) OVERRIDE; 32 33 private: 34 // CoreMIDI callback for MIDI data. 35 // Each callback can contain multiple packets, each of which can contain 36 // multiple MIDI messages. 37 static void ReadMidiDispatch( 38 const MIDIPacketList *pktlist, 39 void *read_proc_refcon, 40 void *src_conn_refcon); 41 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist); 42 43 // An internal callback that runs on MidiSendThread. 44 void SendMidiData(MidiManagerClient* client, 45 uint32 port_index, 46 const std::vector<uint8>& data, 47 double timestamp); 48 49 // Helper 50 static media::MidiPortInfo GetPortInfoFromEndpoint(MIDIEndpointRef endpoint); 51 static double MIDITimeStampToSeconds(MIDITimeStamp timestamp); 52 static MIDITimeStamp SecondsToMIDITimeStamp(double seconds); 53 54 // CoreMIDI 55 MIDIClientRef midi_client_; 56 MIDIPortRef coremidi_input_; 57 MIDIPortRef coremidi_output_; 58 59 enum{ kMaxPacketListSize = 512 }; 60 char midi_buffer_[kMaxPacketListSize]; 61 MIDIPacketList* packet_list_; 62 MIDIPacket* midi_packet_; 63 64 typedef std::map<MIDIEndpointRef, uint32> SourceMap; 65 66 // Keeps track of the index (0-based) for each of our sources. 67 SourceMap source_map_; 68 69 // Keeps track of all destinations. 70 std::vector<MIDIEndpointRef> destinations_; 71 72 // |send_thread_| is used to send MIDI data. 73 base::Thread send_thread_; 74 75 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac); 76 }; 77 78 } // namespace media 79 80 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_ 81