android.media.midi.MidiDeviceStatus Java Examples

The following examples show how to use android.media.midi.MidiDeviceStatus. 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: MidiDeviceMonitor.java    From android-midisuite with Apache License 2.0 6 votes vote down vote up
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
    for(Map.Entry<DeviceCallback, Handler> item : mCallbacks.entrySet()) {
        final DeviceCallback callback = item.getKey();
        Handler handler = item.getValue();
        if(handler == null) {
            callback.onDeviceStatusChanged(status);
        } else {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    callback.onDeviceStatusChanged(status);
                }
            });
        }
    }
}
 
Example #2
Source File: MidiScope.java    From media-samples with Apache License 2.0 5 votes vote down vote up
/**
 * This will get called when clients connect or disconnect.
 * Log device information.
 */
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
    if (mScopeLogger != null) {
        if (status.isInputPortOpen(0)) {
            mScopeLogger.log("=== connected ===");
            String text = MidiPrinter.formatDeviceInfo(
                    status.getDeviceInfo());
            mScopeLogger.log(text);
        } else {
            mScopeLogger.log("--- disconnected ---");
        }
    }
}
 
Example #3
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 #4
Source File: MidiSynthDeviceService.java    From media-samples with Apache License 2.0 5 votes vote down vote up
/**
 * This will get called when clients connect or disconnect.
 */
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
    if (status.isInputPortOpen(0) && !mSynthStarted) {
        mSynthEngine.start();
        mSynthStarted = true;
    } else if (!status.isInputPortOpen(0) && mSynthStarted) {
        mSynthEngine.stop();
        mSynthStarted = false;
    }
}
 
Example #5
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 #6
Source File: MidiSynthDeviceService.java    From android-MidiSynth with Apache License 2.0 5 votes vote down vote up
/**
 * This will get called when clients connect or disconnect.
 */
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
    if (status.isInputPortOpen(0) && !mSynthStarted) {
        mSynthEngine.start();
        mSynthStarted = true;
    } else if (!status.isInputPortOpen(0) && mSynthStarted) {
        mSynthEngine.stop();
        mSynthStarted = false;
    }
}
 
Example #7
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 #8
Source File: MidiScope.java    From android-MidiScope with Apache License 2.0 5 votes vote down vote up
/**
 * This will get called when clients connect or disconnect.
 * Log device information.
 */
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
    if (mScopeLogger != null) {
        if (status.isInputPortOpen(0)) {
            mScopeLogger.log("=== connected ===");
            String text = MidiPrinter.formatDeviceInfo(
                    status.getDeviceInfo());
            mScopeLogger.log(text);
        } else {
            mScopeLogger.log("--- disconnected ---");
        }
    }
}
 
Example #9
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 #10
Source File: MidiScope.java    From android-midisuite with Apache License 2.0 5 votes vote down vote up
/**
 * This will get called when clients connect or disconnect.
 * Log device information.
 */
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
    if (mScopeLogger != null) {
        if (status.isInputPortOpen(0)) {
            mScopeLogger.log("=== connected ===");
            String text = MidiPrinter.formatDeviceInfo(
                    status.getDeviceInfo());
            mScopeLogger.log(text);
        } else {
            mScopeLogger.log("--- disconnected ---");
        }
    }
}
 
Example #11
Source File: MidiSynthDeviceService.java    From android-midisuite with Apache License 2.0 5 votes vote down vote up
/**
 * This will get called when clients connect or disconnect.
 */
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
    if (status.isInputPortOpen(0) && !mSynthStarted) {
        mSynthEngine.start();
        mSynthStarted = true;
    } else if (!status.isInputPortOpen(0) && mSynthStarted){
        mSynthEngine.stop();
        mSynthStarted = false;
    }
}
 
Example #12
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();
                    }
                }
            }
        }
    }
}