Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: media/midi/midi_manager.h

Issue 16025005: Web MIDI API back-end (work-in-progress) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For now disable sending data - fix IPC thread in renderer Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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|.
29 // |timestamp| is the time the data was received, in seconds.
30 virtual void ReceiveMIDIData(int port_index,
31 const uint8* data,
32 size_t length,
33 double timestamp) = 0;
34 };
35
36 // Manages access to all MIDI hardware.
37 class MEDIA_EXPORT MIDIManager {
38 public:
39 enum AccessType {
40 kNoSystemExclusive,
41 kSystemExclusive
42 };
43
44 static MIDIManager* Create();
45
46 MIDIManager();
47 virtual ~MIDIManager();
48
49 // A client calls RequestAccess() to receive and send MIDI data.
50 // If access is approved, the MIDI system is lazily initialized
51 // and the client is registered to receive MIDI data.
52 // Returns |true| if access is approved.
53 bool RequestAccess(MIDIManagerClient* client, int access);
54
55 // A client calls ReleaseAccess() to stop receiving MIDI data.
56 void ReleaseAccess(MIDIManagerClient* client);
57
58 // SendMIDIData() sends one or more messages at the given time.
59 // |port_index| represents the specific output port from output_ports().
60 // |data| represents a series of bytes encoding one or more MIDI messages.
61 // |length| is the number of bytes in |data|.
62 // |timestamp| is the time to send the data, in seconds.
63 virtual void SendMIDIData(int port_index,
64 const uint8* data,
65 size_t length,
66 double timestamp) = 0;
67
68 // input_ports() is a list of MIDI ports for receiving MIDI data.
69 // Each individual port in this list can be identified by its
70 // integer index into this list.
71 const MIDIPortInfoList& input_ports() { return input_ports_; }
72
73 // output_ports() is a list of MIDI ports for sending MIDI data.
74 // Each individual port in this list can be identified by its
75 // integer index into this list.
76 const MIDIPortInfoList& output_ports() { return output_ports_; }
77
78 protected:
79 // Initializes the MIDI system, returning |true| on success.
80 virtual bool Initialize() = 0;
81
82 void AddInputPort(const MIDIPortInfo& info);
83 void AddOutputPort(const MIDIPortInfo& info);
84
85 // Dispatches to all clients.
86 void ReceiveMIDIData(
87 int port_index,
88 const uint8* data,
89 size_t length,
90 double timestamp);
91
92 bool initialized_;
93
94 // Keeps track of all clients who wish to receive MIDI data.
95 typedef std::set<MIDIManagerClient*> ClientList;
96 ClientList clients_;
97
98 // Protects access to our clients.
99 base::Lock clients_lock_;
100
101 MIDIPortInfoList input_ports_;
102 MIDIPortInfoList output_ports_;
103
104 DISALLOW_COPY_AND_ASSIGN(MIDIManager);
105 };
106
107 } // namespace media
108
109 #endif // MEDIA_MIDI_MIDI_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698