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> |
(...skipping 24 matching lines...) Expand all Loading... |
35 // Runs a closure on |client_thread_|. It starts the thread if it isn't | 35 // Runs a closure on |client_thread_|. It starts the thread if it isn't |
36 // running and the destructor isn't called. | 36 // running and the destructor isn't called. |
37 // Caller can bind base::Unretained(this) to |closure| since we join | 37 // Caller can bind base::Unretained(this) to |closure| since we join |
38 // |client_thread_| in the destructor. | 38 // |client_thread_| in the destructor. |
39 void RunOnClientThread(const base::Closure& closure); | 39 void RunOnClientThread(const base::Closure& closure); |
40 | 40 |
41 // Initializes CoreMIDI on |client_thread_| asynchronously. Called from | 41 // Initializes CoreMIDI on |client_thread_| asynchronously. Called from |
42 // StartInitialization(). | 42 // StartInitialization(). |
43 void InitializeCoreMIDI(); | 43 void InitializeCoreMIDI(); |
44 | 44 |
| 45 // CoreMIDI callback for MIDI notification. |
| 46 // Receives MIDI related event notifications from CoreMIDI. |
| 47 static void ReceiveMidiNotifyDispatch(const MIDINotification* message, |
| 48 void* refcon); |
| 49 void ReceiveMidiNotify(const MIDINotification* message); |
| 50 |
45 // CoreMIDI callback for MIDI data. | 51 // CoreMIDI callback for MIDI data. |
46 // Each callback can contain multiple packets, each of which can contain | 52 // Each callback can contain multiple packets, each of which can contain |
47 // multiple MIDI messages. | 53 // multiple MIDI messages. |
48 static void ReadMidiDispatch( | 54 static void ReadMidiDispatch(const MIDIPacketList* packet_list, |
49 const MIDIPacketList *pktlist, | 55 void* read_proc_refcon, |
50 void *read_proc_refcon, | 56 void* src_conn_refcon); |
51 void *src_conn_refcon); | |
52 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist); | 57 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist); |
53 | 58 |
54 // An internal callback that runs on MidiSendThread. | 59 // An internal callback that runs on MidiSendThread. |
55 void SendMidiData(MidiManagerClient* client, | 60 void SendMidiData(MidiManagerClient* client, |
56 uint32 port_index, | 61 uint32 port_index, |
57 const std::vector<uint8>& data, | 62 const std::vector<uint8>& data, |
58 double timestamp); | 63 double timestamp); |
59 | 64 |
60 // CoreMIDI | 65 // CoreMIDI |
61 MIDIClientRef midi_client_; | 66 MIDIClientRef midi_client_; |
62 MIDIPortRef coremidi_input_; | 67 MIDIPortRef coremidi_input_; |
63 MIDIPortRef coremidi_output_; | 68 MIDIPortRef coremidi_output_; |
64 | 69 |
65 enum{ kMaxPacketListSize = 512 }; | 70 enum{ kMaxPacketListSize = 512 }; |
66 char midi_buffer_[kMaxPacketListSize]; | 71 char midi_buffer_[kMaxPacketListSize]; |
67 MIDIPacketList* packet_list_; | 72 MIDIPacketList* packet_list_; |
68 MIDIPacket* midi_packet_; | 73 MIDIPacket* midi_packet_; |
69 | 74 |
| 75 // Keeps track of the index (0-based) for each of our sources. |
70 typedef std::map<MIDIEndpointRef, uint32> SourceMap; | 76 typedef std::map<MIDIEndpointRef, uint32> SourceMap; |
71 | |
72 // Keeps track of the index (0-based) for each of our sources. | |
73 SourceMap source_map_; | 77 SourceMap source_map_; |
74 | 78 |
75 // Keeps track of all destinations. | 79 // Keeps track of all destinations. |
76 std::vector<MIDIEndpointRef> destinations_; | 80 typedef std::vector<MIDIEndpointRef> DestinationVector; |
| 81 DestinationVector destinations_; |
77 | 82 |
78 // |client_thread_| is used to handle platform dependent operations. | 83 // |client_thread_| is used to handle platform dependent operations. |
79 base::Thread client_thread_; | 84 base::Thread client_thread_; |
80 | 85 |
81 // Sets true on destructing object to avoid starting |client_thread_| again. | 86 // Sets true on destructing object to avoid starting |client_thread_| again. |
82 bool shutdown_; | 87 bool shutdown_; |
83 | 88 |
84 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac); | 89 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac); |
85 }; | 90 }; |
86 | 91 |
87 } // namespace media | 92 } // namespace media |
88 | 93 |
89 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_ | 94 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_ |
OLD | NEW |