changeset 27:014c83185b2a

Improved debugging messages.
author Jeremy Gow <jeremy.gow@gmail.com>
date Mon, 12 Nov 2012 22:49:08 +0000
parents c5db34797ff3
children 7212a334d98b
files Block.class Block.java Clock.class Clock.java Experiment.class Experiment.java ExperimentGui$1.class SubjectDataPanel.class SubjectDataPanel.java
diffstat 9 files changed, 57 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
Binary file Block.class has changed
--- a/Block.java	Mon Nov 12 22:48:39 2012 +0000
+++ b/Block.java	Mon Nov 12 22:49:08 2012 +0000
@@ -80,16 +80,21 @@
         // initialise the block 
         hasRun = false; 
         initialiseBlock();
-        // Initialise the Midiplayer 
-        mp = new MidiPlayer(exp.getMidiDirectory().concat(filename), exp.getMidiDeviceNumber());
+
+        // Initialise the Midiplayer - already done in initialiseBlock?
+        //mp = new MidiPlayer(exp.getMidiDirectory().concat(filename), exp.getMidiDeviceNumber(), false);
+
         // Write out stimulus structure for all melodies in block
         //writeStimuli();
     }
 
     /* initialise the block */ 
     public void initialiseBlock() { 
+	if (exp.getDebug())
+	    System.out.println("Initialising block for " + filename);
+
         // Initialise the Midiplayer 
-        mp = new MidiPlayer(exp.getMidiDirectory().concat(filename), exp.getMidiDeviceNumber()); 
+        mp = new MidiPlayer(exp.getMidiDirectory().concat(filename), exp.getMidiDeviceNumber(), false); 
         // Set up the melody structure and the probe positions 
         setupSong(); 
         setupProbes();
@@ -115,7 +120,7 @@
         pitches = mp.getPitches(); 
         tatum = mp.getTatum();
         if (exp.getDebug())
-            System.out.println("Tatum = " + tatum);
+            System.out.println("\nTatum = " + tatum);
     }
 
     private void setupProbes() { 
@@ -139,8 +144,7 @@
 
         while(ppi.hasNext()) { 
             int probe = ((Integer)ppi.next()).intValue();
-            if (exp.getDebug())
-                System.out.println("Probe at " + probe + " out of " + onsets.size());
+	    System.out.println(filename + ": probe at " + (probe + 1) + " out of " + onsets.size());
             // probes.set(probe - numEvents, ProbeID.START_CLOCK); 
             
             probes.set(probe - 1, ProbeID.BEFORE_PROBE); 
@@ -170,10 +174,12 @@
 
     public void printProbes() { 
         Iterator pi = probes.iterator(); 
+        Iterator oi = onsets.iterator(); 
 
         int i = 1; 
-        while(pi.hasNext()) { 
-            System.out.println(filename + " " + i + ": " + pi.next()); 
+	System.out.println("Events for " + filename + "...");
+        while(pi.hasNext() && oi.hasNext()) { 
+            System.out.println("Event " + i + ": " + pi.next() + ", " + oi.next()); 
             i++; 
         }
     }
@@ -233,7 +239,7 @@
             File outputFile = new File(outFile); 
             
             MidiPlayer midip = 
-                new MidiPlayer(exp.getMidiDirectory().concat(midiFile), exp.getMidiDeviceNumber()); 
+                new MidiPlayer(exp.getMidiDirectory().concat(midiFile), exp.getMidiDeviceNumber(), false); 
 
             // Setup the probes 
             ArrayList probePos = filelist.currentProbes(); 
Binary file Clock.class has changed
--- a/Clock.java	Mon Nov 12 22:48:39 2012 +0000
+++ b/Clock.java	Mon Nov 12 22:49:08 2012 +0000
@@ -27,10 +27,13 @@
     private long millisecondsPerTick = 1000; 
     public void  setMillisecondsPerTick(long n) { millisecondsPerTick = n; }
 
+    private boolean debug;
+
     /* Create a new Clock at time midnight. */
-    public Clock() {
+    public Clock(boolean d) {
         this.setBackground(BACKGROUND); 
         this.setPreferredSize (new Dimension (WIDTH, WIDTH));
+	debug = d;
     }
 
     public void run() { 
@@ -47,7 +50,8 @@
         }
         showClock = false;
         showFullClock = false;
-        System.out.println("RUN CLOCK");
+        if (debug)
+	    System.out.println("RUN CLOCK");
         reset();
         revalidate();
         repaint();
@@ -60,7 +64,8 @@
     
     /* Reset the clock to 00:00. */ 
     public void reset() { 
-        System.out.println("RESET!");
+        if (debug)
+	    System.out.println("RESET!");
         minutes = 0; 
     } 
 
@@ -133,7 +138,8 @@
         Graphics2D g2 = (Graphics2D)g;
         g2.setPaint(FOREGROUND);
         
-        System.out.println("minutes_angle = " + minutes_angle + 
+        if (debug) 
+	    System.out.println("minutes_angle = " + minutes_angle + 
                            "; arc_angle = " + arc_angle); 
 
         if (arc_angle == 0 & showFullClock == true) { 
Binary file Experiment.class has changed
--- a/Experiment.java	Mon Nov 12 22:48:39 2012 +0000
+++ b/Experiment.java	Mon Nov 12 22:49:08 2012 +0000
@@ -10,6 +10,7 @@
 import javax.swing.UIManager; 
 import java.awt.*;
 import java.awt.Color;
+import javax.sound.midi.*;
 
 public class Experiment { 
 
@@ -99,11 +100,15 @@
         results.setSubjectID(id); 
         results.setOutputFile(id); 
         getCurrentBlock().getMelodyResults().setSubjectID(id); 
+	System.out.println("Subject ID = " + subjectID);
     }
 
     /* Constructor */ 
     public Experiment (int sc, int cu, int nu, int sl, int md, String la, String ha, String mfd, String inf, String rdr, int fam, int lik, int quest) { 
         
+	if (debug)
+	    displayMIDIDevices();
+
         // Setup variables 
         results = new SubjectResults(this); 
         if (sc == 0) 
@@ -166,8 +171,15 @@
         (new Thread(gui)).start();
         getCurrentBlock().presentStimulus(); 
     }
-    public boolean isRunning() { return getCurrentBlock().isRunning(); }
-    public boolean hasRun() { return getCurrentBlock().hasRun(); } 
+    public boolean isRunning() {
+	Block cur = getCurrentBlock();;
+	return cur != null && cur.isRunning();
+    }
+    
+    public boolean hasRun() {
+	Block cur = getCurrentBlock();
+	return cur != null && cur.hasRun();
+    } 
 
     /* Show the GUI */ 
     public void showGUI(int width, int height) { 
@@ -213,4 +225,21 @@
         int height=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
         exp.showGUI(width, height); 
     }
+
+    /*
+     * Print a list of accessible MIDI devices
+     */
+    protected void displayMIDIDevices() {
+	System.out.println("Searching for MIDI devices...");
+	    
+	MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+	if (devices.length == 0) {
+	    System.out.println("No MIDI devices found");
+	} else {
+	    for (MidiDevice.Info dev : devices) {
+		System.out.println("MIDI device: " + dev);
+	    }
+	}
+    }
+
 }
Binary file ExperimentGui$1.class has changed
Binary file SubjectDataPanel.class has changed
--- a/SubjectDataPanel.java	Mon Nov 12 22:48:39 2012 +0000
+++ b/SubjectDataPanel.java	Mon Nov 12 22:49:08 2012 +0000
@@ -179,7 +179,7 @@
         
         // Put it all together 
         JPanel finishPanel = new JPanel(); 
-	finishButton = new JButton("Finish."); 
+	finishButton = new JButton("Finish"); 
         finishPanel.add(finishButton); 
 
         JPanel topPanel = new JPanel();