annotate Experiment.java @ 9:46c6d604e32c

Add extra command line options to help message. Ignore-this: 45274c510028342470749e79d106cef
author Marcus Pearce <m.pearce@gold.ac.uk>
date Fri, 04 Nov 2011 16:53:17 +0000
parents 235484b93707
children 3dd7636ca811
rev   line source
m@0 1 /*=============================================================================
m@0 2 * File: Experiment.java
m@0 3 * Author: Marcus Pearce <m.pearce@gold.ac.uk>
m@0 4 * Created: <2007-02-14 11:28:27 marcusp>
m@9 5 * Time-stamp: <2011-11-04 16:52:49 marcusp>
m@0 6 *=============================================================================
m@0 7 */
m@0 8
m@0 9 import java.io.*;
m@0 10 import javax.swing.UIManager;
m@0 11 import java.awt.*;
m@0 12 import java.awt.Color;
m@0 13
m@0 14 public class Experiment {
m@0 15
m@0 16 /* pathnames */
m@0 17 private final String BASE_DIRECTORY =
m@0 18 new File("").getAbsolutePath() + File.separator;
m@4 19
m@0 20 public final String RESULTS_DIRECTORY =
m@0 21 BASE_DIRECTORY + "Results" + File.separator;
m@0 22 public final String RESULTS_EXTENSION = ".dat";
m@0 23 public final String SUBJECT_RESULTS_FILE =
m@0 24 RESULTS_DIRECTORY + "subjects" + RESULTS_EXTENSION;
m@0 25
m@4 26 private final String DATA_DIRECTORY =
m@4 27 BASE_DIRECTORY + "Data" + File.separator;
m@7 28 public String INSTRUCTIONS_FILE =
m@0 29 DATA_DIRECTORY + "instructions.html";
m@4 30
m@4 31 public String MIDI_DIRECTORY =
m@4 32 DATA_DIRECTORY + "Midi" + File.separator;
m@4 33 public String MIDIFILELIST_FILE =
m@4 34 MIDI_DIRECTORY + "filelist.txt";
m@4 35 public String PRACTICE_MIDIFILELIST_FILE =
m@4 36 MIDI_DIRECTORY + "pfilelist.txt";
m@4 37
m@0 38
m@0 39 /* The GUI */
m@0 40 private ExperimentGui gui;
m@0 41
m@3 42 /* whether to show the clock */
m@3 43 private boolean showClock;
m@0 44 /* the units of the clock as multiples of the tatum */
m@0 45 private int clockUnits;
m@0 46 /* number of units that clock runs for before a probe event */
m@0 47 private int numUnits;
m@0 48
m@8 49 /* whether to ask about familiarity of each song */
m@8 50 private boolean askFamiliarity;
m@8 51 /* whether to ask about liking of each song */
m@8 52 private boolean askLiking;
m@8 53 /* whether to include final questionnaire */
m@8 54 private boolean finalQuestionnaire;
m@8 55
m@0 56 /* the blocks of the experiment */
m@0 57 Block[] blocks;
m@0 58 int currentBlockID;
m@0 59
m@0 60 /* Subject ID */
m@0 61 private int subjectID;
m@0 62
m@0 63 /* Results */
m@0 64 private SubjectResults results;
m@0 65
m@0 66 /* the details of the rating scale */
m@0 67 private int scaleLength;
m@0 68 private String lowAnchor;
m@0 69 private String highAnchor;
m@0 70
m@1 71 /* the midi device */
m@1 72 private int midiDevice;
m@1 73
m@0 74 /* accessors */
m@8 75 public boolean getAskLiking() { return askLiking; }
m@8 76 public boolean getAskFamiliarity() { return askFamiliarity; }
m@8 77 public boolean getFinalQuestionnaire() { return finalQuestionnaire; }
m@8 78
m@1 79 public int getMidiDeviceNumber() { return midiDevice; }
m@0 80 public int getScaleLength() { return scaleLength; }
m@0 81 public String getLowAnchor() { return lowAnchor; }
m@0 82 public String getHighAnchor() { return highAnchor; }
m@0 83
m@0 84 public String getMidiDirectory() { return MIDI_DIRECTORY; }
m@0 85 public SubjectResults getSubjectResults() { return results; }
m@0 86 public Block getCurrentBlock() { return blocks[currentBlockID]; }
m@0 87 public int getCurrentBlockID() { return currentBlockID + 1; }
m@3 88 public boolean showClock() { return showClock; }
m@0 89 public int getClockUnits() { return clockUnits; }
m@0 90 public int getNumUnits() { return numUnits; }
m@0 91 public String getInstructionsFile() { return INSTRUCTIONS_FILE; }
m@0 92 public int getSubjectID() { return subjectID; }
m@0 93 public void setSubjectID(int id) {
m@0 94 subjectID = id;
m@0 95 results.setSubjectID(id);
m@0 96 results.setOutputFile(id);
m@0 97 getCurrentBlock().getMelodyResults().setSubjectID(id);
m@0 98 }
m@0 99
m@0 100 /* Constructor */
m@8 101 public Experiment (int sc, int cu, int nu, int sl, int md, String la, String ha, String mfd, String inf, int fam, int lik, int quest) {
m@0 102
m@0 103 // Setup variables
m@0 104 results = new SubjectResults(this);
m@3 105 if (sc == 0)
m@3 106 showClock = false;
m@3 107 else
m@3 108 showClock = true;
m@0 109 clockUnits = cu;
m@0 110 numUnits = nu;
m@0 111 scaleLength = sl;
m@1 112 midiDevice = md;
m@0 113 lowAnchor = la;
m@0 114 highAnchor = ha;
m@4 115 MIDI_DIRECTORY = mfd + File.separator;
m@4 116 MIDIFILELIST_FILE = MIDI_DIRECTORY + "filelist.txt";
m@4 117 PRACTICE_MIDIFILELIST_FILE = MIDI_DIRECTORY + "pfilelist.txt";
m@7 118 INSTRUCTIONS_FILE = inf;
m@8 119
m@8 120 if (fam == 0)
m@8 121 askFamiliarity = false;
m@8 122 else
m@8 123 askFamiliarity = true;
m@8 124 if (lik == 0)
m@8 125 askLiking = false;
m@8 126 else
m@8 127 askLiking = true;
m@8 128 if (quest == 0)
m@8 129 finalQuestionnaire = false;
m@8 130 else
m@8 131 finalQuestionnaire = true;
m@8 132
m@8 133
m@8 134
m@0 135
m@0 136 // Initialise the experiment
m@0 137 Block practice = new Block(this, gui, PRACTICE_MIDIFILELIST_FILE,
m@0 138 "Practice", false);
m@0 139 Block main = new Block(this, gui, MIDIFILELIST_FILE,
m@0 140 "Main", true);
m@0 141 blocks = new Block[2];
m@0 142 blocks[0] = practice;
m@0 143 blocks[1] = main;
m@0 144 currentBlockID = 0;
m@0 145
m@0 146 // Create the GUI
m@0 147 gui = new ExperimentGui(this);
m@0 148 }
m@0 149
m@0 150 public Boolean nextBlock() {
m@0 151 boolean lastBlock = true;
m@0 152 if (currentBlockID + 1 < blocks.length)
m@0 153 currentBlockID = currentBlockID + 1;
m@0 154 else
m@0 155 lastBlock = false;
m@0 156 return lastBlock;
m@0 157 }
m@0 158
m@0 159 public void addToSubjectResults(MelodyResults mr) { results.addResult(mr); }
m@0 160
m@0 161 public void runExperiment () {
m@0 162 (new Thread(gui)).start();
m@0 163 getCurrentBlock().presentStimulus();
m@0 164 }
m@0 165 public boolean isRunning() { return getCurrentBlock().isRunning(); }
m@0 166 public boolean hasRun() { return getCurrentBlock().hasRun(); }
m@0 167
m@0 168 /* Show the GUI */
m@0 169 public void showGUI(int width, int height) {
m@0 170 gui.pack();
m@0 171 gui.setSize(width, height);
m@0 172 // UIManager.put("Button.focus", UIManager.get("Button.select"));
m@0 173 gui.setVisible(true);
m@0 174 }
m@0 175
m@0 176 /* Main method */
m@0 177 public static void main(String[] args) {
m@0 178 if (args.length == 0) {
m@0 179 System.out.println("Usage: " + "\t" + "java Experiment " +
m@3 180 "<show clock?> <clock units> <number of units> " +
m@3 181 "<midi device> " +
m@9 182 "<scale length> <low anchor> <high anchor> " +
m@9 183 "<midi file directory> <instructions file> " +
m@9 184 "<familiarity>" + "<pleasantness>" + "<questionnaire>");
m@0 185 System.exit(1);
m@0 186 }
m@0 187
m@0 188 // Parse Arguments
m@3 189 int n = 0;
m@3 190 int sc = Integer.parseInt(args[n++]);
m@0 191 int cu = Integer.parseInt(args[n++]);
m@0 192 int nu = Integer.parseInt(args[n++]);
m@1 193 int md = Integer.parseInt(args[n++]);
m@0 194 int sl = Integer.parseInt(args[n++]);
m@0 195 String la = args[n++];
m@0 196 String ha = args[n++];
m@4 197 String mfd = args[n++];
m@7 198 String inf = args[n++];
m@8 199 int fam = Integer.parseInt(args[n++]);
m@8 200 int lik = Integer.parseInt(args[n++]);
m@8 201 int quest = Integer.parseInt(args[n++]);
m@0 202
m@0 203 // Create experiment
m@8 204 Experiment exp = new Experiment(sc, cu, nu, sl, md, la, ha, mfd, inf, fam, lik, quest);
m@0 205
m@0 206 // Show the GUI
m@0 207 int width=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
m@0 208 int height=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
m@0 209 exp.showGUI(width, height);
m@0 210 }
m@0 211 }