Mercurial > hg > mep
diff Experiment.java @ 0:4031cbb02f08
Initial import.
Ignore-this: 87317e384f22bde48db996355191fa5f
author | Marcus Pearce <m.pearce@gold.ac.uk> |
---|---|
date | Tue, 18 May 2010 11:37:10 +0100 |
parents | |
children | 93ed757b9871 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Experiment.java Tue May 18 11:37:10 2010 +0100 @@ -0,0 +1,157 @@ +/*============================================================================= + * File: Experiment.java + * Author: Marcus Pearce <m.pearce@gold.ac.uk> + * Created: <2007-02-14 11:28:27 marcusp> + * Time-stamp: <2010-05-18 11:13:42 marcusp> + *============================================================================= + */ + +import java.io.*; +import javax.swing.UIManager; +import java.awt.*; +import java.awt.Color; + +public class Experiment { + + /* 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; + + 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"; + + /* The GUI */ + private ExperimentGui gui; + + /* the units of the clock as multiples of the tatum */ + private int clockUnits; + /* number of units that clock runs for before a probe event */ + private int numUnits; + + /* the blocks of the experiment */ + Block[] blocks; + int currentBlockID; + + /* Subject ID */ + private int subjectID; + + /* Results */ + private SubjectResults results; + + /* the details of the rating scale */ + private int scaleLength; + private String lowAnchor; + private String highAnchor; + + /* accessors */ + public int getScaleLength() { return scaleLength; } + public String getLowAnchor() { return lowAnchor; } + public String getHighAnchor() { return highAnchor; } + + public String getMidiDirectory() { return MIDI_DIRECTORY; } + public SubjectResults getSubjectResults() { return results; } + public Block getCurrentBlock() { return blocks[currentBlockID]; } + public int getCurrentBlockID() { return currentBlockID + 1; } + public int getClockUnits() { return clockUnits; } + public int getNumUnits() { return numUnits; } + public String getInstructionsFile() { return INSTRUCTIONS_FILE; } + public int getSubjectID() { return subjectID; } + public void setSubjectID(int id) { + subjectID = id; + results.setSubjectID(id); + results.setOutputFile(id); + getCurrentBlock().getMelodyResults().setSubjectID(id); + } + + /* Constructor */ + public Experiment (int cu, int nu, int sl, String la, String ha) { + + // Setup variables + results = new SubjectResults(this); + clockUnits = cu; + numUnits = nu; + scaleLength = sl; + lowAnchor = la; + highAnchor = ha; + + // Initialise the experiment + Block practice = new Block(this, gui, PRACTICE_MIDIFILELIST_FILE, + "Practice", false); + Block main = new Block(this, gui, MIDIFILELIST_FILE, + "Main", true); + blocks = new Block[2]; + blocks[0] = practice; + blocks[1] = main; + currentBlockID = 0; + + // Create the GUI + gui = new ExperimentGui(this); + } + + public Boolean nextBlock() { + boolean lastBlock = true; + if (currentBlockID + 1 < blocks.length) + currentBlockID = currentBlockID + 1; + else + lastBlock = false; + return lastBlock; + } + + public void addToSubjectResults(MelodyResults mr) { results.addResult(mr); } + + public void runExperiment () { + (new Thread(gui)).start(); + getCurrentBlock().presentStimulus(); + } + public boolean isRunning() { return getCurrentBlock().isRunning(); } + public boolean hasRun() { return getCurrentBlock().hasRun(); } + + /* Show the GUI */ + public void showGUI(int width, int height) { + gui.pack(); + gui.setSize(width, height); + // UIManager.put("Button.focus", UIManager.get("Button.select")); + gui.setVisible(true); + } + + /* Main method */ + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Usage: " + "\t" + "java Experiment " + + "<clock units> <number of units> <scale length>" + + "<low anchor> <high anchor>"); + System.exit(1); + } + + // Parse Arguments + int n = 0; + int cu = Integer.parseInt(args[n++]); + int nu = Integer.parseInt(args[n++]); + int sl = Integer.parseInt(args[n++]); + String la = args[n++]; + String ha = args[n++]; + + // Create experiment + Experiment exp = new Experiment(cu, nu, sl, la, ha); + + // Show the GUI + int width=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); + int height=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); + exp.showGUI(width, height); + } +}