| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 package org.chromium.media.midi; | |
| 6 | |
| 7 import android.annotation.TargetApi; | |
| 8 import android.media.midi.MidiDevice; | |
| 9 import android.media.midi.MidiDeviceInfo; | |
| 10 import android.os.Build; | |
| 11 | |
| 12 import org.chromium.base.annotations.CalledByNative; | |
| 13 import org.chromium.base.annotations.JNINamespace; | |
| 14 | |
| 15 @JNINamespace("media::midi") | |
| 16 /** | |
| 17 * A class implementing media::midi::MidiDeviceAndroid functionality. | |
| 18 */ | |
| 19 @TargetApi(Build.VERSION_CODES.M) | |
| 20 class MidiDeviceAndroid { | |
| 21 /** | |
| 22 * The underlying device. | |
| 23 */ | |
| 24 private final MidiDevice mDevice; | |
| 25 /** | |
| 26 * The input ports in the device. | |
| 27 */ | |
| 28 private final MidiInputPortAndroid[] mInputPorts; | |
| 29 /** | |
| 30 * The output ports in the device. | |
| 31 */ | |
| 32 private final MidiOutputPortAndroid[] mOutputPorts; | |
| 33 /** | |
| 34 * True when the device is open. | |
| 35 */ | |
| 36 private boolean mIsOpen; | |
| 37 | |
| 38 /** | |
| 39 * constructor | |
| 40 * @param device the underlying device | |
| 41 */ | |
| 42 MidiDeviceAndroid(MidiDevice device) { | |
| 43 mIsOpen = true; | |
| 44 mDevice = device; | |
| 45 // Note we use "input" and "output" in the Web MIDI manner. | |
| 46 | |
| 47 mOutputPorts = new MidiOutputPortAndroid[getInfo().getInputPortCount()]; | |
| 48 for (int i = 0; i < mOutputPorts.length; ++i) { | |
| 49 mOutputPorts[i] = new MidiOutputPortAndroid(device, i); | |
| 50 } | |
| 51 | |
| 52 mInputPorts = new MidiInputPortAndroid[getInfo().getOutputPortCount()]; | |
| 53 for (int i = 0; i < mInputPorts.length; ++i) { | |
| 54 mInputPorts[i] = new MidiInputPortAndroid(device, i); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 /** | |
| 59 * Returns true when the device is open. | |
| 60 */ | |
| 61 boolean isOpen() { | |
| 62 return mIsOpen; | |
| 63 } | |
| 64 | |
| 65 /** | |
| 66 * Closes the device. | |
| 67 */ | |
| 68 void close() { | |
| 69 mIsOpen = false; | |
| 70 for (MidiInputPortAndroid port : mInputPorts) { | |
| 71 port.close(); | |
| 72 } | |
| 73 for (MidiOutputPortAndroid port : mOutputPorts) { | |
| 74 port.close(); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 /** | |
| 79 * Returns the underlying device. | |
| 80 */ | |
| 81 MidiDevice getDevice() { | |
| 82 return mDevice; | |
| 83 } | |
| 84 | |
| 85 /** | |
| 86 * Returns the underlying device information. | |
| 87 */ | |
| 88 MidiDeviceInfo getInfo() { | |
| 89 return mDevice.getInfo(); | |
| 90 } | |
| 91 | |
| 92 /** | |
| 93 * Returns the manufacturer name. | |
| 94 */ | |
| 95 @CalledByNative | |
| 96 String getManufacturer() { | |
| 97 return getProperty(MidiDeviceInfo.PROPERTY_MANUFACTURER); | |
| 98 } | |
| 99 | |
| 100 /** | |
| 101 * Returns the product name. | |
| 102 */ | |
| 103 @CalledByNative | |
| 104 String getProduct() { | |
| 105 return getProperty(MidiDeviceInfo.PROPERTY_PRODUCT); | |
| 106 } | |
| 107 | |
| 108 /** | |
| 109 * Returns the version string. | |
| 110 */ | |
| 111 @CalledByNative | |
| 112 String getVersion() { | |
| 113 return getProperty(MidiDeviceInfo.PROPERTY_VERSION); | |
| 114 } | |
| 115 | |
| 116 /** | |
| 117 * Returns the associated input ports. | |
| 118 */ | |
| 119 @CalledByNative | |
| 120 MidiInputPortAndroid[] getInputPorts() { | |
| 121 return mInputPorts; | |
| 122 } | |
| 123 | |
| 124 /** | |
| 125 * Returns the associated output ports. | |
| 126 */ | |
| 127 @CalledByNative | |
| 128 MidiOutputPortAndroid[] getOutputPorts() { | |
| 129 return mOutputPorts; | |
| 130 } | |
| 131 | |
| 132 private String getProperty(String name) { | |
| 133 return mDevice.getInfo().getProperties().getString(name); | |
| 134 } | |
| 135 } | |
| OLD | NEW |