Java 类android.media.midi.MidiDeviceInfo 实例源码

项目:buildAPKsSamples    文件:MidiPrinter.java   
public static String formatDeviceInfo(MidiDeviceInfo info) {
    StringBuilder sb = new StringBuilder();
    if (info != null) {
        Bundle properties = info.getProperties();
        for (String key : properties.keySet()) {
            Object value = properties.get(key);
            sb.append(key).append(" = ").append(value).append('\n');
        }
        for (PortInfo port : info.getPorts()) {
            sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input"
                    : "output");
            sb.append("[").append(port.getPortNumber()).append("] = \"").append(port.getName()
                    + "\"\n");
        }
    }
    return sb.toString();
}
项目:buildAPKsSamples    文件:MidiInputPortSelector.java   
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
项目:buildAPKsSamples    文件:MidiTools.java   
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
项目:buildAPKsSamples    文件:MidiPortWrapper.java   
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
项目:buildAPKsSamples    文件:MidiInputPortSelector.java   
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
项目:buildAPKsSamples    文件:MidiTools.java   
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
项目:buildAPKsSamples    文件:MidiPortWrapper.java   
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
项目:walt    文件:MidiTest.java   
private void findMidiDevice() {
    MidiDeviceInfo[] infos = midiManager.getDevices();
    for(MidiDeviceInfo info : infos) {
        String name = info.getProperties().getString(MidiDeviceInfo.PROPERTY_NAME);
        logger.log("Found MIDI device named " + name);
        if(TEENSY_MIDI_NAME.equals(name)) {
            logger.log("^^^ using this device ^^^");
            isConnecting = true;
            midiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice device) {
                    if (device == null) {
                        logger.log("Error, unable to open MIDI device");
                    } else {
                        logger.log("Opened MIDI device successfully!");
                        midiDevice = device;
                    }
                    isConnecting = false;
                }
            }, null);
            break;
        }
    }
}
项目:android-midisuite    文件:MidiPrinter.java   
public static String formatDeviceInfo(MidiDeviceInfo info) {
    StringBuilder sb = new StringBuilder();
    if (info != null) {
        Bundle properties = info.getProperties();
        for (String key : properties.keySet()) {
            Object value = properties.get(key);
            sb.append(key).append(" = ").append(value).append('\n');
        }
        for (PortInfo port : info.getPorts()) {
            sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input"
                    : "output");
            sb.append("[").append(port.getPortNumber()).append("] = \"").append(port.getName()
                    + "\"\n");
        }
    }
    return sb.toString();
}
项目:android-midisuite    文件:MidiInputPortSelector.java   
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
项目:android-midisuite    文件:MidiTools.java   
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
项目:android-midisuite    文件:MidiDeviceMonitor.java   
@Override
public void onDeviceAdded(final MidiDeviceInfo device) {
    // Call all of the locally registered callbacks.
    for(Map.Entry<DeviceCallback, Handler> item : mCallbacks.entrySet()) {
        final DeviceCallback callback = item.getKey();
        Handler handler = item.getValue();
        if(handler == null) {
            callback.onDeviceAdded(device);
        } else {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    callback.onDeviceAdded(device);
                }
            });
        }
    }
}
项目:android-midisuite    文件:MidiDeviceMonitor.java   
@Override
public void onDeviceRemoved(final MidiDeviceInfo device) {
    for(Map.Entry<DeviceCallback, Handler> item : mCallbacks.entrySet()) {
        final DeviceCallback callback = item.getKey();
        Handler handler = item.getValue();
        if(handler == null) {
            callback.onDeviceRemoved(device);
        } else {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    callback.onDeviceRemoved(device);
                }
            });
        }
    }
}
项目:android-midisuite    文件:MidiPortWrapper.java   
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
项目:LiveNotes    文件:MidiReceiver.java   
private void registerDeviceAddedCallback(final MidiManager midiManager) {
    midiManager.registerDeviceCallback(new MidiManager.DeviceCallback() {
        @Override
        public void onDeviceAdded(MidiDeviceInfo device) {
            if (device.getOutputPortCount() > 0) {
                midiManager.unregisterDeviceCallback(this);
                openDevice(midiManager, device);
            }
        }
    }, null);
}
项目:LiveNotes    文件:MidiReceiver.java   
@Override
public void onDeviceOpened(MidiDevice device) {
    this.device = device;
    stream(device.getInfo().getPorts())
            .filter(port -> port.getType() == MidiDeviceInfo.PortInfo.TYPE_OUTPUT).findFirst()
            .ifPresent(port -> device.openOutputPort(port.getPortNumber()).connect(this));
}
项目:buildAPKsSamples    文件:MidiOutputPortSelector.java   
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    Log.i(MidiConstants.TAG, "onPortSelected: " + wrapper);
    close();

    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {

                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mOutputPort = device.openOutputPort(wrapper.getPortIndex());
                    if (mOutputPort == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open output port for " + info);
                        return;
                    }
                    mOutputPort.connect(mDispatcher);
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openOutputPort might take a while.
    }
}
项目:buildAPKsSamples    文件:MidiPortSelector.java   
@Override
public void onDeviceAdded(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        mAdapter.add(wrapper);
        Log.i(MidiConstants.TAG, wrapper + " was added");
        mAdapter.notifyDataSetChanged();
    }
}
项目:buildAPKsSamples    文件:MidiPortSelector.java   
@Override
public void onDeviceRemoved(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        MidiPortWrapper currentWrapper = mCurrentWrapper;
        mAdapter.remove(wrapper);
        // If the currently selected port was removed then select no port.
        if (wrapper.equals(currentWrapper)) {
            clearSelection();
        }
        mAdapter.notifyDataSetChanged();
        Log.i(MidiConstants.TAG, wrapper + " was removed");
    }
}
项目:buildAPKsSamples    文件:MidiPortSelector.java   
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
    // If an input port becomes busy then remove it from the menu.
    // If it becomes free then add it back to the menu.
    if (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
        MidiDeviceInfo info = status.getDeviceInfo();
        Log.i(MidiConstants.TAG, "MidiPortSelector.onDeviceStatusChanged status = " + status
                + ", mType = " + mType
                + ", activity = " + mActivity.getPackageName()
                + ", info = " + info);
        // Look for transitions from free to busy.
        int portCount = info.getInputPortCount();
        for (int i = 0; i < portCount; ++i) {
            MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
            if (!wrapper.equals(mCurrentWrapper)) {
                if (status.isInputPortOpen(i)) { // busy?
                    if (!mBusyPorts.contains(wrapper)) {
                        // was free, now busy
                        mBusyPorts.add(wrapper);
                        mAdapter.remove(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (mBusyPorts.remove(wrapper)) {
                        // was busy, now free
                        mAdapter.add(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
    }
}
项目:buildAPKsSamples    文件:MidiOutputPortConnectionSelector.java   
/**
 * @param midiManager
 * @param activity
 * @param spinnerId
 * @param type
 */
public MidiOutputPortConnectionSelector(MidiManager midiManager,
        Activity activity, int spinnerId,
        MidiDeviceInfo destinationDeviceInfo, int destinationPortIndex) {
    super(midiManager, activity, spinnerId,
            MidiDeviceInfo.PortInfo.TYPE_OUTPUT);
    mDestinationDeviceInfo = destinationDeviceInfo;
    mDestinationPortIndex = destinationPortIndex;
}
项目:buildAPKsSamples    文件:MidiPortConnector.java   
/**
 * Open a source device and connect its output port to the
 * destinationInputPort.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationInputPort
 */
private void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiInputPort destinationInputPort,
        final OnPortsConnectedListener listener, final Handler handler) {
    mMidiManager.openDevice(sourceDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice device) {
                    if (device == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + sourceDeviceInfo);
                        safeClose();
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + sourceDeviceInfo);
                        // Device was opened so connect the ports.
                        mSourceDevice = device;
                        mConnection = device.connectPorts(
                                destinationInputPort, sourcePortIndex);
                        if (mConnection == null) {
                            Log.e(MidiConstants.TAG, "could not connect to "
                                    + sourceDeviceInfo);
                            safeClose();
                        }
                        if (listener != null) {
                            listener.onPortsConnected(mConnection);
                        }
                    }
                }
            }, handler);
}
项目:buildAPKsSamples    文件:MainActivity.java   
private void setupMidi() {
    // Setup MIDI
    mMidiManager = (MidiManager) getSystemService(MIDI_SERVICE);

    MidiDeviceInfo synthInfo = MidiTools.findDevice(mMidiManager, "AndroidTest",
            "SynthExample");
    int portIndex = 0;
    mPortSelector = new MidiOutputPortConnectionSelector(mMidiManager, this,
            R.id.spinner_synth_sender, synthInfo, portIndex);
    mPortSelector.setConnectedListener(new MyPortsConnectedListener());
}
项目:buildAPKsSamples    文件:MidiOutputPortSelector.java   
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    Log.i(MidiConstants.TAG, "onPortSelected: " + wrapper);
    close();

    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {

                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mOutputPort = device.openOutputPort(wrapper.getPortIndex());
                    if (mOutputPort == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open output port for " + info);
                        return;
                    }
                    mOutputPort.connect(mDispatcher);
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openOutputPort might take a while.
    }
}
项目:buildAPKsSamples    文件:MidiPortSelector.java   
@Override
public void onDeviceAdded(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        mAdapter.add(wrapper);
        Log.i(MidiConstants.TAG, wrapper + " was added");
        mAdapter.notifyDataSetChanged();
    }
}
项目:buildAPKsSamples    文件:MidiPortSelector.java   
@Override
public void onDeviceRemoved(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        MidiPortWrapper currentWrapper = mCurrentWrapper;
        mAdapter.remove(wrapper);
        // If the currently selected port was removed then select no port.
        if (wrapper.equals(currentWrapper)) {
            clearSelection();
        }
        mAdapter.notifyDataSetChanged();
        Log.i(MidiConstants.TAG, wrapper + " was removed");
    }
}
项目:buildAPKsSamples    文件:MidiPortSelector.java   
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
    // If an input port becomes busy then remove it from the menu.
    // If it becomes free then add it back to the menu.
    if (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
        MidiDeviceInfo info = status.getDeviceInfo();
        Log.i(MidiConstants.TAG, "MidiPortSelector.onDeviceStatusChanged status = " + status
                + ", mType = " + mType
                + ", activity = " + mActivity.getPackageName()
                + ", info = " + info);
        // Look for transitions from free to busy.
        int portCount = info.getInputPortCount();
        for (int i = 0; i < portCount; ++i) {
            MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
            if (!wrapper.equals(mCurrentWrapper)) {
                if (status.isInputPortOpen(i)) { // busy?
                    if (!mBusyPorts.contains(wrapper)) {
                        // was free, now busy
                        mBusyPorts.add(wrapper);
                        mAdapter.remove(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (mBusyPorts.remove(wrapper)) {
                        // was busy, now free
                        mAdapter.add(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
    }
}
项目:buildAPKsSamples    文件:MidiOutputPortConnectionSelector.java   
/**
 * @param midiManager
 * @param activity
 * @param spinnerId
 * @param type
 */
public MidiOutputPortConnectionSelector(MidiManager midiManager,
        Activity activity, int spinnerId,
        MidiDeviceInfo destinationDeviceInfo, int destinationPortIndex) {
    super(midiManager, activity, spinnerId,
            MidiDeviceInfo.PortInfo.TYPE_OUTPUT);
    mDestinationDeviceInfo = destinationDeviceInfo;
    mDestinationPortIndex = destinationPortIndex;
}
项目:buildAPKsSamples    文件:MidiPortConnector.java   
/**
 * Open a source device and connect its output port to the
 * destinationInputPort.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationInputPort
 */
private void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiInputPort destinationInputPort,
        final OnPortsConnectedListener listener, final Handler handler) {
    mMidiManager.openDevice(sourceDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice device) {
                    if (device == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + sourceDeviceInfo);
                        safeClose();
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + sourceDeviceInfo);
                        // Device was opened so connect the ports.
                        mSourceDevice = device;
                        mConnection = device.connectPorts(
                                destinationInputPort, sourcePortIndex);
                        if (mConnection == null) {
                            Log.e(MidiConstants.TAG, "could not connect to "
                                    + sourceDeviceInfo);
                            safeClose();
                        }
                        if (listener != null) {
                            listener.onPortsConnected(mConnection);
                        }
                    }
                }
            }, handler);
}
项目:JinsMemeBRIDGE-Android    文件:MemeMIDI.java   
public static boolean checkUsbMidi(Context context) {
  MidiManager midiManager = (MidiManager) context.getSystemService(Context.MIDI_SERVICE);
  if (midiManager != null) {
    final MidiDeviceInfo[] infos = midiManager.getDevices();
    if (infos.length > 0) {
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}
项目:365browser    文件:MidiDeviceAndroid.java   
/**
 * Returns the product name.
 */
@CalledByNative
String getProduct() {
    String product = getProperty(MidiDeviceInfo.PROPERTY_PRODUCT);
    // TODO(crbug.com/636455): Following code to use PROPERTY_NAME is a
    // workaround for a BLE MIDI device issue that Android does not provide
    // information for PROPERTY_MANUFACTURER, PROPERTY_PRODUCT, and
    // PROPERTY_VERSION. Confirmed on Android M and N.
    // See discussion at http://crbug.com/636455 and http://b/32259464.
    if (product == null || product.isEmpty()) {
        return getProperty(MidiDeviceInfo.PROPERTY_NAME);
    }
    return product;
}
项目:365browser    文件:MidiManagerAndroid.java   
private void openDevice(final MidiDeviceInfo info) {
    mManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
        @Override
        public void onDeviceOpened(MidiDevice device) {
            MidiManagerAndroid.this.onDeviceOpened(device, info);
        }
    }, mHandler);
}
项目:365browser    文件:MidiManagerAndroid.java   
/**
 * Called when a midi device is attached.
 * @param info the attached device information.
 */
private void onDeviceAdded(final MidiDeviceInfo info) {
    if (!mIsInitialized) {
        mPendingDevices.add(info);
    }
    openDevice(info);
}
项目:365browser    文件:MidiManagerAndroid.java   
/**
 * Called when a midi device is detached.
 * @param info the detached device information.
 */
private void onDeviceRemoved(MidiDeviceInfo info) {
    for (MidiDeviceAndroid device : mDevices) {
        if (device.isOpen() && device.getInfo().getId() == info.getId()) {
            device.close();
            nativeOnDetached(mNativeManagerPointer, device);
        }
    }
}
项目:365browser    文件:MidiManagerAndroid.java   
private void onDeviceOpened(MidiDevice device, MidiDeviceInfo info) {
    mPendingDevices.remove(info);
    if (device != null) {
        MidiDeviceAndroid xdevice = new MidiDeviceAndroid(device);
        mDevices.add(xdevice);
        if (mIsInitialized) {
            nativeOnAttached(mNativeManagerPointer, xdevice);
        }
    }
    if (!mIsInitialized && mPendingDevices.isEmpty()) {
        nativeOnInitialized(mNativeManagerPointer, mDevices.toArray(new MidiDeviceAndroid[0]));
        mIsInitialized = true;
    }
}
项目:android-midisuite    文件:MainActivity.java   
private void setupMidi() {
    // Setup MIDI
    mMidiManager = (MidiManager) getSystemService(MIDI_SERVICE);

    MidiDeviceInfo synthInfo =  MidiTools.findDevice(mMidiManager, "Mobileer",
            "SynthExample");
    int portIndex = 0;
    mPortSelector = new MidiOutputPortConnectionSelector(mMidiManager, this,
            R.id.spinner_synth_sender, synthInfo, portIndex);
    mPortSelector.setConnectedListener(new MyPortsConnectedListener());
}
项目:android-midisuite    文件:MidiOutputPortSelector.java   
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();

    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {

                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mOutputPort = device.openOutputPort(wrapper.getPortIndex());
                    if (mOutputPort == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open output port for " + info);
                        return;
                    }
                    mOutputPort.connect(mDispatcher);
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openOutputPort might take a while.
    }
}
项目:android-midisuite    文件:MidiPortSelector.java   
@Override
public void onDeviceAdded(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        mAdapter.add(wrapper);
        Log.i(MidiConstants.TAG, wrapper + " was added to " + this);
        mAdapter.notifyDataSetChanged();
    }
}
项目:android-midisuite    文件:MidiPortSelector.java   
@Override
public void onDeviceRemoved(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        MidiPortWrapper currentWrapper = mCurrentWrapper;
        mAdapter.remove(wrapper);
        // If the currently selected port was removed then select no port.
        if (wrapper.equals(currentWrapper)) {
            clearSelection();
        }
        mAdapter.notifyDataSetChanged();
        Log.i(MidiConstants.TAG, wrapper + " was removed");
    }
}
项目:android-midisuite    文件:MidiPortSelector.java   
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
    // If an input port becomes busy then remove it from the menu.
    // If it becomes free then add it back to the menu.
    if (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
        MidiDeviceInfo info = status.getDeviceInfo();
        Log.i(MidiConstants.TAG, "MidiPortSelector.onDeviceStatusChanged status = " + status
                + ", mType = " + mType
                + ", activity = " + mActivity.getPackageName()
                + ", info = " + info);
        // Look for transitions from free to busy.
        int portCount = info.getInputPortCount();
        for (int i = 0; i < portCount; ++i) {
            MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
            if (!wrapper.equals(mCurrentWrapper)) {
                if (status.isInputPortOpen(i)) { // busy?
                    if (!mBusyPorts.contains(wrapper)) {
                        // was free, now busy
                        mBusyPorts.add(wrapper);
                        mAdapter.remove(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (mBusyPorts.remove(wrapper)) {
                        // was busy, now free
                        mAdapter.add(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
    }
}