crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 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 | #include "media/midi/midi_manager.h" |
| 6 | |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 7 | #include "base/bind.h" |
fdoray | a05bf57 | 2016-06-09 08:42:38 -0700 | [diff] [blame] | 8 | #include "base/location.h" |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 9 | #include "base/metrics/histogram_macros.h" |
fdoray | a05bf57 | 2016-06-09 08:42:38 -0700 | [diff] [blame] | 10 | #include "base/single_thread_task_runner.h" |
| 11 | #include "base/threading/thread_task_runner_handle.h" |
ssid | 9134444 | 2015-01-28 04:13:15 -0800 | [diff] [blame] | 12 | #include "base/trace_event/trace_event.h" |
avi | 793390d | 2015-12-22 22:22:36 -0800 | [diff] [blame] | 13 | #include "build/build_config.h" |
crogers@google.com | 542a43a | 2013-07-31 05:16:49 +0000 | [diff] [blame] | 14 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 15 | namespace midi { |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 16 | |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 17 | namespace { |
| 18 | |
| 19 | using Sample = base::HistogramBase::Sample; |
toyoshim | ec2570a | 2016-10-21 02:15:27 -0700 | [diff] [blame] | 20 | using midi::mojom::PortState; |
toyoshim | 2f3a48f | 2016-10-17 01:54:13 -0700 | [diff] [blame] | 21 | using midi::mojom::Result; |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 22 | |
| 23 | // If many users have more devices, this number will be increased. |
| 24 | // But the number is expected to be big enough for now. |
| 25 | const Sample kMaxUmaDevices = 31; |
| 26 | |
| 27 | // Used to count events for usage histogram. |
| 28 | enum class Usage { |
| 29 | CREATED, |
| 30 | CREATED_ON_UNSUPPORTED_PLATFORMS, |
| 31 | SESSION_STARTED, |
| 32 | SESSION_ENDED, |
| 33 | INITIALIZED, |
| 34 | INPUT_PORT_ADDED, |
| 35 | OUTPUT_PORT_ADDED, |
| 36 | |
| 37 | // New items should be inserted here, and |MAX| should point the last item. |
| 38 | MAX = INITIALIZED, |
| 39 | }; |
| 40 | |
| 41 | void ReportUsage(Usage usage) { |
| 42 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.Usage", |
| 43 | static_cast<Sample>(usage), |
| 44 | static_cast<Sample>(Usage::MAX) + 1); |
| 45 | } |
| 46 | |
| 47 | } // namespace |
| 48 | |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame^] | 49 | MidiManager::MidiManager(MidiService* service) |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 50 | : initialization_state_(InitializationState::NOT_STARTED), |
| 51 | finalized_(false), |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame^] | 52 | result_(Result::NOT_INITIALIZED), |
| 53 | service_(service) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 54 | ReportUsage(Usage::CREATED); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 55 | } |
| 56 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 57 | MidiManager::~MidiManager() { |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 58 | // Make sure that Finalize() is called to clean up resources allocated on |
| 59 | // the Chrome_IOThread. |
toyoshim | 131beb5 | 2016-07-25 00:42:41 -0700 | [diff] [blame] | 60 | base::AutoLock auto_lock(lock_); |
| 61 | CHECK(finalized_); |
yukawa@chromium.org | db7ad8b | 2013-12-04 15:42:41 +0000 | [diff] [blame] | 62 | } |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 63 | |
agoode | 7de413f | 2015-04-24 00:13:39 -0700 | [diff] [blame] | 64 | #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ |
| 65 | !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame^] | 66 | MidiManager* MidiManager::Create(MidiService* service) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 67 | ReportUsage(Usage::CREATED_ON_UNSUPPORTED_PLATFORMS); |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame^] | 68 | return new MidiManager(service); |
toyoshim@chromium.org | fc2002e | 2014-05-07 08:10:34 +0000 | [diff] [blame] | 69 | } |
| 70 | #endif |
| 71 | |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 72 | void MidiManager::Shutdown() { |
| 73 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown", |
| 74 | static_cast<int>(result_), |
| 75 | static_cast<int>(Result::MAX) + 1); |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame^] | 76 | bool shutdown_synchronously = false; |
| 77 | { |
| 78 | base::AutoLock auto_lock(lock_); |
| 79 | if (session_thread_runner_) { |
| 80 | if (session_thread_runner_->BelongsToCurrentThread()) { |
| 81 | shutdown_synchronously = true; |
| 82 | } else { |
| 83 | session_thread_runner_->PostTask( |
| 84 | FROM_HERE, base::Bind(&MidiManager::ShutdownOnSessionThread, |
| 85 | base::Unretained(this))); |
| 86 | } |
| 87 | session_thread_runner_ = nullptr; |
| 88 | } else { |
| 89 | finalized_ = true; |
| 90 | } |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 91 | } |
toyoshim | f4d6152 | 2017-02-10 02:03:32 -0800 | [diff] [blame^] | 92 | if (shutdown_synchronously) |
| 93 | ShutdownOnSessionThread(); |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 94 | } |
| 95 | |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 96 | void MidiManager::StartSession(MidiManagerClient* client) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 97 | ReportUsage(Usage::SESSION_STARTED); |
| 98 | |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 99 | bool needs_initialization = false; |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 100 | |
| 101 | { |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 102 | base::AutoLock auto_lock(lock_); |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 103 | if (clients_.find(client) != clients_.end() || |
| 104 | pending_clients_.find(client) != pending_clients_.end()) { |
| 105 | // Should not happen. But just in case the renderer is compromised. |
| 106 | NOTREACHED(); |
| 107 | return; |
| 108 | } |
toyoshim@chromium.org | fc2002e | 2014-05-07 08:10:34 +0000 | [diff] [blame] | 109 | |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 110 | // Do not accept a new request if Shutdown() was already called. |
| 111 | if (finalized_) { |
| 112 | client->CompleteStartSession(Result::INITIALIZATION_ERROR); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | if (initialization_state_ == InitializationState::COMPLETED) { |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 117 | // Platform dependent initialization was already finished for previously |
| 118 | // initialized clients. |
| 119 | if (result_ == Result::OK) { |
| 120 | AddInitialPorts(client); |
| 121 | clients_.insert(client); |
| 122 | } |
| 123 | // Complete synchronously with |result_|; |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 124 | client->CompleteStartSession(result_); |
ochang | ae3bae9 | 2016-01-12 19:42:10 -0800 | [diff] [blame] | 125 | return; |
| 126 | } |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 127 | |
| 128 | // Do not accept a new request if the pending client list contains too |
| 129 | // many clients. |
| 130 | if (pending_clients_.size() >= kMaxPendingClientCount) { |
| 131 | client->CompleteStartSession(Result::INITIALIZATION_ERROR); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | if (initialization_state_ == InitializationState::NOT_STARTED) { |
| 136 | // Set fields protected by |lock_| here and call StartInitialization() |
| 137 | // later. |
| 138 | needs_initialization = true; |
| 139 | session_thread_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 140 | initialization_state_ = InitializationState::STARTED; |
| 141 | } |
| 142 | |
| 143 | pending_clients_.insert(client); |
toyoshim@chromium.org | f77a1e6 | 2014-04-11 13:16:24 +0000 | [diff] [blame] | 144 | } |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 145 | |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 146 | if (needs_initialization) { |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 147 | // Lazily initialize the MIDI back-end. |
| 148 | TRACE_EVENT0("midi", "MidiManager::StartInitialization"); |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 149 | // CompleteInitialization() will be called asynchronously when platform |
| 150 | // dependent initialization is finished. |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 151 | StartInitialization(); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 152 | } |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 153 | } |
| 154 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 155 | void MidiManager::EndSession(MidiManagerClient* client) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 156 | ReportUsage(Usage::SESSION_ENDED); |
| 157 | |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 158 | // At this point, |client| can be in the destruction process, and calling |
ochang | ae3bae9 | 2016-01-12 19:42:10 -0800 | [diff] [blame] | 159 | // any method of |client| is dangerous. Calls on clients *must* be protected |
| 160 | // by |lock_| to prevent race conditions. |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 161 | base::AutoLock auto_lock(lock_); |
toyoshim@chromium.org | 1fa678a | 2014-06-13 09:40:33 +0000 | [diff] [blame] | 162 | clients_.erase(client); |
| 163 | pending_clients_.erase(client); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 164 | } |
| 165 | |
toyoshim | 7dd1248 | 2015-04-07 07:02:49 -0700 | [diff] [blame] | 166 | void MidiManager::AccumulateMidiBytesSent(MidiManagerClient* client, size_t n) { |
agoode | ad116b2 | 2015-12-07 00:00:35 -0800 | [diff] [blame] | 167 | base::AutoLock auto_lock(lock_); |
| 168 | if (clients_.find(client) == clients_.end()) |
| 169 | return; |
| 170 | |
agoode | b02d096 | 2015-12-07 19:45:54 -0800 | [diff] [blame] | 171 | // Continue to hold lock_ here in case another thread is currently doing |
| 172 | // EndSession. |
toyoshim | 7dd1248 | 2015-04-07 07:02:49 -0700 | [diff] [blame] | 173 | client->AccumulateMidiBytesSent(n); |
| 174 | } |
| 175 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 176 | void MidiManager::DispatchSendMidiData(MidiManagerClient* client, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 177 | uint32_t port_index, |
| 178 | const std::vector<uint8_t>& data, |
yhirano@chromium.org | c6d5b7b | 2013-12-20 07:27:23 +0000 | [diff] [blame] | 179 | double timestamp) { |
| 180 | NOTREACHED(); |
| 181 | } |
| 182 | |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 183 | void MidiManager::StartInitialization() { |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 184 | CompleteInitialization(Result::NOT_SUPPORTED); |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 185 | } |
| 186 | |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 187 | void MidiManager::CompleteInitialization(Result result) { |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 188 | base::AutoLock auto_lock(lock_); |
| 189 | if (session_thread_runner_) { |
| 190 | session_thread_runner_->PostTask( |
| 191 | FROM_HERE, base::Bind(&MidiManager::CompleteInitializationInternal, |
| 192 | base::Unretained(this), result)); |
| 193 | } |
yhirano@chromium.org | c6d5b7b | 2013-12-20 07:27:23 +0000 | [diff] [blame] | 194 | } |
| 195 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 196 | void MidiManager::AddInputPort(const MidiPortInfo& info) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 197 | ReportUsage(Usage::INPUT_PORT_ADDED); |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 198 | base::AutoLock auto_lock(lock_); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 199 | input_ports_.push_back(info); |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 200 | for (auto* client : clients_) |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 201 | client->AddInputPort(info); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 202 | } |
| 203 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 204 | void MidiManager::AddOutputPort(const MidiPortInfo& info) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 205 | ReportUsage(Usage::OUTPUT_PORT_ADDED); |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 206 | base::AutoLock auto_lock(lock_); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 207 | output_ports_.push_back(info); |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 208 | for (auto* client : clients_) |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 209 | client->AddOutputPort(info); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 210 | } |
| 211 | |
toyoshim | ec2570a | 2016-10-21 02:15:27 -0700 | [diff] [blame] | 212 | void MidiManager::SetInputPortState(uint32_t port_index, PortState state) { |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 213 | base::AutoLock auto_lock(lock_); |
| 214 | DCHECK_LT(port_index, input_ports_.size()); |
| 215 | input_ports_[port_index].state = state; |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 216 | for (auto* client : clients_) |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 217 | client->SetInputPortState(port_index, state); |
| 218 | } |
| 219 | |
toyoshim | ec2570a | 2016-10-21 02:15:27 -0700 | [diff] [blame] | 220 | void MidiManager::SetOutputPortState(uint32_t port_index, PortState state) { |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 221 | base::AutoLock auto_lock(lock_); |
| 222 | DCHECK_LT(port_index, output_ports_.size()); |
| 223 | output_ports_[port_index].state = state; |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 224 | for (auto* client : clients_) |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 225 | client->SetOutputPortState(port_index, state); |
| 226 | } |
| 227 | |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 228 | void MidiManager::ReceiveMidiData(uint32_t port_index, |
| 229 | const uint8_t* data, |
| 230 | size_t length, |
| 231 | double timestamp) { |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 232 | base::AutoLock auto_lock(lock_); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 233 | |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 234 | for (auto* client : clients_) |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 235 | client->ReceiveMidiData(port_index, data, length, timestamp); |
crogers@google.com | 542a43a | 2013-07-31 05:16:49 +0000 | [diff] [blame] | 236 | } |
| 237 | |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 238 | void MidiManager::CompleteInitializationInternal(Result result) { |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 239 | TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 240 | ReportUsage(Usage::INITIALIZED); |
| 241 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.InputPorts", |
| 242 | static_cast<Sample>(input_ports_.size()), |
| 243 | kMaxUmaDevices + 1); |
| 244 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.OutputPorts", |
| 245 | static_cast<Sample>(output_ports_.size()), |
| 246 | kMaxUmaDevices + 1); |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 247 | |
| 248 | base::AutoLock auto_lock(lock_); |
| 249 | DCHECK(clients_.empty()); |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 250 | DCHECK_EQ(initialization_state_, InitializationState::STARTED); |
| 251 | initialization_state_ = InitializationState::COMPLETED; |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 252 | result_ = result; |
| 253 | |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 254 | for (auto* client : pending_clients_) { |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 255 | if (result_ == Result::OK) { |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 256 | AddInitialPorts(client); |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 257 | clients_.insert(client); |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 258 | } |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 259 | client->CompleteStartSession(result_); |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 260 | } |
| 261 | pending_clients_.clear(); |
| 262 | } |
| 263 | |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 264 | void MidiManager::AddInitialPorts(MidiManagerClient* client) { |
| 265 | lock_.AssertAcquired(); |
| 266 | |
| 267 | for (const auto& info : input_ports_) |
| 268 | client->AddInputPort(info); |
| 269 | for (const auto& info : output_ports_) |
| 270 | client->AddOutputPort(info); |
| 271 | } |
| 272 | |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 273 | void MidiManager::ShutdownOnSessionThread() { |
| 274 | Finalize(); |
| 275 | base::AutoLock auto_lock(lock_); |
| 276 | finalized_ = true; |
| 277 | |
| 278 | // Detach all clients so that they do not call MidiManager methods any more. |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 279 | for (auto* client : clients_) |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 280 | client->Detach(); |
| 281 | } |
| 282 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 283 | } // namespace midi |