-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: library/build.gradle library/repository/jp/kshoji/ble-midi/maven-metadata.xml library/repository/jp/kshoji/ble-midi/maven-metadata.xml.md5 library/repository/jp/kshoji/ble-midi/maven-metadata.xml.sha1
- Loading branch information
Showing
16 changed files
with
422 additions
and
16 deletions.
There are no files selected for viewing
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
Binary file not shown.
1 change: 1 addition & 0 deletions
1
library/repository/jp/kshoji/ble-midi/0.0.7/ble-midi-0.0.7.aar.md5
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8399d9eb0e0d731bc81254762da77319 |
1 change: 1 addition & 0 deletions
1
library/repository/jp/kshoji/ble-midi/0.0.7/ble-midi-0.0.7.aar.sha1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c817c7845b0eb3f2a0df056375227fbb85782ddc |
24 changes: 24 additions & 0 deletions
24
library/repository/jp/kshoji/ble-midi/0.0.7/ble-midi-0.0.7.pom
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>jp.kshoji</groupId> | ||
<artifactId>ble-midi</artifactId> | ||
<version>0.0.7</version> | ||
<packaging>aar</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>jp.kshoji</groupId> | ||
<artifactId>javax-sound-midi</artifactId> | ||
<version>0.0.2</version> | ||
<type>aar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.android.support</groupId> | ||
<artifactId>support-annotations</artifactId> | ||
<version>21.0.3</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
1 change: 1 addition & 0 deletions
1
library/repository/jp/kshoji/ble-midi/0.0.7/ble-midi-0.0.7.pom.md5
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
89673aed8c0b52b53a09a1137ff82f7c |
1 change: 1 addition & 0 deletions
1
library/repository/jp/kshoji/ble-midi/0.0.7/ble-midi-0.0.7.pom.sha1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e612d6a35d5e67b571ca79ca3c4dab665d8777c9 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
c15107f5e2c02e4e9c2d20167816916f | ||
04d16e77c877fa8e88460604ba735e40 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
6a74d79b7c0472191907cecf267e9a7c8531d7cd | ||
4231f69f67134ee0ecf6411f76f79fc284fc373c |
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
143 changes: 143 additions & 0 deletions
143
library/src/main/java/jp/kshoji/blemidi/service/AbstractBleMidiService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package jp.kshoji.blemidi.service; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import jp.kshoji.blemidi.device.MidiInputDevice; | ||
import jp.kshoji.blemidi.device.MidiOutputDevice; | ||
import jp.kshoji.blemidi.listener.OnMidiDeviceAttachedListener; | ||
import jp.kshoji.blemidi.listener.OnMidiDeviceDetachedListener; | ||
import jp.kshoji.blemidi.util.Constants; | ||
|
||
/** | ||
* Abstract Service for BLE MIDI | ||
* | ||
* @author K.Shoji | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
abstract class AbstractBleMidiService extends Service { | ||
|
||
private final Set<MidiInputDevice> midiInputDevices = new HashSet<>(); | ||
private final Set<MidiOutputDevice> midiOutputDevices = new HashSet<>(); | ||
|
||
private OnMidiDeviceAttachedListener midiDeviceAttachedListener = null; | ||
private OnMidiDeviceDetachedListener midiDeviceDetachedListener = null; | ||
|
||
private boolean isRunning = false; | ||
|
||
protected abstract void onStart(); | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
if (!isRunning) { | ||
Log.d(Constants.TAG, "MIDI service starting."); | ||
|
||
onStart(); | ||
|
||
isRunning = true; | ||
} | ||
|
||
return START_REDELIVER_INTENT; // must be restarted if stopped by the system, We must respond to midi events(!) | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
|
||
midiInputDevices.clear(); | ||
|
||
midiOutputDevices.clear(); | ||
|
||
Log.d(Constants.TAG, "MIDI service stopped."); | ||
} | ||
|
||
/** | ||
* Set {@link jp.kshoji.blemidi.listener.OnMidiDeviceDetachedListener} to listen MIDI devices have been connected | ||
* | ||
* @param midiDeviceAttachedListener the event listener | ||
*/ | ||
public void setOnMidiDeviceAttachedListener(@Nullable OnMidiDeviceAttachedListener midiDeviceAttachedListener) { | ||
this.midiDeviceAttachedListener = midiDeviceAttachedListener; | ||
} | ||
|
||
/** | ||
* Set {@link jp.kshoji.blemidi.listener.OnMidiDeviceDetachedListener} to listen MIDI devices have been disconnected | ||
* | ||
* @param midiDeviceDetachedListener the event listener | ||
*/ | ||
public void setOnMidiDeviceDetachedListener(@Nullable OnMidiDeviceDetachedListener midiDeviceDetachedListener) { | ||
this.midiDeviceDetachedListener = midiDeviceDetachedListener; | ||
} | ||
|
||
/** | ||
* Get {@link java.util.Set} of{@link jp.kshoji.blemidi.device.MidiInputDevice} to send MIDI events. | ||
* | ||
* @return the Set of MidiInputDevice | ||
*/ | ||
@NonNull | ||
public Set<MidiInputDevice> getMidiInputDevices() { | ||
return Collections.unmodifiableSet(midiInputDevices); | ||
} | ||
|
||
/** | ||
* Get {@link java.util.Set} of{@link jp.kshoji.blemidi.device.MidiOutputDevice} to send MIDI events. | ||
* | ||
* @return the Set of MidiOutputDevice | ||
*/ | ||
@NonNull | ||
public Set<MidiOutputDevice> getMidiOutputDevices() { | ||
return Collections.unmodifiableSet(midiOutputDevices); | ||
} | ||
|
||
protected OnMidiDeviceAttachedListener serviceMidiDeviceAttachedListener = new OnMidiDeviceAttachedListener() { | ||
|
||
@Override | ||
public void onMidiInputDeviceAttached(@NonNull MidiInputDevice midiInputDevice) { | ||
midiInputDevices.add(midiInputDevice); | ||
|
||
if (midiDeviceAttachedListener != null) { | ||
midiDeviceAttachedListener.onMidiInputDeviceAttached(midiInputDevice); | ||
} | ||
} | ||
|
||
@Override | ||
public void onMidiOutputDeviceAttached(@NonNull MidiOutputDevice midiOutputDevice) { | ||
midiOutputDevices.add(midiOutputDevice); | ||
|
||
if (midiDeviceAttachedListener != null) { | ||
midiDeviceAttachedListener.onMidiOutputDeviceAttached(midiOutputDevice); | ||
} | ||
} | ||
}; | ||
|
||
protected OnMidiDeviceDetachedListener serviceMidiDeviceDetachedListener = new OnMidiDeviceDetachedListener() { | ||
|
||
@Override | ||
public void onMidiInputDeviceDetached(@NonNull MidiInputDevice midiInputDevice) { | ||
midiInputDevice.setOnMidiInputEventListener(null); | ||
midiInputDevices.remove(midiInputDevice); | ||
|
||
if (midiDeviceDetachedListener != null) { | ||
midiDeviceDetachedListener.onMidiInputDeviceDetached(midiInputDevice); | ||
} | ||
} | ||
|
||
@Override | ||
public void onMidiOutputDeviceDetached(@NonNull MidiOutputDevice midiOutputDevice) { | ||
midiOutputDevices.remove(midiOutputDevice); | ||
|
||
if (midiDeviceDetachedListener != null) { | ||
midiDeviceDetachedListener.onMidiOutputDeviceDetached(midiOutputDevice); | ||
} | ||
} | ||
}; | ||
} |
73 changes: 73 additions & 0 deletions
73
library/src/main/java/jp/kshoji/blemidi/service/BleMidiCentralService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package jp.kshoji.blemidi.service; | ||
|
||
import android.content.Intent; | ||
import android.os.Binder; | ||
import android.os.IBinder; | ||
import android.support.annotation.NonNull; | ||
|
||
import jp.kshoji.blemidi.central.BleMidiCentralProvider; | ||
|
||
/** | ||
* Service for BLE MIDI Central | ||
* | ||
* @author K.Shoji | ||
*/ | ||
public final class BleMidiCentralService extends AbstractBleMidiService { | ||
private BleMidiCentralProvider midiProvider = null; | ||
|
||
/** | ||
* Binder for this Service | ||
*/ | ||
public class LocalBinder extends Binder { | ||
|
||
/** | ||
* Get the Service | ||
* | ||
* @return the Service | ||
*/ | ||
@NonNull | ||
public BleMidiCentralService getService() { | ||
return BleMidiCentralService.this; | ||
} | ||
} | ||
|
||
private final IBinder binder = new LocalBinder(); | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return binder; | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
midiProvider = new BleMidiCentralProvider(this); | ||
midiProvider.setOnMidiDeviceAttachedListener(serviceMidiDeviceAttachedListener); | ||
midiProvider.setOnMidiDeviceDetachedListener(serviceMidiDeviceDetachedListener); | ||
midiProvider.startScanDevice(0); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
|
||
stopScanDevice(); | ||
} | ||
|
||
/** | ||
* Starts scanning devices | ||
*/ | ||
public void startScanDevice() { | ||
if (midiProvider != null) { | ||
midiProvider.startScanDevice(0); | ||
} | ||
} | ||
|
||
/** | ||
* Stops scanning devices | ||
*/ | ||
public void stopScanDevice() { | ||
if (midiProvider != null) { | ||
midiProvider.stopScanDevice(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
library/src/main/java/jp/kshoji/blemidi/service/BleMidiPeripheralService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package jp.kshoji.blemidi.service; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Intent; | ||
import android.os.Binder; | ||
import android.os.Build; | ||
import android.os.IBinder; | ||
import android.support.annotation.NonNull; | ||
|
||
import jp.kshoji.blemidi.peripheral.BleMidiPeripheralProvider; | ||
|
||
/** | ||
* Service for BLE MIDI Peripheral | ||
* | ||
* @author K.Shoji | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
public final class BleMidiPeripheralService extends AbstractBleMidiService { | ||
private BleMidiPeripheralProvider midiProvider = null; | ||
|
||
/** | ||
* Binder for this Service | ||
*/ | ||
public class LocalBinder extends Binder { | ||
|
||
/** | ||
* Get the Service | ||
* | ||
* @return the Service | ||
*/ | ||
@NonNull | ||
public BleMidiPeripheralService getService() { | ||
return BleMidiPeripheralService.this; | ||
} | ||
} | ||
|
||
private final IBinder binder = new LocalBinder(); | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return binder; | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
midiProvider = new BleMidiPeripheralProvider(this); | ||
midiProvider.setOnMidiDeviceAttachedListener(serviceMidiDeviceAttachedListener); | ||
midiProvider.setOnMidiDeviceDetachedListener(serviceMidiDeviceDetachedListener); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
|
||
stopAdvertising(); | ||
} | ||
|
||
/** | ||
* Starts advertising | ||
*/ | ||
public void startAdvertising() { | ||
if (midiProvider != null) { | ||
midiProvider.startAdvertising(); | ||
} | ||
} | ||
|
||
/** | ||
* Stops advertising | ||
*/ | ||
public void stopAdvertising() { | ||
if (midiProvider != null) { | ||
midiProvider.stopAdvertising(); | ||
} | ||
} | ||
} |
Oops, something went wrong.