changeset 4:5080b65e6963

Close MIDI sequencer and synthesizer properly and allow user to pass MIDI file directory as a command line argument Ignore-this: dbf86cc9008fba00379b67dd541adb38
author Marcus Pearce <m.pearce@gold.ac.uk>
date Thu, 18 Nov 2010 11:47:32 +0000
parents 6108a8aa9d82
children 135338ba37ef
files Block.java Clock.java Experiment.java ExperimentController.java ExperimentGui.java MidiPlayer.java README SubjectResults.java runExperiment.bat
diffstat 9 files changed, 57 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Block.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/Block.java	Thu Nov 18 11:47:32 2010 +0000
@@ -2,7 +2,7 @@
  * File:       Block.java
  * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
  * Created:    <2008-01-07 10:38:45 marcusp>
- * Time-stamp: <2010-06-08 16:13:27 marcusp>
+ * Time-stamp: <2010-11-18 11:04:31 marcusp>
  *=============================================================================
  */
 
@@ -54,10 +54,11 @@
     public ArrayList getInterOnsetIntervals() { return iois; } 
     public ArrayList getOnsets() { return onsets; } 
     public ArrayList getClockStartTimes() { return clockStartTimes; } 
+    public MidiPlayer getMidiPlayer() { return mp; }
 
     /* set the start time in nanoseconds to NOW */ 
     public long getStartTime() { return startTime; }
-    public void setStartTime() { startTime = System.nanoTime(); } 
+    public void setStartTime() { startTime = System.nanoTime(); }
     
     /* 
      * constructor 
@@ -186,6 +187,7 @@
 
     public void presentStimulus() { 
         // Start the experiment 
+        //mp.stop();
         setStartTime(); 
         mp.play(); 
         hasRun = true; 
--- a/Clock.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/Clock.java	Thu Nov 18 11:47:32 2010 +0000
@@ -45,7 +45,11 @@
             tick(1);
             repaint();
         }
-    } 
+        showClock = false;
+        showFullClock = false;
+        reset();
+        repaint();
+    }
     
     /* Move time on by 1 second. */
     public void tick(int n) {
@@ -69,6 +73,7 @@
     }
     
     private void paintFixationPoint(Graphics g) { 
+        //System.out.println("paintFixationPoint");
 	int left_edge = BORDER;
 	int top = BORDER;
 	int diameter = WIDTH - (BORDER * 2);
@@ -83,6 +88,7 @@
     } 
 
     private void paintClock (Graphics g) { 
+        //System.out.println("paintClock");
 	int minutes_angle = 90 - ((minutes % 60) * 6);
 	int hours_angle = 90 - ((minutes / 60) * 30);
 	int left_edge = BORDER;
--- a/Experiment.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/Experiment.java	Thu Nov 18 11:47:32 2010 +0000
@@ -2,7 +2,7 @@
  * File:       Experiment.java
  * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
  * Created:    <2007-02-14 11:28:27 marcusp>
- * Time-stamp: <2010-06-21 16:51:26 marcusp>
+ * Time-stamp: <2010-11-18 10:55:16 marcusp>
  *=============================================================================
  */
 
@@ -16,24 +16,25 @@
     /* pathnames */ 
     private final String BASE_DIRECTORY = 
         new File("").getAbsolutePath() + File.separator; 
-    private final String DATA_DIRECTORY = 
-        BASE_DIRECTORY + "Data" + File.separator; 
+
     public final String RESULTS_DIRECTORY = 
         BASE_DIRECTORY + "Results" + File.separator; 
-
-    private final String MIDI_DIRECTORY = 
-        DATA_DIRECTORY + "Midi" + File.separator;
-
     public final String RESULTS_EXTENSION = ".dat"; 
     public final String SUBJECT_RESULTS_FILE = 
         RESULTS_DIRECTORY + "subjects" + RESULTS_EXTENSION; 
 
+    private final String DATA_DIRECTORY = 
+        BASE_DIRECTORY + "Data" + File.separator; 
     public final String INSTRUCTIONS_FILE = 
         DATA_DIRECTORY + "instructions.html"; 
-    public final String MIDIFILELIST_FILE = 
-        DATA_DIRECTORY + "filelist.txt"; 
-    public final String PRACTICE_MIDIFILELIST_FILE = 
-        DATA_DIRECTORY + "pfilelist.txt"; 
+
+    public String MIDI_DIRECTORY = 
+        DATA_DIRECTORY + "Midi" + File.separator;
+    public String MIDIFILELIST_FILE = 
+        MIDI_DIRECTORY + "filelist.txt"; 
+    public String PRACTICE_MIDIFILELIST_FILE = 
+        MIDI_DIRECTORY + "pfilelist.txt"; 
+
 
     /* The GUI */ 
     private ExperimentGui gui; 
@@ -86,7 +87,7 @@
     }
 
     /* Constructor */ 
