From 6ab42c36e877ca920212b0a1586268a2e855c2e3 Mon Sep 17 00:00:00 2001 From: Yuichi Araki Date: Mon, 17 Aug 2015 15:22:28 +0900 Subject: MidiScope: Add a sample This brings back MidiScope that was deleted in order to resolve a merge conflict. Change-Id: I027d53ad57eea89827d486918c0000af5521d463 --- media/MidiScope/Application/.gitignore | 16 ++ media/MidiScope/Application/proguard-project.txt | 20 +++ .../android/midiscope/test/SampleTests.java | 54 +++++++ .../Application/src/main/AndroidManifest.xml | 55 +++++++ .../example/android/midiscope/LoggingReceiver.java | 62 ++++++++ .../example/android/midiscope/MainActivity.java | 162 ++++++++++++++++++++ .../com/example/android/midiscope/MidiPrinter.java | 108 ++++++++++++++ .../com/example/android/midiscope/MidiScope.java | 83 +++++++++++ .../com/example/android/midiscope/ScopeLogger.java | 25 ++++ .../src/main/res/drawable-hdpi/ic_clear_all.png | Bin 0 -> 107 bytes .../src/main/res/drawable-mdpi/ic_clear_all.png | Bin 0 -> 83 bytes .../src/main/res/drawable-xhdpi/ic_clear_all.png | Bin 0 -> 99 bytes .../src/main/res/drawable-xxhdpi/ic_clear_all.png | Bin 0 -> 108 bytes .../src/main/res/drawable-xxxhdpi/ic_clear_all.png | Bin 0 -> 98 bytes .../Application/src/main/res/layout/main.xml | 60 ++++++++ .../Application/src/main/res/menu/main.xml | 32 ++++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3022 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 1887 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 3855 bytes .../src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6224 bytes .../src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 8972 bytes .../Application/src/main/res/values/colors.xml | 26 ++++ .../Application/src/main/res/values/strings.xml | 24 +++ .../Application/src/main/res/values/styles.xml | 25 ++++ .../src/main/res/xml/scope_device_info.xml | 24 +++ media/MidiScope/build.gradle | 12 ++ media/MidiScope/buildSrc/build.gradle | 16 ++ media/MidiScope/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + media/MidiScope/gradlew | 164 +++++++++++++++++++++ media/MidiScope/gradlew.bat | 90 +++++++++++ media/MidiScope/screenshots/1-main.png | Bin 0 -> 43259 bytes media/MidiScope/screenshots/2-signals.png | Bin 0 -> 265359 bytes media/MidiScope/screenshots/icon-web.png | Bin 0 -> 34730 bytes media/MidiScope/settings.gradle | 2 + media/MidiScope/template-params.xml | 79 ++++++++++ 36 files changed, 1145 insertions(+) create mode 100644 media/MidiScope/Application/.gitignore create mode 100644 media/MidiScope/Application/proguard-project.txt create mode 100644 media/MidiScope/Application/src/androidTest/java/com/example/android/midiscope/test/SampleTests.java create mode 100644 media/MidiScope/Application/src/main/AndroidManifest.xml create mode 100644 media/MidiScope/Application/src/main/java/com/example/android/midiscope/LoggingReceiver.java create mode 100644 media/MidiScope/Application/src/main/java/com/example/android/midiscope/MainActivity.java create mode 100644 media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiPrinter.java create mode 100644 media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiScope.java create mode 100644 media/MidiScope/Application/src/main/java/com/example/android/midiscope/ScopeLogger.java create mode 100755 media/MidiScope/Application/src/main/res/drawable-hdpi/ic_clear_all.png create mode 100755 media/MidiScope/Application/src/main/res/drawable-mdpi/ic_clear_all.png create mode 100755 media/MidiScope/Application/src/main/res/drawable-xhdpi/ic_clear_all.png create mode 100755 media/MidiScope/Application/src/main/res/drawable-xxhdpi/ic_clear_all.png create mode 100755 media/MidiScope/Application/src/main/res/drawable-xxxhdpi/ic_clear_all.png create mode 100644 media/MidiScope/Application/src/main/res/layout/main.xml create mode 100644 media/MidiScope/Application/src/main/res/menu/main.xml create mode 100755 media/MidiScope/Application/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100755 media/MidiScope/Application/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100755 media/MidiScope/Application/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100755 media/MidiScope/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100755 media/MidiScope/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 media/MidiScope/Application/src/main/res/values/colors.xml create mode 100644 media/MidiScope/Application/src/main/res/values/strings.xml create mode 100644 media/MidiScope/Application/src/main/res/values/styles.xml create mode 100644 media/MidiScope/Application/src/main/res/xml/scope_device_info.xml create mode 100644 media/MidiScope/build.gradle create mode 100644 media/MidiScope/buildSrc/build.gradle create mode 100644 media/MidiScope/gradle/wrapper/gradle-wrapper.jar create mode 100644 media/MidiScope/gradle/wrapper/gradle-wrapper.properties create mode 100755 media/MidiScope/gradlew create mode 100644 media/MidiScope/gradlew.bat create mode 100644 media/MidiScope/screenshots/1-main.png create mode 100644 media/MidiScope/screenshots/2-signals.png create mode 100644 media/MidiScope/screenshots/icon-web.png create mode 100644 media/MidiScope/settings.gradle create mode 100644 media/MidiScope/template-params.xml (limited to 'media') diff --git a/media/MidiScope/Application/.gitignore b/media/MidiScope/Application/.gitignore new file mode 100644 index 00000000..6eb878d4 --- /dev/null +++ b/media/MidiScope/Application/.gitignore @@ -0,0 +1,16 @@ +# Copyright 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +src/template/ +src/common/ +build.gradle diff --git a/media/MidiScope/Application/proguard-project.txt b/media/MidiScope/Application/proguard-project.txt new file mode 100644 index 00000000..f2fe1559 --- /dev/null +++ b/media/MidiScope/Application/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/media/MidiScope/Application/src/androidTest/java/com/example/android/midiscope/test/SampleTests.java b/media/MidiScope/Application/src/androidTest/java/com/example/android/midiscope/test/SampleTests.java new file mode 100644 index 00000000..e132dae9 --- /dev/null +++ b/media/MidiScope/Application/src/androidTest/java/com/example/android/midiscope/test/SampleTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.midiscope.test; + +import com.example.android.midiscope.*; + +import android.test.ActivityInstrumentationTestCase2; + +/** + * Tests for MidiScope sample. + */ +public class SampleTests extends ActivityInstrumentationTestCase2 { + + private MainActivity mTestActivity; + + public SampleTests() { + super(MainActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // Starts the activity under test using the default Intent with: + // action = {@link Intent#ACTION_MAIN} + // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK} + // All other fields are null or empty. + mTestActivity = getActivity(); + } + + /** + * Test if the test fixture has been set up correctly. + */ + public void testPreconditions() { + //Try to add a message to add context to your assertions. These messages will be shown if + //a tests fails and make it easy to understand why a test failed + assertNotNull("mTestActivity is null", mTestActivity); + } + +} diff --git a/media/MidiScope/Application/src/main/AndroidManifest.xml b/media/MidiScope/Application/src/main/AndroidManifest.xml new file mode 100644 index 00000000..c2b1c43f --- /dev/null +++ b/media/MidiScope/Application/src/main/AndroidManifest.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media/MidiScope/Application/src/main/java/com/example/android/midiscope/LoggingReceiver.java b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/LoggingReceiver.java new file mode 100644 index 00000000..23ce8f7c --- /dev/null +++ b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/LoggingReceiver.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.midiscope; + +import android.media.midi.MidiReceiver; +import android.util.Log; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * Convert incoming MIDI messages to a string and write them to a ScopeLogger. + * Assume that messages have been aligned using a MidiFramer. + */ +public class LoggingReceiver extends MidiReceiver { + public static final String TAG = "MidiScope"; + private static final long NANOS_PER_SECOND = TimeUnit.SECONDS.toNanos(1); + private long mStartTime; + private ScopeLogger mLogger; + + public LoggingReceiver(ScopeLogger logger) { + mStartTime = System.nanoTime(); + mLogger = logger; + } + + /* + * @see android.media.midi.MidiReceiver#onReceive(byte[], int, int, long) + */ + @Override + public void onSend(byte[] data, int offset, int count, long timestamp) + throws IOException { + StringBuilder sb = new StringBuilder(); + if (timestamp == 0) { + sb.append(String.format("-----0----: ")); + } else { + long monoTime = timestamp - mStartTime; + double seconds = (double) monoTime / NANOS_PER_SECOND; + sb.append(String.format("%10.3f: ", seconds)); + } + sb.append(MidiPrinter.formatBytes(data, offset, count)); + sb.append(": "); + sb.append(MidiPrinter.formatMessage(data, offset, count)); + String text = sb.toString(); + mLogger.log(text); + Log.i(TAG, text); + } + +} \ No newline at end of file diff --git a/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MainActivity.java b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MainActivity.java new file mode 100644 index 00000000..41d74f03 --- /dev/null +++ b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MainActivity.java @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.midiscope; + +import android.app.ActionBar; +import android.app.Activity; +import android.media.midi.MidiDeviceInfo; +import android.media.midi.MidiManager; +import android.media.midi.MidiReceiver; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.WindowManager; +import android.widget.ScrollView; +import android.widget.TextView; +import android.widget.Toolbar; + +import com.example.android.common.midi.MidiFramer; +import com.example.android.common.midi.MidiOutputPortSelector; +import com.example.android.common.midi.MidiPortWrapper; + +import java.util.LinkedList; + +/** + * App that provides a MIDI echo service. + */ +public class MainActivity extends Activity implements ScopeLogger { + + private static final int MAX_LINES = 100; + + private final LinkedList mLogLines = new LinkedList<>(); + private TextView mLog; + private ScrollView mScroller; + private MidiOutputPortSelector mLogSenderSelector; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + setActionBar((Toolbar) findViewById(R.id.toolbar)); + ActionBar actionBar = getActionBar(); + if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(false); + } + + mLog = (TextView) findViewById(R.id.log); + mScroller = (ScrollView) findViewById(R.id.scroll); + + // Setup MIDI + MidiManager midiManager = (MidiManager) getSystemService(MIDI_SERVICE); + + // Receiver that prints the messages. + MidiReceiver loggingReceiver = new LoggingReceiver(this); + + // Receiver that parses raw data into complete messages. + MidiFramer connectFramer = new MidiFramer(loggingReceiver); + + // Setup a menu to select an input source. + mLogSenderSelector = new MidiOutputPortSelector(midiManager, this, R.id.spinner_senders) { + @Override + public void onPortSelected(final MidiPortWrapper wrapper) { + super.onPortSelected(wrapper); + if (wrapper != null) { + mLogLines.clear(); + MidiDeviceInfo deviceInfo = wrapper.getDeviceInfo(); + if (deviceInfo == null) { + log(getString(R.string.header_text)); + } else { + log(MidiPrinter.formatDeviceInfo(deviceInfo)); + } + } + } + }; + mLogSenderSelector.getSender().connect(connectFramer); + + // Tell the virtual device to log its messages here.. + MidiScope.setScopeLogger(this); + } + + @Override + public void onDestroy() { + mLogSenderSelector.onClose(); + // The scope will live on as a service so we need to tell it to stop + // writing log messages to this Activity. + MidiScope.setScopeLogger(null); + super.onDestroy(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + setKeepScreenOn(menu.findItem(R.id.action_keep_screen_on).isChecked()); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_clear_all: + mLogLines.clear(); + logOnUiThread(""); + break; + case R.id.action_keep_screen_on: + boolean checked = !item.isChecked(); + setKeepScreenOn(checked); + item.setChecked(checked); + break; + } + return super.onOptionsItemSelected(item); + } + + private void setKeepScreenOn(boolean keepScreenOn) { + if (keepScreenOn) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } else { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + } + + @Override + public void log(final String string) { + runOnUiThread(new Runnable() { + @Override + public void run() { + logOnUiThread(string); + } + }); + } + + /** + * Logs a message to our TextView. This needs to be called from the UI thread. + */ + private void logOnUiThread(String s) { + mLogLines.add(s); + if (mLogLines.size() > MAX_LINES) { + mLogLines.removeFirst(); + } + // Render line buffer to one String. + StringBuilder sb = new StringBuilder(); + for (String line : mLogLines) { + sb.append(line).append('\n'); + } + mLog.setText(sb.toString()); + mScroller.fullScroll(View.FOCUS_DOWN); + } +} diff --git a/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiPrinter.java b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiPrinter.java new file mode 100644 index 00000000..9e97c04c --- /dev/null +++ b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiPrinter.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.midiscope; + +import android.media.midi.MidiDeviceInfo; +import android.media.midi.MidiDeviceInfo.PortInfo; +import android.os.Bundle; + +import com.example.android.common.midi.MidiConstants; + +/** + * Format a MIDI message for printing. + */ +public class MidiPrinter { + + public static final String[] CHANNEL_COMMAND_NAMES = { "NoteOff", "NoteOn", + "PolyTouch", "Control", "Program", "Pressure", "Bend" }; + public static final String[] SYSTEM_COMMAND_NAMES = { "SysEx", // F0 + "TimeCode", // F1 + "SongPos", // F2 + "SongSel", // F3 + "F4", // F4 + "F5", // F5 + "TuneReq", // F6 + "EndSysex", // F7 + "TimingClock", // F8 + "F9", // F9 + "Start", // FA + "Continue", // FB + "Stop", // FC + "FD", // FD + "ActiveSensing", // FE + "Reset" // FF + }; + + public static String getName(int status) { + if (status >= 0xF0) { + int index = status & 0x0F; + return SYSTEM_COMMAND_NAMES[index]; + } else if (status >= 0x80) { + int index = (status >> 4) & 0x07; + return CHANNEL_COMMAND_NAMES[index]; + } else { + return "data"; + } + } + + public static String formatBytes(byte[] data, int offset, int count) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < count; i++) { + sb.append(String.format(" %02X", data[offset + i])); + } + return sb.toString(); + } + + public static String formatMessage(byte[] data, int offset, int count) { + StringBuilder sb = new StringBuilder(); + byte statusByte = data[offset++]; + int status = statusByte & 0xFF; + sb.append(getName(status)).append("("); + int numData = MidiConstants.getBytesPerMessage(statusByte) - 1; + if ((status >= 0x80) && (status < 0xF0)) { // channel message + int channel = status & 0x0F; + // Add 1 for humans who think channels are numbered 1-16. + sb.append((channel + 1)).append(", "); + } + for (int i = 0; i < numData; i++) { + if (i > 0) { + sb.append(", "); + } + sb.append(data[offset++]); + } + sb.append(")"); + return sb.toString(); + } + + public static String formatDeviceInfo(MidiDeviceInfo info) { + StringBuilder sb = new StringBuilder(); + if (info != null) { + Bundle properties = info.getProperties(); + for (String key : properties.keySet()) { + Object value = properties.get(key); + sb.append(key).append(" = ").append(value).append('\n'); + } + for (PortInfo port : info.getPorts()) { + sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input" + : "output"); + sb.append("[").append(port.getPortNumber()).append("] = \"").append(port.getName() + + "\"\n"); + } + } + return sb.toString(); + } +} diff --git a/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiScope.java b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiScope.java new file mode 100644 index 00000000..3965d83c --- /dev/null +++ b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/MidiScope.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.midiscope; + +import android.media.midi.MidiDeviceService; +import android.media.midi.MidiDeviceStatus; +import android.media.midi.MidiReceiver; + +import com.example.android.common.midi.MidiFramer; + +import java.io.IOException; + +/** + * Virtual MIDI Device that logs messages to a ScopeLogger. + */ + +public class MidiScope extends MidiDeviceService { + + private static ScopeLogger mScopeLogger; + private MidiReceiver mInputReceiver = new MyReceiver(); + private static MidiFramer mDeviceFramer; + + @Override + public MidiReceiver[] onGetInputPortReceivers() { + return new MidiReceiver[] { mInputReceiver }; + } + + public static ScopeLogger getScopeLogger() { + return mScopeLogger; + } + + public static void setScopeLogger(ScopeLogger logger) { + if (logger != null) { + // Receiver that prints the messages. + LoggingReceiver loggingReceiver = new LoggingReceiver(logger); + mDeviceFramer = new MidiFramer(loggingReceiver); + } + mScopeLogger = logger; + } + + private static class MyReceiver extends MidiReceiver { + @Override + public void onSend(byte[] data, int offset, int count, + long timestamp) throws IOException { + if (mScopeLogger != null) { + // Send raw data to be parsed into discrete messages. + mDeviceFramer.send(data, offset, count, timestamp); + } + } + } + + /** + * This will get called when clients connect or disconnect. + * Log device information. + */ + @Override + public void onDeviceStatusChanged(MidiDeviceStatus status) { + if (mScopeLogger != null) { + if (status.isInputPortOpen(0)) { + mScopeLogger.log("=== connected ==="); + String text = MidiPrinter.formatDeviceInfo( + status.getDeviceInfo()); + mScopeLogger.log(text); + } else { + mScopeLogger.log("--- disconnected ---"); + } + } + } +} diff --git a/media/MidiScope/Application/src/main/java/com/example/android/midiscope/ScopeLogger.java b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/ScopeLogger.java new file mode 100644 index 00000000..dc52efd6 --- /dev/null +++ b/media/MidiScope/Application/src/main/java/com/example/android/midiscope/ScopeLogger.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.midiscope; + +public interface ScopeLogger { + /** + * Write the text string somewhere that the user can see it. + * @param text + */ + void log(String text); +} diff --git a/media/MidiScope/Application/src/main/res/drawable-hdpi/ic_clear_all.png b/media/MidiScope/Application/src/main/res/drawable-hdpi/ic_clear_all.png new file mode 100755 index 00000000..e23d886c Binary files /dev/null and b/media/MidiScope/Application/src/main/res/drawable-hdpi/ic_clear_all.png differ diff --git a/media/MidiScope/Application/src/main/res/drawable-mdpi/ic_clear_all.png b/media/MidiScope/Application/src/main/res/drawable-mdpi/ic_clear_all.png new file mode 100755 index 00000000..dca30487 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/drawable-mdpi/ic_clear_all.png differ diff --git a/media/MidiScope/Application/src/main/res/drawable-xhdpi/ic_clear_all.png b/media/MidiScope/Application/src/main/res/drawable-xhdpi/ic_clear_all.png new file mode 100755 index 00000000..fef5dcd2 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/drawable-xhdpi/ic_clear_all.png differ diff --git a/media/MidiScope/Application/src/main/res/drawable-xxhdpi/ic_clear_all.png b/media/MidiScope/Application/src/main/res/drawable-xxhdpi/ic_clear_all.png new file mode 100755 index 00000000..51d2d3da Binary files /dev/null and b/media/MidiScope/Application/src/main/res/drawable-xxhdpi/ic_clear_all.png differ diff --git a/media/MidiScope/Application/src/main/res/drawable-xxxhdpi/ic_clear_all.png b/media/MidiScope/Application/src/main/res/drawable-xxxhdpi/ic_clear_all.png new file mode 100755 index 00000000..9dbccf36 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/drawable-xxxhdpi/ic_clear_all.png differ diff --git a/media/MidiScope/Application/src/main/res/layout/main.xml b/media/MidiScope/Application/src/main/res/layout/main.xml new file mode 100644 index 00000000..71c52aa6 --- /dev/null +++ b/media/MidiScope/Application/src/main/res/layout/main.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + diff --git a/media/MidiScope/Application/src/main/res/menu/main.xml b/media/MidiScope/Application/src/main/res/menu/main.xml new file mode 100644 index 00000000..abb1842a --- /dev/null +++ b/media/MidiScope/Application/src/main/res/menu/main.xml @@ -0,0 +1,32 @@ + + + + + + + + + diff --git a/media/MidiScope/Application/src/main/res/mipmap-hdpi/ic_launcher.png b/media/MidiScope/Application/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100755 index 00000000..4a755241 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/media/MidiScope/Application/src/main/res/mipmap-mdpi/ic_launcher.png b/media/MidiScope/Application/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100755 index 00000000..09a42710 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/media/MidiScope/Application/src/main/res/mipmap-xhdpi/ic_launcher.png b/media/MidiScope/Application/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100755 index 00000000..e9c9a361 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/media/MidiScope/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png b/media/MidiScope/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100755 index 00000000..6e79c3bc Binary files /dev/null and b/media/MidiScope/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/media/MidiScope/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/media/MidiScope/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100755 index 00000000..638d4e13 Binary files /dev/null and b/media/MidiScope/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/media/MidiScope/Application/src/main/res/values/colors.xml b/media/MidiScope/Application/src/main/res/values/colors.xml new file mode 100644 index 00000000..eef48d88 --- /dev/null +++ b/media/MidiScope/Application/src/main/res/values/colors.xml @@ -0,0 +1,26 @@ + + + + #009688 + #00796B + #B2DFDB + #FFC107 + #212121 + #727272 + #FFFFFF + #B6B6B6 + diff --git a/media/MidiScope/Application/src/main/res/values/strings.xml b/media/MidiScope/Application/src/main/res/values/strings.xml new file mode 100644 index 00000000..52beb4e1 --- /dev/null +++ b/media/MidiScope/Application/src/main/res/values/strings.xml @@ -0,0 +1,24 @@ + + + + Select a MIDI source from the Spinner above or send messages to MidiScope. + Clear Log + Keep Screen On + + "none" + + diff --git a/media/MidiScope/Application/src/main/res/values/styles.xml b/media/MidiScope/Application/src/main/res/values/styles.xml new file mode 100644 index 00000000..00360096 --- /dev/null +++ b/media/MidiScope/Application/src/main/res/values/styles.xml @@ -0,0 +1,25 @@ + + + + + + + diff --git a/media/MidiScope/Application/src/main/res/xml/scope_device_info.xml b/media/MidiScope/Application/src/main/res/xml/scope_device_info.xml new file mode 100644 index 00000000..f89f1109 --- /dev/null +++ b/media/MidiScope/Application/src/main/res/xml/scope_device_info.xml @@ -0,0 +1,24 @@ + + + + + + + diff --git a/media/MidiScope/build.gradle b/media/MidiScope/build.gradle new file mode 100644 index 00000000..9b6a9ce4 --- /dev/null +++ b/media/MidiScope/build.gradle @@ -0,0 +1,12 @@ + + +// BEGIN_EXCLUDE +import com.example.android.samples.build.SampleGenPlugin +apply plugin: SampleGenPlugin + +samplegen { + pathToBuild "../../../../build" + pathToSamplesCommon "../../common" +} +apply from: "../../../../build/build.gradle" +// END_EXCLUDE diff --git a/media/MidiScope/buildSrc/build.gradle b/media/MidiScope/buildSrc/build.gradle new file mode 100644 index 00000000..d77115d0 --- /dev/null +++ b/media/MidiScope/buildSrc/build.gradle @@ -0,0 +1,16 @@ + +repositories { + jcenter() +} +dependencies { + compile 'org.freemarker:freemarker:2.3.20' +} + +sourceSets { + main { + groovy { + srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy") + } + } +} + diff --git a/media/MidiScope/gradle/wrapper/gradle-wrapper.jar b/media/MidiScope/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..8c0fb64a Binary files /dev/null and b/media/MidiScope/gradle/wrapper/gradle-wrapper.jar differ diff --git a/media/MidiScope/gradle/wrapper/gradle-wrapper.properties b/media/MidiScope/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..afb32963 --- /dev/null +++ b/media/MidiScope/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Apr 10 15:27:10 PDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip diff --git a/media/MidiScope/gradlew b/media/MidiScope/gradlew new file mode 100755 index 00000000..91a7e269 --- /dev/null +++ b/media/MidiScope/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/media/MidiScope/gradlew.bat b/media/MidiScope/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/media/MidiScope/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/media/MidiScope/screenshots/1-main.png b/media/MidiScope/screenshots/1-main.png new file mode 100644 index 00000000..0b4fb8e8 Binary files /dev/null and b/media/MidiScope/screenshots/1-main.png differ diff --git a/media/MidiScope/screenshots/2-signals.png b/media/MidiScope/screenshots/2-signals.png new file mode 100644 index 00000000..7e4b443e Binary files /dev/null and b/media/MidiScope/screenshots/2-signals.png differ diff --git a/media/MidiScope/screenshots/icon-web.png b/media/MidiScope/screenshots/icon-web.png new file mode 100644 index 00000000..6daec5cd Binary files /dev/null and b/media/MidiScope/screenshots/icon-web.png differ diff --git a/media/MidiScope/settings.gradle b/media/MidiScope/settings.gradle new file mode 100644 index 00000000..0a5c310b --- /dev/null +++ b/media/MidiScope/settings.gradle @@ -0,0 +1,2 @@ + +include 'Application' diff --git a/media/MidiScope/template-params.xml b/media/MidiScope/template-params.xml new file mode 100644 index 00000000..8caea80e --- /dev/null +++ b/media/MidiScope/template-params.xml @@ -0,0 +1,79 @@ + + + + MidiScope + Media + com.example.android.midiscope + 23 + 23 + + + + + + + + +