├── AndroidMidiTest
├── .gitignore
├── build.gradle
├── libs
│ └── easymock-3.1.jar
├── .project
├── .classpath
└── javatests
│ └── com
│ └── noisepages
│ └── nettoyeur
│ └── midi
│ └── util
│ ├── SystemMessageEncoderTest.java
│ └── SystemMessageDecoderTest.java
├── settings.gradle
├── MidiPlayer
├── .gitignore
├── src
│ ├── META-INF
│ │ └── MANIFEST.MF
│ └── com
│ │ └── noisepages
│ │ └── nettoyeur
│ │ └── midi
│ │ ├── player
│ │ ├── MidiSequenceObserver.java
│ │ └── MidiPlayerService.java
│ │ └── file
│ │ ├── InvalidMidiDataException.java
│ │ ├── MidiEvent.java
│ │ ├── Patch.java
│ │ └── FastShortMessage.java
├── res
│ ├── drawable-hdpi
│ │ └── icon.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── values
│ │ └── strings.xml
│ └── layout
│ │ ├── main.xml
│ │ └── main_usb.xml
├── project.properties
├── .classpath
├── build.gradle
├── .project
├── AndroidManifest.xml
└── build.xml
├── AndroidMidi
├── .gitignore
├── res
│ ├── drawable
│ │ └── din5.png
│ ├── layout
│ │ ├── device_name.xml
│ │ └── device_list.xml
│ └── values
│ │ └── strings.xml
├── AndroidManifest.xml
├── project.properties
├── .classpath
├── .project
├── src
│ └── com
│ │ └── noisepages
│ │ └── nettoyeur
│ │ ├── usb
│ │ ├── ConnectionFailedException.java
│ │ ├── DeviceNotConnectedException.java
│ │ ├── UsbException.java
│ │ ├── InterfaceNotAvailableException.java
│ │ ├── UsbBroadcastHandler.java
│ │ ├── util
│ │ │ ├── AsyncDeviceInfoLookup.java
│ │ │ └── UsbDeviceSelector.java
│ │ ├── midi
│ │ │ └── util
│ │ │ │ ├── UsbMidiInputSelector.java
│ │ │ │ └── UsbMidiOutputSelector.java
│ │ ├── DeviceInfo.java
│ │ └── UsbDeviceWithInfo.java
│ │ ├── bluetooth
│ │ ├── BluetoothDisabledException.java
│ │ ├── BluetoothNotConnectedException.java
│ │ ├── BluetoothUnavailableException.java
│ │ ├── BluetoothException.java
│ │ ├── BluetoothSppObserver.java
│ │ ├── util
│ │ │ ├── DeviceListActivity.java
│ │ │ └── BluetoothDeviceSelector.java
│ │ └── midi
│ │ │ └── BluetoothMidiDevice.java
│ │ ├── midi
│ │ ├── MidiDevice.java
│ │ ├── util
│ │ │ ├── SystemMessageReceiver.java
│ │ │ ├── SystemMessageEncoder.java
│ │ │ └── SystemMessageDecoder.java
│ │ ├── ToWireConverter.java
│ │ ├── FromWireConverter.java
│ │ └── MidiReceiver.java
│ │ └── common
│ │ └── RawByteReceiver.java
├── build.gradle
└── build.xml
├── UsbMidiDemo
├── .gitignore
├── res
│ ├── drawable
│ │ ├── icon.png
│ │ ├── black1.png
│ │ ├── black11.png
│ │ ├── black2.png
│ │ ├── black21.png
│ │ ├── black3.png
│ │ ├── black31.png
│ │ ├── black4.png
│ │ ├── black41.png
│ │ ├── black5.png
│ │ ├── black51.png
│ │ ├── header.png
│ │ ├── white1.png
│ │ ├── white11.png
│ │ ├── white2.png
│ │ ├── white21.png
│ │ ├── white3.png
│ │ ├── white31.png
│ │ ├── white4.png
│ │ ├── white41.png
│ │ ├── white5.png
│ │ ├── white51.png
│ │ ├── white6.png
│ │ ├── white61.png
│ │ ├── white7.png
│ │ ├── white71.png
│ │ ├── white8.png
│ │ └── white81.png
│ ├── menu
│ │ └── menu.xml
│ ├── values
│ │ └── strings.xml
│ └── layout
│ │ └── main.xml
├── project.properties
├── .classpath
├── build.gradle
├── .project
├── AndroidManifest.xml
├── LICENSE.txt
└── build.xml
├── UsbMidiTest
├── .gitignore
├── ic_launcher-web.png
├── libs
│ └── android-support-v4.jar
├── res
│ ├── values
│ │ ├── styles.xml
│ │ └── strings.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── drawable-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_action_search.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_action_search.png
│ ├── drawable-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_action_search.png
│ ├── menu
│ │ └── menu.xml
│ └── layout
│ │ └── activity_main.xml
├── .classpath
├── project.properties
├── build.gradle
├── proguard-project.txt
├── .project
├── AndroidManifest.xml
└── LICENSE.txt
├── BluetoothMidiDemo
├── .gitignore
├── res
│ ├── drawable
│ │ ├── icon.png
│ │ ├── black1.png
│ │ ├── black11.png
│ │ ├── black2.png
│ │ ├── black21.png
│ │ ├── black3.png
│ │ ├── black31.png
│ │ ├── black4.png
│ │ ├── black41.png
│ │ ├── black5.png
│ │ ├── black51.png
│ │ ├── header.png
│ │ ├── white1.png
│ │ ├── white11.png
│ │ ├── white2.png
│ │ ├── white21.png
│ │ ├── white3.png
│ │ ├── white31.png
│ │ ├── white4.png
│ │ ├── white41.png
│ │ ├── white5.png
│ │ ├── white51.png
│ │ ├── white6.png
│ │ ├── white61.png
│ │ ├── white7.png
│ │ ├── white71.png
│ │ ├── white8.png
│ │ └── white81.png
│ ├── menu
│ │ └── menu.xml
│ ├── values
│ │ └── strings.xml
│ └── layout
│ │ └── main.xml
├── project.properties
├── .classpath
├── build.gradle
├── .project
├── AndroidManifest.xml
├── LICENSE.txt
└── build.xml
├── BluetoothMidiTest
├── .gitignore
├── res
│ ├── drawable-hdpi
│ │ └── icon.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── values
│ │ └── strings.xml
│ └── layout
│ │ └── main.xml
├── project.properties
├── .classpath
├── build.gradle
├── .project
├── AndroidManifest.xml
├── LICENSE.txt
├── build.xml
└── src
│ └── com
│ └── noisepages
│ └── nettoyeur
│ └── miditest
│ └── BluetoothMidiTest.java
├── midi3v3.fzz
├── midi3v3bb.jpg
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README
├── .gitignore
├── midi3v3.txt
├── btmonitor.py
├── gradlew.bat
└── gradlew
/AndroidMidiTest/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':AndroidMidi'
2 |
--------------------------------------------------------------------------------
/MidiPlayer/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | local.properties
4 |
--------------------------------------------------------------------------------
/AndroidMidi/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | local.properties
4 |
--------------------------------------------------------------------------------
/UsbMidiDemo/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | local.properties
4 |
--------------------------------------------------------------------------------
/UsbMidiTest/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | local.properties
4 |
--------------------------------------------------------------------------------
/BluetoothMidiDemo/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | local.properties
4 |
--------------------------------------------------------------------------------
/BluetoothMidiTest/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | local.properties
4 |
--------------------------------------------------------------------------------
/midi3v3.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/midi3v3.fzz
--------------------------------------------------------------------------------
/midi3v3bb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/midi3v3bb.jpg
--------------------------------------------------------------------------------
/MidiPlayer/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Created-By: 1.6.0_24 (Apple Inc.)
3 |
4 |
--------------------------------------------------------------------------------
/AndroidMidiTest/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | sourceSets {
3 | main.java.srcDirs = ['javatests']
4 | }
5 |
--------------------------------------------------------------------------------
/UsbMidiTest/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiTest/ic_launcher-web.png
--------------------------------------------------------------------------------
/AndroidMidi/res/drawable/din5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/AndroidMidi/res/drawable/din5.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/icon.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/AndroidMidiTest/libs/easymock-3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/AndroidMidiTest/libs/easymock-3.1.jar
--------------------------------------------------------------------------------
/MidiPlayer/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/MidiPlayer/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/MidiPlayer/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/MidiPlayer/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/MidiPlayer/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/MidiPlayer/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black1.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black11.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black2.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black21.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black3.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black31.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black4.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black41.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black5.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/black51.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/black51.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/header.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white1.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white11.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white2.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white21.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white3.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white31.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white4.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white41.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white5.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white51.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white51.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white6.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white61.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white61.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white7.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white71.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white71.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white8.png
--------------------------------------------------------------------------------
/UsbMidiDemo/res/drawable/white81.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiDemo/res/drawable/white81.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/icon.png
--------------------------------------------------------------------------------
/UsbMidiTest/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/UsbMidiTest/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black1.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black11.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black2.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black21.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black3.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black31.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black4.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black41.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black5.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/black51.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/black51.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/header.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white1.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white11.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white2.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white21.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white3.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white31.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white4.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white41.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white5.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white51.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white51.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white6.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white61.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white61.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white7.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white71.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white71.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white8.png
--------------------------------------------------------------------------------
/BluetoothMidiDemo/res/drawable/white81.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nettoyeurny/btmidi/HEAD/BluetoothMidiDemo/res/drawable/white81.png
--------------------------------------------------------------------------------
/UsbMidiTest/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
InvalidMidiDataException indicates that inappropriate MIDI
31 | * data was encountered. This often means that the data is invalid in and of
32 | * itself, from the perspective of the MIDI specification. An example would
33 | * be an undefined status byte. However, the exception might simply
34 | * mean that the data was invalid in the context it was used, or that
35 | * the object to which the data was given was unable to parse or use it.
36 | * For example, a file reader might not be able to parse a Type 2 MIDI file, even
37 | * though that format is defined in the MIDI specification.
38 | *
39 | * @author Kara Kytle
40 | */
41 | public class InvalidMidiDataException extends Exception {
42 |
43 | private static final long serialVersionUID = 1L;
44 |
45 |
46 | /**
47 | * Constructs an InvalidMidiDataException with
48 | * null for its error detail message.
49 | */
50 | public InvalidMidiDataException() {
51 |
52 | super();
53 | }
54 |
55 |
56 | /**
57 | * Constructs an InvalidMidiDataException with the
58 | * specified detail message.
59 | *
60 | * @param message the string to display as an error detail message
61 | */
62 | public InvalidMidiDataException(String message) {
63 |
64 | super(message);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/usb/util/UsbDeviceSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.usb.util;
16 |
17 | import java.util.List;
18 |
19 | import android.app.AlertDialog.Builder;
20 | import android.app.Dialog;
21 | import android.app.DialogFragment;
22 | import android.content.DialogInterface;
23 | import android.content.DialogInterface.OnClickListener;
24 | import android.os.Bundle;
25 |
26 | import com.noisepages.nettoyeur.midi.R;
27 | import com.noisepages.nettoyeur.usb.UsbDeviceWithInfo;
28 |
29 | public abstract class UsbDeviceSelector{@link Sequence} object. The
32 | * duration of a tick is specified by the timing information contained
33 | * in the MIDI file or Sequence object.
34 | *
35 | * In Java Sound,
42 | * To select what instrument should play the notes on a particular MIDI
43 | * channel, two kinds of MIDI message are used that specify a patch location:
44 | * a bank-select command, and a program-change channel command. The Java Sound
45 | * equivalent is the
46 | * {@link MidiChannel#programChange(int, int) programChange(int, int)}
47 | * method of MidiEvent objects are typically contained in a
36 | * {@link Track}, and Tracks are likewise
37 | * contained in a Sequence.
38 | *
39 | *
40 | * @author David Rivas
41 | * @author Kara Kytle
42 | */
43 | public class MidiEvent {
44 |
45 |
46 | // Instance variables
47 |
48 | /**
49 | * The MIDI message for this event.
50 | */
51 | private final MidiMessage message;
52 |
53 |
54 | /**
55 | * The tick value for this event.
56 | */
57 | private long tick;
58 |
59 |
60 | /**
61 | * Constructs a new MidiEvent.
62 | * @param message the MIDI message contained in the event
63 | * @param tick the time-stamp for the event, in MIDI ticks
64 | */
65 | public MidiEvent(MidiMessage message, long tick) {
66 |
67 | this.message = message;
68 | this.tick = tick;
69 | }
70 |
71 | /**
72 | * Obtains the MIDI message contained in the event.
73 | * @return the MIDI message
74 | */
75 | public MidiMessage getMessage() {
76 | return message;
77 | }
78 |
79 |
80 | /**
81 | * Sets the time-stamp for the event, in MIDI ticks
82 | * @param tick the new time-stamp, in MIDI ticks
83 | */
84 | public void setTick(long tick) {
85 | this.tick = tick;
86 | }
87 |
88 |
89 | /**
90 | * Obtains the time-stamp for the event, in MIDI ticks
91 | * @return the time-stamp for the event, in MIDI ticks
92 | */
93 | public long getTick() {
94 | return tick;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/bluetooth/util/DeviceListActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Derived from DeviceListActivity.java in android-7/samples/BluetoothChat
3 | *
4 | * Modifications Copyright (C) 2011 Peter Brinkmann (peter.brinkmann@gmail.com)
5 | *
6 | * Copyright (C) 2009 The Android Open Source Project
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9 | * in compliance with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software distributed under the License
14 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15 | * or implied. See the License for the specific language governing permissions and limitations under
16 | * the License.
17 | */
18 |
19 | package com.noisepages.nettoyeur.bluetooth.util;
20 |
21 | import java.util.Set;
22 |
23 | import com.noisepages.nettoyeur.midi.R;
24 |
25 | import android.app.Activity;
26 | import android.bluetooth.BluetoothAdapter;
27 | import android.bluetooth.BluetoothDevice;
28 | import android.content.Intent;
29 | import android.os.Bundle;
30 | import android.view.View;
31 | import android.widget.AdapterView;
32 | import android.widget.ArrayAdapter;
33 | import android.widget.ListView;
34 | import android.widget.TextView;
35 | import android.widget.AdapterView.OnItemClickListener;
36 |
37 |
38 | /**
39 | * A simple activity that offers the user a list of paired Bluetooth devices to choose from.
40 | */
41 | public class DeviceListActivity extends Activity {
42 |
43 | public static final String DEVICE_ADDRESS = "device_address";
44 |
45 | private BluetoothAdapter btAdapter;
46 | private ArrayAdapterPatch object represents a location, on a MIDI
31 | * synthesizer, into which a single instrument is stored (loaded).
32 | * Every Instrument object has its own Patch
33 | * object that specifies the memory location
34 | * into which that instrument should be loaded. The
35 | * location is specified abstractly by a bank index and a program number (not by
36 | * any scheme that directly refers to a specific address or offset in RAM).
37 | * This is a hierarchical indexing scheme: MIDI provides for up to 16384 banks,
38 | * each of which contains up to 128 program locations. For example, a
39 | * minimal sort of synthesizer might have only one bank of instruments, and
40 | * only 32 instruments (programs) in that bank.
41 | * MidiChannel.
48 | *
49 | * @see Instrument
50 | * @see Instrument#getPatch()
51 | * @see MidiChannel#programChange(int, int)
52 | * @see Synthesizer#loadInstruments(Soundbank, Patch[])
53 | * @see Soundbank
54 | * @see Sequence#getPatchList()
55 | *
56 | * @author Kara Kytle
57 | */
58 |
59 | public class Patch {
60 |
61 |
62 | /**
63 | * Bank index
64 | */
65 | private final int bank;
66 |
67 |
68 | /**
69 | * Program change number
70 | */
71 | private final int program;
72 |
73 |
74 | /**
75 | * Constructs a new patch object from the specified bank and program
76 | * numbers.
77 | * @param bank the bank index (in the range from 0 to 16383)
78 | * @param program the program index (in the range from 0 to 127)
79 | */
80 | public Patch(int bank, int program) {
81 |
82 | this.bank = bank;
83 | this.program = program;
84 | }
85 |
86 |
87 | /**
88 | * Returns the number of the bank that contains the instrument
89 | * whose location this Patch specifies.
90 | * @return the bank number, whose range is from 0 to 16383
91 | * @see MidiChannel#programChange(int, int)
92 | */
93 | public int getBank() {
94 |
95 | return bank;
96 | }
97 |
98 |
99 | /**
100 | * Returns the index, within
101 | * a bank, of the instrument whose location this Patch specifies.
102 | * @return the instrument's program number, whose range is from 0 to 127
103 | *
104 | * @see MidiChannel#getProgram
105 | * @see MidiChannel#programChange(int)
106 | * @see MidiChannel#programChange(int, int)
107 | */
108 | public int getProgram() {
109 |
110 | return program;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/bluetooth/midi/BluetoothMidiDevice.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.bluetooth.midi;
16 |
17 | import java.io.ByteArrayOutputStream;
18 | import java.io.IOException;
19 |
20 | import com.noisepages.nettoyeur.bluetooth.BluetoothDisabledException;
21 | import com.noisepages.nettoyeur.bluetooth.BluetoothSppConnection;
22 | import com.noisepages.nettoyeur.bluetooth.BluetoothSppObserver;
23 | import com.noisepages.nettoyeur.bluetooth.BluetoothUnavailableException;
24 | import com.noisepages.nettoyeur.common.RawByteReceiver;
25 | import com.noisepages.nettoyeur.midi.FromWireConverter;
26 | import com.noisepages.nettoyeur.midi.MidiDevice;
27 | import com.noisepages.nettoyeur.midi.MidiReceiver;
28 | import com.noisepages.nettoyeur.midi.ToWireConverter;
29 |
30 |
31 | /**
32 | * Basic support for MIDI In/Out over Bluetooth.
33 | *
34 | * @author Peter Brinkmann
35 | */
36 | public class BluetoothMidiDevice implements MidiDevice {
37 |
38 | private final BluetoothSppConnection btConnection;
39 | private final ToWireConverter toWire = new ToWireConverter(new RawByteReceiver() {
40 | private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
41 | private boolean inBlock = false;
42 |
43 | @Override
44 | public void onBytesReceived(int nBytes, byte[] buffer) {
45 | if (inBlock) {
46 | outputStream.write(buffer, 0, nBytes);
47 | } else {
48 | try {
49 | btConnection.write(buffer, 0, nBytes);
50 | } catch (IOException e) {
51 | e.printStackTrace();
52 | }
53 | }
54 | }
55 |
56 | @Override
57 | public boolean beginBlock() {
58 | outputStream.reset();
59 | inBlock = true;
60 | return true;
61 | }
62 |
63 | @Override
64 | public void endBlock() {
65 | if (inBlock) {
66 | try {
67 | btConnection.write(outputStream.toByteArray(), 0, outputStream.size());
68 | } catch (IOException e) {
69 | e.printStackTrace();
70 | }
71 | inBlock = false;
72 | } else {
73 | throw new IllegalStateException("Not in block mode");
74 | }
75 | }
76 | });
77 |
78 | /**
79 | * Constructor.
80 | *
81 | * @param observer for handling Bluetooth connection events
82 | * @param receiver for handling events from the Bluetooth input stream
83 | * @throws BluetoothDisabledException
84 | * @throws BluetoothUnavailableException
85 | */
86 | public BluetoothMidiDevice(BluetoothSppObserver observer, MidiReceiver receiver)
87 | throws BluetoothUnavailableException, BluetoothDisabledException {
88 | btConnection = new BluetoothSppConnection(observer, new FromWireConverter(receiver), 64);
89 | }
90 |
91 | /**
92 | * Attempts to connect to the given Bluetooth device.
93 | *
94 | * @param addr String representation of the MAC address of the Bluetooth device
95 | * @throws IOException
96 | */
97 | public void connect(String addr) throws IOException {
98 | btConnection.connect(addr);
99 | }
100 |
101 | /**
102 | * Stops all Bluetooth threads and closes the Bluetooth connection.
103 | */
104 | @Override
105 | public void close() {
106 | btConnection.stop();
107 | }
108 |
109 | /**
110 | * @return the MIDI receiver that sends messages to the Bluetooth output stream
111 | */
112 | public MidiReceiver getMidiOut() {
113 | return toWire;
114 | }
115 |
116 | /**
117 | * @return the state of the underlying Bluetooth connection
118 | */
119 | public BluetoothSppConnection.State getConnectionState() {
120 | return btConnection.getConnectionState();
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/midi/util/SystemMessageDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.midi.util;
16 |
17 | import java.io.ByteArrayOutputStream;
18 |
19 | /**
20 | * Utility class for decoding MIDI system messages. Instances of this class parse an incoming stream
21 | * of MIDI bytes, e.g., from the onRawByte method of MidiReceiver, and extract system messages.
22 | *
23 | * @author Peter Brinkmann (peter.brinkmann@gmail.com)
24 | */
25 | public class SystemMessageDecoder {
26 |
27 | private enum State {
28 | SYSTEM_EXCLUSIVE, TIME_CODE, SONG_POSITION, SONG_SELECT, NONE
29 | };
30 |
31 | private final SystemMessageReceiver receiver;
32 | private State state = State.NONE;
33 | private int firstByte = -1;
34 | private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
35 |
36 | public SystemMessageDecoder(SystemMessageReceiver receiver) {
37 | this.receiver = receiver;
38 | }
39 |
40 | /**
41 | * Handles an incoming MIDI byte.
42 | *
43 | * @param value to be decoded
44 | * @return true if the byte was handled as part of a system message
45 | */
46 | public boolean decodeByte(byte value) {
47 | boolean byteHandled = true;
48 | switch (value) {
49 | // Handle system common messages.
50 | case (byte) 0xf0:
51 | buffer.reset();
52 | state = State.SYSTEM_EXCLUSIVE;
53 | break;
54 | case (byte) 0xf1:
55 | state = State.TIME_CODE;
56 | break;
57 | case (byte) 0xf2:
58 | firstByte = -1;
59 | state = State.SONG_POSITION;
60 | break;
61 | case (byte) 0xf3:
62 | state = State.SONG_SELECT;
63 | break;
64 | case (byte) 0xf6:
65 | receiver.onTuneRequest();
66 | state = State.NONE;
67 | break;
68 | case (byte) 0xf7:
69 | if (state == State.SYSTEM_EXCLUSIVE) {
70 | receiver.onSystemExclusive(buffer.toByteArray());
71 | }
72 | state = State.NONE;
73 | break;
74 | // Handel system real time messages. Note that those don't reset the state since they may be
75 | // interleaved with sysex messages.
76 | case (byte) 0xf8:
77 | receiver.onTimingClock();
78 | break;
79 | case (byte) 0xfa:
80 | receiver.onStart();
81 | break;
82 | case (byte) 0xfb:
83 | receiver.onContinue();
84 | break;
85 | case (byte) 0xfc:
86 | receiver.onStop();
87 | break;
88 | case (byte) 0xfe:
89 | receiver.onActiveSensing();
90 | break;
91 | case (byte) 0xff:
92 | receiver.onSystemReset();
93 | break;
94 | default:
95 | if (value >= 0) {
96 | switch (state) {
97 | case SYSTEM_EXCLUSIVE:
98 | buffer.write(value);
99 | break;
100 | case TIME_CODE:
101 | receiver.onTimeCode(value);
102 | state = State.NONE;
103 | break;
104 | case SONG_POSITION:
105 | if (firstByte < 0) {
106 | firstByte = value;
107 | } else {
108 | receiver.onSongPosition((value << 7) | firstByte);
109 | state = State.NONE;
110 | }
111 | break;
112 | case SONG_SELECT:
113 | receiver.onSongSelect(value);
114 | state = State.NONE;
115 | break;
116 | default:
117 | byteHandled = false;
118 | break;
119 | }
120 | } else {
121 | state = State.NONE;
122 | byteHandled = false;
123 | }
124 | break;
125 | }
126 | return byteHandled;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/usb/DeviceInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.usb;
16 |
17 | import java.io.IOException;
18 | import java.util.Scanner;
19 |
20 | import org.apache.http.HttpResponse;
21 | import org.apache.http.client.ClientProtocolException;
22 | import org.apache.http.client.HttpClient;
23 | import org.apache.http.client.methods.HttpGet;
24 | import org.apache.http.impl.client.DefaultHttpClient;
25 |
26 | import android.hardware.usb.UsbDevice;
27 |
28 | /**
29 | * Support for retrieving human-readable names of USB devices from the web
30 | * (http://usb-ids.gowdy.us/index.html).
31 | *
32 | * @author Peter Brinkmann (peter.brinkmann@gmail.com)
33 | */
34 | public class DeviceInfo {
35 |
36 | private final String vendor;
37 | private final String product;
38 |
39 | /**
40 | * Synchronously retrieves device info from the web. This method must not be invoked on the main
41 | * thread as it performs blocking network operations that may cause the app to become
42 | * unresponsive.
43 | *
44 | * Requires android.permission.INTERNET.
45 | *
46 | * @param device for which to retrieve information
47 | * @return device info, or null on failure
48 | */
49 | public static DeviceInfo retrieveDeviceInfo(UsbDevice device) {
50 | DeviceInfo info = null;
51 | try {
52 | info = retrieveDeviceInfo(device.getVendorId(), device.getProductId());
53 | } catch (ClientProtocolException e) {
54 | e.printStackTrace();
55 | } catch (IOException e) {
56 | e.printStackTrace();
57 | }
58 | return info;
59 | }
60 |
61 | /**
62 | * Constructor for default instances of DeviceInfo, populated with numerical IDs rather than
63 | * human-readable names.
64 | */
65 | public DeviceInfo(UsbDevice device) {
66 | this(asFourDigitHex(device.getVendorId()), asFourDigitHex(device.getProductId()));
67 | }
68 |
69 | private DeviceInfo(String vendor, String product) {
70 | this.vendor = vendor;
71 | this.product = product;
72 | }
73 |
74 | public String getVendor() {
75 | return vendor;
76 | }
77 |
78 | public String getProduct() {
79 | return product;
80 | }
81 |
82 | private static String asFourDigitHex(int id) {
83 | return Integer.toHexString(0x10000 | id).substring(1);
84 | }
85 |
86 | private static DeviceInfo retrieveDeviceInfo(int vendorId, int productId)
87 | throws ClientProtocolException, IOException {
88 | String vendorHex = asFourDigitHex(vendorId);
89 | String productHex = asFourDigitHex(productId);
90 | String url = "http://usb-ids.gowdy.us/read/UD/" + vendorHex;
91 | String vendorName = null;
92 | String productName = null;
93 | vendorName = getName(url);
94 | productName = getName(url + "/" + productHex);
95 | return (vendorName != null && productName != null)
96 | ? new DeviceInfo(vendorName, productName)
97 | : null;
98 | }
99 |
100 | private static String getName(String url) throws ClientProtocolException, IOException {
101 | HttpClient client = new DefaultHttpClient();
102 | HttpGet request = new HttpGet(url);
103 | HttpResponse response = client.execute(request);
104 | Scanner scanner = new Scanner(response.getEntity().getContent());
105 | while (scanner.hasNext()) {
106 | String line = scanner.nextLine();
107 | int start = line.indexOf("Name:") + 6;
108 | if (start > 5) {
109 | int end = line.indexOf("<", start);
110 | if (end > start) {
111 | return line.substring(start, end);
112 | }
113 | }
114 | }
115 | return null;
116 | }
117 |
118 | @Override
119 | public String toString() {
120 | return vendor + ":" + product;
121 | }
122 |
123 | @Override
124 | public int hashCode() {
125 | return 31 * vendor.hashCode() + product.hashCode();
126 | }
127 |
128 | @Override
129 | public boolean equals(Object o) {
130 | return (o instanceof DeviceInfo) && ((DeviceInfo) o).vendor.equals(vendor)
131 | && ((DeviceInfo) o).product.equals(product);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/midi/MidiReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.midi;
16 |
17 | import com.noisepages.nettoyeur.midi.util.SystemMessageDecoder;
18 |
19 |
20 | /**
21 | * Callbacks for handling MIDI events and connection changes. Note that this interface chooses
22 | * sanity over compliance with the MIDI standard, i.e., channel numbers start at 0, and pitch bend
23 | * values are centered at 0.
24 | *
25 | * @author Peter Brinkmann (peter.brinkmann@gmail.com)
26 | */
27 | public interface MidiReceiver {
28 |
29 | /**
30 | * Handles note off events.
31 | *
32 | * @param channel starting at 0
33 | * @param key
34 | * @param velocity
35 | */
36 | void onNoteOff(int channel, int key, int velocity);
37 |
38 | /**
39 | * Handles note on events.
40 | *
41 | * @param channel starting at 0
42 | * @param key
43 | * @param velocity
44 | */
45 | void onNoteOn(int channel, int key, int velocity);
46 |
47 | /**
48 | * Handles polyphonic aftertouch events.
49 | *
50 | * @param channel starting at 0
51 | * @param key
52 | * @param velocity
53 | */
54 | void onPolyAftertouch(int channel, int key, int velocity);
55 |
56 | /**
57 | * Handles a control change message.
58 | *
59 | * @param channel starting at 0
60 | * @param controller
61 | * @param value
62 | */
63 | void onControlChange(int channel, int controller, int value);
64 |
65 | /**
66 | * Handles a program change message.
67 | *
68 | * @param channel starting at 0
69 | * @param program
70 | */
71 | void onProgramChange(int channel, int program);
72 |
73 | /**
74 | * Handles a channel aftertouch event.
75 | *
76 | * @param channel starting at 0
77 | * @param velocity
78 | */
79 | void onAftertouch(int channel, int velocity);
80 |
81 | /**
82 | * Handles a pitch bend event.
83 | *
84 | * @param channel starting at 0
85 | * @param value centered at 0, ranging from -8192 to 8191
86 | */
87 | void onPitchBend(int channel, int value);
88 |
89 | /**
90 | * Handles a raw MIDI byte; a raw byte is a byte that is received from the Bluetooth device but
91 | * doesn't belong to any of the channel messages that are explicitly handled by this interface.
92 | *
93 | * The idea is that we don't want to burden this basic interface with support for obscure system
94 | * messages, but at the same time we don't want to hide any MIDI events from client code. If you
95 | * need system messages, you can handle them by calling the decodeByte method of
96 | * {@link SystemMessageDecoder} from here.
97 | *
98 | * @param value raw MIDI byte
99 | */
100 | void onRawByte(byte value);
101 |
102 | /**
103 | * Begin assembling subsequent MIDI messages into one buffer. This is an optional optimization
104 | * that allows wire format converters to reduce the number of buffers they need to send, and it
105 | * provides a hint that several messages are supposed to occur at the same time.
106 | *
107 | * @return true if block mode is supported
108 | */
109 | boolean beginBlock();
110 |
111 | /**
112 | * Optionally concludes a block of buffers. If block mode is supported, this call will cause the
113 | * messages received since the beginBlock() call to be handled, e.g., by writing them to a USB or
114 | * other device.
115 | */
116 | void endBlock();
117 |
118 | public static class DummyReceiver implements MidiReceiver {
119 | @Override
120 | public void onNoteOff(int channel, int key, int velocity) {}
121 |
122 | @Override
123 | public void onNoteOn(int channel, int key, int velocity) {}
124 |
125 | @Override
126 | public void onPolyAftertouch(int channel, int key, int velocity) {}
127 |
128 | @Override
129 | public void onControlChange(int channel, int controller, int value) {}
130 |
131 | @Override
132 | public void onProgramChange(int channel, int program) {}
133 |
134 | @Override
135 | public void onAftertouch(int channel, int velocity) {}
136 |
137 | @Override
138 | public void onPitchBend(int channel, int value) {}
139 |
140 | @Override
141 | public void onRawByte(byte value) {}
142 |
143 | @Override
144 | public boolean beginBlock() {
145 | return false;
146 | }
147 |
148 | @Override
149 | public void endBlock() {}
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/MidiPlayer/src/com/noisepages/nettoyeur/midi/file/FastShortMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Sun designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Sun in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 | * CA 95054 USA or visit www.sun.com if you need additional information or
23 | * have any questions.
24 | */
25 |
26 | package com.noisepages.nettoyeur.midi.file;
27 |
28 |
29 | /**
30 | * an optimized ShortMessage that does not need an array
31 | *
32 | * @author Florian Bomers
33 | */
34 | class FastShortMessage extends ShortMessage {
35 | private int packedMsg;
36 |
37 | public FastShortMessage(int packedMsg) throws InvalidMidiDataException {
38 | this.packedMsg = packedMsg;
39 | getDataLength(packedMsg & 0xFF); // to check for validity
40 | }
41 |
42 | /** Creates a FastShortMessage from this ShortMessage */
43 | public FastShortMessage(ShortMessage msg) {
44 | this.packedMsg = msg.getStatus()
45 | | (msg.getData1() << 8)
46 | | (msg.getData2() << 16);
47 | }
48 |
49 | int getPackedMsg() {
50 | return packedMsg;
51 | }
52 |
53 | public byte[] getMessage() {
54 | int length = 0;
55 | try {
56 | // fix for bug 4851018: MidiMessage.getLength and .getData return wrong values
57 | // fix for bug 4890405: Reading MidiMessage byte array fails in 1.4.2
58 | length = getDataLength(packedMsg & 0xFF) + 1;
59 | } catch (InvalidMidiDataException imde) {
60 | // should never happen
61 | }
62 | byte[] returnedArray = new byte[length];
63 | if (length>0) {
64 | returnedArray[0] = (byte) (packedMsg & 0xFF);
65 | if (length>1) {
66 | returnedArray[1] = (byte) ((packedMsg & 0xFF00) >> 8);
67 | if (length>2) {
68 | returnedArray[2] = (byte) ((packedMsg & 0xFF0000) >> 16);
69 | }
70 | }
71 | }
72 | return returnedArray;
73 | }
74 |
75 | public int getLength() {
76 | try {
77 | return getDataLength(packedMsg & 0xFF) + 1;
78 | } catch (InvalidMidiDataException imde) {
79 | // should never happen
80 | }
81 | return 0;
82 | }
83 |
84 | public void setMessage(int status) throws InvalidMidiDataException {
85 | // check for valid values
86 | int dataLength = getDataLength(status); // can throw InvalidMidiDataException
87 | if (dataLength != 0) {
88 | super.setMessage(status); // throws Exception
89 | }
90 | packedMsg = (packedMsg & 0xFFFF00) | (status & 0xFF);
91 | }
92 |
93 |
94 | public void setMessage(int status, int data1, int data2) throws InvalidMidiDataException {
95 | getDataLength(status); // can throw InvalidMidiDataException
96 | packedMsg = (status & 0xFF) | ((data1 & 0xFF) << 8) | ((data2 & 0xFF) << 16);
97 | }
98 |
99 |
100 | public void setMessage(int command, int channel, int data1, int data2) throws InvalidMidiDataException {
101 | getDataLength(command); // can throw InvalidMidiDataException
102 | packedMsg = (command & 0xF0) | (channel & 0x0F) | ((data1 & 0xFF) << 8) | ((data2 & 0xFF) << 16);
103 | }
104 |
105 |
106 | public int getChannel() {
107 | return packedMsg & 0x0F;
108 | }
109 |
110 | public int getCommand() {
111 | return packedMsg & 0xF0;
112 | }
113 |
114 | public int getData1() {
115 | return (packedMsg & 0xFF00) >> 8;
116 | }
117 |
118 | public int getData2() {
119 | return (packedMsg & 0xFF0000) >> 16;
120 | }
121 |
122 | public int getStatus() {
123 | return packedMsg & 0xFF;
124 | }
125 |
126 | /**
127 | * Creates a new object of the same class and with the same contents
128 | * as this object.
129 | * @return a clone of this instance.
130 | */
131 | public Object clone() {
132 | try {
133 | return new FastShortMessage(packedMsg);
134 | } catch (InvalidMidiDataException imde) {
135 | // should never happen
136 | }
137 | return null;
138 | }
139 |
140 | } // class FastShortMsg
141 |
--------------------------------------------------------------------------------
/AndroidMidiTest/javatests/com/noisepages/nettoyeur/midi/util/SystemMessageEncoderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.midi.util;
16 |
17 | import org.easymock.EasyMock;
18 | import org.junit.Before;
19 | import org.junit.Test;
20 |
21 | import com.noisepages.nettoyeur.midi.MidiReceiver;
22 |
23 | public class SystemMessageEncoderTest {
24 |
25 | MidiReceiver receiver;
26 | SystemMessageEncoder encoder;
27 |
28 | @Before
29 | public void setUp() {
30 | receiver = EasyMock.createStrictMock(MidiReceiver.class);
31 | encoder = new SystemMessageEncoder(receiver);
32 | }
33 |
34 | @Test
35 | public void testSystemExclusive() {
36 | receiver.onRawByte((byte) 0xf0);
37 | receiver.onRawByte((byte) 0xf7);
38 | receiver.onRawByte((byte) 0xf0);
39 | receiver.onRawByte((byte) 0x00);
40 | receiver.onRawByte((byte) 0x7f);
41 | receiver.onRawByte((byte) 0x03);
42 | receiver.onRawByte((byte) 0xf7);
43 | EasyMock.replay(receiver);
44 | encoder.onSystemExclusive(new byte[0]);
45 | encoder.onSystemExclusive(new byte[] {0x00, 0x7f, 0x03});
46 | EasyMock.verify(receiver);
47 | }
48 |
49 | @Test
50 | public void testTimeCode() {
51 | receiver.onRawByte((byte) 0xf1);
52 | receiver.onRawByte((byte) 0x00);
53 | receiver.onRawByte((byte) 0xf1);
54 | receiver.onRawByte((byte) 0x7f);
55 | receiver.onRawByte((byte) 0xf1);
56 | receiver.onRawByte((byte) 0x61);
57 | EasyMock.replay(receiver);
58 | encoder.onTimeCode(0x00);
59 | encoder.onTimeCode(0x7f);
60 | encoder.onTimeCode(0x61);
61 | EasyMock.verify(receiver);
62 | }
63 |
64 | @Test
65 | public void testSongPosition() {
66 | receiver.onRawByte((byte) 0xf2);
67 | receiver.onRawByte((byte) 0x00);
68 | receiver.onRawByte((byte) 0x00);
69 | receiver.onRawByte((byte) 0xf2);
70 | receiver.onRawByte((byte) 0x7f);
71 | receiver.onRawByte((byte) 0x7f);
72 | receiver.onRawByte((byte) 0xf2);
73 | receiver.onRawByte((byte) 0x03);
74 | receiver.onRawByte((byte) 0x01);
75 | EasyMock.replay(receiver);
76 | encoder.onSongPosition(0);
77 | encoder.onSongPosition(0x3fff);
78 | encoder.onSongPosition(0x0083);
79 | EasyMock.verify(receiver);
80 | }
81 |
82 | @Test(expected = IllegalArgumentException.class)
83 | public void testBadSongPosition1() {
84 | encoder.onSongPosition(-1);
85 | }
86 |
87 | @Test(expected = IllegalArgumentException.class)
88 | public void testBadSongPosition2() {
89 | encoder.onSongPosition(0x4000);
90 | }
91 |
92 | @Test
93 | public void testSongSelect() {
94 | receiver.onRawByte((byte) 0xf3);
95 | receiver.onRawByte((byte) 0x00);
96 | receiver.onRawByte((byte) 0xf3);
97 | receiver.onRawByte((byte) 0x7f);
98 | receiver.onRawByte((byte) 0xf3);
99 | receiver.onRawByte((byte) 0x45);
100 | EasyMock.replay(receiver);
101 | encoder.onSongSelect(0);
102 | encoder.onSongSelect(0x7f);
103 | encoder.onSongSelect(0x45);
104 | EasyMock.verify(receiver);
105 | }
106 |
107 | @Test(expected = IllegalArgumentException.class)
108 | public void testBadSongIndex1() {
109 | encoder.onSongSelect(-1);
110 | }
111 |
112 | @Test(expected = IllegalArgumentException.class)
113 | public void testBadSongIndex2() {
114 | encoder.onSongSelect(128);
115 | }
116 |
117 | @Test
118 | public void testTuneRequest() {
119 | receiver.onRawByte((byte) 0xf6);
120 | EasyMock.replay(receiver);
121 | encoder.onTuneRequest();
122 | EasyMock.verify(receiver);
123 |
124 | }
125 |
126 | @Test
127 | public void testTimingClock() {
128 | receiver.onRawByte((byte) 0xf8);
129 | EasyMock.replay(receiver);
130 | encoder.onTimingClock();
131 | EasyMock.verify(receiver);
132 | }
133 |
134 | @Test
135 | public void testStart() {
136 | receiver.onRawByte((byte) 0xfa);
137 | EasyMock.replay(receiver);
138 | encoder.onStart();
139 | EasyMock.verify(receiver);
140 | }
141 |
142 | @Test
143 | public void testContinue() {
144 | receiver.onRawByte((byte) 0xfb);
145 | EasyMock.replay(receiver);
146 | encoder.onContinue();
147 | EasyMock.verify(receiver);
148 | }
149 |
150 | @Test
151 | public void testStop() {
152 | receiver.onRawByte((byte) 0xfc);
153 | EasyMock.replay(receiver);
154 | encoder.onStop();
155 | EasyMock.verify(receiver);
156 | }
157 |
158 | @Test
159 | public void testActiveSensing() {
160 | receiver.onRawByte((byte) 0xfe);
161 | EasyMock.replay(receiver);
162 | encoder.onActiveSensing();
163 | EasyMock.verify(receiver);
164 | }
165 |
166 | @Test
167 | public void testSystemReset() {
168 | receiver.onRawByte((byte) 0xff);
169 | EasyMock.replay(receiver);
170 | encoder.onSystemReset();
171 | EasyMock.verify(receiver);
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/MidiPlayer/src/com/noisepages/nettoyeur/midi/player/MidiPlayerService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann
3 | *
4 | * This program is free software; you can redistribute it and/or modify it under the terms of the
5 | * GNU General Public License as published by the Free Software Foundation; either version 2 of the
6 | * License, or (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 | * General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License along with this program; if
13 | * not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14 | * 02110-1301 USA.
15 | */
16 |
17 | package com.noisepages.nettoyeur.midi.player;
18 |
19 | import java.io.InputStream;
20 |
21 | import android.app.Notification;
22 | import android.app.PendingIntent;
23 | import android.app.Service;
24 | import android.content.Intent;
25 | import android.net.Uri;
26 | import android.os.Binder;
27 | import android.os.IBinder;
28 |
29 | import com.noisepages.nettoyeur.midi.FromWireConverter;
30 | import com.noisepages.nettoyeur.midi.MidiDevice;
31 | import com.noisepages.nettoyeur.midi.MidiReceiver;
32 |
33 |
34 | public class MidiPlayerService extends Service {
35 |
36 | public enum ConnectionType {
37 | NONE, BLUETOOTH, USB,
38 | }
39 |
40 | private static final CharSequence TAG = "MidiPlayerService";
41 | private static final int ID = 1;
42 |
43 | private volatile ConnectionType connectionType = ConnectionType.NONE;
44 | private volatile MidiDevice midiDevice = null;
45 | private volatile MidiSequence midiSequence = null;
46 | private volatile FromWireConverter midiConverter = null;
47 | private volatile Uri uri = null;
48 |
49 | private final Binder binder = new MidiPlayerServiceBinder();
50 |
51 | public class MidiPlayerServiceBinder extends Binder {
52 | public MidiPlayerService getService() {
53 | return MidiPlayerService.this;
54 | }
55 | }
56 |
57 | @Override
58 | public IBinder onBind(Intent intent) {
59 | return binder;
60 | }
61 |
62 | @Override
63 | public boolean onUnbind(Intent intent) {
64 | reset();
65 | return super.onUnbind(intent);
66 | }
67 |
68 | public void reset() {
69 | if (isInitialized()) {
70 | pause();
71 | }
72 | if (midiDevice != null) {
73 | midiDevice.close();
74 | midiDevice = null;
75 | midiConverter = null;
76 | }
77 | connectionType = ConnectionType.NONE;
78 | stopForeground(true);
79 | }
80 |
81 | public boolean isInitialized() {
82 | return midiSequence != null;
83 | }
84 |
85 | public ConnectionType getConnectionType() {
86 | return connectionType;
87 | }
88 |
89 | public boolean loadMidiSequence(Uri uri, final MidiSequenceObserver observer) {
90 | if (isInitialized()) {
91 | pause();
92 | }
93 | try {
94 | InputStream is = getContentResolver().openInputStream(uri);
95 | midiSequence = new MidiSequence(is, new MidiSequenceObserver() {
96 | @Override
97 | public void onPlaybackFinished(MidiSequence sequence) {
98 | observer.onPlaybackFinished(sequence);
99 | stopForeground(true);
100 | }
101 | });
102 | this.uri = uri;
103 | } catch (Exception e) {
104 | e.printStackTrace();
105 | return false;
106 | }
107 | return true;
108 | }
109 |
110 | public long getDuration() {
111 | return isInitialized() ? midiSequence.duration : 0;
112 | }
113 |
114 | public Uri getUri() {
115 | return uri;
116 | }
117 |
118 | public void connectBluetooth(MidiDevice device, MidiReceiver receiver) {
119 | reset();
120 | midiDevice = device;
121 | midiConverter = new FromWireConverter(receiver);
122 | connectionType = ConnectionType.BLUETOOTH;
123 | }
124 |
125 | public void connectUsb(MidiDevice device, MidiReceiver receiver) {
126 | reset();
127 | midiDevice = device;
128 | midiConverter = new FromWireConverter(receiver);
129 | connectionType = ConnectionType.USB;
130 | }
131 |
132 | public boolean isPlaying() {
133 | return isInitialized() && midiSequence.isPlaying();
134 | }
135 |
136 | @SuppressWarnings("deprecation")
137 | public void start(Intent intent) {
138 | if (!isInitialized()) {
139 | throw new IllegalStateException("MidiPlayerService not initialized");
140 | }
141 | PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
142 | Notification notification = new Notification(R.drawable.din5, TAG, System.currentTimeMillis());
143 | notification.setLatestEventInfo(this, TAG, "Return to MidiPlayer", pi);
144 | notification.flags |= Notification.FLAG_ONGOING_EVENT;
145 | startForeground(ID, notification);
146 | midiSequence.start(midiConverter);
147 | }
148 |
149 | public void pause() {
150 | if (!isInitialized()) {
151 | throw new IllegalStateException("MidiPlayerService not initialized");
152 | }
153 | midiSequence.pause();
154 | stopForeground(true);
155 | }
156 |
157 | public void rewind() {
158 | if (!isInitialized()) {
159 | throw new IllegalStateException("MidiPlayerService not initialized");
160 | }
161 | midiSequence.rewind();
162 | stopForeground(true);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/BluetoothMidiTest/src/com/noisepages/nettoyeur/miditest/BluetoothMidiTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the
4 | * file, "LICENSE.txt," in this distribution.
5 | *
6 | */
7 |
8 | package com.noisepages.nettoyeur.miditest;
9 |
10 | import java.io.IOException;
11 |
12 | import android.app.Activity;
13 | import android.bluetooth.BluetoothDevice;
14 | import android.content.Intent;
15 | import android.text.method.ScrollingMovementMethod;
16 | import android.view.View;
17 | import android.view.View.OnClickListener;
18 | import android.widget.Button;
19 | import android.widget.TextView;
20 | import android.widget.Toast;
21 |
22 | import com.noisepages.nettoyeur.bluetooth.BluetoothSppConnection;
23 | import com.noisepages.nettoyeur.bluetooth.BluetoothSppObserver;
24 | import com.noisepages.nettoyeur.bluetooth.midi.BluetoothMidiDevice;
25 | import com.noisepages.nettoyeur.bluetooth.util.DeviceListActivity;
26 | import com.noisepages.nettoyeur.midi.MidiReceiver;
27 |
28 | public class BluetoothMidiTest extends Activity implements OnClickListener {
29 |
30 | private static final String TAG = "Midi Test";
31 |
32 | private static final int CONNECT = 1;
33 |
34 | private Button connect;
35 | private Button play;
36 | private TextView logs;
37 |
38 | private BluetoothMidiDevice midiService = null;
39 |
40 | private Toast toast = null;
41 |
42 | private void toast(final String msg) {
43 | runOnUiThread(new Runnable() {
44 | @Override
45 | public void run() {
46 | if (toast == null) {
47 | toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
48 | }
49 | toast.setText(TAG + ": " + msg);
50 | toast.show();
51 | }
52 | });
53 | }
54 |
55 | private void post(final String s) {
56 | runOnUiThread(new Runnable() {
57 | @Override
58 | public void run() {
59 | logs.append(s + ((s.endsWith("\n")) ? "" : "\n"));
60 | }
61 | });
62 | }
63 |
64 | private final BluetoothSppObserver observer = new BluetoothSppObserver() {
65 | @Override
66 | public void onDeviceConnected(BluetoothDevice device) {
67 | post("device connected: " + device);
68 | }
69 |
70 | @Override
71 | public void onConnectionLost() {
72 | post("connection lost");
73 | }
74 |
75 | @Override
76 | public void onConnectionFailed() {
77 | post("connection failed");
78 | }
79 | };
80 |
81 | private final MidiReceiver receiver = new MidiReceiver() {
82 | @Override
83 | public void onNoteOff(int channel, int key, int velocity) {
84 | post("note off: " + channel + ", " + key + ", " + velocity);
85 | }
86 |
87 | @Override
88 | public void onNoteOn(int channel, int key, int velocity) {
89 | post("note on: " + channel + ", " + key + ", " + velocity);
90 | }
91 |
92 | @Override
93 | public void onAftertouch(int channel, int velocity) {
94 | post("aftertouch: " + channel + ", " + velocity);
95 | }
96 |
97 | @Override
98 | public void onControlChange(int channel, int controller, int value) {
99 | post("control change: " + channel + ", " + controller + ", " + value);
100 | }
101 |
102 | @Override
103 | public void onPitchBend(int channel, int value) {
104 | post("pitch bend: " + channel + ", " + value);
105 | }
106 |
107 | @Override
108 | public void onPolyAftertouch(int channel, int key, int velocity) {
109 | post("polyphonic aftertouch: " + channel + ", " + key + ", " + velocity);
110 | }
111 |
112 | @Override
113 | public void onProgramChange(int channel, int program) {
114 | post("program change: " + channel + ", " + program);
115 | }
116 |
117 | @Override
118 | public void onRawByte(byte value) {
119 | post("raw byte: " + Integer.toHexString(value));
120 | }
121 |
122 | @Override
123 | public boolean beginBlock() {
124 | return false;
125 | }
126 |
127 | @Override
128 | public void endBlock() {}
129 | };
130 |
131 | @Override
132 | protected void onCreate(android.os.Bundle savedInstanceState) {
133 | super.onCreate(savedInstanceState);
134 | initGui();
135 | try {
136 | midiService = new BluetoothMidiDevice(observer, receiver);
137 | } catch (IOException e) {
138 | toast("MIDI not available");
139 | finish();
140 | }
141 | };
142 |
143 | @Override
144 | protected void onDestroy() {
145 | super.onDestroy();
146 | cleanup();
147 | }
148 |
149 | private void initGui() {
150 | setContentView(R.layout.main);
151 | connect = (Button) findViewById(R.id.connect_button);
152 | connect.setOnClickListener(this);
153 | play = (Button) findViewById(R.id.play_button);
154 | play.setOnClickListener(this);
155 | logs = (TextView) findViewById(R.id.log_box);
156 | logs.setMovementMethod(new ScrollingMovementMethod());
157 | }
158 |
159 | private void cleanup() {
160 | if (midiService != null) {
161 | midiService.close();
162 | midiService = null;
163 | }
164 | }
165 |
166 | @Override
167 | public void finish() {
168 | cleanup();
169 | super.finish();
170 | }
171 |
172 | private int note = 60;
173 | private boolean on = false;
174 |
175 | @Override
176 | public void onClick(View v) {
177 | switch (v.getId()) {
178 | case R.id.connect_button:
179 | if (midiService.getConnectionState() == BluetoothSppConnection.State.NONE) {
180 | startActivityForResult(new Intent(this, DeviceListActivity.class), CONNECT);
181 | } else {
182 | midiService.close();
183 | }
184 | break;
185 | case R.id.play_button:
186 | if (!on) {
187 | midiService.getMidiOut().onNoteOn(0, note, 80);
188 | } else {
189 | midiService.getMidiOut().onNoteOff(0, note, 64);
190 | note++;
191 | }
192 | on = !on;
193 | default:
194 | break;
195 | }
196 | }
197 |
198 | @Override
199 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
200 | switch (requestCode) {
201 | case CONNECT:
202 | if (resultCode == Activity.RESULT_OK) {
203 | String address = data.getExtras().getString(DeviceListActivity.DEVICE_ADDRESS);
204 | try {
205 | midiService.connect(address);
206 | } catch (IOException e) {
207 | toast(e.getMessage());
208 | }
209 | }
210 | break;
211 | }
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/AndroidMidi/src/com/noisepages/nettoyeur/usb/UsbDeviceWithInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.usb;
16 |
17 | import android.annotation.TargetApi;
18 | import android.app.PendingIntent;
19 | import android.content.BroadcastReceiver;
20 | import android.content.Context;
21 | import android.content.Intent;
22 | import android.content.IntentFilter;
23 | import android.hardware.usb.UsbDevice;
24 | import android.hardware.usb.UsbManager;
25 | import android.os.Build;
26 |
27 | /**
28 | * Wrapper for {@link UsbDevice} that also holds a {@link DeviceInfo} object, plus a few convenience
29 | * methods for handling USB permissions.
30 | *
31 | * @author Peter Brinkmann (peter.brinkmann@gmail.com)
32 | */
33 | @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
34 | public class UsbDeviceWithInfo {
35 |
36 | private static final String ACTION_USB_PERMISSION = "com.noisepages.nettoyeur.usb.USB_PERMISSION";
37 |
38 | private static BroadcastReceiver broadcastReceiver = null;
39 |
40 | protected final UsbDevice device;
41 | private volatile DeviceInfo info;
42 | private volatile boolean hasReadableInfo = false;
43 |
44 | /**
45 | * Convenience method for handling responses to USB permission requests, to be called in the
46 | * onCreate method of activities that connect to USB devices. Activities that use call this method
47 | * also have to uninstall the permission handler in their onDestroy method (see
48 | * uninstallPermissionHandler).
49 | *
50 | * @param context the current context, e.g., the activity invoking this method
51 | * @param handler
52 | */
53 | public static void installBroadcastHandler(Context context, final UsbBroadcastHandler handler) {
54 | uninstallBroadcastHandler(context);
55 | broadcastReceiver = new BroadcastReceiver() {
56 | @Override
57 | public void onReceive(Context context, Intent intent) {
58 | String action = intent.getAction();
59 | UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
60 | if (device == null) return;
61 | if (ACTION_USB_PERMISSION.equals(action)) {
62 | if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
63 | handler.onPermissionGranted(device);
64 | } else {
65 | handler.onPermissionDenied(device);
66 | }
67 | } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
68 | handler.onDeviceDetached(device);
69 | }
70 | }
71 | };
72 | context.registerReceiver(broadcastReceiver, new IntentFilter(ACTION_USB_PERMISSION));
73 | context.registerReceiver(broadcastReceiver, new IntentFilter(
74 | UsbManager.ACTION_USB_DEVICE_DETACHED));
75 | }
76 |
77 | /**
78 | * Uninstalls the permission handler; must be called in the onDestroy method of activities that
79 | * install a permission handler.
80 | *
81 | * @param context the current context, e.g., the activity invoking this method
82 | */
83 | public static void uninstallBroadcastHandler(Context context) {
84 | if (broadcastReceiver != null) {
85 | try {
86 | context.unregisterReceiver(broadcastReceiver);
87 | } catch (IllegalArgumentException e) {
88 | // Do nothing. This exception is entirely benign; it'll happen if we try to remove a
89 | // receiver that
90 | // isn't there, which is a reasonable thing to do in some situations.
91 | }
92 | broadcastReceiver = null;
93 | }
94 | }
95 |
96 | /**
97 | * Convenience method for requesting permission to use the USB device; may only be called if a
98 | * permission handler is installed.
99 | *
100 | * @param context the current context, e.g., the activity invoking this method
101 | */
102 | public void requestPermission(Context context) {
103 | if (broadcastReceiver == null) {
104 | throw new IllegalStateException(
105 | "installPermissionHandler must be called before requesting permission");
106 | }
107 | ((UsbManager) context.getSystemService(Context.USB_SERVICE)).requestPermission(device,
108 | PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0));
109 | }
110 |
111 | /**
112 | * Constructor.
113 | *
114 | * @param device to be wrapped
115 | */
116 | public UsbDeviceWithInfo(UsbDevice device) {
117 | this.device = device;
118 | info = new DeviceInfo(device);
119 | }
120 |
121 | /**
122 | * Checks whether a given USB device equals the device wrapped by this instance; useful for
123 | * checking whether {@link UsbBroadcastHandler} callbacks are for a particular instance of
124 | * UsbDeviceWithInfo.
125 | *
126 | * @param otherDevice to compare this device to
127 | * @return true if otherDevice equals the USB device wrapped by this instance
128 | */
129 | public boolean matches(UsbDevice otherDevice) {
130 | return this.device.equals(otherDevice);
131 | }
132 |
133 | /**
134 | * Note: The return value may change over the lifetime of this object. By default, it is populated
135 | * with numerical information from the underlying UsbDevice object, but if
136 | * retrieveReadableDeviceInfo is invoked, then it may be replaced with human readable data
137 | * retrieved from the web.
138 | *
139 | * @return the current device info
140 | */
141 | public DeviceInfo getCurrentDeviceInfo() {
142 | return info;
143 | }
144 |
145 | /**
146 | * Attempts to replace the default device info with human readable device info from the web; must
147 | * not be called on the main thread as it performs an online lookup and may cause the app to
148 | * become unresponsive.
149 | *
150 | * Requires android.permission.INTERNET.
151 | *
152 | * @return true on success
153 | */
154 | public boolean retrieveReadableDeviceInfo() {
155 | if (hasReadableInfo) return true;
156 | DeviceInfo readableInfo = DeviceInfo.retrieveDeviceInfo(device);
157 | if (readableInfo != null) {
158 | info = readableInfo;
159 | hasReadableInfo = true;
160 | }
161 | return hasReadableInfo;
162 | }
163 |
164 | @Override
165 | public String toString() {
166 | return device.toString();
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/AndroidMidiTest/javatests/com/noisepages/nettoyeur/midi/util/SystemMessageDecoderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Peter Brinkmann (peter.brinkmann@gmail.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.noisepages.nettoyeur.midi.util;
16 |
17 | import static org.junit.Assert.*;
18 |
19 | import org.easymock.EasyMock;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | public class SystemMessageDecoderTest {
24 |
25 | private SystemMessageDecoder decoder;
26 | private SystemMessageReceiver receiver;
27 |
28 | @Before
29 | public void setUp() {
30 | receiver = EasyMock.createStrictMock(SystemMessageReceiver.class);
31 | decoder = new SystemMessageDecoder(receiver);
32 | }
33 |
34 | @Test
35 | public void testSysex() {
36 | receiver.onSystemExclusive(EasyMock.aryEq(new byte[0]));
37 | byte[] msg = new byte[] {0x20, 0x01, 0x02, 0x00, 0x7f, 0x60};
38 | receiver.onSystemExclusive(EasyMock.aryEq(msg));
39 | receiver.onSystemExclusive(EasyMock.aryEq(new byte[0]));
40 | EasyMock.replay(receiver);
41 | assertTrue(decoder.decodeByte((byte) 0xf0));
42 | assertTrue(decoder.decodeByte((byte) 0xf7));
43 | assertTrue(decoder.decodeByte((byte) 0xf0));
44 | for (byte b : msg) {
45 | assertTrue(decoder.decodeByte(b));
46 | }
47 | assertTrue(decoder.decodeByte((byte) 0xf7));
48 | assertTrue(decoder.decodeByte((byte) 0xf0));
49 | assertTrue(decoder.decodeByte((byte) 0xf7));
50 | EasyMock.verify(receiver);
51 | }
52 |
53 | @Test
54 | public void testTimeCode() {
55 | receiver.onTimeCode(0);
56 | receiver.onTimeCode(0x7f);
57 | receiver.onTimeCode(0x40);
58 | EasyMock.replay(receiver);
59 | assertTrue(decoder.decodeByte((byte) 0xf1));
60 | assertTrue(decoder.decodeByte((byte) 0x00));
61 | assertTrue(decoder.decodeByte((byte) 0xf1));
62 | assertTrue(decoder.decodeByte((byte) 0x7f));
63 | assertTrue(decoder.decodeByte((byte) 0xf1));
64 | assertTrue(decoder.decodeByte((byte) 0x40));
65 | EasyMock.verify(receiver);
66 | }
67 |
68 | @Test
69 | public void testSongPosition() {
70 | receiver.onSongPosition(0x00);
71 | receiver.onSongPosition(0x60);
72 | receiver.onSongPosition(0x80);
73 | receiver.onSongPosition(0x3fff);
74 | EasyMock.replay(receiver);
75 | assertTrue(decoder.decodeByte((byte) 0xf2));
76 | assertTrue(decoder.decodeByte((byte) 0x00));
77 | assertTrue(decoder.decodeByte((byte) 0x00));
78 | assertTrue(decoder.decodeByte((byte) 0xf2));
79 | assertTrue(decoder.decodeByte((byte) 0x60));
80 | assertTrue(decoder.decodeByte((byte) 0x00));
81 | assertTrue(decoder.decodeByte((byte) 0xf2));
82 | assertTrue(decoder.decodeByte((byte) 0x00));
83 | assertTrue(decoder.decodeByte((byte) 0x01));
84 | assertTrue(decoder.decodeByte((byte) 0xf2));
85 | assertTrue(decoder.decodeByte((byte) 0x7f));
86 | assertTrue(decoder.decodeByte((byte) 0x7f));
87 | EasyMock.verify(receiver);
88 | }
89 |
90 | @Test
91 | public void testSongSelect() {
92 | receiver.onSongSelect(0x00);
93 | receiver.onSongSelect(0x35);
94 | receiver.onSongSelect(0x7f);
95 | EasyMock.replay(receiver);
96 | assertTrue(decoder.decodeByte((byte) 0xf3));
97 | assertTrue(decoder.decodeByte((byte) 0x00));
98 | assertTrue(decoder.decodeByte((byte) 0xf3));
99 | assertTrue(decoder.decodeByte((byte) 0x35));
100 | assertTrue(decoder.decodeByte((byte) 0xf3));
101 | assertTrue(decoder.decodeByte((byte) 0x7f));
102 | EasyMock.verify(receiver);
103 | }
104 |
105 | @Test
106 | public void testTuneRequest() {
107 | receiver.onTuneRequest();
108 | EasyMock.replay(receiver);
109 | assertTrue(decoder.decodeByte((byte) 0xf6));
110 | EasyMock.verify(receiver);
111 | }
112 |
113 | @Test
114 | public void testTimingClock() {
115 | receiver.onTimingClock();
116 | EasyMock.replay(receiver);
117 | assertTrue(decoder.decodeByte((byte) 0xf8));
118 | EasyMock.verify(receiver);
119 | }
120 |
121 | @Test
122 | public void testStart() {
123 | receiver.onStart();
124 | EasyMock.replay(receiver);
125 | assertTrue(decoder.decodeByte((byte) 0xfa));
126 | EasyMock.verify(receiver);
127 | }
128 |
129 | @Test
130 | public void testContinue() {
131 | receiver.onContinue();
132 | EasyMock.replay(receiver);
133 | assertTrue(decoder.decodeByte((byte) 0xfb));
134 | EasyMock.verify(receiver);
135 | }
136 |
137 | @Test
138 | public void testStop() {
139 | receiver.onStop();
140 | EasyMock.replay(receiver);
141 | assertTrue(decoder.decodeByte((byte) 0xfc));
142 | EasyMock.verify(receiver);
143 | }
144 |
145 | @Test
146 | public void testActiveSensing() {
147 | receiver.onActiveSensing();
148 | EasyMock.replay(receiver);
149 | assertTrue(decoder.decodeByte((byte) 0xfe));
150 | EasyMock.verify(receiver);
151 | }
152 |
153 | @Test
154 | public void testSystemReset() {
155 | receiver.onSystemReset();
156 | EasyMock.replay(receiver);
157 | assertTrue(decoder.decodeByte((byte) 0xff));
158 | EasyMock.verify(receiver);
159 | }
160 |
161 | @Test
162 | public void testUnhandled() {
163 | receiver.onTuneRequest();
164 | EasyMock.replay(receiver);
165 | assertFalse(decoder.decodeByte((byte) 0x00));
166 | assertFalse(decoder.decodeByte((byte) 0xf4));
167 | assertFalse(decoder.decodeByte((byte) 0xf5));
168 | assertFalse(decoder.decodeByte((byte) 0xf9));
169 | assertFalse(decoder.decodeByte((byte) 0xfd));
170 | assertTrue(decoder.decodeByte((byte) 0xf0));
171 | assertTrue(decoder.decodeByte((byte) 0xf6));
172 | assertFalse(decoder.decodeByte((byte) 0x00));
173 | assertTrue(decoder.decodeByte((byte) 0xf7));
174 | EasyMock.verify(receiver);
175 | }
176 |
177 | @Test
178 | public void testInterleaved() {
179 | receiver.onStart();
180 | receiver.onSystemExclusive(EasyMock.aryEq(new byte[] {0x01, 0x02, 0x03, 0x04}));
181 | EasyMock.replay(receiver);
182 | assertTrue(decoder.decodeByte((byte) 0xf0));
183 | assertTrue(decoder.decodeByte((byte) 0x01));
184 | assertTrue(decoder.decodeByte((byte) 0x02));
185 | assertTrue(decoder.decodeByte((byte) 0xfa)); // Start message in the middle of a sysex message.
186 | assertTrue(decoder.decodeByte((byte) 0x03));
187 | assertTrue(decoder.decodeByte((byte) 0x04));
188 | assertTrue(decoder.decodeByte((byte) 0xf7));
189 | EasyMock.verify(receiver);
190 | }
191 | }
192 |
--------------------------------------------------------------------------------