-    public Experiment (int sc, int cu, int nu, int sl, int md, String la, String ha) { 
+    public Experiment (int sc, int cu, int nu, int sl, int md, String la, String ha, String mfd) { 
         
         // Setup variables 
         results = new SubjectResults(this); 
@@ -100,6 +101,9 @@
         midiDevice = md;
         lowAnchor = la;
         highAnchor = ha;
+        MIDI_DIRECTORY = mfd + File.separator;
+        MIDIFILELIST_FILE = MIDI_DIRECTORY + "filelist.txt"; 
+        PRACTICE_MIDIFILELIST_FILE = MIDI_DIRECTORY + "pfilelist.txt"; 
 
         // Initialise the experiment 
         Block practice = new Block(this, gui, PRACTICE_MIDIFILELIST_FILE, 
@@ -147,7 +151,8 @@
             System.out.println("Usage: " + "\t" + "java Experiment " + 
                                "<show clock?> <clock units> <number of units> " + 
                                "<midi device> " + 
-                               "<scale length> <low anchor> <high anchor>"); 
+                               "<scale length> <low anchor> <high anchor>" +
+                               "<midi file directory>");
             System.exit(1);
         }
         
@@ -160,9 +165,10 @@
         int sl = Integer.parseInt(args[n++]); 
         String la = args[n++];
         String ha = args[n++];
+        String mfd = args[n++];
 
         // Create experiment 
-        Experiment exp = new Experiment(sc, cu, nu, sl, md, la, ha);
+        Experiment exp = new Experiment(sc, cu, nu, sl, md, la, ha, mfd);
         
         // Show the GUI 
         int width=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
--- a/ExperimentController.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/ExperimentController.java	Thu Nov 18 11:47:32 2010 +0000
@@ -2,7 +2,7 @@
  * File:       ExperimentController.java
  * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
  * Created:    <2007-12-14 12:06:10 marcusp>
- * Time-stamp: <2010-06-14 13:20:03 marcusp>
+ * Time-stamp: <2010-11-18 11:04:51 marcusp>
  *=============================================================================
  */
 
@@ -115,6 +115,8 @@
                 block.addMelodyQA("liked", answer2); 
                 block.storeMelodyResult();
                 results.writeResults();
+                // close the midi player
+                block.getMidiPlayer().stop();
                 // proceed to ... 
                 String nextFile = block.nextFile();
                 if (nextFile == null) { 
--- a/ExperimentGui.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/ExperimentGui.java	Thu Nov 18 11:47:32 2010 +0000
@@ -2,7 +2,7 @@
  * File:       ExperimentGui.java
  * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
  * Created:    <2007-02-14 16:42:31 marcusp>
- * Time-stamp: <2010-06-21 16:50:53 marcusp>
+ * Time-stamp: <2010-11-18 11:46:46 marcusp>
  *=============================================================================
  */
 
@@ -105,6 +105,7 @@
 
     /* Show the Fixation Point */ 
     public void showFixationPoint() { 
+        //System.out.println("showFixationPoint");
         clock.showClock = false; 
         clock.showFullClock = false; 
         clock.repaint(); 
--- a/MidiPlayer.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/MidiPlayer.java	Thu Nov 18 11:47:32 2010 +0000
@@ -2,7 +2,7 @@
  * File:       MidiPlayer.java
  * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
  * Created:    <2007-02-14 12:13:56 marcusp>
- * Time-stamp: <2010-06-08 16:12:05 marcusp>
+ * Time-stamp: <2010-11-18 11:01:56 marcusp>
  *=============================================================================
  */
 
@@ -300,6 +300,13 @@
     } 
 
     public void stop() { 
-        sequencer.close(); 
-    } 
+        if (synthesizer != null) {
+            synthesizer.close();
+        }
+        if (sequencer != null) {
+            sequencer.close();
+        }
+        sequencer = null;
+        synthesizer = null;
+    }
 } 
--- a/README	Mon Jun 21 17:37:24 2010 +0100
+++ b/README	Thu Nov 18 11:47:32 2010 +0000
@@ -5,7 +5,7 @@
 
 USAGE 
 
-  java Experiment <show clock?> <multiple> <n> <midi device> <scale length> <low anchor> <high anchor>
+  java Experiment <show clock?> <multiple> <n> <midi device> <scale length> <low anchor> <high anchor> <midi file directory>
 
 where <show clock?> specifies whether to show the clock (0 = no; 1 =
 yes) and <multiple> and <n> are integers: the clock runs for <n> time
@@ -19,16 +19,19 @@
 (e.g., "highly unexpected", "highly expected" with a scale length of
 7). 
 
+<midi file directory> is the directory where the midi files are stored
+
 See runExperiment.bat for an example.
 
 To use in a study:
 
-1. put the relevant midi files in Data/Midi;
+1. put the relevant midi files in the directory specified by <midi
+file directory> (e.g., Data/Midi/)
 
-2. edit pfilelist.txt and filelist.txt to contain the midi files
-played in the practice and main blocks respectively: put one file on
-each line followed by a list of note numbers to probe with the visual
-clock.
+2. edit pfilelist.txt and filelist.txt (also in <midi file directory>) to
+contain the midi files played in the practice and main blocks
+respectively: put one file on each line followed by a list of note
+numbers to probe with the visual clock.
 
 3. edit Data/instructions.html if necessary.
 
--- a/SubjectResults.java	Mon Jun 21 17:37:24 2010 +0100
+++ b/SubjectResults.java	Thu Nov 18 11:47:32 2010 +0000
@@ -2,7 +2,7 @@
  * File:       SubjectResults.java
  * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
  * Created:    <2007-12-12 10:44:12 marcusp>
- * Time-stamp: <2010-06-14 13:11:36 marcusp>
+ * Time-stamp: <2010-11-16 15:28:10 marcusp>
  *=============================================================================
  */
 
--- a/runExperiment.bat	Mon Jun 21 17:37:24 2010 +0100
+++ b/runExperiment.bat	Thu Nov 18 11:47:32 2010 +0000
@@ -1,1 +1,1 @@
-java Experiment 1 1 4 0 7 "Highly unexpected" "Highly expected"
+java Experiment 1 1 4 0 7 "Highly unexpected" "Highly expected" "/home/marcusp/research/projects/idyom2/MelodicExpectationParadigm/Data/Midi/hymns/"