android.media.midi.MidiInputPort Java Examples

The following examples show how to use android.media.midi.MidiInputPort. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MidiPortConnector.java    From media-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #2
Source File: MidiPortConnector.java    From media-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: MidiPortConnector.java    From android-MidiSynth with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: MidiPortConnector.java    From android-MidiScope with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: MidiPortConnector.java    From android-midisuite with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: MidiPortConnector.java    From media-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Open two devices and connect their ports.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationDeviceInfo
 * @param destinationPortIndex
 */
public void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiDeviceInfo destinationDeviceInfo,
        final int destinationPortIndex,
        final OnPortsConnectedListener listener, final Handler handler) {
    safeClose();
    mMidiManager.openDevice(destinationDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice destinationDevice) {
                    if (destinationDevice == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + destinationDeviceInfo);
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        mDestinationDevice = destinationDevice;
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + destinationDeviceInfo);
                        // Destination device was opened so go to next step.
                        MidiInputPort destinationInputPort = destinationDevice
                                .openInputPort(destinationPortIndex);
                        if (destinationInputPort != null) {
                            Log.i(MidiConstants.TAG,
                                    "connectToDevicePort opened port on "
                                            + destinationDeviceInfo);
                            connectToDevicePort(sourceDeviceInfo,
                                    sourcePortIndex,
                                    destinationInputPort,
                                    listener, handler);
                        } else {
                            Log.e(MidiConstants.TAG,
                                    "could not open port on "
                                            + destinationDeviceInfo);
                            safeClose();
                            if (listener != null) {
                                listener.onPortsConnected(null);
                            }
                        }
                    }
                }
            }, handler);
}
 
Example #7
Source File: MidiPortConnector.java    From media-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Open two devices and connect their ports.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationDeviceInfo
 * @param destinationPortIndex
 */
public void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiDeviceInfo destinationDeviceInfo,
        final int destinationPortIndex,
        final OnPortsConnectedListener listener, final Handler handler) {
    safeClose();
    mMidiManager.openDevice(destinationDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice destinationDevice) {
                    if (destinationDevice == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + destinationDeviceInfo);
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        mDestinationDevice = destinationDevice;
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + destinationDeviceInfo);
                        // Destination device was opened so go to next step.
                        MidiInputPort destinationInputPort = destinationDevice
                                .openInputPort(destinationPortIndex);
                        if (destinationInputPort != null) {
                            Log.i(MidiConstants.TAG,
                                    "connectToDevicePort opened port on "
                                            + destinationDeviceInfo);
                            connectToDevicePort(sourceDeviceInfo,
                                    sourcePortIndex,
                                    destinationInputPort,
                                    listener, handler);
                        } else {
                            Log.e(MidiConstants.TAG,
                                    "could not open port on "
                                            + destinationDeviceInfo);
                            safeClose();
                            if (listener != null) {
                                listener.onPortsConnected(null);
                            }
                        }
                    }
                }
            }, handler);
}
 
Example #8
Source File: MidiOutputPortImpl.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void openInputPort(MidiDevice device) {
	MidiInputPort port = device.openInputPort(this.portInfo.getPortNumber());
	if( port != null ) {
		this.connection.connect(device, port);
	}
}
 
Example #9
Source File: MidiOutputPortConection.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void connect(MidiDevice midiDevice, MidiInputPort midiInputPort) {
	this.midiDevice = midiDevice;
	this.midiInputPort = midiInputPort;
}
 
Example #10
Source File: MidiOutputPortConection.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public MidiInputPort getMidiInputPort() {
	return this.midiInputPort;
}
 
Example #11
Source File: MidiPortConnector.java    From android-MidiSynth with Apache License 2.0 4 votes vote down vote up
/**
 * Open two devices and connect their ports.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationDeviceInfo
 * @param destinationPortIndex
 */
