Mercurial > hg > mep
comparison MidiPlayer.java @ 39:796b3e3e053f
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<variable<MidiDevs.length), or list the available devices on start up.
Changed ExperimentGui.java and SubjectDataPanel.java to add familiarity question if familiarity question isn't included at the presentation of each stimuli.
author | CBussey |
---|---|
date | Fri, 31 May 2013 17:40:59 +0100 |
parents | 7102e646b223 |
children | 75354c638975 |
comparison
equal
deleted
inserted
replaced
38:a36ca20cffd4 | 39:796b3e3e053f |
---|---|
43 /* variables */ | 43 /* variables */ |
44 private Sequencer sequencer = null; | 44 private Sequencer sequencer = null; |
45 private Synthesizer synthesizer = null; | 45 private Synthesizer synthesizer = null; |
46 private Sequence sequence = null; | 46 private Sequence sequence = null; |
47 private ArrayList<Long> onsets, offsets = null; | 47 private ArrayList<Long> onsets, offsets = null; |
48 private ArrayList<Integer> pitches, velocities = null; | 48 private ArrayList<Integer> pitches, velocities = null; |
49 private int midiDevice = 0; /* 4 for usb midi device */ | 49 private File midiFile; |
50 private boolean defaultMD = false; | |
51 private int midiDevice; | |
50 private boolean debug; | 52 private boolean debug; |
51 | 53 |
52 /* accessors */ | 54 /* accessors */ |
53 public Sequencer getSequencer() { return sequencer; } | 55 public Sequencer getSequencer() { return sequencer; } |
54 | 56 public boolean usingDefault() { return defaultMD; } |
55 /* Constructors */ | 57 |
56 public MidiPlayer(String path, int deviceNumber, boolean d) { | 58 /* Constructors */ |
57 File midiFile = new File(path); | 59 public MidiPlayer(String path, int deviceNumber, boolean d) { |
58 midiDevice = deviceNumber; | 60 if(deviceNumber == -1) { |
59 debug = d; | 61 defaultMD = true; |
60 | 62 midiDevice = 0; |
61 // Get sequence | 63 } |
64 else{ | |
65 midiDevice = deviceNumber; | |
66 } | |
67 midiFile = new File(path); | |
68 debug = d; | |
69 setup(); | |
70 } | |
71 | |
72 private void setup(){ | |
73 // Get sequence | |
62 try { sequence = MidiSystem.getSequence(midiFile); } | 74 try { sequence = MidiSystem.getSequence(midiFile); } |
63 catch (InvalidMidiDataException e) { | 75 catch (InvalidMidiDataException e) { |
64 e.printStackTrace(); | 76 e.printStackTrace(); |
65 System.exit(1); | 77 System.exit(1); |
66 } | 78 } |
67 catch (IOException e) { | 79 catch (IOException e) { |
68 e.printStackTrace(); | |
69 System.exit(1); | |
70 } | |
71 // Get sequencer | |
72 try { sequencer = MidiSystem.getSequencer(); } | |
73 catch (MidiUnavailableException e) { | |
74 e.printStackTrace(); | 80 e.printStackTrace(); |
75 System.exit(1); | 81 System.exit(1); |
76 } | 82 } |
77 //sequencer.setTempoInBPM(bpm); | 83 //sequencer.setTempoInBPM(bpm); |
78 // Workaround bug in JDK | 84 // Workaround bug in JDK |
84 // synthesizer.close(); | 90 // synthesizer.close(); |
85 // } | 91 // } |
86 // } | 92 // } |
87 // } | 93 // } |
88 // }); | 94 // }); |
89 // Open sequencer | 95 // Set up MIDI output for sequence |
90 try { sequencer.open(); } | |
91 catch (MidiUnavailableException e) { | |
92 e.printStackTrace(); | |
93 System.exit(1); | |
94 } | |
95 // Assign sequence to sequencer | |
96 try { sequencer.setSequence(sequence); } | |
97 catch (InvalidMidiDataException e) { | |
98 e.printStackTrace(); | |
99 System.exit(1); | |
100 } | |
101 // Set up MIDI output for sequence | |
102 try { | 96 try { |
103 MidiDevice.Info msinfo[] = MidiSystem.getMidiDeviceInfo(); | 97 MidiDevice.Info msinfo[] = MidiSystem.getMidiDeviceInfo(); |
104 for(int i = 0; i < msinfo.length; i++) { | 98 for(int i = 0; i < msinfo.length; i++) { |
105 MidiDevice.Info m = msinfo[i]; | 99 System.out.println("Carl: "+i); |
106 // System.out.println("Name: " + m.getName() + | 100 MidiDevice.Info m = msinfo[i]; |
107 // "; Vendor: " + m.getVendor() + | 101 System.out.println("Name: " + m.getName() + |
108 // "; Version: " + m.getVersion()); | 102 "; Vendor: " + m.getVendor() + |
103 "; Version: " + m.getVersion()); | |
109 } | 104 } |
105 MidiDevice synth = MidiSystem.getMidiDevice(msinfo[midiDevice]); | |
106 synth.open(); | |
107 // Get sequencer | |
108 try { sequencer = MidiSystem.getSequencer(defaultMD); } | |
109 catch (MidiUnavailableException e) { | |
110 e.printStackTrace(); | |
111 System.exit(1); | |
112 } | |
110 // synthesizer = MidiSystem.getSynthesizer(); | 113 // synthesizer = MidiSystem.getSynthesizer(); |
111 MidiDevice synth = MidiSystem.getMidiDevice(msinfo[midiDevice]); | 114 |
115 try { sequencer.open(); }//// | |
116 catch (MidiUnavailableException e) { | |
117 e.printStackTrace(); | |
118 System.exit(1); | |
119 } | |
120 // Assign sequence to sequencer | |
121 try { sequencer.setSequence(sequence); } | |
122 catch (InvalidMidiDataException e) { | |
123 e.printStackTrace(); | |
124 System.exit(1); | |
125 }//// | |
112 | 126 |
113 // Change the patch | 127 // Change the patch |
114 // MidiChannel channels[] = synthesizer.getChannels(); | 128 // MidiChannel channels[] = synthesizer.getChannels(); |
115 // for (int i = 0; i < channels.length; i++) | 129 // for (int i = 0; i < channels.length; i++) |
116 // channels[i].programChange(65); | 130 // channels[i].programChange(65); |
117 | 131 |
118 synth.open(); | |
119 Receiver synthReceiver = synth.getReceiver(); | 132 Receiver synthReceiver = synth.getReceiver(); |
120 Transmitter seqTransmitter = sequencer.getTransmitter(); | 133 Transmitter seqTransmitter = sequencer.getTransmitter(); |
121 seqTransmitter.setReceiver(synthReceiver); | 134 seqTransmitter.setReceiver(synthReceiver); |
122 | 135 |
123 } | 136 } |