[jfretsfx~subversion:9] File menu working and now using Instrument Tuner. Solo follow nearly work

  • From: mattwrock@kenai.com
  • To: commits@jfretsfx.kenai.com
  • Subject: [jfretsfx~subversion:9] File menu working and now using Instrument Tuner. Solo follow nearly work
  • Date: Thu, 8 Oct 2009 13:38:20 +0000

Project:    jfretsfx
Repository: subversion
Revision:   9
Author:     mattwrock
Date:       2009-10-08 13:38:18 UTC
Link:       

Log Message:
------------
File menu working and now using Instrument Tuner. Solo follow nearly workiing 
perfectly.


Revisions:
----------
9


Modified Paths:
---------------
JFretsFX/src/jfretsfx/main.fx
JFretsFX/src/jfretsfx/Tuner.fx
JFretsFX/src/jfretsfx/Note.fx


Diffs:
------
Index: JFretsFX/src/jfretsfx/main.fx
===================================================================
--- JFretsFX/src/jfretsfx/main.fx       (revision 8)
+++ JFretsFX/src/jfretsfx/main.fx       (revision 9)
@@ -45,8 +45,17 @@
 
 import java.lang.StringBuilder;
 
+import javafx.ext.swing.SwingComponent;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
 
 
+
 /**
  * @author Matt Warman
  */
@@ -113,27 +122,31 @@
             getTone(x,y)
         };
         var noteName: String;
+        var octave: String;
     //    println(tone);
     //    println(tone.length());
         if(tone.length() == 3)
         {
             noteName = tone.substring(0,2);
+            octave = tone.substring(2);
         }
         else
         {
             noteName = tone.substring(0, 1);
+            octave = tone.substring(1);
         }
-        removeNotes();
         note = Note {
             x: x;
             y: y;
             value: noteName;
+            octave: octave;
             duration: "www";
         }
-        insert note into stage.scene.content;
-        println("solo {solo} ");
         if(solo == false)
         {
+            removeNotes();
+            insert note into stage.scene.content;
+            println("solo {solo} ");
             println("playing single note ");
             playSingleNote(note);
         }
@@ -166,6 +179,7 @@
 //            var url: URL = new URL("{__DIR__}resources/SONiVOX GS250.SF2");
 //            var sb: File = new File("{__DIR__}resources/SONiVOX 
GS250.SF2");
 //            var sb: File = new File("{__DIR__}/jfretsfx/resources/SONiVOX 
GS250.SF2");
+            var sb: File = new File("c:/soundbanks/SONiVOX GS250.SF2");
 //            soundbank = MidiSystem.getSoundbank(url);
                 soundbank = synth.getDefaultSoundbank();
             //Not working from reading within jar uncomment to test again
@@ -331,65 +345,75 @@
         };
     }
     var soloList: ArrayList = setSoloSample();
