Skip to content

Instantly share code, notes, and snippets.

@kshoji
Created April 10, 2015 03:00
Show Gist options
  • Save kshoji/6aaff44bee5da2a9af3e to your computer and use it in GitHub Desktop.
Save kshoji/6aaff44bee5da2a9af3e to your computer and use it in GitHub Desktop.
Android BLE MIDI code snippets
repositories {
maven {
// 1. Add an URL entry
url 'https://github.com/kshoji/BLE-MIDI-for-Android/raw/master/library/repository'
}
mavenCentral()
}
dependencies {
// 2. Add the dependency entry
compile 'jp.kshoji:ble-midi:0.0.3:@aar'
}
repositories {
maven {
// 1. URLを追加
url 'https://github.com/kshoji/BLE-MIDI-for-Android/raw/master/library/repository'
}
mavenCentral()
}
dependencies {
// 2. 依存性情報を追加
compile 'jp.kshoji:ble-midi:0.0.3:@aar'
}
public class CentralActivity extends Activity {
BleMidiCentralProvider bleMidiCentralProvider;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bleMidiCentralProvider = new BleMidiCentralProvider(this);
...
}
...
}
bleMidiCentralProvider.disconnectDevice(midiOutputDevice);
@Override
protected void onDestroy() {
super.onDestroy();
if (bleMidiCentralProvider != null) {
bleMidiCentralProvider.terminate();
}
...
}
bleMidiCentralProvider.setOnMidiDeviceAttachedListener(new OnMidiDeviceAttachedListener() {
@Override
public void onMidiInputDeviceAttached(MidiInputDevice midiInputDevice) {
// TODO MIDI Input device is connected
midiInputDevice.setOnMidiInputEventListener(onMidiInputEventListener);
}
@Override
public void onMidiOutputDeviceAttached(MidiOutputDevice midiOutputDevice) {
// TODO MIDI Output device is connected
}
});
bleMidiCentralProvider.setOnMidiDeviceDetachedListener(new OnMidiDeviceDetachedListener() {
@Override
public void onMidiInputDeviceDetached(MidiInputDevice midiInputDevice) {
// TODO MIDI Input device is disconnected
}
@Override
public void onMidiOutputDeviceDetached(MidiOutputDevice midiOutputDevice) {
// TODO MIDI Input device is disconnected
}
});
OnMidiInputEventListener onMidiInputEventListener = new OnMidiInputEventListener() {
@Override
public void onMidiNoteOn(MidiInputDevice sender, int channel, int note, int velocity) {
// TODO MIDI Note On event received
}
...
}
midiOutputDevice.sendMidiNoteOn(channel, note, velocity);
midiInputDevice.setOnMidiInputEventListener(onMidiInputEventListener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment