Java Code Examples for android.media.midi.MidiDeviceInfo#getInputPortCount()

The following examples show how to use android.media.midi.MidiDeviceInfo#getInputPortCount() . 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: MidiPortSelector.java    From media-samples with Apache License 2.0 5 votes vote down vote up
@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();
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: MidiPortSelector.java    From media-samples with Apache License 2.0 5 votes vote down vote up
@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();
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: MidiOutputPortProviderImpl.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public List<MidiOutputPort> listPorts() {
	if( this.ports == null ) {
		this.ports = new ArrayList<MidiOutputPort>();
	} else {
		this.ports.clear();
	}

	if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M ) {
		TGActivity activity = TGActivityController.getInstance(this.context).getActivity();
		if( activity != null && activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
			MidiManager midiManager = (MidiManager) activity.getSystemService(Context.MIDI_SERVICE);
			MidiDeviceInfo[] infos = midiManager.getDevices();
			for(MidiDeviceInfo info : infos) {
				if( info.getInputPortCount() > 0 ) {
					MidiDeviceInfo.PortInfo[] portInfos = info.getPorts();
					for(MidiDeviceInfo.PortInfo portInfo : portInfos) {
						if( portInfo.getType() == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
							this.ports.add(new MidiOutputPortImpl(this.context, info, portInfo));
						}
					}
				}
			}
		}
	}

	return this.ports;
}
 
Example 4
Source File: MidiPortSelector.java    From android-MidiSynth with Apache License 2.0 5 votes vote down vote up
@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();
                    }
                }
            }
        }
    }
}
 
Example 5
Source File: MidiPortSelector.java    From android-MidiScope with Apache License 2.0 5 votes vote down vote up
@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();
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: MidiPortSelector.java    From android-midisuite with Apache License 2.0 5 votes vote down vote up
@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();
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: MidiPortSelector.java    From media-samples with Apache License 2.0 4 votes vote down vote up
private int getInfoPortCount(final MidiDeviceInfo info) {
    int portCount = (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT)
            ? info.getInputPortCount() : info.getOutputPortCount();
    return portCount;
}
 
Example 8
Source File: MidiPortSelector.java    From media-samples with Apache License 2.0 4 votes vote down vote up
private int getInfoPortCount(final MidiDeviceInfo info) {
    int portCount = (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT)
            ? info.getInputPortCount() : info.getOutputPortCount();
    return portCount;
}
 
Example 9
Source File: MidiPortSelector.java    From android-MidiSynth with Apache License 2.0 4 votes vote down vote up
private int getInfoPortCount(final MidiDeviceInfo info) {
    int portCount = (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT)
            ? info.getInputPortCount() : info.getOutputPortCount();
    return portCount;
}
 
Example 10
Source File: MidiPortSelector.java    From android-MidiScope with Apache License 2.0 4 votes vote down vote up
private int getInfoPortCount(final MidiDeviceInfo info) {
    int portCount = (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT)
            ? info.getInputPortCount() : info.getOutputPortCount();
    return portCount;
}
 
Example 11
Source File: MidiPortSelector.java    From android-midisuite with Apache License 2.0 4 votes vote down vote up
private int getInfoPortCount(final MidiDeviceInfo info) {
    int portCount = (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT)
            ? info.getInputPortCount() : info.getOutputPortCount();
    return portCount;
}