本文整理汇总了Java中android.media.midi.MidiManager类的典型用法代码示例。如果您正苦于以下问题:Java MidiManager类的具体用法?Java MidiManager怎么用?Java MidiManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MidiManager类属于android.media.midi包,在下文中一共展示了MidiManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPortSelected
import android.media.midi.MidiManager; //导入依赖的package包/类
@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.
}
}
示例2: findDevice
import android.media.midi.MidiManager; //导入依赖的package包/类
/**
* @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;
}
示例3: findMidiDevice
import android.media.midi.MidiManager; //导入依赖的package包/类
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;
}
}
}
示例4: onActivityResult
import android.media.midi.MidiManager; //导入依赖的package包/类
@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);
}
}
}
示例5: MidiReceiver
import android.media.midi.MidiManager; //导入依赖的package包/类
public MidiReceiver(Context context, CloseableReceiver listener) {
this.listener = listener;
MidiManager midiManager = (MidiManager) context.getSystemService(Context.MIDI_SERVICE);
stream(midiManager.getDevices())
.filter(device -> device.getOutputPortCount() > 0).findFirst()
.ifPresentOrElse(device -> openDevice(midiManager, device),
() -> registerDeviceAddedCallback(midiManager));
}
示例6: registerDeviceAddedCallback
import android.media.midi.MidiManager; //导入依赖的package包/类
private void registerDeviceAddedCallback(final MidiManager midiManager) {
midiManager.registerDeviceCallback(new MidiManager.DeviceCallback() {
@Override
public void onDeviceAdded(MidiDeviceInfo device) {
if (device.getOutputPortCount() > 0) {
midiManager.unregisterDeviceCallback(this);
openDevice(midiManager, device);
}
}
}, null);
}
示例7: onPortSelected
import android.media.midi.MidiManager; //导入依赖的package包/类
@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.
}
}
示例8: MidiOutputPortConnectionSelector
import android.media.midi.MidiManager; //导入依赖的package包/类
/**
* @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;
}
示例9: connectToDevicePort
import android.media.midi.MidiManager; //导入依赖的package包/类
/**
* 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);
}
示例10: setupMidi
import android.media.midi.MidiManager; //导入依赖的package包/类
private void setupMidi() {
// Setup MIDI
mMidiManager = (MidiManager) getSystemService(MIDI_SERVICE);
MidiDeviceInfo synthInfo = MidiTools.findDevice(mMidiManager, "AndroidTest",
"SynthExample");
int portIndex = 0;
mPortSelector = new MidiOutputPortConnectionSelector(mMidiManager, this,
R.id.spinner_synth_sender, synthInfo, portIndex);
mPortSelector.setConnectedListener(new MyPortsConnectedListener());
}
示例11: checkUsbMidi
import android.media.midi.MidiManager; //导入依赖的package包/类
public static boolean checkUsbMidi(Context context) {
MidiManager midiManager = (MidiManager) context.getSystemService(Context.MIDI_SERVICE);
if (midiManager != null) {
final MidiDeviceInfo[] infos = midiManager.getDevices();
if (infos.length > 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}
示例12: onItemSelected
import android.media.midi.MidiManager; //导入依赖的package包/类
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println(i);
m.openDevice(infos[midiDevice], new MidiManager.OnDeviceOpenedListener() {
@Override
public void onDeviceOpened(MidiDevice device) {
if (device == null) {
Toast.makeText(getApplicationContext(), "Could not open device!",
Toast.LENGTH_LONG).show();
} else {
inputPort = device.openInputPort(0);
}
}
}, new Handler(Looper.getMainLooper()));
}
示例13: MidiTest
import android.media.midi.MidiManager; //导入依赖的package包/类
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();
}
示例14: openDevice
import android.media.midi.MidiManager; //导入依赖的package包/类
private void openDevice(final MidiDeviceInfo info) {
mManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
@Override
public void onDeviceOpened(MidiDevice device) {
MidiManagerAndroid.this.onDeviceOpened(device, info);
}
}, mHandler);
}
示例15: onCreate
import android.media.midi.MidiManager; //导入依赖的package包/类
@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);
}