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

Unified Diff: media/midi/java/src/org/chromium/media/midi/MidiDeviceAndroid.java

Issue 1177973003: [Web MIDI] Use Android MIDI API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: media/midi/java/src/org/chromium/media/midi/MidiDeviceAndroid.java
diff --git a/media/midi/java/src/org/chromium/media/midi/MidiDeviceAndroid.java b/media/midi/java/src/org/chromium/media/midi/MidiDeviceAndroid.java
new file mode 100644
index 0000000000000000000000000000000000000000..e78784f347630ac0272c72f015baf41a52ab1822
--- /dev/null
+++ b/media/midi/java/src/org/chromium/media/midi/MidiDeviceAndroid.java
@@ -0,0 +1,132 @@
+// Copyright 2015 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.
+
+package org.chromium.media.midi;
+
+import android.media.midi.MidiDevice;
+import android.media.midi.MidiDeviceInfo;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+@JNINamespace("media::midi")
+/**
+ * A class implementing media::midi::MidiDeviceAndroid functionality.
+ */
+class MidiDeviceAndroid {
+ /**
+ * The underlying device.
+ */
+ private MidiDevice mDevice;
+ /**
+ * The input ports in the device.
+ */
+ private MidiInputPortAndroid[] mInputPorts;
+ /**
+ * The output ports in the device.
+ */
+ private MidiOutputPortAndroid[] mOutputPorts;
+ /**
+ * True when the device is open.
+ */
+ private boolean mIsOpen;
+
+ /**
+ * constructor
+ * @param device the underlying device
+ */
+ MidiDeviceAndroid(MidiDevice device) {
+ mIsOpen = true;
+ mDevice = device;
+ // Note we use "input" and "output" in the WebMIDI manner.
+
+ mOutputPorts = new MidiOutputPortAndroid[getInfo().getInputPortCount()];
+ for (int i = 0; i < mOutputPorts.length; ++i) {
+ mOutputPorts[i] = new MidiOutputPortAndroid(device.openInputPort(i));
philburk 2015/08/19 01:40:15 This will open all the input ports on the device i
philburk 2015/08/19 01:40:15 openInputPort() can fail and return null if the po
yhirano 2015/08/19 06:32:02 Done.
yhirano 2015/08/19 06:32:02 Hm, WebMIDI spec has explicit open / close, but we
philburk 2015/08/19 20:22:26 Maybe. I am not sure how your code works. I just k
yhirano 2015/08/20 07:38:29 With this CL MidiInputPort is opened when the firs
Takashi Toyoshima 2015/09/07 16:42:19 Web MIDI introduced open() and close() methods rec
+ }
+
+ mInputPorts = new MidiInputPortAndroid[getInfo().getOutputPortCount()];
+ for (int i = 0; i < mInputPorts.length; ++i) {
+ mInputPorts[i] = new MidiInputPortAndroid(device.openOutputPort(i));
+ }
+ }
+
+ /**
+ * Returns true when the device is open.
+ */
+ boolean isOpen() {
+ return mIsOpen;
+ }
+
+ /**
+ * Closes the device.
+ */
+ void close() {
+ mIsOpen = false;
+ for (MidiInputPortAndroid port: mInputPorts) {
+ port.close();
+ }
+ for (MidiOutputPortAndroid port: mOutputPorts) {
+ port.close();
+ }
+ }
+
+ /**
+ * Returns the underlying device.
+ */
+ MidiDevice getDevice() {
+ return mDevice;
+ }
+
+ /**
+ * Returns the underlying device information.
+ */
+ MidiDeviceInfo getInfo() {
+ return mDevice.getInfo();
+ }
+
+ /**
+ * Returns the manufacturer name.
+ */
+ @CalledByNative
+ String getManufacturer() {
+ return getProperty(MidiDeviceInfo.PROPERTY_MANUFACTURER);
+ }
+
+ /**
+ * Returns the product name.
+ */
+ @CalledByNative
+ String getProduct() {
+ return getProperty(MidiDeviceInfo.PROPERTY_PRODUCT);
+ }
+
+ /**
+ * Returns the version string.
+ */
+ @CalledByNative
+ String getVersion() {
+ return getProperty(MidiDeviceInfo.PROPERTY_VERSION);
+ }
+
+ /**
+ * Returns the associated input ports.
+ */
+ @CalledByNative
+ MidiInputPortAndroid[] getInputPorts() {
+ return mInputPorts;
+ }
+
+ /**
+ * Returns the associated output ports.
+ */
+ @CalledByNative
+ MidiOutputPortAndroid[] getOutputPorts() {
+ return mOutputPorts;
+ }
+
+ private String getProperty(String name) {
+ return mDevice.getInfo().getProperties().getString(name);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698