Created
April 10, 2015 03:00
-
-
Save kshoji/6aaff44bee5da2a9af3e to your computer and use it in GitHub Desktop.
Android BLE MIDI code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CentralActivity extends Activity { | |
BleMidiCentralProvider bleMidiCentralProvider; | |
@Override | |
public void onCreate(final Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
bleMidiCentralProvider = new BleMidiCentralProvider(this); | |
... | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bleMidiCentralProvider.disconnectDevice(midiOutputDevice); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
if (bleMidiCentralProvider != null) { | |
bleMidiCentralProvider.terminate(); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OnMidiInputEventListener onMidiInputEventListener = new OnMidiInputEventListener() { | |
@Override | |
public void onMidiNoteOn(MidiInputDevice sender, int channel, int note, int velocity) { | |
// TODO MIDI Note On event received | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
midiOutputDevice.sendMidiNoteOn(channel, note, velocity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
midiInputDevice.setOnMidiInputEventListener(onMidiInputEventListener); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment