Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 049badad461d53ffbb93ef8600db68635f054f68 @BBuchholz BBuchholz committed Oct 17, 2011
Showing with 2,226 additions and 0 deletions.
  1. +7 −0 .classpath
  2. +2 −0 .gitignore
  3. +33 −0 .project
  4. +5 −0 .settings/org.eclipse.jdt.core.prefs
  5. +24 −0 AndroidManifest.xml
  6. +11 −0 README
  7. +11 −0 default.properties
  8. +40 −0 proguard.cfg
  9. BIN res/drawable-hdpi/icon.png
  10. BIN res/drawable-ldpi/icon.png
  11. BIN res/drawable-mdpi/icon.png
  12. +21 −0 res/layout/main.xml
  13. +9 −0 res/menu/fretboard_menu.xml
  14. +9 −0 res/values/strings.xml
  15. +33 −0 src/com/nineworldsdeep/droidmuse/ClefActivity.java
  16. +33 −0 src/com/nineworldsdeep/droidmuse/DroidMuseActivity.java
  17. +79 −0 src/com/nineworldsdeep/droidmuse/MainTabWidget.java
  18. +48 −0 src/com/nineworldsdeep/droidmuse/Note.java
  19. +107 −0 src/com/nineworldsdeep/droidmuse/NoteHelper.java
  20. +35 −0 src/com/nineworldsdeep/droidmuse/ToastMaker.java
  21. +117 −0 src/com/nineworldsdeep/droidmuse/guitar/DefaultMapping.java
  22. +55 −0 src/com/nineworldsdeep/droidmuse/guitar/Fret.java
  23. +45 −0 src/com/nineworldsdeep/droidmuse/guitar/FretRangeChangeListener.java
  24. +315 −0 src/com/nineworldsdeep/droidmuse/guitar/Fretboard.java
  25. +98 −0 src/com/nineworldsdeep/droidmuse/guitar/FretboardPosition.java
  26. +189 −0 src/com/nineworldsdeep/droidmuse/guitar/GuitarActivity.java
  27. +54 −0 src/com/nineworldsdeep/droidmuse/guitar/GuitarString.java
  28. +27 −0 src/com/nineworldsdeep/droidmuse/guitar/IMapping.java
  29. +128 −0 src/com/nineworldsdeep/droidmuse/guitar/LogicalFretboard.java
  30. +45 −0 src/com/nineworldsdeep/droidmuse/guitar/StringNumChangeListener.java
  31. +51 −0 src/com/nineworldsdeep/droidmuse/guitar/TuningListener.java
  32. +55 −0 src/com/nineworldsdeep/droidmuse/keys/BlackUiKey.java
  33. +185 −0 src/com/nineworldsdeep/droidmuse/keys/Keyboard.java
  34. +34 −0 src/com/nineworldsdeep/droidmuse/keys/KeyboardActivity.java
  35. +208 −0 src/com/nineworldsdeep/droidmuse/keys/LogicalKeyboard.java
  36. +58 −0 src/com/nineworldsdeep/droidmuse/keys/UiPianoKey.java
  37. +55 −0 src/com/nineworldsdeep/droidmuse/keys/WhiteUiKey.java
7 .classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
2 .gitignore
@@ -0,0 +1,2 @@
+bin/
+gen/
33 .project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>DroidMuse</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
5 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+#Wed Oct 05 10:12:43 CDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
24 AndroidManifest.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.nineworldsdeep.droidmuse"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+
+
+ <activity android:name="com.nineworldsdeep.droidmuse.MainTabWidget" android:label="@string/app_name"
+ android:theme="@android:style/Theme.NoTitleBar">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity android:name="com.nineworldsdeep.droidmuse.ClefActivity" />
+ <activity android:name="com.nineworldsdeep.droidmuse.guitar.GuitarActivity" />
+ <activity android:name="com.nineworldsdeep.droidmuse.keys.KeyboardActivity" />
+
+
+ </application>
+ <uses-sdk android:minSdkVersion="8" />
+
+</manifest>
11 README
@@ -0,0 +1,11 @@
+DroidMuse is my very first Android project, and is centered around
+building UI components for music related applications.
+
+Much of its current state (as of 10/17/2011) is the result of a trial
+and error coding process as I became more familiar with Android development
+and as such it is a little rough around the edges.
+
+I am currently in the process of refactoring the various elements
+into reusable components for other projects.
+
+-Brent
11 default.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
40 proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
BIN res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 res/layout/main.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/tabhost"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="5dp">
+ <TabWidget
+ android:id="@android:id/tabs"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+ <FrameLayout
+ android:id="@android:id/tabcontent"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="5dp" />
+ </LinearLayout>
+</TabHost>
9 res/menu/fretboard_menu.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/change_tuning"
+ android:title="@string/change_tuning" />
+ <item android:id="@+id/set_num_strings"
+ android:title="@string/set_num_strings" />
+ <item android:id="@+id/set_fret_range"
+ android:title="@string/set_fret_range" />
+</menu>
9 res/values/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World!</string>
+ <string name="app_name">Droid Muse</string>
+ <string name="change_tuning">Tuning</string>
+ <string name="set_num_strings">Strings</string>
+ <string name="set_fret_range">Fret Range</string>
+
+</resources>
33 src/com/nineworldsdeep/droidmuse/ClefActivity.java
@@ -0,0 +1,33 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class ClefActivity extends Activity {
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ TextView textview = new TextView(this);
+ textview.setText("This is the Treble and Bass Clef tab");
+ setContentView(textview);
+ }
+}
33 src/com/nineworldsdeep/droidmuse/DroidMuseActivity.java
@@ -0,0 +1,33 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse;
+
+import com.nineworldsdeep.droidmuse.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class DroidMuseActivity extends Activity {
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+}
79 src/com/nineworldsdeep/droidmuse/MainTabWidget.java
@@ -0,0 +1,79 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse;
+
+import com.nineworldsdeep.droidmuse.R;
+import com.nineworldsdeep.droidmuse.R.drawable;
+import com.nineworldsdeep.droidmuse.R.layout;
+import com.nineworldsdeep.droidmuse.guitar.GuitarActivity;
+import com.nineworldsdeep.droidmuse.keys.KeyboardActivity;
+
+import android.app.TabActivity;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.widget.TabHost;
+import android.widget.TabHost.OnTabChangeListener;
+
+public class MainTabWidget extends TabActivity {
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ TabHost tabHost = getTabHost(); // The activity TabHost
+ TabHost.TabSpec spec; // Resusable TabSpec for each tab
+ Intent intent; // Reusable Intent for each tab
+
+ // Create an Intent to launch an Activity for the tab (to be reused)
+ intent = new Intent().setClass(this, ClefActivity.class);
+
+ // Initialize a TabSpec for each tab and add it to the TabHost
+ spec = tabHost.newTabSpec("clef").setIndicator("one").setContent(intent);
+ tabHost.addTab(spec);
+
+ // Do the same for the other tabs
+ intent = new Intent().setClass(this, GuitarActivity.class);
+ spec = tabHost.newTabSpec("guitar").setIndicator("two").setContent(intent);
+ tabHost.addTab(spec);
+
+ intent = new Intent().setClass(this, KeyboardActivity.class);
+ spec = tabHost.newTabSpec("keyboard").setIndicator("three").setContent(intent);
+ tabHost.addTab(spec);
+
+
+ tabHost.setOnTabChangedListener(new OnTabChangeListener(){
+
+ public void onTabChanged(String tabId) {
+
+ if(tabId.equals("keyboard") || tabId.equals("clef")){
+
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }else if(tabId.equals("guitar")){
+
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ }
+
+
+ });
+
+ tabHost.setCurrentTab(2);
+ }
+}
48 src/com/nineworldsdeep/droidmuse/Note.java
@@ -0,0 +1,48 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse;
+
+import java.util.HashMap;
+
+public class Note {
+
+ private int positionalValue;
+ private String noteName;
+
+
+ public Note(int notePosVal, String name) {
+ //TODO: this should be posVal
+ //logic is currently for absVal (prototyping)
+ this.positionalValue = notePosVal;
+ this.noteName = name;
+ }
+
+
+
+
+
+ public int getPositionalValue() {
+ return positionalValue;
+ }
+
+ public String getNoteName() {
+ return noteName;
+ }
+
+}
107 src/com/nineworldsdeep/droidmuse/NoteHelper.java
@@ -0,0 +1,107 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse;
+
+import java.util.HashMap;
+
+public class NoteHelper {
+
+ private HashMap<String,Integer> absValMap =
+ new HashMap<String,Integer>();
+
+ public NoteHelper(){
+ for(int i = 0; i < 12; i++){
+ Note n = new Note(i, this.toNoteName(i));
+ this.absValMap.put(n.getNoteName().toLowerCase(), i);
+ }
+ }
+
+ public int toAbsValue(int noteVal){
+ while(noteVal < 0){
+ noteVal += 12;
+ }
+ while(noteVal > 11){
+ noteVal -= 12;
+ }
+ return noteVal;
+ }
+
+
+ public Note fromName(String name){
+ int i = 0;
+ if(this.absValMap.containsKey(name.toLowerCase())){
+ i = this.absValMap.get(name.toLowerCase());
+ }
+ return new Note(i, this.toNoteName(i));
+ }
+
+ public boolean isValidNoteName(String name){
+ return this.absValMap.containsKey(name.toLowerCase());
+ }
+
+ public String toNoteName(int posVal) {
+
+ posVal = this.toAbsValue(posVal);
+
+ String name = "?";
+ //TODO: name parse should be in scale
+ //then based on the scale you will know whether
+ //accidentals should be displayed as flats or sharps
+
+ switch(posVal){
+ case 0:
+ name = "C";
+ break;
+ case 1:
+ name = "C#/Db";
+ break;
+ case 2:
+ name = "D";
+ break;
+ case 3:
+ name = "D#/Eb";
+ break;
+ case 4:
+ name = "E";
+ break;
+ case 5:
+ name = "F";
+ break;
+ case 6:
+ name = "F#/Gb";
+ break;
+ case 7:
+ name = "G";
+ break;
+ case 8:
+ name = "G#/Ab";
+ break;
+ case 9:
+ name = "A";
+ break;
+ case 10:
+ name = "A#/Bb";
+ break;
+ case 11:
+ name = "B";
+ break;
+ }
+ return name;
+ }
+}
35 src/com/nineworldsdeep/droidmuse/ToastMaker.java
@@ -0,0 +1,35 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse;
+
+import android.content.Context;
+import android.widget.Toast;
+
+//a utility class I sometimes use for debugging
+public class ToastMaker {
+
+ public static void makeToast(Context context, CharSequence text){
+
+ int duration = Toast.LENGTH_SHORT;
+ Toast toast;
+
+ toast = Toast.makeText(context, text, duration);
+ toast.show();
+ }
+}
117 src/com/nineworldsdeep/droidmuse/guitar/DefaultMapping.java
@@ -0,0 +1,117 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import java.util.HashMap;
+
+import com.nineworldsdeep.droidmuse.Note;
+import com.nineworldsdeep.droidmuse.NoteHelper;
+
+public class DefaultMapping implements IMapping {
+
+ private HashMap<Integer,Note> stringTunings;
+ private NoteHelper helper = new NoteHelper();
+
+
+ public DefaultMapping(){
+ //TODO: map to midi
+ //currently just works off absoluteVal, should be midi positionalVal
+ this.stringTunings = new HashMap<Integer,Note>();
+
+ Note eNote = new Note(4, helper.toNoteName(4));
+ Note aNote = new Note(9, helper.toNoteName(9));
+ Note dNote = new Note(2, helper.toNoteName(2));
+ Note gNote = new Note(7, helper.toNoteName(7));
+ Note bNote = new Note(11, helper.toNoteName(11));
+ Note eNoteHigh = new Note(4, helper.toNoteName(4));
+
+ this.stringTunings.put(0, eNote);
+ this.stringTunings.put(1, aNote);
+ this.stringTunings.put(2, dNote);
+ this.stringTunings.put(3, gNote);
+ this.stringTunings.put(4, bNote);
+ this.stringTunings.put(5, eNoteHigh);
+
+ //this.setSixStringTuning("E,A,D,G,B,E");
+ }
+
+ public String setSixStringTuning(String tuning){
+ String[] notes = tuning.split(",");
+ if(notes.length != 6){
+ return "tuning failed length check";
+ }
+
+
+ for(int i = 0; i < 6; i++){
+ if(!helper.isValidNoteName(notes[i])){
+ return "tuning failed name check";
+ }
+ }
+
+ for(int i = 0; i < 6; i++){
+ if(!this.stringTunings.containsKey(i)){
+ return "tuning failed key check";
+ }
+ }
+
+ for(int i = 0; i < 6; i++){
+ this.stringTunings.put(i, helper.fromName(notes[i]));
+ }
+ return "tuning changed.";
+ }
+
+ public String getFretViewLabel(int viewFretPosition){
+ return "" + viewFretPosition;
+ }
+
+ public String getNoteName(int viewFretPosition, int viewStringPosition) {
+ int zeroFretPosVal = this.stringTunings.get(viewStringPosition).getPositionalValue();
+ int posVal = zeroFretPosVal + viewFretPosition;
+ return helper.toNoteName(posVal);
+ }
+
+ public String getStringViewLabel(int viewStringPosition) {
+
+ String s = "?";
+
+ if(this.stringTunings.containsKey(viewStringPosition)){
+ s = this.stringTunings.get(viewStringPosition).getNoteName();
+ }
+
+ return s;
+
+ }
+
+ public String getSixStringTuning() {
+
+ String s = "";
+
+ for(int i = 0; i < this.stringTunings.size(); i++){
+ if(this.stringTunings.containsKey(i)){
+ if(s.length() > 0){
+ s += ",";
+ }
+ s += this.stringTunings.get(i).getNoteName();
+ }
+ }
+
+ return s;
+ }
+
+}
55 src/com/nineworldsdeep/droidmuse/guitar/Fret.java
@@ -0,0 +1,55 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import android.graphics.Point;
+import android.graphics.PointF;
+
+public class Fret {
+
+ Point[] points = new Point[2];
+ boolean zeroFret = false;
+ int positionalId;
+ private PointF labelPosition;
+
+ public Fret(Point left, Point right, boolean isZeroFret, int positionalId, PointF labelPosition){
+ this.points[0] = left;
+ this.points[1] = right;
+ this.zeroFret = isZeroFret;
+ this.positionalId = positionalId;
+ this.labelPosition = labelPosition;
+ }
+
+ public Point[] getPoints() {
+ return points;
+ }
+
+ public boolean isZeroFret() {
+ return zeroFret;
+ }
+
+ public int getPositionalId() {
+ return positionalId;
+ }
+
+ public PointF getFretLabelPosition() {
+ return labelPosition;
+ }
+
+}
45 src/com/nineworldsdeep/droidmuse/guitar/FretRangeChangeListener.java
@@ -0,0 +1,45 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+
+public class FretRangeChangeListener implements OnClickListener {
+
+ private GuitarActivity _guitarActivity;
+ private Dialog _sender;
+
+ public FretRangeChangeListener(GuitarActivity ga) {
+ this._guitarActivity = ga;
+ }
+
+ public void onClick(DialogInterface dialog, int numStringsSelection) {
+ // TODO Auto-generated method stub
+ int firstFret = Integer.parseInt((String)Fretboard.fretRangeOpts[numStringsSelection]);
+ this._guitarActivity.setFretRange(firstFret);
+ this._sender.dismiss();
+ }
+
+ public void setSender(Dialog dialog) {
+ this._sender = dialog;
+ }
+
+}
315 src/com/nineworldsdeep/droidmuse/guitar/Fretboard.java
@@ -0,0 +1,315 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.graphics.PointF;
+import android.graphics.RectF;
+import android.graphics.Paint.Align;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class Fretboard extends View {
+
+ static final CharSequence[] stringNumOpts = {"4", "5", "6"};
+ static final CharSequence[] fretRangeOpts = {"1", "2", "3",
+ "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
+ "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"};
+
+ int _height;
+ int _width;
+
+ Bitmap _bitmap;
+ Canvas _canvas;
+ Paint _paint;
+
+ private LogicalFretboard _logicalBoard;
+ private IMapping _mapping;
+ private int numberOfStrings = 6;
+ private int numberOfFrets = 4;
+ private int firstDisplayFret = 1;
+
+ ArrayList<Fret> frets;
+ ArrayList<GuitarString> strings;
+
+
+ private void calculateLinePlacements() {
+
+ int width = this._width;
+ int height = this._height;
+
+ int lowStringMargin = 30;
+ int highStringMargin = 10;
+
+ //EDIT: trying to fix the layout distribution issues
+ //int zeroFretMargin = 60;
+ int zeroFretMargin = (int)(this._paint.getTextSize() * 1.5); //we want truncation
+ int twelfthFretMargin = zeroFretMargin;
+
+ int stringPadding = 15;
+ int fretPadding = 15;
+
+ /*
+ * EDIT: trying to fix the layout distribution issues
+ int fretSpacing = (height - zeroFretMargin - twelfthFretMargin - (fretPadding * 2))
+ / (numberOfFrets) ;
+ */
+
+ int fretSpacing = (height - zeroFretMargin - twelfthFretMargin - fretPadding)
+ / (numberOfFrets + 1);
+
+ int stringSpacing = (width - lowStringMargin - highStringMargin - stringPadding * 2)
+ / (numberOfStrings - 1);
+
+
+ Point p1, p2;
+ int xVal, yVal;
+
+ int lowStringEdge = lowStringMargin;
+ int highStringEdge = width - highStringMargin;
+ //EDIT: trying to fix the layout distribution issues
+ //int zeroFretEdge = zeroFretMargin;
+ int zeroFretEdge = zeroFretMargin + fretSpacing - fretPadding;
+ int twelfthFretEdge = height - twelfthFretMargin;
+
+ float fretLabelOffsetX = lowStringMargin / 2;
+ float fretLabelOffsetY = this._paint.getTextSize() / 2;
+ float stringLabelOffsetY = this._paint.getTextSize() * 1.5F;
+
+ //initializing these here fixes responsivity loss on screen flip
+ this.frets = new ArrayList<Fret>();
+ this.strings = new ArrayList<GuitarString>();
+
+ //frets
+ for(int i = 0; i <= numberOfFrets; i++){
+ Point[] fretPoints = new Point[2];
+
+ yVal = zeroFretEdge + fretPadding + i * fretSpacing;
+ p1 = new Point(lowStringEdge, yVal);
+ p2 = new Point(highStringEdge, yVal);
+ fretPoints[0] = p1;
+ fretPoints[1] = p2;
+ PointF labelPosition = new PointF(fretLabelOffsetX, yVal + fretLabelOffsetY);
+ int posId = 0;
+ if(i > 0){
+ posId = i + firstDisplayFret - 1;
+ }
+ this.frets.add(new Fret(fretPoints[0], fretPoints[1], i == 0, posId, labelPosition));
+ }
+
+ //strings
+ for(int i = 0; i < numberOfStrings; i++){
+ Point[] stringPoints = new Point[2];
+ xVal = lowStringEdge + stringPadding + i * stringSpacing;
+ p1 = new Point(xVal, zeroFretEdge);
+ p2 = new Point(xVal, twelfthFretEdge);
+ stringPoints[0] = p1;
+ stringPoints[1] = p2;
+ PointF labelPos = new PointF(xVal, stringLabelOffsetY);
+ PointF noteLabelPos = new PointF(xVal, twelfthFretEdge + stringLabelOffsetY);
+ this.strings.add(new GuitarString(stringPoints[0], stringPoints[1], i, labelPos, noteLabelPos));
+ }
+
+ _logicalBoard = new LogicalFretboard(fretSpacing, stringSpacing);
+
+ this.SetupPositions();
+ }
+
+ private void SetupPositions() {
+ for(GuitarString string : this.strings){
+ for(Fret fret : this.frets){
+ _logicalBoard.registerPosition(string, fret);
+ }
+ }
+ }
+
+
+
+
+
+ private void drawBoard(){
+
+ _bitmap = Bitmap.createBitmap(this._width, this._height, Bitmap.Config.ARGB_8888);
+ this._canvas = new Canvas(_bitmap);
+
+ for(Fret f : this.frets){
+ Point[] fPts = f.getPoints();
+ PointF fretLabelPos = f.getFretLabelPosition();
+ String fretLabel = this._mapping.getFretViewLabel(f.getPositionalId());
+ this._canvas.drawLine(fPts[0].x, fPts[0].y, fPts[1].x, fPts[1].y, this._paint);
+ this._canvas.drawText(fretLabel, fretLabelPos.x, fretLabelPos.y, this._paint);
+ }
+
+ for(GuitarString string : this.strings){
+ Point[] sPts = string.getPoints();
+ PointF stringLabelPos = string.getStringLabelPosition();
+ String stringLabel = this._mapping.getStringViewLabel(string.getPositionalId());
+ this._canvas.drawLine(sPts[0].x, sPts[0].y, sPts[1].x, sPts[1].y, this._paint);
+ this._canvas.drawText(stringLabel, stringLabelPos.x, stringLabelPos.y, this._paint);
+ int noteViewPos = this._logicalBoard.getHighestHeldNoteOnString(string.getPositionalId());
+ if(noteViewPos > -1){
+ PointF noteLabelPos = string.getNoteLabelPosition();
+ String noteLabel = this._mapping.getNoteName(noteViewPos, string.getPositionalId());
+ this._canvas.drawText(noteLabel, noteLabelPos.x, noteLabelPos.y, this._paint);
+ }
+ }
+
+ for(FretboardPosition pos : this._logicalBoard.getPositions()){
+ if(this._logicalBoard.isHighestHeldNoteOnString(pos)){
+ //TODO: path.addArc(oval) and path.setFill to make solid(? guessing)
+ //this._paint.setStyle(Paint.Style.FILL_AND_STROKE);
+ this._canvas.drawOval(pos.getDrawRegion(), this._paint);
+
+ }else if(pos.isZeroFret()){
+ if(this._logicalBoard.isSilent(pos.getStringPosId())){
+ //draw x
+ RectF reg = pos.getDrawRegion();
+ this._canvas.drawLine(reg.left, reg.top,
+ reg.right, reg.bottom, this._paint);
+ this._canvas.drawLine(reg.right, reg.top,
+ reg.left, reg.bottom, this._paint);
+ }
+ }
+ }
+
+ //tell runtime to refresh view
+ this.invalidate();
+
+ }
+
+ public Fretboard(Context context) {
+ super(context);
+ this._paint = new Paint();
+ this._paint.setColor(Color.WHITE);
+ this._paint.setStyle(Paint.Style.STROKE);
+ this._paint.setTextAlign(Align.CENTER);
+
+ this._mapping = new DefaultMapping();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
+ this._height = View.MeasureSpec.getSize(heightMeasureSpec);
+ this._width = View.MeasureSpec.getSize(widthMeasureSpec);
+
+ this.setMeasuredDimension(this._width, this._height);
+
+ this.calculateLinePlacements();
+ this.drawBoard();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas){
+ canvas.drawBitmap(this._bitmap, 0, 0, this._paint);
+ }
+
+
+ public boolean onTouchEvent(MotionEvent evt){
+ if(evt.getAction() == MotionEvent.ACTION_DOWN){
+ boolean positionFound = this._logicalBoard.togglePosition(evt.getX(), evt.getY());
+ if(positionFound){
+ this.drawBoard();
+ }
+ }
+ return true;
+ }
+
+ public String changeTuning(String tuningValues) {
+ String success = this._mapping.setSixStringTuning(tuningValues);
+
+ this.calculateLinePlacements();
+ this.drawBoard();
+
+ return success;
+ }
+
+ public boolean setNumberOfStrings(int i) {
+ if(i >= 4 && i <= 6){
+ this.numberOfStrings = i;
+ this.calculateLinePlacements();
+ this.drawBoard();
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+
+ public int getNumberOfStrings() {
+ return numberOfStrings;
+ }
+
+
+ public int getFirstDisplayFret() {
+ return firstDisplayFret;
+ }
+
+ public void setFirstDisplayFret(int firstFret) {
+ // TODO Auto-generated method stub
+ this.firstDisplayFret = firstFret;
+ this.calculateLinePlacements();
+ this.drawBoard();
+ }
+
+ public void setSelectedPositions(int[] selectedPositions) {
+ // needs to be in this order, first method resets logical board
+ this.calculateLinePlacements();
+ this._logicalBoard.setHeldPositions(selectedPositions);
+ this.drawBoard();
+ }
+
+ public int[] getSelectedPositions(){
+ return this._logicalBoard.getHeldPositions();
+ }
+
+ public String getTuning() {
+ return this._mapping.getSixStringTuning();
+ }
+
+ public void setTuning(String tuning) {
+ this._mapping.setSixStringTuning(tuning);
+ }
+
+ public void setNumberOfStringsNoDraw(int numStrings) {
+ // TODO Auto-generated method stub
+ this.numberOfStrings = numStrings;
+ }
+
+ public void setFirstDisplayFretNoDraw(int firstFret) {
+ // TODO Auto-generated method stub
+ this.firstDisplayFret = firstFret;
+ }
+
+ public void setSelectedPositionsNoDraw(int[] posMap) {
+ // TODO Auto-generated method stub
+ this._logicalBoard.setHeldPositions(posMap);
+ }
+
+ public void setTuningNoDraw(String tuning) {
+ // TODO Auto-generated method stub
+ this._mapping.setSixStringTuning(tuning);
+ }
+}
98 src/com/nineworldsdeep/droidmuse/guitar/FretboardPosition.java
@@ -0,0 +1,98 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import android.graphics.RectF;
+
+public class FretboardPosition {
+ private boolean highlighted;
+ private RectF touchRegion, drawRegion;
+ private boolean zeroFret = false;
+ private int stringPosId, fretPosId;
+ private boolean valid;
+
+ public FretboardPosition(float left, float top, float right, float bottom, Fret fret, GuitarString string){
+ this.touchRegion = new RectF(left,top,right,bottom);
+ this.drawRegion = this.generateDrawRegion(touchRegion);
+ highlighted = false;
+ this.zeroFret = fret.isZeroFret();
+ this.stringPosId = string.getPositionalId();
+ this.fretPosId = fret.getPositionalId();
+ }
+
+ public int getStringPosId() {
+ return stringPosId;
+ }
+
+ public int getFretPosId() {
+ return fretPosId;
+ }
+
+ public boolean isZeroFret() {
+ return zeroFret;
+ }
+
+ public boolean isHighlighted() {
+ return highlighted;
+ }
+
+ public void setHighlighted(boolean highlighted) {
+ this.highlighted = highlighted;
+ }
+
+ public boolean isValid(){
+ return this.valid;
+ }
+
+ public void setValid(boolean valid){
+ this.valid = valid;
+ }
+
+ public RectF getTouchRegion(){
+ return this.touchRegion;
+ }
+
+ public RectF getDrawRegion(){
+ return this.drawRegion;
+ }
+
+ private RectF generateDrawRegion(RectF tRegion){
+
+ float newLeft, newRight, newTop, newBottom;
+ float height = tRegion.bottom - tRegion.top;
+ float width = tRegion.right - tRegion.left;
+ float smallerDimension = (height > width) ? width : height;
+ float widthOffset = width / 2;
+ float heightOffset = height / 2;
+ float drawRegionRadius = smallerDimension / 4;
+
+ float xMid = tRegion.left + widthOffset;
+ float yMid = tRegion.top + heightOffset;
+
+ newTop = yMid - drawRegionRadius;
+ newBottom = yMid + drawRegionRadius;
+ newLeft = xMid - drawRegionRadius;
+ newRight = xMid + drawRegionRadius;
+
+
+ return new RectF(newLeft,newTop,newRight,newBottom);
+
+ }
+
+}
189 src/com/nineworldsdeep/droidmuse/guitar/GuitarActivity.java
@@ -0,0 +1,189 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import com.nineworldsdeep.droidmuse.R;
+import com.nineworldsdeep.droidmuse.R.id;
+import com.nineworldsdeep.droidmuse.R.menu;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class GuitarActivity extends Activity{
+
+ static final int DIALOG_NUM_STRINGS = 0;
+ static final int DIALOG_TUNING = 1;
+ static final int DIALOG_FRET_RANGE = 2;
+
+ private Fretboard _fretboard;
+
+ @Override
+ public void onSaveInstanceState(Bundle sis){
+
+ sis.putInt("numStrings", this._fretboard.getNumberOfStrings());
+ sis.putInt("firstFret", this._fretboard.getFirstDisplayFret());
+ sis.putString("tuning", this._fretboard.getTuning());
+ //TODO: erring out
+ //sis.putIntArray("posMap", this._fretboard.getSelectedPositions());
+ super.onSaveInstanceState(sis);
+
+
+ }
+
+ @Override
+ public void onRestoreInstanceState(Bundle sis){
+
+ super.onRestoreInstanceState(sis);
+
+
+
+ if(sis != null){
+ int numStrings = sis.getInt("numStrings");
+ int firstFret = sis.getInt("firstFret");
+ String tuning = sis.getString("tuning");
+ int[] posMap = sis.getIntArray("posMap");
+
+ this._fretboard.setNumberOfStringsNoDraw(numStrings);
+ this._fretboard.setFirstDisplayFretNoDraw(firstFret);
+ this._fretboard.setTuningNoDraw(tuning);
+ //TODO: erring out
+ //this._fretboard.setSelectedPositionsNoDraw(posMap);
+ }
+
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this._fretboard = new Fretboard(this);
+ setContentView(this._fretboard);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu){
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.fretboard_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item){
+
+
+
+ //handle item selection
+ switch(item.getItemId()){
+ case R.id.change_tuning:
+ showDialog(DIALOG_TUNING);
+ return true;
+ case R.id.set_num_strings:
+ showDialog(DIALOG_NUM_STRINGS);
+ return true;
+ case R.id.set_fret_range:
+ showDialog(DIALOG_FRET_RANGE);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+
+ }
+
+ @Override
+ protected Dialog onCreateDialog(int id){
+ Dialog dialog = null;
+
+ switch(id){
+ case DIALOG_NUM_STRINGS:
+ //define dialog
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Select Number of Strings");
+ StringNumChangeListener listener = new StringNumChangeListener(this);
+ builder.setSingleChoiceItems(Fretboard.stringNumOpts, -1, listener);
+
+ dialog = builder.create();
+ listener.setSender(dialog);
+
+ break;
+ case DIALOG_TUNING:
+ //define dialog
+ AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
+ builder1.setTitle("Enter Six String Tuning");
+
+ final EditText input = new EditText(this);
+ input.setText(this._fretboard.getTuning());
+ TuningListener listener1 = new TuningListener(this, input);
+
+ builder1.setView(input);
+
+ builder1.setPositiveButton("OK", listener1);
+ builder1.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ //cancelled
+ }
+ });
+
+ dialog = builder1.create();
+ break;
+ case DIALOG_FRET_RANGE:
+ //define dialog
+ AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
+ builder2.setTitle("Select First Display Fret");
+ FretRangeChangeListener listener2 = new FretRangeChangeListener(this);
+ builder2.setSingleChoiceItems(Fretboard.fretRangeOpts, -1, listener2);
+
+ dialog = builder2.create();
+ listener2.setSender(dialog);
+ break;
+ }
+
+ return dialog;
+ }
+
+ public void setNumberStrings(int numStrings) {
+ // TODO Auto-generated method stub
+ this._fretboard.setNumberOfStrings(numStrings);
+ }
+
+ public void setFretRange(int firstFret) {
+ // TODO Auto-generated method stub
+ this._fretboard.setFirstDisplayFret(firstFret);
+ }
+
+ public String changeTuning(String tuningValues) {
+ return this._fretboard.changeTuning(tuningValues);
+ }
+
+ public void setSelectedPositions(int[] selectedPositions){
+ this._fretboard.setSelectedPositions(selectedPositions);
+ }
+
+}
54 src/com/nineworldsdeep/droidmuse/guitar/GuitarString.java
@@ -0,0 +1,54 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import android.graphics.Point;
+import android.graphics.PointF;
+
+public class GuitarString {
+
+ Point[] points = new Point[2];
+ int positionalId;
+ PointF labelPos, noteLabelPos;
+
+ public GuitarString(Point lowEnd, Point highEnd, int positionalId, PointF labelPos, PointF noteLabelPos){
+ this.points[0] = lowEnd;
+ this.points[1] = highEnd;
+ this.positionalId = positionalId;
+ this.labelPos = labelPos;
+ this.noteLabelPos = noteLabelPos;
+ }
+
+ public Point[] getPoints() {
+ return points;
+ }
+
+ public int getPositionalId() {
+ return positionalId;
+ }
+
+ public PointF getStringLabelPosition() {
+ return labelPos;
+ }
+
+ public PointF getNoteLabelPosition(){
+ return noteLabelPos;
+ }
+
+}
27 src/com/nineworldsdeep/droidmuse/guitar/IMapping.java
@@ -0,0 +1,27 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+public interface IMapping {
+ public String getFretViewLabel(int viewFretPosition);
+ public String getStringViewLabel(int viewStringPosition);
+ public String getNoteName(int viewFretPosition, int viewStringPosition);
+ public String setSixStringTuning(String tuning);
+ public String getSixStringTuning();
+}
128 src/com/nineworldsdeep/droidmuse/guitar/LogicalFretboard.java
@@ -0,0 +1,128 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import android.graphics.Point;
+import android.graphics.PointF;
+import android.graphics.RectF;
+
+public class LogicalFretboard {
+
+ private int fretSpacing, stringSpacing;
+
+ //TODO: come up with a better variable name (lol)
+ private HashMap<Integer,Integer> stringFretPresses =
+ new HashMap<Integer,Integer>();
+
+ private ArrayList<FretboardPosition> positions =
+ new ArrayList<FretboardPosition>();
+
+ public LogicalFretboard(int fretSpacing, int stringSpacing){
+
+ this.fretSpacing = fretSpacing;
+ this.stringSpacing = stringSpacing;
+ }
+
+
+
+ public void registerPosition(GuitarString string, Fret fret){
+
+ Point[] fretPts, stringPts;
+
+ fretPts = fret.getPoints();
+ stringPts = string.getPoints();
+
+ int stringOffset = this.stringSpacing / 2;
+ int bottom = fretPts[0].y;
+ int top = bottom - this.fretSpacing;
+ int left = stringPts[0].x - stringOffset;
+ int right = stringPts[0].x + stringOffset;
+
+ this.positions.add(new FretboardPosition(left, top, right, bottom, fret, string));
+ //register string and set to silent string
+ this.stringFretPresses.put(string.getPositionalId(), -1);
+ }
+
+ public boolean togglePosition(float x, float y){
+ boolean found = false;
+ for(FretboardPosition fp : this.positions){
+ if(fp.getTouchRegion().contains(x,y)){
+ if(this.stringFretPresses.get(fp.getStringPosId()) == fp.getFretPosId()){
+ //silent string
+ this.stringFretPresses.put(fp.getStringPosId(), -1);
+ }else{
+ this.stringFretPresses.put(fp.getStringPosId(), fp.getFretPosId());
+ }
+ found = true;
+ }
+ }
+ return found;
+ }
+
+ public void setHeldPositions(int[] posMap){
+ for(int i = 0; i < posMap.length; i++){
+ if(this.stringFretPresses.containsKey(i)){
+ this.stringFretPresses.put(i, posMap[i]);
+ }
+ }
+ }
+
+ public int[] getHeldPositions(){
+ int[] posMap = new int[this.stringFretPresses.size()];
+
+ for(int i = 0; i < this.stringFretPresses.size(); i++){
+ if(this.stringFretPresses.containsKey(i)){
+ posMap[i] = this.stringFretPresses.get(i);
+ }
+ }
+
+ return posMap;
+ }
+
+ public boolean isHighestHeldNoteOnString(FretboardPosition pos){
+ int stringPosId = pos.getStringPosId();
+ int fretPosId = pos.getFretPosId();
+ return this.getHighestHeldNoteOnString(stringPosId) == fretPosId;
+ }
+
+ public int getHighestHeldNoteOnString(int stringPosId){
+ if(this.stringFretPresses.containsKey(stringPosId)){
+ return this.stringFretPresses.get(stringPosId);
+ }else{
+ return -1;
+ }
+ }
+
+ public boolean isSilent(int stringPosId){
+ if(this.stringFretPresses.containsKey(stringPosId)){
+ return this.stringFretPresses.get(stringPosId) == -1;
+ }else{
+ return false;
+ }
+ }
+
+ public Iterable<FretboardPosition> getPositions() {
+ return this.positions;
+ }
+}
+
+
45 src/com/nineworldsdeep/droidmuse/guitar/StringNumChangeListener.java
@@ -0,0 +1,45 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+
+public class StringNumChangeListener implements OnClickListener {
+
+ private GuitarActivity _guitarActivity;
+ private Dialog _sender;
+
+ public StringNumChangeListener(GuitarActivity ga) {
+ this._guitarActivity = ga;
+ }
+
+ public void onClick(DialogInterface dialog, int numStringsSelection) {
+ // TODO Auto-generated method stub
+ int numStrings = Integer.parseInt((String)Fretboard.stringNumOpts[numStringsSelection]);
+ this._guitarActivity.setNumberStrings(numStrings);
+ this._sender.dismiss();
+ }
+
+ public void setSender(Dialog dialog) {
+ this._sender = dialog;
+ }
+
+}
51 src/com/nineworldsdeep/droidmuse/guitar/TuningListener.java
@@ -0,0 +1,51 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.guitar;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.widget.EditText;
+import android.widget.Toast;
+
+public class TuningListener implements OnClickListener {
+
+ private GuitarActivity _guitarActivity;
+ private EditText _input;
+
+ public TuningListener(GuitarActivity guitarActivity, EditText input) {
+ // TODO Auto-generated constructor stub
+ this._guitarActivity = guitarActivity;
+ this._input = input;
+ }
+
+ public void onClick(DialogInterface dialog, int which) {
+
+ Context context = this._guitarActivity.getApplicationContext();
+ CharSequence text = "undefined";
+ int duration = Toast.LENGTH_SHORT;
+ Toast toast;
+
+ text = this._guitarActivity.changeTuning(this._input.getText().toString());
+
+ toast = Toast.makeText(context, text, duration);
+ toast.show();
+ }
+
+}
55 src/com/nineworldsdeep/droidmuse/keys/BlackUiKey.java
@@ -0,0 +1,55 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.keys;
+
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Paint.Style;
+
+public class BlackUiKey extends UiPianoKey {
+
+ private static final Paint myDotPaint, myKeyPaint;
+
+ static {
+ myDotPaint = new Paint();
+ myKeyPaint = new Paint();
+
+ myDotPaint.setStyle(Style.FILL_AND_STROKE);
+ myDotPaint.setColor(Color.BLACK);
+
+ myKeyPaint.setStyle(Style.FILL_AND_STROKE);
+ myKeyPaint.setColor(Color.WHITE);
+ }
+
+ public BlackUiKey(float left, float top, float right, float bottom, int chromaticIndex) {
+ super(left, top, right, bottom, chromaticIndex);
+
+ }
+
+ public Paint getMyDotPaint() {
+
+ return myDotPaint;
+ }
+
+ public Paint getMyKeyPaint() {
+
+ return myKeyPaint;
+ }
+
+}
185 src/com/nineworldsdeep/droidmuse/keys/Keyboard.java
@@ -0,0 +1,185 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.keys;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class Keyboard extends View {
+
+ UiPianoKey[] whiteKeys = new UiPianoKey[14];
+ UiPianoKey[] blackKeys = new UiPianoKey[10];
+
+ int _height;
+ int _width;
+
+ int whiteKeyHeight, whiteKeyWidth, blackKeyHeight, blackKeyWidth;
+ int outerMargin = 10;
+
+ Bitmap _bitmap;
+ Canvas _canvas;
+ Paint _paint;
+
+ private LogicalKeyboard _logicalBoard = new LogicalKeyboard();
+
+ public Keyboard(Context context) {
+ super(context);
+
+ this._paint = new Paint();
+ this._paint.setColor(Color.WHITE);
+ this._paint.setStyle(Paint.Style.STROKE);
+ }
+
+ private void calculateKeys(){
+
+ float top = this.outerMargin;
+ float whiteKeyLeft = this.outerMargin;
+ float whiteKeyRight = 0;
+ float whiteKeyBottom = top + whiteKeyHeight;
+ float blackKeyLeft = 0;
+ float blackKeyRight = 0;
+ float blackKeyBottom = top + blackKeyHeight;
+
+ int blackKeyIndex = 0;
+ int chromaticIndex = 0;
+
+ for(int i = 0; i < whiteKeys.length; i++){
+
+ whiteKeyRight = whiteKeyLeft + this.whiteKeyWidth;
+ blackKeyLeft = whiteKeyLeft + whiteKeyWidth - blackKeyWidth / 2;
+ blackKeyRight = blackKeyLeft + this.blackKeyWidth;
+
+ this.whiteKeys[i] =
+ new WhiteUiKey(whiteKeyLeft,top,whiteKeyRight,whiteKeyBottom,chromaticIndex);
+ chromaticIndex++;
+
+ //since black keys are positioned relative to whiteKeys, we need
+ //to skip over those whiteKey indexes for which no blackKey is drawn
+ switch(i){
+ case 2: case 6: case 9: case 13:
+ //do nothing
+ break;
+ default:
+ this.blackKeys[blackKeyIndex] =
+ new BlackUiKey(blackKeyLeft,top,blackKeyRight,blackKeyBottom,chromaticIndex);
+ blackKeyIndex++;
+ chromaticIndex++;
+ break;
+ }
+
+ whiteKeyLeft = whiteKeyRight;
+ }
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
+ this._height = View.MeasureSpec.getSize(heightMeasureSpec);
+ this._width = View.MeasureSpec.getSize(widthMeasureSpec);
+
+ this.whiteKeyHeight = _height - 2 * outerMargin;
+ this.whiteKeyWidth = (_width - 2 * outerMargin) / 14;
+ this.blackKeyHeight = this.whiteKeyHeight * 2 / 3;
+ this.blackKeyWidth = (_width - 2 * outerMargin) / 24;
+
+ this.setMeasuredDimension(_width, _height);
+
+ this._bitmap = Bitmap.createBitmap(_width, _height, Bitmap.Config.ARGB_8888);
+ this._canvas = new Canvas(_bitmap);
+
+ this.calculateKeys();
+ this.drawKeyboard();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas){
+ canvas.drawBitmap(this._bitmap, 0, 0, this._paint);
+ }
+
+ private void drawKeyboard() {
+
+ this._canvas.drawColor(Color.BLACK);
+
+ //we keep the two key sets separate so we can ensure that
+ //the black keys get drawn over the top of the white keys
+ drawKeyArray(whiteKeys);
+ drawKeyArray(blackKeys);
+
+ invalidate();
+ }
+
+ private void drawKeyArray(UiPianoKey[] keys) {
+ for(UiPianoKey key : keys){
+
+ this._canvas.drawRect(key, key.getMyKeyPaint());
+ if(this._logicalBoard.get(key.getChromaticIndex())){
+ this._canvas.drawCircle(key.getDotX(), key.getDotY(), key.getDotRadius(), key.getMyDotPaint());
+ }
+ }
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent evt){
+ if(evt.getAction() == MotionEvent.ACTION_DOWN){
+ boolean positionFound = togglePosition(evt.getX(), evt.getY());
+ if(positionFound){
+ this.drawKeyboard();
+ }
+ }
+ return true;
+ }
+
+ private boolean togglePosition(float x, float y) {
+
+ boolean found = false;
+
+ found = toggleKey(x,y,blackKeys);
+
+ if(!found){
+
+ found = toggleKey(x,y,whiteKeys);
+ }
+
+
+
+ return found;
+ }
+
+ private boolean toggleKey(float x, float y, UiPianoKey[] keys){
+
+ boolean found = false;
+
+ for(UiPianoKey key : keys){
+
+ if(!found && key.contains(x, y)){
+
+ this._logicalBoard.toggle(key.getChromaticIndex());
+ found = true;
+ }
+ }
+
+ return found;
+ }
+
+
+}
34 src/com/nineworldsdeep/droidmuse/keys/KeyboardActivity.java
@@ -0,0 +1,34 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.keys;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class KeyboardActivity extends Activity {
+
+ private Keyboard _keyboard;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this._keyboard = new Keyboard(this);
+ setContentView(this._keyboard);
+ }
+}
208 src/com/nineworldsdeep/droidmuse/keys/LogicalKeyboard.java
@@ -0,0 +1,208 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.keys;
+
+public class LogicalKeyboard {
+
+ private boolean[] keys = new boolean[24];
+
+ public void clearAll(){
+ for(int i = 0; i < keys.length; i++){
+ keys[i] = false;
+ }
+ }
+
+ public boolean get(int keyIndex){
+ return keys[keyIndex];
+ }
+
+ public void set(int keyIndex, boolean val){
+ keys[keyIndex] = val;
+ }
+
+ public void toggle(int keyIndex){
+ keys[keyIndex] = !keys[keyIndex];
+ }
+
+ public void toggleBlackKey(int blackKeyIndex){
+ setBlackKey(blackKeyIndex,!getBlackKey(blackKeyIndex));
+ }
+
+ public void toggleWhiteKey(int whiteKeyIndex){
+ setWhiteKey(whiteKeyIndex,!getWhiteKey(whiteKeyIndex));
+ }
+
+ public boolean getBlackKey(int blackKeyIndex){
+
+ switch(blackKeyIndex){
+ case 0:
+ return keys[1];
+ case 1:
+ return keys[3];
+ case 2:
+ return keys[6];
+ case 3:
+ return keys[8];
+ case 4:
+ return keys[10];
+ case 5:
+ return keys[13];
+ case 6:
+ return keys[15];
+ case 7:
+ return keys[18];
+ case 8:
+ return keys[20];
+ case 9:
+ return keys[22];
+ default:
+ return false;
+ }
+ }
+
+ public boolean getWhiteKey(int whiteKeyIndex){
+
+ switch(whiteKeyIndex){
+
+ case 0:
+ return keys[0];
+ case 1:
+ return keys[2];
+ case 2:
+ return keys[4];
+ case 3:
+ return keys[5];
+ case 4:
+ return keys[7];
+ case 5:
+ return keys[9];
+ case 6:
+ return keys[11];
+ case 7:
+ return keys[12];
+ case 8:
+ return keys[14];
+ case 9:
+ return keys[16];
+ case 10:
+ return keys[17];
+ case 11:
+ return keys[19];
+ case 12:
+ return keys[21];
+ case 13:
+ return keys[23];
+ default:
+ return false;
+ }
+ }
+
+ public void setBlackKey(int blackKeyIndex,boolean val){
+
+ switch(blackKeyIndex){
+
+ case 0:
+ keys[1] = val;
+ break;
+ case 1:
+ keys[3] = val;
+ break;
+ case 2:
+ keys[6] = val;
+ break;
+ case 3:
+ keys[8] = val;
+ break;
+ case 4:
+ keys[10] = val;
+ break;
+ case 5:
+ keys[13] = val;
+ break;
+ case 6:
+ keys[15] = val;
+ break;
+ case 7:
+ keys[18] = val;
+ break;
+ case 8:
+ keys[20] = val;
+ break;
+ case 9:
+ keys[22] = val;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void setWhiteKey(int whiteKeyIndex,boolean val){
+
+ switch(whiteKeyIndex){
+
+ case 0:
+ keys[0] = val;
+ break;
+ case 1:
+ keys[2] = val;
+ break;
+ case 2:
+ keys[4] = val;
+ break;
+ case 3:
+ keys[5] = val;
+ break;
+ case 4:
+ keys[7] = val;
+ break;
+ case 5:
+ keys[9] = val;
+ break;
+ case 6:
+ keys[11] = val;
+ break;
+ case 7:
+ keys[12] = val;
+ break;
+ case 8:
+ keys[14] = val;
+ break;
+ case 9:
+ keys[16] = val;
+ break;
+ case 10:
+ keys[17] = val;
+ break;
+ case 11:
+ keys[19] = val;
+ break;
+ case 12:
+ keys[21] = val;
+ break;
+ case 13:
+ keys[23] = val;
+ break;
+ default:
+ break;
+ }
+ }
+
+}
+
+
58 src/com/nineworldsdeep/droidmuse/keys/UiPianoKey.java
@@ -0,0 +1,58 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.keys;
+
+import android.graphics.Paint;
+import android.graphics.RectF;
+
+public abstract class UiPianoKey extends RectF{
+
+ private float dotX, dotY, dotRadius;
+ private int chromaticIndex;
+
+ public UiPianoKey(float left, float top, float right, float bottom, int chromaticIndex) {
+ super(left,top,right,bottom);
+ this.chromaticIndex = chromaticIndex;
+ float width = right - left;
+ dotX = (left + width / 2.0f);
+ dotY = (bottom - width / 2.0f);
+ dotRadius = (width / 4.0f);
+ }
+
+ public int getChromaticIndex(){
+ return this.chromaticIndex;
+ }
+
+ public float getDotX() {
+ return dotX;
+ }
+
+ public float getDotY() {
+ return dotY;
+ }
+
+ public float getDotRadius() {
+ return dotRadius;
+ }
+
+ public abstract Paint getMyDotPaint();
+
+ public abstract Paint getMyKeyPaint();
+
+}
55 src/com/nineworldsdeep/droidmuse/keys/WhiteUiKey.java
@@ -0,0 +1,55 @@
+/*
+ * This file is part of DroidMuse.
+ *
+ * DroidMuse is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DroidMuse is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DroidMuse. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nineworldsdeep.droidmuse.keys;
+
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Paint.Style;
+
+public class WhiteUiKey extends UiPianoKey {
+
+ private static final Paint myDotPaint, myKeyPaint;
+
+ static {
+ myDotPaint = new Paint();
+ myKeyPaint = new Paint();
+
+ myDotPaint.setStyle(Style.FILL_AND_STROKE);
+ myDotPaint.setColor(Color.WHITE);
+
+ myKeyPaint.setStyle(Style.STROKE);
+ myKeyPaint.setColor(Color.WHITE);
+ }
+
+ public WhiteUiKey(float left, float top, float right, float bottom, int chromaticIndex) {
+ super(left, top, right, bottom, chromaticIndex);
+
+ }
+
+ public Paint getMyDotPaint() {
+
+ return myDotPaint;
+ }
+
+ public Paint getMyKeyPaint() {
+
+ return myKeyPaint;
+ }
+
+}

0 comments on commit 049bada

Please sign in to comment.
Something went wrong with that request. Please try again.