+    var missed = 0;
     //The First note gets set elsewhere
     //Compare that note against not selected on the fretboard
     function playFollow() : Void
     {
-          //this is set to force the pattern string. The string is broken
-          //remove when fixed.
-         id = 9;
          println("note value: {note.value}");
          println("follow value: {followNote.value}");
         if(note.value.equals(followNote.value))
         {
-            //if we finish the solo, play it
-            println("id {id}");
-//            println("size {soloList.size()}");
+            // remove this. I just dont want the user to play 36 notes
+//            if(id  < soloList.size())
             id++;
-            // remove this. I just dont want the user to play 36 notes
-            //            if(id  < soloList.size())
+            delete note from stage.scene.content;
             if(id  < 9)
             {
-//                delete followNote from stage.scene.content;
+                playSingleNote(followNote);
+                println("id {id}");
+                removeNotes();
                 followNote = soloList.get(id) as Note;
+                println("new follow value: {followNote.value}");
                 insert followNote into stage.scene.content;
             }
+            //if we finish the solo, play it
             else
             {
+                delete followNote from stage.scene.content;
+                solo = false;
                 var iterator = soloList.iterator();
                 var notes;
                 var sb: StringBuilder = new StringBuilder();
+               
                 while(iterator.hasNext())
                 {
                      notes = iterator.next() as Note;
-                     sb.append(notes.value);
-                    println("note {notes.value}");
-                     sb.append(notes.duration);
-                     sb.append(" ");
-//                    insert notes into stage.scene.content;
-//                    delete notes from stage.scene.content
+                     insert notes into stage.scene.content;
+                     playSingleNote(notes);
+                    delete notes from stage.scene.content;
+//                     sb.append(notes.value);
+//                     sb.append(notes.octave);
+//                    println("note {notes.value}");
+//                     sb.append(notes.duration);
+//                     sb.append(" ");
                 }
-                println("pattern {sb.toString()}");
-                try
-                {
-                    openPlayer();
-                    def player = new Player(seqr);
-                    var v: Voice = list.get(voice.selectedIndex) as Voice;
-                    def patternString = "T{bpm.text} {v.midi} 
{sb.toString()}";
-                    println("pattern  {patternString}");
-                    var pat: Pattern = new Pattern(patternString);
-                    player.play(pat);
-                    player.close();
-                    seqr.close();
-                } catch (ex: MidiUnavailableException) {
-                    println(ex.getMessage())
-                }
+                var total = id;
+                var correct = total - missed;
+                Alert.inform("Play Solo", "You got {correct} notes of out 
{total}");
+                missed = 0;
+//                println("pattern {sb.toString()}");
+//                try
+//                {
+//                    openPlayer();
+//                    def player = new Player(seqr);
+//                    var v: Voice = list.get(voice.selectedIndex) as Voice;
+//                    def patternString = "T{bpm.text} {v.midi} 
{sb.toString()}";
+//                    println("pattern  {patternString}");
+//                    var pat: Pattern = new Pattern(patternString);
+//                    player.play(pat);
+//                    player.close();
+//                    seqr.close();
+//                } catch (ex: MidiUnavailableException) {
+//                    println(ex.getMessage())
+//                }
             }
         }
         else
         {
             //Alert the user of the wrong note
-            Alert.inform("Play Solo", "This is not the right note");
+            missed ++;
+            Alert.inform("Play Solo", "This is not the right note. The right 
note is {note.value}{note.octave}");
         }
 
     }
@@ -405,9 +429,9 @@
             if(nt.duration != null)
             {
                 duration = nt.duration;
-            }            
-            def patternString = "T{bpm.text} {v.midi} {getTone(nt.x, 
nt.y)}{duration}";
-            println("pattern  {patternString}");
+            } 
+            var patternString = "T{bpm.text} {v.midi} {getTone(nt.x, 
nt.y)}{duration}";
+            println("single pattern  {patternString}");
             var pat: Pattern = new Pattern(patternString);
             player.play(pat);
             player.close();
