Mercurial > hg > mep
changeset 23:9fc8683b8fed
Fixed GUI button presses, had their background change as feedback and added ability to record responses for a probe tone at the end of a sequence
author | JShulver |
---|---|
date | Wed, 07 Nov 2012 18:22:01 +0000 |
parents | 5c54f5213f3d |
children | 7102e646b223 |
files | Block$1.class Block.class Block.java Clock.class Clock.java ExperimentController.class ExperimentController.java ExperimentGui$1.class ExperimentGui.class ExperimentGui.java MidiPlayer.class MidiPlayer.java StimulusPanel.class StimulusPanel.java |
diffstat | 14 files changed, 76 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/Block.java Wed Oct 31 15:16:26 2012 +0000 +++ b/Block.java Wed Nov 07 18:22:01 2012 +0000 @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.ArrayList; import java.util.Iterator; +import java.util.HashMap; import java.io.*; public class Block { @@ -30,7 +31,10 @@ private MidiPlayer mp; /* Probe positions, note onsets, durations, IOIs and pitches */ - private ArrayList probes, onsets, iois, durations, pitches, clockStartTimes; + //private ArrayList probes, onsets, iois, durations, pitches, clockStartTimes; + private ArrayList<Integer> iois, pitches; + private ArrayList<Long> onsets, durations, clockStartTimes; + private ArrayList<ProbeID> probes; private long tatum; /* The start of the song in nanoseconds */ @@ -51,9 +55,9 @@ public long getTatum() { return tatum; } public MelodyResults getMelodyResults() { return mResults; } public ArrayList getProbePositions() { return probes; } - public ArrayList getInterOnsetIntervals() { return iois; } - public ArrayList getOnsets() { return onsets; } - public ArrayList getClockStartTimes() { return clockStartTimes; } + public ArrayList<Integer> getInterOnsetIntervals() { return iois; } + public ArrayList<Long> getOnsets() { return onsets; } + public ArrayList<Long> getClockStartTimes() { return clockStartTimes; } public MidiPlayer getMidiPlayer() { return mp; } /* set the start time in nanoseconds to NOW */ @@ -124,7 +128,6 @@ //probeValues.add(ProbeID.PROBE_EX); ArrayList probeValues = new ArrayList(probePos.size()); - for (int i = 0; i < probePos.size(); i++) probeValues.add(ProbeID.PROBE); Iterator pvi = probeValues.iterator(); @@ -139,6 +142,7 @@ if (exp.getDebug()) System.out.println("Probe at " + probe + " out of " + onsets.size()); // probes.set(probe - numEvents, ProbeID.START_CLOCK); + probes.set(probe - 1, ProbeID.BEFORE_PROBE); probes.set(probe, (ProbeID)pvi.next()); if (probe < (onsets.size() - 1)) @@ -162,6 +166,7 @@ e.printStackTrace(); } } + public void printProbes() { Iterator pi = probes.iterator(); @@ -295,7 +300,15 @@ int eventIndex = 1; //writeHeader(w); - + //might be sensible to create the hashmap somewhere else + HashMap<ProbeID, Integer> idMap = new HashMap<ProbeID, Integer>(); + idMap.put(ProbeID.NOT_PROBE, 0); + idMap.put(ProbeID.START_CLOCK, 0); + idMap.put(ProbeID.BEFORE_PROBE, 0); + idMap.put(ProbeID.AFTER_PROBE, 0); + idMap.put(ProbeID.PROBE, 1); + idMap.put(ProbeID.PROBE_EX, 2); + idMap.put(ProbeID.PROBE_UNEX, 1); while(oi.hasNext()) { long onset = ((Long)oi.next()).longValue(); int pitch = ((Integer)piti.next()).intValue(); @@ -304,26 +317,16 @@ int probe = 0; - switch(p) { - case NOT_PROBE: - case START_CLOCK: - case BEFORE_PROBE: - case AFTER_PROBE: - break; - case PROBE: - case PROBE_EX: - case PROBE_UNEX: - if (p == ProbeID.PROBE_UNEX) - probe = 1; - else if (p == ProbeID.PROBE_EX) - probe = 2; - else if (p == ProbeID.PROBE) - probe = 1; - break; - default: - System.out.println("Unexpected probe id: " + p); - break; + if(idMap.containsKey(p)) + { + probe = idMap.get(p); + System.out.println("Adding probe: "); } + + else + System.out.println("Unexpected probe id: " + p); + + w.write(composition + " " + eventIndex + " " + onset + " " + pitch + " " + probe + "\n");
--- a/Clock.java Wed Oct 31 15:16:26 2012 +0000 +++ b/Clock.java Wed Nov 07 18:22:01 2012 +0000 @@ -47,7 +47,9 @@ } showClock = false; showFullClock = false; + System.out.println("RUN CLOCK"); reset(); + revalidate(); repaint(); } @@ -58,18 +60,21 @@ /* Reset the clock to 00:00. */ public void reset() { + System.out.println("RESET!"); minutes = 0; } /* Draw the clock or fixation point. */ public void paintComponent (Graphics g) { - super.paintComponent (g); + super.paintComponent (g); if (showClock == true) { paintClock(g); } else { - paintFixationPoint(g); + paintFixationPoint(g); } + //just ensure that java knows we want to draw new things + revalidate(); } private void paintFixationPoint(Graphics g) { @@ -94,7 +99,7 @@ int left_edge = BORDER; int top = BORDER; int diameter = WIDTH - (BORDER * 2); - int radius = diameter / 2; + int radius = diameter / 2; int centrex = left_edge + radius; int centrey = top + radius; @@ -104,7 +109,7 @@ g.drawOval(left_edge, top, diameter, diameter); // draw the hour numbers - int offset = 0; + int offset = 0; for(int i = 1; i <= 12; i++) { int hours_pos = 90 - (i * 30); int x = (centrex - offset) + @@ -128,8 +133,8 @@ Graphics2D g2 = (Graphics2D)g; g2.setPaint(FOREGROUND); - //System.out.println("minutes_angle = " + minutes_angle + - // "; arc_angle = " + arc_angle); + System.out.println("minutes_angle = " + minutes_angle + + "; arc_angle = " + arc_angle); if (arc_angle == 0 & showFullClock == true) { g2.fillOval(left_edge, top, diameter, diameter);
--- a/ExperimentController.java Wed Oct 31 15:16:26 2012 +0000 +++ b/ExperimentController.java Wed Nov 07 18:22:01 2012 +0000 @@ -117,18 +117,17 @@ block.addMelodyQA("known", answer1); } else block.addMelodyQA("known", "-1"); - if (exp.getAskLiking()) { String answer2 = (String)(sp.getQ2Box().getSelectedItem()); block.addMelodyQA("liked", answer2); } else block.addMelodyQA("liked", "-1"); - block.storeMelodyResult(); results.writeResults(); // close the midi player block.getMidiPlayer().stop(); // proceed to ... + String nextFile = block.nextFile(); if (nextFile == null) { boolean nb = exp.nextBlock(); @@ -137,6 +136,7 @@ gui.getInterBlockPanel().setText(); gui.getInterBlockPanel().updateMessageDisplay(); gui.showCard("interblock"); + sp.resetButtonBackgrounds(); } else { // ... write results and subject questionnaire results.writeResults(); @@ -144,19 +144,23 @@ } } else { // ... next melody within block + sp.resetButtonBackgrounds(); sp.setSongNumberText(); sp.defaultAnswers(); gui.setAcceptingResponses(false); block.initialiseBlock(); exp.runExperiment(); + } } } else { JButton[] rButtons = sp.getResponseButtons(); for (int i = 0; i < rButtons.length; i++) { + System.out.println("getAcceptingResponses: " + gui.getAcceptingResponses()); if (source == rButtons[i] && (exp.isRunning() || exp.hasRun()) && gui.getAcceptingResponses()) { - block.addResponse(i+1, time); + block.addResponse(i+1, time); gui.setAcceptingResponses(false); + rButtons[i].setBackground(Color.red); } } }
--- a/ExperimentGui.java Wed Oct 31 15:16:26 2012 +0000 +++ b/ExperimentGui.java Wed Nov 07 18:22:01 2012 +0000 @@ -33,7 +33,7 @@ public Boolean getAcceptingResponses() { return acceptingResponses; } public void setAcceptingResponses(Boolean b) { if (exp.getDebug()) - System.out.println("Changing acceptingResponses from " + acceptingResponses + " to " + b); + System.out.println("\n\nChanging acceptingResponses from " + acceptingResponses + " to " + b); acceptingResponses = b; } public Experiment getExperiment() { return exp; } @@ -109,7 +109,7 @@ /* Show the Fixation Point */ public void showFixationPoint() { - //System.out.println("showFixationPoint"); + System.out.println("showFixationPoint"); clock.showClock = false; clock.showFullClock = false; clock.repaint(); @@ -130,9 +130,10 @@ showFixationPoint(); } + /* Run method for this thread */ public void run() { - + System.out.println("Run!"); //showFixationPoint(); clock.reset(); showClock(); @@ -160,7 +161,10 @@ int clockUnit = 0; boolean clockTicking = false; - while(oi.hasNext()) { + do { //using a do-while construct allows the user to enter a value at the end + //this should not really be in the 'view' anyway... + System.out.println("TATUM: " +tatum); + tatumInMilliseconds = tatum/1000; if (exp.getDebug()) System.out.println("Ticking = " + clockTicking + "; clockUnit = " + clockUnit + @@ -171,16 +175,18 @@ if (clockTicking == true && clockUnit == 0) tick(nMinutes); - if (currentOnset == nextClockStartTime) { + if (currentOnset >= nextClockStartTime) { //new Thread(clock).start(); clock.reset(); showClock(); clockTicking = true; if (ci.hasNext()) nextClockStartTime = ((Long)(ci.next())).longValue(); + else + nextClockStartTime = Long.MAX_VALUE; } - - if (currentOnset == nextEventOnset) { + if (currentOnset >= nextEventOnset) { + probe = (ProbeID)pi.next(); // Manipulate display depending on probe identifier switch (probe) { case NOT_PROBE: @@ -222,17 +228,17 @@ break; } // Update probe identifier and onset - probe = (ProbeID)pi.next(); + if (exp.getDebug()) System.out.println("Next probe = " + probe); nextEventOnset =((Long)(oi.next())).longValue(); - } + } // sleep for a tatum try { Thread.sleep(tatumInMilliseconds); } catch (InterruptedException e) {} currentOnset += tatum; clockUnit = (clockUnit + 1) % clockUnits; - } + } while(oi.hasNext()); showFixationPoint(); } }
--- a/MidiPlayer.java Wed Oct 31 15:16:26 2012 +0000 +++ b/MidiPlayer.java Wed Nov 07 18:22:01 2012 +0000 @@ -279,7 +279,9 @@ } /* return the tatum of the midi file */ - public long getTatum() { + public long getTatum() { + + Object[] durs = getDurations().toArray(); Object[] rests = getDeltaST().toArray(); long tatum = -1; @@ -290,12 +292,13 @@ long min = dur; if (rest != 0) min = Math.min(dur, rest); - + System.out.println("Min: " + min); if (tatum < 0) tatum = dur; else if (min < tatum) tatum = min; } + //tatum = sequence.getResolution()*1000; return tatum; }
--- a/StimulusPanel.java Wed Oct 31 15:16:26 2012 +0000 +++ b/StimulusPanel.java Wed Nov 07 18:22:01 2012 +0000 @@ -127,6 +127,15 @@ this.add(southPanel, BorderLayout.SOUTH); } + + //resets the background colour of the buttons + public void resetButtonBackgrounds() { + for(JButton button : responseButton) { + button.setBackground(UIManager.getColor( "Button.background" )); + } + } + + public void setSongNumberText() { String m = "Block " +