From 94a01600b0ed79546653faf7a49f47230d90bd86 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 27 Mar 2012 21:50:01 -0700 Subject: [PATCH] Rest of changes for native sound engine integration. --- android/.classpath | 5 +-- android/.project | 10 ++++++ android/AndroidManifest.xml | 8 +++-- android/default.properties | 2 +- android/jni/Android.mk | 10 +++++- android/jni/Application.mk | 2 ++ .../android/widgets/piano/PianoView.java | 32 +++++++++++++++++++ cpp/src/android_glue.cc | 7 ---- 8 files changed, 62 insertions(+), 14 deletions(-) diff --git a/android/.classpath b/android/.classpath index c247676..a607c7f 100644 --- a/android/.classpath +++ b/android/.classpath @@ -6,6 +6,7 @@ - - + + + diff --git a/android/.project b/android/.project index 7be155a..6c6f44d 100644 --- a/android/.project +++ b/android/.project @@ -15,6 +15,16 @@ + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/NDK Builder.launch + + + com.android.ide.eclipse.adt.ResourceManagerBuilder diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 7e98da2..96edba4 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -4,11 +4,11 @@ package="com.google.synthesizer" android:versionCode="2" android:versionName="0.9"> - + @@ -64,10 +64,12 @@ android:name=".android.ui.KarplusStrongActivity" android:label="@string/karplus_strong" android:screenOrientation="landscape" /> + - \ No newline at end of file + diff --git a/android/default.properties b/android/default.properties index e2e8061..4686f7f 100644 --- a/android/default.properties +++ b/android/default.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-8 +target=android-9 diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 249e1df..51f5e08 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -3,7 +3,8 @@ LOCAL_PATH := $(call my-dir)/../../cpp/src include $(CLEAR_VARS) LOCAL_MODULE := synth LOCAL_CPP_EXTENSION := .cc -LOCAL_SRC_FILES := dx7note.cc \ +LOCAL_SRC_FILES := android_glue.cc \ + dx7note.cc \ env.cc \ fm_core.cc \ fm_op_kernel.cc \ @@ -14,5 +15,12 @@ LOCAL_SRC_FILES := dx7note.cc \ sin.cc \ synth_unit.cc +# for native audio +LOCAL_LDLIBS += -lOpenSLES +# for logging +LOCAL_LDLIBS += -llog + +LOCAL_CFLAGS := -O3 + include $(BUILD_SHARED_LIBRARY) diff --git a/android/jni/Application.mk b/android/jni/Application.mk index caf3b26..eab2761 100644 --- a/android/jni/Application.mk +++ b/android/jni/Application.mk @@ -1 +1,3 @@ APP_STL := stlport_static +APP_ABI := armeabi-v7a + diff --git a/android/src/com/google/synthesizer/android/widgets/piano/PianoView.java b/android/src/com/google/synthesizer/android/widgets/piano/PianoView.java index b397e93..0099ffb 100644 --- a/android/src/com/google/synthesizer/android/widgets/piano/PianoView.java +++ b/android/src/com/google/synthesizer/android/widgets/piano/PianoView.java @@ -16,6 +16,9 @@ package com.google.synthesizer.android.widgets.piano; +import java.util.HashMap; +import java.util.Map; + import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -23,8 +26,11 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; + import com.google.synthesizer.R; +import com.google.synthesizer.android.AndroidGlue; import com.google.synthesizer.core.model.composite.MultiChannelSynthesizer; +import com.google.synthesizer.core.music.Note; /** * PianoView is a UI widget that simulates a music keyboard. @@ -350,6 +356,32 @@ public class PianoView extends View { }); } + /** + * Connects the PianoView to an AndroidGlue. This should probably be a MidiListener instead, + * though... + */ + public void bindTo(final AndroidGlue midiSink) { + this.setPianoViewListener(new PianoViewListener() { + { + fingerMap_ = new HashMap(); + } + public void noteDown(double logFrequency, int finger, boolean retriggerIfOn) { + noteUp(finger); + int midiNote = Note.getKeyforLog12TET(logFrequency); + fingerMap_.put(finger, midiNote); + midiSink.sendMidi(new byte[] {(byte) 0x90, (byte) midiNote, 64}); + } + public void noteUp(int finger) { + if (fingerMap_.containsKey(finger)) { + int midiNote = fingerMap_.get(finger); + fingerMap_.remove(finger); + midiSink.sendMidi(new byte[] {(byte) 0x80, (byte) midiNote, 64}); + } + } + private Map fingerMap_; + }); + } + // The most recent screen rect that this keyboard was drawn into. // // This is basically a stack variable for onDraw. It's a member variable only so that we can diff --git a/cpp/src/android_glue.cc b/cpp/src/android_glue.cc index a1e4505..97d1a8e 100644 --- a/cpp/src/android_glue.cc +++ b/cpp/src/android_glue.cc @@ -47,13 +47,6 @@ extern "C" void BqPlayerCallback(SLAndroidSimpleBufferQueueItf queueItf, cur_buffer = (cur_buffer + 1) % N_BUFFERS; } -extern "C" JNIEXPORT jint JNICALL -Java_com_google_synthesizer_android_AndroidGlue_hello(JNIEnv *env, - jobject thiz) { - LOGI("here %d!", 42); - return 42; -} - void CreateEngine() { SLresult result; result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);