# HG changeset patch # User CBussey # Date 1370018459 -3600 # Node ID 796b3e3e053fae15a1dcc4eacf5c75f987cfda15 # Parent a36ca20cffd4571456a5db57b0e41e0ab5afeb59 Changed MidiPlayer.java to allow the use of external sequencer programs (e.g. Garageband). Changed Experiment.java to allow user to specify in commandline whether to use default MidiDevice (true), specified MidiDevice (0 " + - " " + - " " + - " " + - "" + "" + "" + ""); - System.exit(1); + showUsage(); } } + + public static void showUsage(){ + System.out.println("Usage: " + "\t" + "java Experiment " + + " " + + " " + + " " + + " " + + "" + "" + "" + ""); + System.exit(1); + } /* * Print a list of accessible MIDI devices */ - protected void displayMIDIDevices() { + public static 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); + for (int i=0; idevices.length-1 || device<0){ + output = false; + } + else { output = true; } + } catch(NumberFormatException e) { + output = false; + } + return output; + } private int positiveInteger(int x, int def) { if (x > 0) diff -r a36ca20cffd4 -r 796b3e3e053f ExperimentGui.java --- a/ExperimentGui.java Fri Nov 16 10:39:57 2012 +0000 +++ b/ExperimentGui.java Fri May 31 17:40:59 2013 +0100 @@ -65,7 +65,7 @@ instructionsPanel = new InstructionsPanel(this); stimulusPanel = new StimulusPanel(this, clock); interBlockPanel = new InterBlockPanel(exp); - subjectDataPanel = new SubjectDataPanel(this, exp.getSubjectResults()); + subjectDataPanel = new SubjectDataPanel(this, exp.getSubjectResults(), !exp.getAskFamiliarity()); stimulusPanel.setResponseEnabled(false); diff -r a36ca20cffd4 -r 796b3e3e053f MidiPlayer.java --- a/MidiPlayer.java Fri Nov 16 10:39:57 2012 +0000 +++ b/MidiPlayer.java Fri May 31 17:40:59 2013 +0100 @@ -45,20 +45,32 @@ private Synthesizer synthesizer = null; private Sequence sequence = null; private ArrayList onsets, offsets = null; - private ArrayList pitches, velocities = null; - private int midiDevice = 0; /* 4 for usb midi device */ + private ArrayList pitches, velocities = null; + private File midiFile; + private boolean defaultMD = false; + private int midiDevice; private boolean debug; /* accessors */ - public Sequencer getSequencer() { return sequencer; } + public Sequencer getSequencer() { return sequencer; } + public boolean usingDefault() { return defaultMD; } - /* Constructors */ - public MidiPlayer(String path, int deviceNumber, boolean d) { - File midiFile = new File(path); - midiDevice = deviceNumber; - debug = d; - - // Get sequence + /* Constructors */ + public MidiPlayer(String path, int deviceNumber, boolean d) { + if(deviceNumber == -1) { + defaultMD = true; + midiDevice = 0; + } + else{ + midiDevice = deviceNumber; + } + midiFile = new File(path); + debug = d; + setup(); + } + + private void setup(){ + // Get sequence try { sequence = MidiSystem.getSequence(midiFile); } catch (InvalidMidiDataException e) { e.printStackTrace(); @@ -68,12 +80,6 @@ e.printStackTrace(); System.exit(1); } - // Get sequencer - try { sequencer = MidiSystem.getSequencer(); } - catch (MidiUnavailableException e) { - e.printStackTrace(); - System.exit(1); - } //sequencer.setTempoInBPM(bpm); // Workaround bug in JDK // sequencer.addMetaEventListener(new MetaEventListener() { @@ -86,36 +92,43 @@ // } // } // }); - // Open sequencer - try { sequencer.open(); } - catch (MidiUnavailableException e) { - e.printStackTrace(); - System.exit(1); - } - // Assign sequence to sequencer - try { sequencer.setSequence(sequence); } - catch (InvalidMidiDataException e) { - e.printStackTrace(); - System.exit(1); - } - // Set up MIDI output for sequence + // Set up MIDI output for sequence try { MidiDevice.Info msinfo[] = MidiSystem.getMidiDeviceInfo(); for(int i = 0; i < msinfo.length; i++) { - MidiDevice.Info m = msinfo[i]; -// System.out.println("Name: " + m.getName() + -// "; Vendor: " + m.getVendor() + -// "; Version: " + m.getVersion()); + System.out.println("Carl: "+i); + MidiDevice.Info m = msinfo[i]; + System.out.println("Name: " + m.getName() + + "; Vendor: " + m.getVendor() + + "; Version: " + m.getVersion()); } + MidiDevice synth = MidiSystem.getMidiDevice(msinfo[midiDevice]); + synth.open(); + // Get sequencer + try { sequencer = MidiSystem.getSequencer(defaultMD); } + catch (MidiUnavailableException e) { + e.printStackTrace(); + System.exit(1); + } // synthesizer = MidiSystem.getSynthesizer(); - MidiDevice synth = MidiSystem.getMidiDevice(msinfo[midiDevice]); + + try { sequencer.open(); }//// + catch (MidiUnavailableException e) { + e.printStackTrace(); + System.exit(1); + } + // Assign sequence to sequencer + try { sequencer.setSequence(sequence); } + catch (InvalidMidiDataException e) { + e.printStackTrace(); + System.exit(1); + }//// // Change the patch // MidiChannel channels[] = synthesizer.getChannels(); // for (int i = 0; i < channels.length; i++) // channels[i].programChange(65); - - synth.open(); + Receiver synthReceiver = synth.getReceiver(); Transmitter seqTransmitter = sequencer.getTransmitter(); seqTransmitter.setReceiver(synthReceiver); diff -r a36ca20cffd4 -r 796b3e3e053f SubjectDataPanel.java --- a/SubjectDataPanel.java Fri Nov 16 10:39:57 2012 +0000 +++ b/SubjectDataPanel.java Fri May 31 17:40:59 2013 +0100 @@ -16,18 +16,25 @@ /* variables */ private JTextField ageField, listeningField, nationalityField; private JComboBox sexBox, handBox, hearingBox, ethnicityBox, - goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9; + goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9, goldMSI3_10; private JButton finishButton; - private SubjectResults results; + private SubjectResults results; + + private boolean askFamiliarity = false; /* accessors */ public JButton getFinishButton() { return finishButton; } - /* constructor */ - public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) { - + /* constructors */ + public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) { + this(gui, sr, false); + } + + public SubjectDataPanel(ExperimentGui gui, SubjectResults sr, boolean askFamiliarity) { + + this.askFamiliarity = askFamiliarity; results = sr; JPanel questionsPanel = new JPanel(); @@ -177,6 +184,16 @@ c.anchor = GridBagConstraints.WEST; questionsPanel.add(goldMSI3_9, c); + if(askFamiliarity){ + c.gridy = 16; + String[] goldMSI3_10o = {"", "25%", "50%", "75%", "100%"}; + goldMSI3_10 = new JComboBox(goldMSI3_10o); + c.anchor = GridBagConstraints.EAST; + questionsPanel.add(new JLabel("I was familiar with approximately ------- of the study songs."), c); + c.anchor = GridBagConstraints.WEST; + questionsPanel.add(goldMSI3_10, c); + } + // Put it all together JPanel finishPanel = new JPanel(); finishButton = new JButton("Finish"); @@ -237,13 +254,17 @@ String[] goldMSI3_8a = {"GoldMSI3.8", (String)goldMSI3_8.getSelectedItem()}; subjectData.add(goldMSI3_8a); String[] goldMSI3_9a = {"GoldMSI3.9", (String)goldMSI3_9.getSelectedItem()}; - subjectData.add(goldMSI3_9a); + if(askFamiliarity){ + subjectData.add(goldMSI3_9a); + String[] goldMSI3_10a = {"GoldMSI3.10", (String)goldMSI3_10.getSelectedItem()}; + subjectData.add(goldMSI3_10a); + } - results.setSubjectData(subjectData); + results.setSubjectData(subjectData); } public boolean allDataEntered () { - if (ageField.getText().equals("") || + if (ageField.getText().equals("") || sexBox.getSelectedItem().equals("") || handBox.getSelectedItem().equals("") || ethnicityBox.getSelectedItem().equals("") || @@ -258,10 +279,11 @@ goldMSI3_6.getSelectedItem().equals("") || goldMSI3_7.getSelectedItem().equals("") || goldMSI3_8.getSelectedItem().equals("") || - goldMSI3_9.getSelectedItem().equals("") + goldMSI3_9.getSelectedItem().equals("") ) - return false; - else return true; + return false; + else if (askFamiliarity && goldMSI3_10.getSelectedItem().equals("")) return false; + else return true; } public void addFinishButtonListener(ActionListener al) {