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.
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_MAC_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_MAC_H_
8 #include <CoreMIDI/MIDIServices.h>
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"
21 class MEDIA_EXPORT MidiManagerMac
: public MidiManager
{
24 virtual ~MidiManagerMac();
26 // MidiManager implementation.
27 virtual MidiResult
Initialize() OVERRIDE
;
28 virtual void DispatchSendMidiData(MidiManagerClient
* client
,
30 const std::vector
<uint8
>& data
,
31 double timestamp
) OVERRIDE
;
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
);
43 // An internal callback that runs on MidiSendThread.
44 void SendMidiData(MidiManagerClient
* client
,
46 const std::vector
<uint8
>& data
,
50 static media::MidiPortInfo
GetPortInfoFromEndpoint(MIDIEndpointRef endpoint
);
51 static double MIDITimeStampToSeconds(MIDITimeStamp timestamp
);
52 static MIDITimeStamp
SecondsToMIDITimeStamp(double seconds
);
55 MIDIClientRef midi_client_
;
56 MIDIPortRef coremidi_input_
;
57 MIDIPortRef coremidi_output_
;
59 enum{ kMaxPacketListSize
= 512 };
60 char midi_buffer_
[kMaxPacketListSize
];
61 MIDIPacketList
* packet_list_
;
62 MIDIPacket
* midi_packet_
;
64 typedef std::map
<MIDIEndpointRef
, uint32
> SourceMap
;
66 // Keeps track of the index (0-based) for each of our sources.
67 SourceMap source_map_
;
69 // Keeps track of all destinations.
70 std::vector
<MIDIEndpointRef
> destinations_
;
72 // |send_thread_| is used to send MIDI data.
73 base::Thread send_thread_
;
75 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac
);
80 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_