Mercurial > hg > mep
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4031cbb02f08 |
---|---|
1 /*============================================================================= | |
2 * File: Experiment.java | |
3 * Author: Marcus Pearce <m.pearce@gold.ac.uk> | |
4 * Created: <2007-02-14 11:28:27 marcusp> | |
5 * Time-stamp: <2010-05-18 11:13:42 marcusp> | |
6 *============================================================================= | |
7 */ | |
8 | |
9 import java.io.*; | |
10 import javax.swing.UIManager; | |
11 import java.awt.*; | |
12 import java.awt.Color; | |
13 | |
14 public class Experiment { | |
15 | |
16 /* pathnames */ | |
17 private final String BASE_DIRECTORY = | |
18 new File("").getAbsolutePath() + File.separator; | |
19 private final String DATA_DIRECTORY = | |
20 BASE_DIRECTORY + "Data" + File.separator; | |
21 public final String RESULTS_DIRECTORY = | |
22 BASE_DIRECTORY + "Results" + File.separator; | |
23 | |
24 private final String MIDI_DIRECTORY = | |
25 DATA_DIRECTORY + "Midi" + File.separator; | |
26 | |
27 public final String RESULTS_EXTENSION = ".dat"; | |
28 public final String SUBJECT_RESULTS_FILE = | |
29 RESULTS_DIRECTORY + "subjects" + RESULTS_EXTENSION; | |
30 | |
31 public final String INSTRUCTIONS_FILE = | |
32 DATA_DIRECTORY + "instructions.html"; | |
33 public final String MIDIFILELIST_FILE = | |
34 DATA_DIRECTORY + "filelist.txt"; | |
35 public final String PRACTICE_MIDIFILELIST_FILE = | |
36 DATA_DIRECTORY + "pfilelist.txt"; | |
37 | |
38 /* The GUI */ | |
39 private ExperimentGui gui; | |
40 | |
41 /* the units of the clock as multiples of the tatum */ | |
42 private int clockUnits; | |
43 /* number of units that clock runs for before a probe event */ | |
44 private int numUnits; | |
45 | |
46 /* the blocks of the experiment */ | |
47 Block[] blocks; | |
48 int currentBlockID; | |
49 | |
50 /* Subject ID */ | |
51 private int subjectID; | |
52 | |
53 /* Results */ | |
54 private SubjectResults results; | |
55 | |
56 /* the details of the rating scale */ | |
57 private int scaleLength; | |
58 private String lowAnchor; | |
59 private String highAnchor; | |
60 | |
61 /* accessors */ | |
62 public int getScaleLength() { return scaleLength; } | |
63 public String getLowAnchor() { return lowAnchor; } | |
64 public String getHighAnchor() { return highAnchor; } | |
65 | |
66 public String getMidiDirectory() { return MIDI_DIRECTORY; } | |
67 public SubjectResults getSubjectResults() { return results; } | |
68 public Block getCurrentBlock() { return blocks[currentBlockID]; } | |
69 public int getCurrentBlockID() { return currentBlockID + 1; } | |
70 public int getClockUnits() { return clockUnits; } | |
71 public int getNumUnits() { return numUnits; } | |
72 public String getInstructionsFile() { return INSTRUCTIONS_FILE; } | |
73 public int getSubjectID() { return subjectID; } | |
74 public void setSubjectID(int id) { | |
75 subjectID = id; | |
76 results.setSubjectID(id); | |
77 results.setOutputFile(id); | |
78 getCurrentBlock().getMelodyResults().setSubjectID(id); | |
79 } | |
80 | |
81 /* Constructor */ | |
82 public Experiment (int cu, int nu, int sl, String la, String ha) { | |
83 | |
84 // Setup variables | |
85 results = new SubjectResults(this); | |
86 clockUnits = cu; | |
87 numUnits = nu; | |
88 scaleLength = sl; | |
89 lowAnchor = la; | |
90 highAnchor = ha; | |
91 | |
92 // Initialise the experiment | |
93 Block practice = new Block(this, gui, PRACTICE_MIDIFILELIST_FILE, | |
94 "Practice", false); | |
95 Block main = new Block(this, gui, MIDIFILELIST_FILE, | |
96 "Main", true); | |
97 blocks = new Block[2]; | |
98 blocks[0] = practice; | |
99 blocks[1] = main; | |
100 currentBlockID = 0; | |
101 | |
102 // Create the GUI | |
103 gui = new ExperimentGui(this); | |
104 } | |
105 | |
106 public Boolean nextBlock() { | |
107 boolean lastBlock = true; | |
108 if (currentBlockID + 1 < blocks.length) | |
109 currentBlockID = currentBlockID + 1; | |
110 else | |
111 lastBlock = false; | |
112 return lastBlock; | |
113 } | |
114 | |
115 public void addToSubjectResults(MelodyResults mr) { results.addResult(mr); } | |
116 | |
117 public void runExperiment () { | |
118 (new Thread(gui)).start(); | |
119 getCurrentBlock().presentStimulus(); | |
120 } | |
121 public boolean isRunning() { return getCurrentBlock().isRunning(); } | |
122 public boolean hasRun() { return getCurrentBlock().hasRun(); } | |
123 | |
124 /* Show the GUI */ | |
125 public void showGUI(int width, int height) { | |
126 gui.pack(); | |
127 gui.setSize(width, height); | |
128 // UIManager.put("Button.focus", UIManager.get("Button.select")); | |
129 gui.setVisible(true); | |
130 } | |
131 | |
132 /* Main method */ | |
133 public static void main(String[] args) { | |
134 if (args.length == 0) { | |
135 System.out.println("Usage: " + "\t" + "java Experiment " + | |
136 "<clock units> <number of units> <scale length>" + | |
137 "<low anchor> <high anchor>"); | |
138 System.exit(1); | |
139 } | |
140 | |
141 // Parse Arguments | |
142 int n = 0; | |
143 int cu = Integer.parseInt(args[n++]); | |
144 int nu = Integer.parseInt(args[n++]); | |
145 int sl = Integer.parseInt(args[n++]); | |
146 String la = args[n++]; | |
147 String ha = args[n++]; | |
148 | |
149 // Create experiment | |
150 Experiment exp = new Experiment(cu, nu, sl, la, ha); | |
151 | |
152 // Show the GUI | |
153 int width=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); | |
154 int height=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); | |
155 exp.showGUI(width, height); | |
156 } | |
157 } |