| 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_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ |
| 6 #define MEDIA_MIDI_MIDI_MANAGER_H_ | 6 #define MEDIA_MIDI_MIDI_MANAGER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 14 #include "media/midi/midi_port_info.h" | 14 #include "media/midi/midi_port_info.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 // A MIDIManagerClient registers with the MIDIManager to receive MIDI data. | 18 // A MidiManagerClient registers with the MidiManager to receive MIDI data. |
| 19 // See MIDIManager::RequestAccess() and MIDIManager::ReleaseAccess() | 19 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() |
| 20 // for details. | 20 // for details. |
| 21 class MEDIA_EXPORT MIDIManagerClient { | 21 class MEDIA_EXPORT MidiManagerClient { |
| 22 public: | 22 public: |
| 23 virtual ~MIDIManagerClient() {} | 23 virtual ~MidiManagerClient() {} |
| 24 | 24 |
| 25 // ReceiveMIDIData() is called when MIDI data has been received from the | 25 // ReceiveMidiData() is called when MIDI data has been received from the |
| 26 // MIDI system. | 26 // MIDI system. |
| 27 // |port_index| represents the specific input port from input_ports(). | 27 // |port_index| represents the specific input port from input_ports(). |
| 28 // |data| represents a series of bytes encoding one or more MIDI messages. | 28 // |data| represents a series of bytes encoding one or more MIDI messages. |
| 29 // |length| is the number of bytes in |data|. | 29 // |length| is the number of bytes in |data|. |
| 30 // |timestamp| is the time the data was received, in seconds. | 30 // |timestamp| is the time the data was received, in seconds. |
| 31 virtual void ReceiveMIDIData(uint32 port_index, | 31 virtual void ReceiveMidiData(uint32 port_index, |
| 32 const uint8* data, | 32 const uint8* data, |
| 33 size_t length, | 33 size_t length, |
| 34 double timestamp) = 0; | 34 double timestamp) = 0; |
| 35 | 35 |
| 36 // AccumulateMIDIBytesSent() is called to acknowledge when bytes have | 36 // AccumulateMidiBytesSent() is called to acknowledge when bytes have |
| 37 // successfully been sent to the hardware. | 37 // successfully been sent to the hardware. |
| 38 // This happens as a result of the client having previously called | 38 // This happens as a result of the client having previously called |
| 39 // MIDIManager::DispatchSendMIDIData(). | 39 // MidiManager::DispatchSendMidiData(). |
| 40 virtual void AccumulateMIDIBytesSent(size_t n) = 0; | 40 virtual void AccumulateMidiBytesSent(size_t n) = 0; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Manages access to all MIDI hardware. | 43 // Manages access to all MIDI hardware. |
| 44 class MEDIA_EXPORT MIDIManager { | 44 class MEDIA_EXPORT MidiManager { |
| 45 public: | 45 public: |
| 46 static MIDIManager* Create(); | 46 static MidiManager* Create(); |
| 47 | 47 |
| 48 MIDIManager(); | 48 MidiManager(); |
| 49 virtual ~MIDIManager(); | 49 virtual ~MidiManager(); |
| 50 | 50 |
| 51 // A client calls StartSession() to receive and send MIDI data. | 51 // A client calls StartSession() to receive and send MIDI data. |
| 52 // If the session is ready to start, the MIDI system is lazily initialized | 52 // If the session is ready to start, the MIDI system is lazily initialized |
| 53 // and the client is registered to receive MIDI data. | 53 // and the client is registered to receive MIDI data. |
| 54 // Returns |true| if the session succeeds to start. | 54 // Returns |true| if the session succeeds to start. |
| 55 bool StartSession(MIDIManagerClient* client); | 55 bool StartSession(MidiManagerClient* client); |
| 56 | 56 |
| 57 // A client calls ReleaseSession() to stop receiving MIDI data. | 57 // A client calls ReleaseSession() to stop receiving MIDI data. |
| 58 void EndSession(MIDIManagerClient* client); | 58 void EndSession(MidiManagerClient* client); |
| 59 | 59 |
| 60 // DispatchSendMIDIData() is called when MIDI data should be sent to the MIDI | 60 // DispatchSendMidiData() is called when MIDI data should be sent to the MIDI |
| 61 // system. | 61 // system. |
| 62 // This method is supposed to return immediately and should not block. | 62 // This method is supposed to return immediately and should not block. |
| 63 // |port_index| represents the specific output port from output_ports(). | 63 // |port_index| represents the specific output port from output_ports(). |
| 64 // |data| represents a series of bytes encoding one or more MIDI messages. | 64 // |data| represents a series of bytes encoding one or more MIDI messages. |
| 65 // |length| is the number of bytes in |data|. | 65 // |length| is the number of bytes in |data|. |
| 66 // |timestamp| is the time to send the data, in seconds. A value of 0 | 66 // |timestamp| is the time to send the data, in seconds. A value of 0 |
| 67 // means send "now" or as soon as possible. | 67 // means send "now" or as soon as possible. |
| 68 // The default implementation is for unsupported platforms. | 68 // The default implementation is for unsupported platforms. |
| 69 virtual void DispatchSendMIDIData(MIDIManagerClient* client, | 69 virtual void DispatchSendMidiData(MidiManagerClient* client, |
| 70 uint32 port_index, | 70 uint32 port_index, |
| 71 const std::vector<uint8>& data, | 71 const std::vector<uint8>& data, |
| 72 double timestamp); | 72 double timestamp); |
| 73 | 73 |
| 74 // input_ports() is a list of MIDI ports for receiving MIDI data. | 74 // input_ports() is a list of MIDI ports for receiving MIDI data. |
| 75 // Each individual port in this list can be identified by its | 75 // Each individual port in this list can be identified by its |
| 76 // integer index into this list. | 76 // integer index into this list. |
| 77 const MIDIPortInfoList& input_ports() { return input_ports_; } | 77 const MidiPortInfoList& input_ports() { return input_ports_; } |
| 78 | 78 |
| 79 // output_ports() is a list of MIDI ports for sending MIDI data. | 79 // output_ports() is a list of MIDI ports for sending MIDI data. |
| 80 // Each individual port in this list can be identified by its | 80 // Each individual port in this list can be identified by its |
| 81 // integer index into this list. | 81 // integer index into this list. |
| 82 const MIDIPortInfoList& output_ports() { return output_ports_; } | 82 const MidiPortInfoList& output_ports() { return output_ports_; } |
| 83 | 83 |
| 84 protected: | 84 protected: |
| 85 // Initializes the MIDI system, returning |true| on success. | 85 // Initializes the MIDI system, returning |true| on success. |
| 86 // The default implementation is for unsupported platforms. | 86 // The default implementation is for unsupported platforms. |
| 87 virtual bool Initialize(); | 87 virtual bool Initialize(); |
| 88 | 88 |
| 89 void AddInputPort(const MIDIPortInfo& info); | 89 void AddInputPort(const MidiPortInfo& info); |
| 90 void AddOutputPort(const MIDIPortInfo& info); | 90 void AddOutputPort(const MidiPortInfo& info); |
| 91 | 91 |
| 92 // Dispatches to all clients. | 92 // Dispatches to all clients. |
| 93 void ReceiveMIDIData(uint32 port_index, | 93 void ReceiveMidiData(uint32 port_index, |
| 94 const uint8* data, | 94 const uint8* data, |
| 95 size_t length, | 95 size_t length, |
| 96 double timestamp); | 96 double timestamp); |
| 97 | 97 |
| 98 bool initialized_; | 98 bool initialized_; |
| 99 | 99 |
| 100 // Keeps track of all clients who wish to receive MIDI data. | 100 // Keeps track of all clients who wish to receive MIDI data. |
| 101 typedef std::set<MIDIManagerClient*> ClientList; | 101 typedef std::set<MidiManagerClient*> ClientList; |
| 102 ClientList clients_; | 102 ClientList clients_; |
| 103 | 103 |
| 104 // Protects access to our clients. | 104 // Protects access to our clients. |
| 105 base::Lock clients_lock_; | 105 base::Lock clients_lock_; |
| 106 | 106 |
| 107 MIDIPortInfoList input_ports_; | 107 MidiPortInfoList input_ports_; |
| 108 MIDIPortInfoList output_ports_; | 108 MidiPortInfoList output_ports_; |
| 109 | 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(MIDIManager); | 110 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 } // namespace media | 113 } // namespace media |
| 114 | 114 |
| 115 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 115 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
| OLD | NEW |