public void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiDeviceInfo destinationDeviceInfo,
        final int destinationPortIndex,
        final OnPortsConnectedListener listener, final Handler handler) {
    safeClose();
    mMidiManager.openDevice(destinationDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice destinationDevice) {
                    if (destinationDevice == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + destinationDeviceInfo);
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        mDestinationDevice = destinationDevice;
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + destinationDeviceInfo);
                        // Destination device was opened so go to next step.
                        MidiInputPort destinationInputPort = destinationDevice
                                .openInputPort(destinationPortIndex);
                        if (destinationInputPort != null) {
                            Log.i(MidiConstants.TAG,
                                    "connectToDevicePort opened port on "
                                            + destinationDeviceInfo);
                            connectToDevicePort(sourceDeviceInfo,
                                    sourcePortIndex,
                                    destinationInputPort,
                                    listener, handler);
                        } else {
                            Log.e(MidiConstants.TAG,
                                    "could not open port on "
                                            + destinationDeviceInfo);
                            safeClose();
                            if (listener != null) {
                                listener.onPortsConnected(null);
                            }
                        }
                    }
                }
            }, handler);
}
 
Example #12
Source File: MidiPortConnector.java    From android-MidiScope with Apache License 2.0 4 votes vote down vote up
/**
 * Open two devices and connect their ports.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationDeviceInfo
 * @param destinationPortIndex
 */
public void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiDeviceInfo destinationDeviceInfo,
        final int destinationPortIndex,
        final OnPortsConnectedListener listener, final Handler handler) {
    safeClose();
    mMidiManager.openDevice(destinationDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice destinationDevice) {
                    if (destinationDevice == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + destinationDeviceInfo);
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        mDestinationDevice = destinationDevice;
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + destinationDeviceInfo);
                        // Destination device was opened so go to next step.
                        MidiInputPort destinationInputPort = destinationDevice
                                .openInputPort(destinationPortIndex);
                        if (destinationInputPort != null) {
                            Log.i(MidiConstants.TAG,
                                    "connectToDevicePort opened port on "
                                            + destinationDeviceInfo);
                            connectToDevicePort(sourceDeviceInfo,
                                    sourcePortIndex,
                                    destinationInputPort,
                                    listener, handler);
                        } else {
                            Log.e(MidiConstants.TAG,
                                    "could not open port on "
                                            + destinationDeviceInfo);
                            safeClose();
                            if (listener != null) {
                                listener.onPortsConnected(null);
                            }
                        }
                    }
                }
            }, handler);
}
 
Example #13
Source File: MidiPortConnector.java    From android-midisuite with Apache License 2.0 4 votes vote down vote up
/**
 * Open two devices and connect their ports.
 * Then notify listener of the result.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationDeviceInfo
 * @param destinationPortIndex
 * @param listener
 * @param handler
 */
public void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiDeviceInfo destinationDeviceInfo,
        final int destinationPortIndex,
        final OnPortsConnectedListener listener, final Handler handler) {
    safeClose();
    mMidiManager.openDevice(destinationDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice destinationDevice) {
                    if (destinationDevice == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + destinationDeviceInfo);
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        mDestinationDevice = destinationDevice;
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + destinationDeviceInfo);
                        // Destination device was opened so go to next step.
                        MidiInputPort destinationInputPort = destinationDevice
                                .openInputPort(destinationPortIndex);
                        if (destinationInputPort != null) {
                            Log.i(MidiConstants.TAG,
                                    "connectToDevicePort opened port on "
                                            + destinationDeviceInfo);
                            connectToDevicePort(sourceDeviceInfo,
                                    sourcePortIndex,
                                    destinationInputPort,
                                    listener, handler);
                        } else {
                            Log.e(MidiConstants.TAG,
                                    "could not open port on "
                                            + destinationDeviceInfo);
                            safeClose();
                            if (listener != null) {
                                listener.onPortsConnected(null);
                            }
                        }
                    }
                }
            }, handler);
}