Index: media/midi/midi_manager.h |
diff --git a/media/midi/midi_manager.h b/media/midi/midi_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..55030cb0b10798bdb8af22990e41abe3cc8f42a0 |
--- /dev/null |
+++ b/media/midi/midi_manager.h |
@@ -0,0 +1,86 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_MIDI_MIDI_MANAGER_H_ |
+#define MEDIA_MIDI_MIDI_MANAGER_H_ |
+ |
+#include <set> |
+ |
+#include "base/basictypes.h" |
+#include "base/synchronization/lock.h" |
+#include "media/base/media_export.h" |
+#include "media/midi/midi_port_info.h" |
+ |
+namespace media { |
+ |
+// Manages access to all MIDI hardware. |
+class MEDIA_EXPORT MIDIManager { |
+ public: |
+ enum AccessType { |
+ kNoSystemExclusive, |
+ kSystemExclusive |
+ }; |
+ |
+ class Client { |
scherkus (not reviewing)
2013/06/12 01:28:47
although it is prevalent elsewhere in media code,
Chris Rogers
2013/06/12 20:34:35
Done.
|
+ public: |
+ virtual ~Client() {} |
+ virtual void ReceiveMIDIData( |
scherkus (not reviewing)
2013/06/12 01:28:47
needs docs
Chris Rogers
2013/06/12 20:34:35
Added comments for this and similar methods in thi
|
+ int port_index, |
+ const uint8* data, |
+ size_t length, |
+ double timestamp) = 0; |
+ }; |
+ |
+ static MIDIManager* Create(); |
+ |
+ MIDIManager(); |
+ virtual ~MIDIManager(); |
+ |
+ // If access is approved, lazily initializes the MIDI system |
+ // and registers the client to receive MIDI data. |
+ // Returns |true| if access is approved. |
+ bool RequestAccess(Client* client, int access); |
+ void ReleaseAccess(Client* client); |
+ |
+ // Send one or more messages at the given time. |
+ virtual void SendMIDIData(int port_index, |
+ const uint8* data, |
+ size_t length, |
+ double timestamp) = 0; |
+ |
+ const MIDIPortInfoList& input_ports() { return input_ports_; } |
+ const MIDIPortInfoList& output_ports() { return output_ports_; } |
+ |
+ protected: |
+ // Initializes the MIDI system, returning |true| on success. |
+ virtual bool Initialize() = 0; |
+ |
+ void AddInputPort(const MIDIPortInfo& info); |
+ void AddOutputPort(const MIDIPortInfo& info); |
+ |
+ // Dispatches to all clients. |
+ void ReceiveMIDIData( |
+ int port_index, |
+ const uint8* data, |
+ size_t length, |
+ double timestamp); |
+ |
+ bool initialized_; |
+ |
+ // Keeps track of all clients who wish to receive MIDI data. |
+ typedef std::set<Client*> ClientList; |
+ ClientList clients_; |
+ |
+ // Protects access to our clients. |
+ base::Lock clients_lock_; |
+ |
+ MIDIPortInfoList input_ports_; |
+ MIDIPortInfoList output_ports_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MIDIManager); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_MIDI_MIDI_MANAGER_H_ |