android.media.midi.MidiDevice Java Examples

The following examples show how to use android.media.midi.MidiDevice. 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: MidiOutputPortImpl.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void openInCurrentThread() {
	TGActivity activity = TGActivityController.getInstance(this.context).getActivity();

	MidiManager midiManager = (MidiManager) activity.getSystemService(Context.MIDI_SERVICE);
	midiManager.openDevice(this.info, new MidiManager.OnDeviceOpenedListener() {
		public void onDeviceOpened(MidiDevice device) {
			try {
				if (device != null) {
					openInputPort(device);
				}
			} finally {
				updateConnectingStatus(false);
			}
		}
	}, new Handler(Looper.getMainLooper()));
}
 
Example #2
Source File: MidiInputPortSelector.java    From media-samples with Apache License 2.0 6 votes vote down vote up
@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.
    }
}
 
Example #3
Source File: MidiDeviceAndroid.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * constructor
 * @param device the underlying device
 */
MidiDeviceAndroid(MidiDevice device) {
    mIsOpen = true;
    mDevice = device;
    // Note we use "input" and "output" in the Web MIDI manner.

    mOutputPorts = new MidiOutputPortAndroid[getInfo().getInputPortCount()];
    for (int i = 0; i < mOutputPorts.length; ++i) {
        mOutputPorts[i] = new MidiOutputPortAndroid(device, i);
    }

    mInputPorts = new MidiInputPortAndroid[getInfo().getOutputPortCount()];
    for (int i = 0; i < mInputPorts.length; ++i) {
        mInputPorts[i] = new MidiInputPortAndroid(device, i);
    }
}
 
Example #4
Source File: MidiInputPortSelector.java    From android-MidiSynth with Apache License 2.0 6 votes vote down vote up
@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.
    }
}
 
Example #5
Source File: MidiInputPortSelector.java    From android-MidiScope with Apache License 2.0 6 votes vote down vote up
@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.
    }
}
 
Example #6
Source File: MidiTest.java    From walt with Apache License 2.0 6 votes vote down vote up
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;
        }
    }
}
 
Example #7
Source File: MidiInputPortSelector.java    From android-midisuite with Apache License 2.0 6 votes vote down vote up
@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.
    }
}
 
Example #8
Source File: MidiInputPortSelector.java    From media-samples with Apache License 2.0 6 votes vote down vote up
@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.
    }
}
 
Example #9
Source File: MainActivity.java    From android-midisuite with Apache License 2.0 6 votes vote down vote up
private void onBluetoothDeviceOpen(final BluetoothDevice bluetoothDevice,
        final MidiDevice midiDevice) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (midiDevice != null) {
                BluetoothMidiDeviceTracker tracker = new BluetoothMidiDeviceTracker(
                        bluetoothDevice, midiDevice);
                mOpenDeviceListAdapter.addDevice(tracker);
            } else {
                Toast.makeText(MainActivity.this,
                        "MIDI device open failed!", Toast.LENGTH_LONG)
                        .show();
            }
        }
    });
}
 
Example #10
Source File: MainActivity.java    From android-midisuite with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent data) {
    if (requestCode == REQUEST_BLUETOOTH_SCAN && resultCode == RESULT_OK) {
        final BluetoothDevice fBluetoothDevice = (BluetoothDevice) data
                .getParcelableExtra("device");
        if (fBluetoothDevice != null) {
            Log.i(TAG, "Bluetooth device name = "
                    + fBluetoothDevice.getName()
                    + ", address = "
                    + fBluetoothDevice.getAddress());
            mMidiManager.openBluetoothDevice(fBluetoothDevice,
                    new MidiManager.OnDeviceOpenedListener() {
                        @Override
                        public void onDeviceOpened(MidiDevice device) {
                            onBluetoothDeviceOpen(fBluetoothDevice, device);
                        }
                    }, null);
        }
    }
}
 
Example #11
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 #12
Source File: MidiOutputPortSelector.java    From android-midisuite with Apache License 2.0 5 votes vote down vote up
@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.
    }
}
 
Example #13
Source File: MidiManagerAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void openDevice(final MidiDeviceInfo info) {
    mManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
        @Override
        public void onDeviceOpened(MidiDevice device) {
            MidiManagerAndroid.this.onDeviceOpened(device, info);
        }
    }, mHandler);
}
 
Example #14
Source File: MidiOutputPortSelector.java    From android-MidiScope with Apache License 2.0 5 votes vote down vote up
@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.
    }
}
 
Example #15
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 #16
Source File: MidiOutputPortSelector.java    From android-MidiSynth with Apache License 2.0 5 votes vote down vote up
@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.
    }
}
 
Example #17
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 #18
Source File: MidiManagerAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #19
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 #20
Source File: MidiOutputPortSelector.java    From media-samples with Apache License 2.0 5 votes vote down vote up
@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.
    }
}
 
Example #21
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 #22
Source File: MidiOutputPortSelector.java    From media-samples with Apache License 2.0 5 votes vote down vote up
@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.
    }
}
 
Example #23
Source File: MidiDeviceAndroid.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the underlying device.
 */
MidiDevice getDevice() {
    return mDevice;
}
 
Example #24
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 #25
Source File: MidiOutputPortConection.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public MidiDevice getMidiDevice() {
	return this.midiDevice;
}
 
Example #26
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 #27
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 #28
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 #29
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 #30
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);
}