android.media.midi.MidiManager Java Examples
The following examples show how to use
android.media.midi.MidiManager.
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: MidiInputPortSelector.java From media-samples with Apache License 2.0 | 6 votes |
@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 #2
Source File: MidiOutputPortImpl.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
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 #3
Source File: MidiTest.java From walt with Apache License 2.0 | 6 votes |
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 #4
Source File: MidiInputPortSelector.java From android-MidiSynth with Apache License 2.0 | 6 votes |
@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: MidiTools.java From media-samples with Apache License 2.0 | 6 votes |
/** * @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; }
Example #6
Source File: MidiTools.java From android-MidiSynth with Apache License 2.0 | 6 votes |
/** * @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; }
Example #7
Source File: MidiInputPortSelector.java From android-MidiScope with Apache License 2.0 | 6 votes |
@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: MidiTools.java From android-midisuite with Apache License 2.0 | 6 votes |
/** * @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; }
Example #9
Source File: MainActivity.java From android-midisuite with Apache License 2.0 | 6 votes |
@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 #10
Source File: MidiInputPortSelector.java From media-samples with Apache License 2.0 | 6 votes |
@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 #11
Source File: MidiTools.java From media-samples with Apache License 2.0 | 6 votes |
/** * @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; }
Example #12
Source File: MidiInputPortSelector.java From android-midisuite with Apache License 2.0 | 6 votes |
@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 #13
Source File: MidiTools.java From android-MidiScope with Apache License 2.0 | 6 votes |
/** * @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; }
Example #14
Source File: MainActivity.java From android-midisuite with Apache License 2.0 | 5 votes |
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()); }
Example #15
Source File: MidiOutputPortProviderImpl.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
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 #16
Source File: MidiManagerAndroid.java From 365browser with Apache License 2.0 | 5 votes |
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 #17
Source File: MainActivity.java From android-MidiSynth with Apache License 2.0 | 5 votes |
private void setupMidi() { // Setup MIDI MidiManager midiManager = (MidiManager) getSystemService(MIDI_SERVICE); MidiDeviceInfo synthInfo = MidiTools.findDevice(midiManager, "AndroidTest", "SynthExample"); int portIndex = 0; mPortSelector = new MidiOutputPortConnectionSelector(midiManager, this, R.id.spinner_synth_sender, synthInfo, portIndex); mPortSelector.setConnectedListener(new MyPortsConnectedListener()); }
Example #18
Source File: MidiOutputPortSelector.java From android-MidiSynth with Apache License 2.0 | 5 votes |
@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 #19
Source File: MidiOutputPortConnectionSelector.java From android-MidiSynth with Apache License 2.0 | 5 votes |
/** * @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; }
Example #20
Source File: MainActivity.java From android-midisuite with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLog = (TextView) findViewById(R.id.log); mScroller = (ScrollView) findViewById(R.id.scroll); // Setup MIDI mMidiManager = (MidiManager) getSystemService(MIDI_SERVICE); // Receiver that prints the messages. mLoggingReceiver = new LoggingReceiver(this); // Receivers that parses raw data into complete messages. mConnectFramer = new MidiFramer(mLoggingReceiver); // Setup a menu to select an input source. mLogSenderSelector = new MidiOutputPortSelector(mMidiManager, this, R.id.spinner_senders) { @Override public void onPortSelected(final MidiPortWrapper wrapper) { super.onPortSelected(wrapper); if (wrapper != null) { log(MidiPrinter.formatDeviceInfo(wrapper.getDeviceInfo())); } } }; mDirectReceiver = new MyDirectReceiver(); mLogSenderSelector.getSender().connect(mDirectReceiver); // Tell the virtual device to log its messages here.. MidiScope.setScopeLogger(this); }
Example #21
Source File: MidiPortConnector.java From android-MidiSynth with Apache License 2.0 | 5 votes |
/** * 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 android-midisuite with Apache License 2.0 | 5 votes |
@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 #23
Source File: MidiPortConnector.java From android-MidiScope with Apache License 2.0 | 5 votes |
/** * 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 #24
Source File: MidiOutputPortSelector.java From android-MidiScope with Apache License 2.0 | 5 votes |
@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 #25
Source File: MidiOutputPortConnectionSelector.java From android-MidiScope with Apache License 2.0 | 5 votes |
/** * @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; }
Example #26
Source File: MidiTest.java From walt with Apache License 2.0 | 5 votes |
MidiTest(Context context) { super(context); inputRepetitions = getIntPreference(context, R.string.preference_midi_in_reps, 100); outputRepetitions = getIntPreference(context, R.string.preference_midi_out_reps, 10); midiManager = (MidiManager) context.getSystemService(Context.MIDI_SERVICE); findMidiDevice(); }
Example #27
Source File: MidiOutputPortSelector.java From media-samples with Apache License 2.0 | 5 votes |
@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 #28
Source File: MidiPortConnector.java From media-samples with Apache License 2.0 | 5 votes |
/** * 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 #29
Source File: MidiOutputPortConnectionSelector.java From media-samples with Apache License 2.0 | 5 votes |
/** * @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; }
Example #30
Source File: MidiOutputPortConnectionSelector.java From media-samples with Apache License 2.0 | 5 votes |
/** * @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; }