@@ -421,161 +445,391 @@
  {
       var sl: ArrayList = new ArrayList();
       var note1: Note;
-      var note2: Note;
-      var note3: Note;
-      var note4 = Note {
+        //Assemble Notes
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "w"
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret4 + 15;
+            y: col2 - 10;
+            value: "Eb"
+            octave: "5"
+            duration: "h."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "h."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "h."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret4 + 15;
+            y: col2 - 10;
+            value: "Eb"
+            octave: "5"
+            duration: "h."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "h"
+        }
+        sl.add(note1);
+        note1 = Note {
             x: fret8 + 15;
             y: col2 - 10;
             value: "G"
-            duration: "w"
+            octave: "5"
+            duration: "h"
         }
-      var note5 = Note {
+        sl.add(note1);
+        note1 = Note {
             x: fret5 + 15;
             y: col2 - 10;
             value: "E"
-            duration: "w"
+            octave: "5"
+            duration: "h"
         }
-      var note6 = Note {
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "q."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret8 + 15;
+            y: col2 - 10;
+            value: "G"
+            octave: "5"
+            duration: "q."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret5 + 15;
+            y: col2 - 10;
+            value: "E"
+            octave: "5"
+            duration: "q."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "q"
+        }
+        sl.add(note1);
+        note1 = Note {
             x: fret10 + 15;
             y: col2 - 10;
             value: "A"
-            duration: "w"
+            octave: "5"
+            duration: "q"
         }
-        //Assemble Notes
-        note2 = Note {
+        sl.add(note1);
+        note1 = Note {
             x: fret7 + 15;
             y: col2 - 10;
             value: "Gb"
-            duration: "w"
+            octave: "5"
+            duration: "q"
         }
-        sl.add(note2);
-        note3.duration = "h.";
-        sl.add(note3);
+        sl.add(note1);
         note1 = Note {
             x: fret0 + 20;
             y: col2 - 10;
             value: "B"
-            duration: "h."
+            octave: "4"
+            duration: "i."
         }
-        sl.add(note1); note2 = Note {
+        sl.add(note1);
+        note1 = Note {
+            x: fret10 + 15;
+            y: col2 - 10;
+            value: "A"
+            octave: "5"
+            duration: "i."
+        }
+        sl.add(note1);
+        note1 = Note {
             x: fret7 + 15;
             y: col2 - 10;
             value: "Gb"
-            duration: "h."
+            octave: "5"
+            duration: "i."
         }
-        sl.add(note3);
-        note1.duration = "h";
         sl.add(note1);
-        note4 = Note {
-            x: fret8 + 15;
+        note1 = Note {
+            x: fret0 + 20;
             y: col2 - 10;
-            value: "G"
-            duration: "h"
+            value: "B"
+            octave: "4"
+            duration: "i."
         }
-        sl.add(note4);
-        note5.duration = "h";
-        sl.add(note5);
-        note1.duration = "q.";
-        sl.add(note1); note4 = Note {
+        sl.add(note1);
+        note1 = Note {
             x: fret8 + 15;
             y: col2 - 10;
             value: "G"
-            duration: "q."
+            octave: "5"
+            duration: "i"
         }
-        sl.add(note4);
-        note5.duration = "q.";
-        sl.add(note5);
-        note1.duration = "q";
         sl.add(note1);
-        note6.duration = "q";
-        sl.add(note6);
-        note2.duration = "q";
-        sl.add(note2);
-        note1.duration = "i.";
+        note1 = Note {
+            x: fret5 + 15;
+            y: col2 - 10;
+            value: "E"
+            octave: "5"
+            duration: "i"
+        }
         sl.add(note1);
-        note6.duration = "i.";
-        sl.add(note6);
-        note2.duration = "i.";
-        sl.add(note2);
-        note1.duration = "i.";
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "i"
+        }
         sl.add(note1);
-        note4.duration = "i";
-        sl.add(note4);
-        note5.duration = "i";
-        sl.add(note5);
-        note1.duration = "i";
-        sl.add(note1); note4 = Note {
+        note1 = Note {
             x: fret8 + 15;
             y: col2 - 10;
             value: "G"
+            octave: "5"
             duration: "s."
         }
-        sl.add(note4);
-        note5.duration = "s.";
-        sl.add(note5);
-        note1.duration = "s.";
         sl.add(note1);
-        note2.duration = "s";
-        sl.add(note2);
-        note3.duration = "s";
-        sl.add(note3);
-        note1.duration = "s";
+        note1 = Note {
+            x: fret5 + 15;
+            y: col2 - 10;
+            value: "E"
+            octave: "5"
+            duration: "s."
+        }
         sl.add(note1);
-        note2.duration = "t.";
-        sl.add(note2);
-        note3.duration = "t.";
-        sl.add(note3);
-        note1.duration = "t.";
-        sl.add(note1); note4 = Note {
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "s."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "s"
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret4 + 15;
+            y: col2 - 10;
+            value: "Eb"
+            octave: "5"
+            duration: "s"
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "s"
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret4 + 15;
+            y: col2 - 10;
+            value: "Eb"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
             x: fret8 + 15;
             y: col2 - 10;
             value: "G"
+            octave: "5"
             duration: "t."
         }
-        sl.add(note4);
-        note5.duration = "t.";
-        sl.add(note5);
-        note1.duration = "t.";
-        sl.add(note1); note4 = Note {
+        sl.add(note1);
+        note1 = Note {
+            x: fret5 + 15;
+            y: col2 - 10;
+            value: "E"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
             x: fret8 + 15;
             y: col2 - 10;
             value: "G"
+            octave: "5"
             duration: "t."
         }
-        sl.add(note4);
-        note5.duration = "t.";
-        sl.add(note5);
-        note1.duration = "t.";
         sl.add(note1);
-        note6.duration = "t.";
-        sl.add(note6);
-        note2.duration = "t.";
-        sl.add(note2);
-        note1.duration = "t.";
+        note1 = Note {
+            x: fret5 + 15;
+            y: col2 - 10;
+            value: "E"
+            octave: "5"
+            duration: "t."
+        }
         sl.add(note1);
-        note6.duration = "t.";
-        sl.add(note6);
-        note2.duration = "t.";
-        sl.add(note2);
-        note1.duration = "t.";
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "t."
+        }
         sl.add(note1);
-        note4 = Note {
+        note1 = Note {
+            x: fret10 + 15;
+            y: col2 - 10;
+            value: "A"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret10 + 15;
+            y: col2 - 10;
+            value: "A"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
             x: fret8 + 15;
             y: col2 - 10;
             value: "G"
+            octave: "5"
             duration: "t."
         }
-        sl.add(note4);
-        note5.duration = "t.";
-        sl.add(note5);
-        note1.duration = "t.";
         sl.add(note1);
-        note2.duration = "t.";
-        sl.add(note2);
-        note3.duration = "t.";
-        sl.add(note3);
-        note1.duration = "w";
+        note1 = Note {
+            x: fret5 + 15;
+            y: col2 - 10;
+            value: "E"
+            octave: "5"
+            duration: "t."
+        }
         sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret7 + 15;
+            y: col2 - 10;
+            value: "Gb"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret4 + 15;
+            y: col2 - 10;
+            value: "Eb"
+            octave: "5"
+            duration: "t."
+        }
+        sl.add(note1);
+        note1 = Note {
+            x: fret0 + 20;
+            y: col2 - 10;
+            value: "B"
+            octave: "4"
+            duration: "w"
+        }
+        sl.add(note1);
         return sl;
 
  }
@@ -784,34 +1038,34 @@
         }
     }
 
-//var selected = "";
-//var handler = ActionListener {
-//  public override function actionPerformed( e: ActionEvent ) {
-//    selected = e.getActionCommand() ;
-//  }
-//};
-//var menuBar = new JMenuBar();
-//
-//var menu = new JMenu("File");
-//menu.setMnemonic(KeyEvent.VK_F);
-//menuBar.add(menu);
-//
-//var menuItem = new JMenuItem("Instrument Tuner");
-//menuItem.setAccelerator(
-//    KeyStroke.getKeyStroke(KeyEvent.VK_T));
-//    handler = ActionListener {
-//        public override function actionPerformed( e: ActionEvent ) {
-//            new Tuner;
-//        }
-//    }
-//menuItem.addActionListener(handler);
-//menu.add(menuItem);
-//var w : Number = 480 on replace { fxMenuBar.width = w ; } ;
-//var fxMenuBar : SwingComponent = SwingComponent.wrap(menuBar);
-//fxMenuBar.width = w;
-//fxMenuBar.layoutX=0;
-//fxMenuBar.layoutY=0;
+var selected = "";
+var handler = ActionListener {
+  public override function actionPerformed( e: ActionEvent ) {
+    selected = e.getActionCommand() ;
+  }
+};
+var menuBar = new JMenuBar();
 
+var menu = new JMenu("File");
+menu.setMnemonic(KeyEvent.VK_F);
+menuBar.add(menu);
+
+var menuItem = new JMenuItem("Instrument Tuner");
+menuItem.setAccelerator(
+    KeyStroke.getKeyStroke(KeyEvent.VK_T));
+    handler = ActionListener {
+        public override function actionPerformed( e: ActionEvent ) {
+            new Tuner;
+        }
+    }
+menuItem.addActionListener(handler);
+menu.add(menuItem);
+var w : Number = 480 on replace { fxMenuBar.width = w ; } ;
+var fxMenuBar : SwingComponent = SwingComponent.wrap(menuBar);
+fxMenuBar.width = w;
+fxMenuBar.layoutX=0;
+fxMenuBar.layoutY=0;
+
     class Model
     {
         var ch: Chord;
@@ -889,7 +1143,7 @@
     {
         tuner = new Tuner();
     }
-//    tuner.stage.visible == true;
+    tuner.stage.visible == true;
 }
 
 var stage: Stage = Stage {
@@ -899,7 +1153,7 @@
     height: 500
     scene: Scene {
         content: [
-//            fxMenuBar,
+            fxMenuBar,
             Text {
                 translateX: 20
                 translateY: 35
@@ -935,14 +1189,6 @@
                     playChord();
                 }
             },
-//            Button {
-//                text: "Tuner"
-//                translateY: 20
-//                translateX: 650
-//                action: function() {
-//                    getTuner();
-//                }
-//            },
             Button {
                 text: "Solo"
                 translateY: 20
@@ -952,7 +1198,6 @@
                     {
                         solo = true;
                         followNote = soloList.get(0) as Note;
-                        note = followNote;
                         insert followNote into stage.scene.content;
                         playSingleNote(followNote);
                     }
Index: JFretsFX/src/jfretsfx/Note.fx
===================================================================
--- JFretsFX/src/jfretsfx/Note.fx       (revision 8)
+++ JFretsFX/src/jfretsfx/Note.fx       (revision 9)
@@ -29,6 +29,7 @@
     public var row : Number;
     public var col : Number;
     public var value: String;
+    public var octave: String;
     public var duration: String;
     override function create() : Node {
         Group {
Index: JFretsFX/src/jfretsfx/Tuner.fx
===================================================================
--- JFretsFX/src/jfretsfx/Tuner.fx      (revision 8)
+++ JFretsFX/src/jfretsfx/Tuner.fx      (revision 9)
@@ -178,7 +178,7 @@
         seqr.getTransmitter().setReceiver(synth.getReceiver());
         synth.loadInstrument(synth.getDefaultSoundbank().getInstrument(new 
Patch(0, 30)));
         player = new Player(seqr);
-        var patternString = "T90 I[30] {tone}w";
+        var patternString = "T90 I[24] {tone}w";
         println("pattern  {patternString}");
         var pat: Pattern = new Pattern(patternString);
         player.play(pat);
@@ -297,7 +297,7 @@
         content: "This is the standard tuning for a guitar"
     }
 
-    var stage: Stage = Stage
+    public var stage: Stage = Stage
     {
         title: "Instrument Tuner"
         width: 250
@@ -310,16 +310,16 @@
                 translateX: 20
                 content: "Tuning Type:"
             },
-            Button
-            {
-                translateX: 50
-                translateY: 50
-                text: "Stop Tuner"
-                action: function()
-                    {
-                        stopTone();
-                    }
-                },
+//            Button
+//            {
+//                translateX: 50
+//                translateY: 50
+//                text: "Stop Tuner"
+//                action: function()
+//                    {
+//                        stopTone();
+//                    }
+//                },
 
             tunings,
             tuningDesc,





[jfretsfx~subversion:9] File menu working and now using Instrument Tuner. Solo follow nearly work

mattwrock 10/08/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close