OLD | NEW |
---|---|
(Empty) | |
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_H_ | |
6 #define MEDIA_MIDI_MIDI_MANAGER_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/synchronization/lock.h" | |
12 #include "media/base/media_export.h" | |
13 #include "media/midi/midi_port_info.h" | |
14 | |
15 namespace media { | |
16 | |
17 // A MIDIManagerClient registers with the MIDIManager to receive MIDI data. | |
18 // See MIDIManager::RequestAccess() and MIDIManager::ReleaseAccess() | |
19 // for details. | |
20 class MEDIA_EXPORT MIDIManagerClient { | |
21 public: | |
22 virtual ~MIDIManagerClient() {} | |
23 | |
24 // ReceiveMIDIData() is called when MIDI data has been received from the | |
25 // MIDI system. | |
26 // |port_index| represents the specific input port from input_ports(). | |
27 // |data| represents a series of bytes encoding one or more MIDI messages. | |
28 // |length| is the number of bytes in |data|. | |
scherkus (not reviewing)
2013/06/13 02:05:41
fix indenting
Chris Rogers
2013/06/14 00:47:33
Done.
| |
29 // |timestamp| is the time the data was received, in seconds. | |
30 virtual void ReceiveMIDIData( | |
31 int port_index, | |
32 const uint8* data, | |
33 size_t length, | |
34 double timestamp) = 0; | |
35 }; | |
36 | |
37 // Manages access to all MIDI hardware. | |
38 class MEDIA_EXPORT MIDIManager { | |
39 public: | |
40 enum AccessType { | |
41 kNoSystemExclusive, | |
42 kSystemExclusive | |
43 }; | |
44 | |
45 static MIDIManager* Create(); | |
46 | |
47 MIDIManager(); | |
48 virtual ~MIDIManager(); | |
49 | |
50 // A client calls RequestAccess() to receive and send MIDI data. | |
51 // If access is approved, the MIDI system is lazily initialized | |
52 // and the client is registered to receive MIDI data. | |
53 // Returns |true| if access is approved. | |
54 bool RequestAccess(MIDIManagerClient* client, int access); | |
55 | |
56 // A client calls ReleaseAccess() to stop receiving MIDI data. | |
57 void ReleaseAccess(MIDIManagerClient* client); | |
58 | |
59 // SendMIDIData() sends one or more messages at the given time. | |
60 // |port_index| represents the specific output port from output_ports(). | |
61 // |data| represents a series of bytes encoding one or more MIDI messages. | |
62 // |length| is the number of bytes in |data|. | |
63 // |timestamp| is the time to send the data, in seconds. | |
64 virtual void SendMIDIData(int port_index, | |
65 const uint8* data, | |
66 size_t length, | |
67 double timestamp) = 0; | |
68 | |
69 // input_ports() is a list of MIDI ports for receiving MIDI data. | |
70 // Each individual port in this list can be identified by its | |
71 // integer index into this list. | |
72 const MIDIPortInfoList& input_ports() { return input_ports_; } | |
73 | |
74 // output_ports() is a list of MIDI ports for sending MIDI data. | |
75 // Each individual port in this list can be identified by its | |
76 // integer index into this list. | |
77 const MIDIPortInfoList& output_ports() { return output_ports_; } | |
78 | |
79 protected: | |
80 // Initializes the MIDI system, returning |true| on success. | |
81 virtual bool Initialize() = 0; | |
82 | |
83 void AddInputPort(const MIDIPortInfo& info); | |
84 void AddOutputPort(const MIDIPortInfo& info); | |
85 | |
86 // Dispatches to all clients. | |
87 void ReceiveMIDIData( | |
88 int port_index, | |
89 const uint8* data, | |
90 size_t length, | |
91 double timestamp); | |
92 | |
93 bool initialized_; | |
94 | |
95 // Keeps track of all clients who wish to receive MIDI data. | |
96 typedef std::set<MIDIManagerClient*> ClientList; | |
97 ClientList clients_; | |
98 | |
99 // Protects access to our clients. | |
100 base::Lock clients_lock_; | |
101 | |
102 MIDIPortInfoList input_ports_; | |
103 MIDIPortInfoList output_ports_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(MIDIManager); | |
106 }; | |
107 | |
108 } // namespace media | |
109 | |
110 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | |
OLD | NEW |