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/callback.h"
15 #include "base/compiler_specific.h"
16 #include "base/threading/thread.h"
17 #include "media/midi/midi_export.h"
18 #include "media/midi/midi_manager.h"
19 #include "media/midi/midi_port_info.h"
24 class MIDI_EXPORT MidiManagerMac final
: public MidiManager
{
27 ~MidiManagerMac() override
;
29 // MidiManager implementation.
30 void StartInitialization() override
;
31 void DispatchSendMidiData(MidiManagerClient
* client
,
33 const std::vector
<uint8
>& data
,
34 double timestamp
) override
;
37 // Runs a closure on |client_thread_|. It starts the thread if it isn't
38 // running and the destructor isn't called.
39 // Caller can bind base::Unretained(this) to |closure| since we join
40 // |client_thread_| in the destructor.
41 void RunOnClientThread(const base::Closure
& closure
);
43 // Initializes CoreMIDI on |client_thread_| asynchronously. Called from
44 // StartInitialization().
45 void InitializeCoreMIDI();
47 // CoreMIDI callback for MIDI notification.
48 // Receives MIDI related event notifications from CoreMIDI.
49 static void ReceiveMidiNotifyDispatch(const MIDINotification
* message
,
51 void ReceiveMidiNotify(const MIDINotification
* message
);
53 // CoreMIDI callback for MIDI data.
54 // Each callback can contain multiple packets, each of which can contain
55 // multiple MIDI messages.
56 static void ReadMidiDispatch(const MIDIPacketList
* packet_list
,
57 void* read_proc_refcon
,
58 void* src_conn_refcon
);
59 virtual void ReadMidi(MIDIEndpointRef source
, const MIDIPacketList
*pktlist
);
61 // An internal callback that runs on MidiSendThread.
62 void SendMidiData(MidiManagerClient
* client
,
64 const std::vector
<uint8
>& data
,
68 MIDIClientRef midi_client_
;
69 MIDIPortRef coremidi_input_
;
70 MIDIPortRef coremidi_output_
;
71 std::vector
<uint8
> midi_buffer_
;
73 // Keeps track of the index (0-based) for each of our sources.
74 typedef std::map
<MIDIEndpointRef
, uint32
> SourceMap
;
75 SourceMap source_map_
;
77 // Keeps track of all destinations.
78 typedef std::vector
<MIDIEndpointRef
> DestinationVector
;
79 DestinationVector destinations_
;
81 // |client_thread_| is used to handle platform dependent operations.
82 base::Thread client_thread_
;
84 // Sets true on destructing object to avoid starting |client_thread_| again.
87 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac
);
93 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_