blob: 1d5838b2697a752853c86035cd43a93420f6c41d [file] [log] [blame]
crogers@google.com27356e42013-06-22 04:03:03 +00001// 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#include "media/midi/midi_manager.h"
6
crogers@google.com542a43a2013-07-31 05:16:49 +00007#include "base/bind.h"
8#include "base/bind_helpers.h"
crogers@google.com542a43a2013-07-31 05:16:49 +00009
crogers@google.com27356e42013-06-22 04:03:03 +000010namespace media {
11
dnicoara@chromium.org9f2a6f02014-01-03 21:25:00 +000012#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA)
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000013// TODO(toyoshim): implement MIDIManager for other platforms.
crogers@google.com27356e42013-06-22 04:03:03 +000014MIDIManager* MIDIManager::Create() {
yhirano@chromium.orgc6d5b7b2013-12-20 07:27:23 +000015 return new MIDIManager;
crogers@google.com27356e42013-06-22 04:03:03 +000016}
17#endif
18
19MIDIManager::MIDIManager()
20 : initialized_(false) {
21}
22
yukawa@chromium.orgdb7ad8b2013-12-04 15:42:41 +000023MIDIManager::~MIDIManager() {
24}
crogers@google.com27356e42013-06-22 04:03:03 +000025
toyoshim@chromium.org235b09e2013-07-25 16:23:14 +000026bool MIDIManager::StartSession(MIDIManagerClient* client) {
crogers@google.com27356e42013-06-22 04:03:03 +000027 // Lazily initialize the MIDI back-end.
28 if (!initialized_)
29 initialized_ = Initialize();
30
31 if (initialized_) {
32 base::AutoLock auto_lock(clients_lock_);
33 clients_.insert(client);
34 }
35
36 return initialized_;
37}
38
toyoshim@chromium.org235b09e2013-07-25 16:23:14 +000039void MIDIManager::EndSession(MIDIManagerClient* client) {
crogers@google.com27356e42013-06-22 04:03:03 +000040 base::AutoLock auto_lock(clients_lock_);
41 ClientList::iterator i = clients_.find(client);
42 if (i != clients_.end())
43 clients_.erase(i);
44}
45
yhirano@chromium.orgc6d5b7b2013-12-20 07:27:23 +000046void MIDIManager::DispatchSendMIDIData(MIDIManagerClient* client,
47 uint32 port_index,
48 const std::vector<uint8>& data,
49 double timestamp) {
50 NOTREACHED();
51}
52
53bool MIDIManager::Initialize() {
54 return false;
55}
56
crogers@google.com27356e42013-06-22 04:03:03 +000057void MIDIManager::AddInputPort(const MIDIPortInfo& info) {
58 input_ports_.push_back(info);
59}
60
61void MIDIManager::AddOutputPort(const MIDIPortInfo& info) {
62 output_ports_.push_back(info);
63}
64
65void MIDIManager::ReceiveMIDIData(
toyoshim@chromium.orgae6ad362013-08-27 15:30:20 +000066 uint32 port_index,
crogers@google.com27356e42013-06-22 04:03:03 +000067 const uint8* data,
68 size_t length,
69 double timestamp) {
70 base::AutoLock auto_lock(clients_lock_);
71
crogers@google.com27356e42013-06-22 04:03:03 +000072 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i)
73 (*i)->ReceiveMIDIData(port_index, data, length, timestamp);
crogers@google.com542a43a2013-07-31 05:16:49 +000074}
75
crogers@google.com27356e42013-06-22 04:03:03 +000076} // namespace media