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