1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.view.classic; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.GridBagLayout; |
28 |
import java.awt.Insets; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
|
33 |
import javax.swing.BorderFactory; |
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JFileChooser; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JRadioButton; |
42 |
import javax.swing.ButtonGroup; |
43 |
import javax.swing.JSpinner; |
44 |
import javax.swing.JTextField; |
45 |
import javax.swing.SpinnerNumberModel; |
46 |
|
47 |
import net.sf.juife.JuifeUtils; |
48 |
import net.sf.juife.Wizard; |
49 |
|
50 |
import net.sf.juife.event.TaskEvent; |
51 |
import net.sf.juife.event.TaskListener; |
52 |
|
53 |
import net.sf.juife.wizard.DefaultWizardModel; |
54 |
import net.sf.juife.wizard.UserInputPage; |
55 |
import net.sf.juife.wizard.WizardPage; |
56 |
|
57 |
import org.jsampler.AudioDeviceModel; |
58 |
import org.jsampler.CC; |
59 |
import org.jsampler.HF; |
60 |
import org.jsampler.MidiDeviceModel; |
61 |
|
62 |
import org.jsampler.event.ListEvent; |
63 |
import org.jsampler.event.ListListener; |
64 |
import org.jsampler.event.MidiDeviceListEvent; |
65 |
import org.jsampler.event.MidiDeviceListListener; |
66 |
|
67 |
import org.jsampler.task.Channel.SetAudioOutputDevice; |
68 |
import org.jsampler.task.Channel.SetMidiInputChannel; |
69 |
import org.jsampler.task.Channel.SetMidiInputDevice; |
70 |
import org.jsampler.task.Channel.SetMidiInputPort; |
71 |
import org.jsampler.task.LoadEngine; |
72 |
import org.jsampler.task.LoadInstrument; |
73 |
|
74 |
import org.linuxsampler.lscp.AudioOutputDevice; |
75 |
import org.linuxsampler.lscp.MidiInputDevice; |
76 |
import org.linuxsampler.lscp.MidiPort; |
77 |
import org.linuxsampler.lscp.SamplerEngine; |
78 |
|
79 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
80 |
|
81 |
|
82 |
/** |
83 |
* |
84 |
* @author Grigor Iliev |
85 |
*/ |
86 |
public class NewChannelWizard extends Wizard { |
87 |
|
88 |
/** Creates a new instance of <code>NewChannelWizard</code>. */ |
89 |
public |
90 |
NewChannelWizard() { |
91 |
super(CC.getMainFrame(), i18n.getLabel("NewChannelWizard.title")); |
92 |
|
93 |
setModel(new NewChannelWizardModel()); |
94 |
} |
95 |
|
96 |
} |
97 |
|
98 |
class NewChannelWizardModel extends DefaultWizardModel { |
99 |
private final MidiDeviceWizardPage midiDevicePage = new MidiDeviceWizardPage(); |
100 |
private final MidiPortWizardPage midiPortPage = new MidiPortWizardPage(); |
101 |
private final MidiChannelWizardPage midiChannelPage = new MidiChannelWizardPage(); |
102 |
private final AudioDeviceWizardPage audioDevicePage = new AudioDeviceWizardPage(); |
103 |
private final EngineWizardPage enginePage = new EngineWizardPage(); |
104 |
private final InstrumentWizardPage instrumentPage = new InstrumentWizardPage(); |
105 |
private final ConfirmationWizardPage confirmationPage = new ConfirmationWizardPage(); |
106 |
|
107 |
NewChannelWizardModel() { |
108 |
addPage(midiDevicePage); |
109 |
addPage(midiPortPage); |
110 |
addPage(midiChannelPage); |
111 |
addStep(i18n.getLabel("NewChannelWizard.step1"), 3); |
112 |
|
113 |
addPage(audioDevicePage); |
114 |
addStep(i18n.getLabel("NewChannelWizard.step2")); |
115 |
|
116 |
addPage(enginePage); |
117 |
addStep(i18n.getLabel("NewChannelWizard.step3")); |
118 |
|
119 |
addPage(instrumentPage); |
120 |
addStep(i18n.getLabel("NewChannelWizard.step4")); |
121 |
|
122 |
addPage(confirmationPage); |
123 |
addStep(i18n.getLabel("NewChannelWizard.step5")); |
124 |
|
125 |
setLast(confirmationPage); |
126 |
} |
127 |
|
128 |
/** |
129 |
* Moves to the next page in the wizard. |
130 |
* @return The next page in the wizard. |
131 |
*/ |
132 |
public WizardPage |
133 |
next() { |
134 |
if(getCurrentPage() == midiDevicePage && !midiDevicePage.getCustomSettings()) { |
135 |
super.next(); super.next(); |
136 |
} |
137 |
|
138 |
return super.next(); |
139 |
} |
140 |
|
141 |
/** |
142 |
* Moves to the previous page in the wizard. |
143 |
* @return The previous page in the wizard. |
144 |
* @see #hasPrevious |
145 |
*/ |
146 |
public WizardPage |
147 |
previous() { |
148 |
if(getCurrentPage() == audioDevicePage && !midiDevicePage.getCustomSettings()) { |
149 |
super.previous(); super.previous(); |
150 |
} |
151 |
|
152 |
return super.previous(); |
153 |
} |
154 |
|
155 |
/** |
156 |
* Gets the selected MIDI device. |
157 |
* @return The selected MIDI device or <code>null</code> |
158 |
* if there is no MIDI device selected. |
159 |
*/ |
160 |
public MidiInputDevice |
161 |
getSelectedMidiDevice() { return midiDevicePage.getSelectedDevice(); } |
162 |
|
163 |
/** |
164 |
* Determines whether the user chooses to specify custom MIDI device settings. |
165 |
* @return <code>true</code> if the user chooses to specify custom MIDI device settings, |
166 |
* <code>false</code> otherwise. |
167 |
*/ |
168 |
public boolean |
169 |
getCustomMidiSettings() { return midiDevicePage.getCustomSettings(); } |
170 |
|
171 |
/** |
172 |
* Gets the selected MIDI input port. |
173 |
* @return The selected MIDI input port. |
174 |
*/ |
175 |
public MidiPort |
176 |
getSelectedMidiPort() { return midiPortPage.getSelectedPort(); } |
177 |
|
178 |
/** |
179 |
* Gets the selected MIDI channel. |
180 |
* @return The number of the selected MIDI channel or -1 which means all channels. |
181 |
*/ |
182 |
public int |
183 |
getSelectedMidiChannel() { return midiChannelPage.getSelectedChannel(); } |
184 |
|
185 |
/** |
186 |
* Gets the selected audio device. |
187 |
* @return The selected audio device or <code>null</code> if there is no device selected. |
188 |
*/ |
189 |
public AudioOutputDevice |
190 |
getSelectedAudioDevice() { return audioDevicePage.getSelectedDevice(); } |
191 |
|
192 |
/** |
193 |
* Gets the selected sampler engine to be used. |
194 |
* @return The selected sampler engine to be used. |
195 |
*/ |
196 |
public SamplerEngine |
197 |
getSelectedEngine() { return enginePage.getSelectedEngine(); } |
198 |
|
199 |
/** |
200 |
* Gets the name of the selected instrument file. |
201 |
* @return The name of the selected instrument file. |
202 |
*/ |
203 |
public String |
204 |
getSelectedFile() { return instrumentPage.getSelectedFile(); } |
205 |
|
206 |
/** |
207 |
* Gets the index of the instrument in the instrument file. |
208 |
* @return The index of the instrument in the instrument file. |
209 |
*/ |
210 |
public int |
211 |
getInstrumentIndex() { return instrumentPage.getInstrumentIndex(); } |
212 |
} |
213 |
|
214 |
class MidiDeviceWizardPage extends UserInputPage { |
215 |
private final JLabel lDevice = new JLabel(i18n.getLabel("MidiDeviceWizardPage.lDevice")); |
216 |
private final JComboBox cbDevices = new JComboBox(); |
217 |
private final JButton btnNewDevice = |
218 |
new JButton(i18n.getButtonLabel("MidiDeviceWizardPage.btnNewDevice")); |
219 |
private final JRadioButton rbDefaultSettings = |
220 |
new JRadioButton(i18n.getButtonLabel("MidiDeviceWizardPage.rbDefaultSettings")); |
221 |
private final JRadioButton rbCustomSettings = |
222 |
new JRadioButton(i18n.getButtonLabel("MidiDeviceWizardPage.rbCustomSettings")); |
223 |
|
224 |
MidiDeviceWizardPage() { |
225 |
super(i18n.getLabel("MidiDeviceWizardPage.subtitle")); |
226 |
|
227 |
setMainInstructions(i18n.getLabel("MidiDeviceWizardPage.mainInstructions")); |
228 |
|
229 |
JPanel p = new JPanel(); |
230 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
231 |
|
232 |
p.add(lDevice); |
233 |
|
234 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
235 |
|
236 |
for(MidiDeviceModel m : CC.getSamplerModel().getMidiDeviceModels()) { |
237 |
cbDevices.addItem(m.getDeviceInfo()); |
238 |
} |
239 |
|
240 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
241 |
if(cbDevices.getItemCount() == 0) enableDevComp(false); |
242 |
|
243 |
p.add(cbDevices); |
244 |
|
245 |
CC.getSamplerModel().addMidiDeviceListListener(getHandler()); |
246 |
|
247 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
248 |
p.add(btnNewDevice); |
249 |
p.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
250 |
|
251 |
JPanel mainPane = new JPanel(); |
252 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
253 |
mainPane.add(p); |
254 |
|
255 |
mainPane.add(Box.createRigidArea(new Dimension(0, 6))); |
256 |
|
257 |
rbDefaultSettings.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
258 |
mainPane.add(rbDefaultSettings); |
259 |
rbCustomSettings.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
260 |
mainPane.add(rbCustomSettings); |
261 |
|
262 |
ButtonGroup btnGroup = new ButtonGroup(); |
263 |
btnGroup.add(rbDefaultSettings); |
264 |
btnGroup.add(rbCustomSettings); |
265 |
rbDefaultSettings.setSelected(true); |
266 |
|
267 |
setMainPane(mainPane); |
268 |
|
269 |
btnNewDevice.addActionListener(new ActionListener() { |
270 |
public void |
271 |
actionPerformed(ActionEvent e) { |
272 |
new NewMidiDeviceDlg(getWizardDialog()).setVisible(true); |
273 |
} |
274 |
}); |
275 |
} |
276 |
|
277 |
/** |
278 |
* Gets the selected device. |
279 |
* @return The selected device or <code>null</code> if there is no device selected. |
280 |
*/ |
281 |
public MidiInputDevice |
282 |
getSelectedDevice() { return (MidiInputDevice)cbDevices.getSelectedItem(); } |
283 |
|
284 |
private void |
285 |
enableDevComp(boolean b) { |
286 |
cbDevices.setEnabled(b); |
287 |
rbDefaultSettings.setEnabled(b); |
288 |
rbCustomSettings.setEnabled(b); |
289 |
} |
290 |
|
291 |
/** |
292 |
* Determines whether the user chooses to specify custom device settings. |
293 |
* @return <code>true</code> if the user chooses to specify custom device settings, |
294 |
* <code>false</code> otherwise. |
295 |
*/ |
296 |
public boolean |
297 |
getCustomSettings() { return rbCustomSettings.isSelected(); } |
298 |
|
299 |
private final Handler handler = new Handler(); |
300 |
|
301 |
private Handler |
302 |
getHandler() { return handler; } |
303 |
|
304 |
private class Handler implements MidiDeviceListListener { |
305 |
public void |
306 |
deviceAdded(MidiDeviceListEvent e) { |
307 |
updateDeviceList(e.getMidiDeviceModel().getDeviceInfo()); |
308 |
} |
309 |
|
310 |
public void |
311 |
deviceRemoved(MidiDeviceListEvent e) { updateDeviceList(null); } |
312 |
|
313 |
private void |
314 |
updateDeviceList(MidiInputDevice dev) { |
315 |
cbDevices.removeAllItems(); |
316 |
|
317 |
for(MidiDeviceModel m : CC.getSamplerModel().getMidiDeviceModels()) { |
318 |
cbDevices.addItem(m.getDeviceInfo()); |
319 |
} |
320 |
|
321 |
if(cbDevices.getItemCount() == 0) enableDevComp(false); |
322 |
else { |
323 |
enableDevComp(true); |
324 |
cbDevices.setSelectedItem(dev); |
325 |
} |
326 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
327 |
} |
328 |
} |
329 |
} |
330 |
|
331 |
class MidiPortWizardPage extends UserInputPage { |
332 |
private final JLabel lPort = new JLabel(i18n.getLabel("MidiPortWizardPage.lPort")); |
333 |
private final JComboBox cbPorts = new JComboBox(); |
334 |
|
335 |
MidiPortWizardPage() { |
336 |
super(i18n.getLabel("MidiPortWizardPage.subtitle")); |
337 |
|
338 |
setMainInstructions(i18n.getLabel("MidiPortWizardPage.mainInstructions")); |
339 |
|
340 |
JPanel p = new JPanel(); |
341 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
342 |
|
343 |
p.add(lPort); |
344 |
|
345 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
346 |
|
347 |
cbPorts.setMaximumSize(cbPorts.getPreferredSize()); |
348 |
|
349 |
p.add(cbPorts); |
350 |
|
351 |
setMainPane(p); |
352 |
} |
353 |
|
354 |
public void |
355 |
preinitPage() { |
356 |
updatePorts(((NewChannelWizardModel)getWizardModel()).getSelectedMidiDevice()); |
357 |
} |
358 |
|
359 |
/** |
360 |
* Gets the selected MIDI input port. |
361 |
* @return The selected MIDI input port. |
362 |
*/ |
363 |
public MidiPort |
364 |
getSelectedPort() { return (MidiPort)cbPorts.getSelectedItem(); } |
365 |
|
366 |
public void |
367 |
updatePorts(MidiInputDevice dev) { |
368 |
Object current = cbPorts.getSelectedItem(); |
369 |
cbPorts.removeAllItems(); |
370 |
|
371 |
if(dev != null) for(MidiPort p : dev.getMidiPorts()) cbPorts.addItem(p); |
372 |
if(current != null) cbPorts.setSelectedItem(current); |
373 |
cbPorts.setEnabled(cbPorts.getItemCount() > 0); |
374 |
cbPorts.setMaximumSize(cbPorts.getPreferredSize()); |
375 |
} |
376 |
} |
377 |
|
378 |
class MidiChannelWizardPage extends UserInputPage { |
379 |
private final JLabel lChannel = new JLabel(i18n.getLabel("MidiChannelWizardPage.lChannel")); |
380 |
private final JComboBox cbChannels = new JComboBox(); |
381 |
|
382 |
MidiChannelWizardPage() { |
383 |
super(i18n.getLabel("MidiChannelWizardPage.subtitle")); |
384 |
|
385 |
setMainInstructions(i18n.getLabel("MidiChannelWizardPage.mainInstructions")); |
386 |
|
387 |
JPanel p = new JPanel(); |
388 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
389 |
|
390 |
p.add(lChannel); |
391 |
|
392 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
393 |
|
394 |
cbChannels.addItem("All"); |
395 |
for(int i = 1; i <= 16; i++) cbChannels.addItem(String.valueOf(i)); |
396 |
cbChannels.setMaximumSize(cbChannels.getPreferredSize()); |
397 |
|
398 |
p.add(cbChannels); |
399 |
|
400 |
setMainPane(p); |
401 |
} |
402 |
|
403 |
/** |
404 |
* Gets the selected MIDI channel. |
405 |
* @return The number of the selected MIDI channel or -1 which means all channels. |
406 |
*/ |
407 |
public int |
408 |
getSelectedChannel() { |
409 |
Object o = cbChannels.getSelectedItem(); |
410 |
if(o == null) return -1; |
411 |
|
412 |
return o.toString().equals("All") ? -1 : Integer.parseInt(o.toString()); |
413 |
} |
414 |
} |
415 |
|
416 |
class AudioDeviceWizardPage extends UserInputPage { |
417 |
private final JLabel lDevice = new JLabel(i18n.getLabel("AudioDeviceWizardPage.lDevice")); |
418 |
private final JComboBox cbDevices = new JComboBox(); |
419 |
private final JButton btnNewDevice = |
420 |
new JButton(i18n.getButtonLabel("AudioDeviceWizardPage.btnNewDevice")); |
421 |
|
422 |
AudioDeviceWizardPage() { |
423 |
super(i18n.getLabel("AudioDeviceWizardPage.subtitle")); |
424 |
|
425 |
setMainInstructions(i18n.getLabel("AudioDeviceWizardPage.mainInstructions")); |
426 |
setAdditionalInstructions ( |
427 |
i18n.getLabel("AudioDeviceWizardPage.additionalInstructions") |
428 |
); |
429 |
|
430 |
JPanel p = new JPanel(); |
431 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
432 |
|
433 |
p.add(lDevice); |
434 |
|
435 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
436 |
|
437 |
for(AudioDeviceModel m : CC.getSamplerModel().getAudioDeviceModels()) { |
438 |
cbDevices.addItem(m.getDeviceInfo()); |
439 |
} |
440 |
|
441 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
442 |
if(cbDevices.getItemCount() == 0) cbDevices.setEnabled(false); |
443 |
|
444 |
p.add(cbDevices); |
445 |
|
446 |
CC.getSamplerModel().addAudioDeviceListListener(getHandler()); |
447 |
|
448 |
p.add(Box.createRigidArea(new Dimension(12, 0))); |
449 |
p.add(btnNewDevice); |
450 |
|
451 |
setMainPane(p); |
452 |
|
453 |
btnNewDevice.addActionListener(new ActionListener() { |
454 |
public void |
455 |
actionPerformed(ActionEvent e) { |
456 |
new NewAudioDeviceDlg(getWizardDialog()).setVisible(true); |
457 |
} |
458 |
}); |
459 |
} |
460 |
|
461 |
/** |
462 |
* Gets the selected device. |
463 |
* @return The selected device or <code>null</code> if there is no device selected. |
464 |
*/ |
465 |
public AudioOutputDevice |
466 |
getSelectedDevice() { return (AudioOutputDevice)cbDevices.getSelectedItem(); } |
467 |
|
468 |
private final Handler handler = new Handler(); |
469 |
|
470 |
private Handler |
471 |
getHandler() { return handler; } |
472 |
|
473 |
private class Handler implements ListListener<AudioDeviceModel> { |
474 |
public void |
475 |
entryAdded(ListEvent<AudioDeviceModel> e) { |
476 |
updateDeviceList(e.getEntry().getDeviceInfo()); |
477 |
} |
478 |
|
479 |
public void |
480 |
entryRemoved(ListEvent<AudioDeviceModel> e) { updateDeviceList(null); } |
481 |
|
482 |
private void |
483 |
updateDeviceList(AudioOutputDevice dev) { |
484 |
cbDevices.removeAllItems(); |
485 |
|
486 |
for(AudioDeviceModel m : CC.getSamplerModel().getAudioDeviceModels()) { |
487 |
cbDevices.addItem(m.getDeviceInfo()); |
488 |
} |
489 |
|
490 |
if(cbDevices.getItemCount() == 0) cbDevices.setEnabled(false); |
491 |
else { |
492 |
cbDevices.setEnabled(true); |
493 |
cbDevices.setSelectedItem(dev); |
494 |
} |
495 |
cbDevices.setMaximumSize(cbDevices.getPreferredSize()); |
496 |
} |
497 |
} |
498 |
} |
499 |
|
500 |
class EngineWizardPage extends UserInputPage { |
501 |
private final JLabel lEngine = new JLabel(i18n.getLabel("EngineWizardPage.lEngine")); |
502 |
private final JComboBox cbEngines = new JComboBox(); |
503 |
|
504 |
EngineWizardPage() { |
505 |
super(i18n.getLabel("EngineWizardPage.subtitle")); |
506 |
|
507 |
setMainInstructions(i18n.getLabel("EngineWizardPage.mainInstructions")); |
508 |
|
509 |
JPanel p = new JPanel(); |
510 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
511 |
|
512 |
p.add(lEngine); |
513 |
|
514 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
515 |
|
516 |
for(Object o : CC.getSamplerModel().getEngines()) { |
517 |
cbEngines.addItem(o); |
518 |
} |
519 |
|
520 |
cbEngines.setMaximumSize(cbEngines.getPreferredSize()); |
521 |
|
522 |
p.add(cbEngines); |
523 |
|
524 |
setMainPane(p); |
525 |
} |
526 |
|
527 |
/** |
528 |
* Gets the selected sampler engine to be used. |
529 |
* @return The selected sampler engine to be used. |
530 |
*/ |
531 |
public SamplerEngine |
532 |
getSelectedEngine() { return (SamplerEngine)cbEngines.getSelectedItem(); } |
533 |
} |
534 |
|
535 |
class InstrumentWizardPage extends UserInputPage { |
536 |
private final JLabel lFilename = new JLabel(i18n.getLabel("InstrumentChooser.lFilename")); |
537 |
private final JLabel lIndex = new JLabel(i18n.getLabel("InstrumentChooser.lIndex")); |
538 |
|
539 |
private final JTextField tfFilename = new JTextField(); |
540 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
541 |
|
542 |
private final JButton btnBrowse = |
543 |
new JButton(i18n.getLabel("InstrumentChooser.btnBrowse")); |
544 |
|
545 |
|
546 |
InstrumentWizardPage() { |
547 |
super(i18n.getLabel("InstrumentWizardPage.subtitle")); |
548 |
|
549 |
setMainInstructions(i18n.getLabel("InstrumentWizardPage.mainInstructions")); |
550 |
|
551 |
JPanel p = new JPanel(); |
552 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
553 |
|
554 |
p.add(lFilename); |
555 |
|
556 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
557 |
|
558 |
tfFilename.setPreferredSize ( |
559 |
new Dimension(200, tfFilename.getPreferredSize().height) |
560 |
); |
561 |
tfFilename.setMaximumSize(tfFilename.getPreferredSize()); |
562 |
p.add(tfFilename); |
563 |
|
564 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
565 |
|
566 |
spinnerIndex.setMaximumSize(spinnerIndex.getPreferredSize()); |
567 |
p.add(spinnerIndex); |
568 |
|
569 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
570 |
|
571 |
p.add(btnBrowse); |
572 |
|
573 |
p.setMaximumSize(p.getPreferredSize()); |
574 |
setMainPane(p); |
575 |
|
576 |
btnBrowse.addActionListener(new ActionListener() { |
577 |
public void |
578 |
actionPerformed(ActionEvent e) { onBrowse(); } |
579 |
}); |
580 |
|
581 |
btnBrowse.requestFocusInWindow(); |
582 |
} |
583 |
|
584 |
public void |
585 |
preinitPage() { |
586 |
NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel(); |
587 |
if(model.getSelectedAudioDevice() == null) { |
588 |
String s = i18n.getLabel("InstrumentWizardPage.additionalInstructions"); |
589 |
setAdditionalInstructions(s); |
590 |
} else { setAdditionalInstructions(""); } |
591 |
} |
592 |
|
593 |
public boolean |
594 |
mayGoToNext() { |
595 |
NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel(); |
596 |
if(model.getSelectedAudioDevice() == null && getSelectedFile().length() > 0) { |
597 |
String s = i18n.getError("InstrumentWizardPage.selectAODevice!"); |
598 |
HF.showErrorMessage(s, getWizardDialog()); |
599 |
return false; |
600 |
} else { |
601 |
return true; |
602 |
} |
603 |
} |
604 |
|
605 |
/** |
606 |
* Gets the name of the instrument file. |
607 |
* @return The name of the instrument file. |
608 |
*/ |
609 |
public String |
610 |
getSelectedFile() { return tfFilename.getText(); } |
611 |
|
612 |
/** |
613 |
* Gets the index of the instrument in the instrument file. |
614 |
* @return The index of the instrument in the instrument file. |
615 |
*/ |
616 |
public int |
617 |
getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); } |
618 |
|
619 |
private void |
620 |
onBrowse() { |
621 |
JFileChooser fc = new JFileChooser(); |
622 |
int result = fc.showOpenDialog(this); |
623 |
if(result == JFileChooser.APPROVE_OPTION) { |
624 |
tfFilename.setText(fc.getSelectedFile().getPath()); |
625 |
} |
626 |
} |
627 |
} |
628 |
|
629 |
class ConfirmationWizardPage extends WizardPage { |
630 |
private MidiInputDevice midiDev = null; |
631 |
private MidiPort midiPort = null; |
632 |
private int midiChannel = -1; |
633 |
private AudioOutputDevice audioDev = null; |
634 |
private SamplerEngine engine = null; |
635 |
private String instrFile = null; |
636 |
private int instrIndex; |
637 |
|
638 |
private final JLabel lInfo = new JLabel(i18n.getLabel("ConfirmationWizardPage.lInfo")); |
639 |
|
640 |
private final JLabel lMidiDevice = |
641 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiDevice")); |
642 |
private final JLabel lMidiPort = |
643 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiPort")); |
644 |
private final JLabel lMidiChannel = |
645 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiChannel")); |
646 |
private final JLabel lEngine = |
647 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lEngine")); |
648 |
private final JLabel lInstrFile = |
649 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lInstrFile")); |
650 |
private final JLabel lInstrIndex = |
651 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lInstrIndex")); |
652 |
private final JLabel lAudioDevice = |
653 |
new JLabel(i18n.getLabel("ConfirmationWizardPage.lAudioDevice")); |
654 |
|
655 |
private final JTextField tfMidiDevice = new EnhancedTextField(); |
656 |
private final JTextField tfMidiPort = new EnhancedTextField(); |
657 |
private final JTextField tfMidiChannel = new EnhancedTextField(); |
658 |
private final JTextField tfEngine = new EnhancedTextField(); |
659 |
private final JTextField tfInstrFile = new EnhancedTextField(); |
660 |
private final JTextField tfInstrIndex = new EnhancedTextField(); |
661 |
private final JTextField tfAudioDevice = new EnhancedTextField(); |
662 |
|
663 |
ConfirmationWizardPage() { |
664 |
super(i18n.getLabel("ConfirmationWizardPage.subtitle"), "", Type.CONFIRMATION_PAGE); |
665 |
|
666 |
GridBagLayout gridbag = new GridBagLayout(); |
667 |
GridBagConstraints c = new GridBagConstraints(); |
668 |
|
669 |
//JPanel mainPane = new JPanel(); |
670 |
|
671 |
setLayout(gridbag); |
672 |
|
673 |
c.fill = GridBagConstraints.NONE; |
674 |
|
675 |
c.gridx = 0; |
676 |
c.gridy = 1; |
677 |
c.anchor = GridBagConstraints.EAST; |
678 |
c.insets = new Insets(3, 3, 3, 3); |
679 |
gridbag.setConstraints(lMidiDevice, c); |
680 |
add(lMidiDevice); |
681 |
|
682 |
c.gridx = 0; |
683 |
c.gridy = 2; |
684 |
gridbag.setConstraints(lMidiPort, c); |
685 |
add(lMidiPort); |
686 |
|
687 |
c.gridx = 0; |
688 |
c.gridy = 3; |
689 |
gridbag.setConstraints(lMidiChannel, c); |
690 |
add(lMidiChannel); |
691 |
|
692 |
c.gridx = 0; |
693 |
c.gridy = 4; |
694 |
gridbag.setConstraints(lEngine, c); |
695 |
add(lEngine); |
696 |
|
697 |
c.gridx = 0; |
698 |
c.gridy = 5; |
699 |
gridbag.setConstraints(lInstrFile, c); |
700 |
add(lInstrFile); |
701 |
|
702 |
c.gridx = 0; |
703 |
c.gridy = 6; |
704 |
gridbag.setConstraints(lInstrIndex, c); |
705 |
add(lInstrIndex); |
706 |
|
707 |
c.gridx = 0; |
708 |
c.gridy = 7; |
709 |
gridbag.setConstraints(lAudioDevice, c); |
710 |
add(lAudioDevice); |
711 |
|
712 |
c.fill = GridBagConstraints.HORIZONTAL; |
713 |
c.gridx = 1; |
714 |
c.gridy = 1; |
715 |
c.weightx = 1.0; |
716 |
c.anchor = GridBagConstraints.WEST; |
717 |
gridbag.setConstraints(tfMidiDevice, c); |
718 |
add(tfMidiDevice); |
719 |
|
720 |
c.gridx = 1; |
721 |
c.gridy = 2; |
722 |
gridbag.setConstraints(tfMidiPort, c); |
723 |
add(tfMidiPort); |
724 |
|
725 |
c.gridx = 1; |
726 |
c.gridy = 3; |
727 |
gridbag.setConstraints(tfMidiChannel, c); |
728 |
add(tfMidiChannel); |
729 |
|
730 |
c.gridx = 1; |
731 |
c.gridy = 4; |
732 |
gridbag.setConstraints(tfEngine, c); |
733 |
add(tfEngine); |
734 |
|
735 |
c.gridx = 1; |
736 |
c.gridy = 5; |
737 |
gridbag.setConstraints(tfInstrFile, c); |
738 |
add(tfInstrFile); |
739 |
|
740 |
c.gridx = 1; |
741 |
c.gridy = 6; |
742 |
gridbag.setConstraints(tfInstrIndex, c); |
743 |
add(tfInstrIndex); |
744 |
|
745 |
c.gridx = 1; |
746 |
c.gridy = 7; |
747 |
gridbag.setConstraints(tfAudioDevice, c); |
748 |
add(tfAudioDevice); |
749 |
|
750 |
lInfo.setFont(lInfo.getFont().deriveFont(java.awt.Font.PLAIN)); |
751 |
|
752 |
c.gridx = 0; |
753 |
c.gridy = 0; |
754 |
c.gridwidth = 2; |
755 |
c.insets = new Insets(12, 3, 17, 3); |
756 |
c.anchor = GridBagConstraints.NORTH; |
757 |
gridbag.setConstraints(lInfo, c); |
758 |
add(lInfo); |
759 |
|
760 |
JPanel p = new JPanel(); |
761 |
p.setOpaque(false); |
762 |
c.gridx = 0; |
763 |
c.gridy = 8; |
764 |
c.weightx = 1.0; |
765 |
c.weighty = 1.0; |
766 |
c.insets = new Insets(0, 0, 0, 0); |
767 |
gridbag.setConstraints(p, c); |
768 |
add(p); |
769 |
|
770 |
} |
771 |
|
772 |
public void |
773 |
preinitPage() { |
774 |
NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel(); |
775 |
setMidiDevice(model.getSelectedMidiDevice()); |
776 |
|
777 |
|
778 |
if(model.getCustomMidiSettings()) { |
779 |
setMidiPort(model.getSelectedMidiPort()); |
780 |
setMidiChannel(model.getSelectedMidiChannel()); |
781 |
} else { |
782 |
MidiInputDevice mdev = model.getSelectedMidiDevice(); |
783 |
if(mdev == null) setMidiPort(null); |
784 |
else if(mdev.getMidiPorts().length < 1) setMidiPort(null); |
785 |
else setMidiPort(mdev.getMidiPort(0)); |
786 |
|
787 |
setMidiChannel(-1); |
788 |
} |
789 |
|
790 |
setEngine(model.getSelectedEngine()); |
791 |
setAudioDevice(model.getSelectedAudioDevice()); |
792 |
setInstrumentFile(model.getSelectedFile()); |
793 |
setInstrumentIndex(model.getInstrumentIndex()); |
794 |
} |
795 |
|
796 |
/** |
797 |
* Invoked when the user clicks the 'Finish' button |
798 |
* while this page is the current page of the wizard. |
799 |
* @return <code>true</code> |
800 |
*/ |
801 |
public boolean |
802 |
mayFinish() { |
803 |
final org.jsampler.task.Channel.Add ac = new org.jsampler.task.Channel.Add(); |
804 |
|
805 |
ac.addTaskListener(new TaskListener() { |
806 |
public void |
807 |
taskPerformed(TaskEvent e) { |
808 |
if(ac.doneWithErrors()) return; |
809 |
doIt(ac.getResult()); |
810 |
} |
811 |
}); |
812 |
|
813 |
CC.getTaskQueue().add(ac); |
814 |
|
815 |
return true; |
816 |
} |
817 |
|
818 |
private void |
819 |
doIt(int chn) { |
820 |
if(getEngine() != null) |
821 |
CC.getTaskQueue().add(new LoadEngine(getEngine().getName(), chn)); |
822 |
|
823 |
/*if(getMidiDPort() != null) CC.getTaskQueue().add ( |
824 |
new SetChannelMidiInputPort(chn, getMidiPort().) |
825 |
);*/ |
826 |
|
827 |
MidiInputDevice d = getMidiDevice(); |
828 |
if(d != null) { |
829 |
CC.getTaskQueue().add(new SetMidiInputChannel(chn, d.getDeviceId())); |
830 |
|
831 |
if(getMidiPort() != null) { |
832 |
int port = -1; |
833 |
for(int i = 0; i < d.getMidiPortCount(); i++) { |
834 |
if(d.getMidiPort(i) == getMidiPort()) { |
835 |
port = i; |
836 |
break; |
837 |
} |
838 |
} |
839 |
|
840 |
if(port != -1) CC.getTaskQueue().add ( |
841 |
new SetMidiInputPort(chn, port) |
842 |
); |
843 |
} |
844 |
|
845 |
|
846 |
int mc = (getMidiChannel() == -1 ? -1 : getMidiChannel() - 1); |
847 |
CC.getTaskQueue().add(new SetMidiInputChannel(chn, mc)); |
848 |
} |
849 |
|
850 |
|
851 |
|
852 |
if(getAudioDevice() != null) CC.getTaskQueue().add ( |
853 |
new SetAudioOutputDevice(chn, getAudioDevice().getDeviceId()) |
854 |
); |
855 |
|
856 |
if(getInstrumentFile().length() > 0) CC.getTaskQueue().add ( |
857 |
new LoadInstrument(getInstrumentFile(), getInstrumentIndex(), chn) |
858 |
); |
859 |
} |
860 |
|
861 |
/** |
862 |
* Gets the audio output device to be used by this sampler channel. |
863 |
* @return The audio output device to be used by this sampler channel. |
864 |
*/ |
865 |
public AudioOutputDevice |
866 |
getAudioDevice() { return audioDev; } |
867 |
|
868 |
/** |
869 |
* Sets the audio output device to be used by this sampler channel. |
870 |
* @param dev The audio output device to be used by this sampler channel. |
871 |
*/ |
872 |
public void |
873 |
setAudioDevice(AudioOutputDevice dev) { |
874 |
audioDev = dev; |
875 |
if(dev == null) { |
876 |
tfAudioDevice.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
877 |
} else { |
878 |
tfAudioDevice.setText(dev.getDeviceId() + " (" + dev.getDriverName() + ")"); |
879 |
} |
880 |
} |
881 |
|
882 |
/** |
883 |
* Gets the sampler engine to be used. |
884 |
* @return The sampler engine to be used. |
885 |
*/ |
886 |
public SamplerEngine |
887 |
getEngine() { return engine; } |
888 |
|
889 |
/** |
890 |
* Sets the sampler engine to be used. |
891 |
* @param engine The sampler engine to be used. |
892 |
*/ |
893 |
public void |
894 |
setEngine(SamplerEngine engine) { |
895 |
this.engine = engine; |
896 |
if(engine == null) { |
897 |
tfEngine.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
898 |
} else { |
899 |
tfEngine.setText(engine.getName() + " (" + engine.getDescription() + ")"); |
900 |
} |
901 |
} |
902 |
|
903 |
/** |
904 |
* Gets the name of the instrument file. |
905 |
* @return The name of the instrument file. |
906 |
*/ |
907 |
public String |
908 |
getInstrumentFile() { return instrFile; } |
909 |
|
910 |
/** |
911 |
* Sets the name of the instrument file. |
912 |
* @param file The name of the instrument file. |
913 |
*/ |
914 |
public void |
915 |
setInstrumentFile(String file) { |
916 |
instrFile = file; |
917 |
|
918 |
if(file.length() == 0) { |
919 |
tfInstrFile.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
920 |
} else { |
921 |
tfInstrFile.setText(file); |
922 |
} |
923 |
} |
924 |
|
925 |
/** |
926 |
* Gets the index of the instrument in the instrument file. |
927 |
* @return The index of the instrument in the instrument file. |
928 |
*/ |
929 |
public int |
930 |
getInstrumentIndex() { return instrIndex; } |
931 |
|
932 |
/** |
933 |
* Sets the index of the instrument in the instrument file. |
934 |
* @param idx The index of the instrument in the instrument file. |
935 |
*/ |
936 |
public void |
937 |
setInstrumentIndex(int idx) { |
938 |
instrIndex = idx; |
939 |
tfInstrIndex.setText(String.valueOf(idx)); |
940 |
} |
941 |
|
942 |
/** |
943 |
* Gets the MIDI channel to which this sampler channel will listen to. |
944 |
* @return The MIDI channel to which this sampler channel will listen to |
945 |
* (-1 means all channels). |
946 |
* . |
947 |
*/ |
948 |
public int |
949 |
getMidiChannel() { return midiChannel; } |
950 |
|
951 |
/** |
952 |
* Sets the MIDI channel to which this sampler channel will listen to. |
953 |
* @param chn The MIDI channel to which this sampler channel will listen to |
954 |
* (-1 means all channels). |
955 |
* . |
956 |
*/ |
957 |
public void |
958 |
setMidiChannel(int chn) { |
959 |
midiChannel = chn; |
960 |
tfMidiChannel.setText(chn == -1 ? "All" : String.valueOf(chn)); |
961 |
} |
962 |
|
963 |
/** |
964 |
* Gets the MIDI input device to which this sampler channel will be connected to. |
965 |
* @return The MIDI input device to which this sampler channel will be connected to. |
966 |
*/ |
967 |
public MidiInputDevice |
968 |
getMidiDevice() { return midiDev; } |
969 |
|
970 |
/** |
971 |
* Sets the MIDI input device to which this sampler channel will be connected to. |
972 |
* @param dev The numerical id of the MIDI input device to which |
973 |
* this sampler channel will be connected to. |
974 |
*/ |
975 |
public void |
976 |
setMidiDevice(MidiInputDevice dev) { |
977 |
midiDev = dev; |
978 |
|
979 |
if(dev == null) { |
980 |
tfMidiDevice.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
981 |
} else { |
982 |
tfMidiDevice.setText(dev.getDeviceId() + " (" + dev.getDriverName() + ")"); |
983 |
} |
984 |
} |
985 |
|
986 |
/** |
987 |
* Gets the MIDI input port. |
988 |
* @return The MIDI input port. |
989 |
*/ |
990 |
public MidiPort |
991 |
getMidiPort() { return midiPort; } |
992 |
|
993 |
/** |
994 |
* Sets the MIDI input port. |
995 |
* @param port The MIDI input port. |
996 |
*/ |
997 |
public void |
998 |
setMidiPort(MidiPort port) { |
999 |
midiPort = port; |
1000 |
|
1001 |
if(port == null) { |
1002 |
tfMidiPort.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified")); |
1003 |
} else { |
1004 |
tfMidiPort.setText(port.getName()); |
1005 |
} |
1006 |
} |
1007 |
|
1008 |
private class EnhancedTextField extends JTextField { |
1009 |
EnhancedTextField() { |
1010 |
setEditable(false); |
1011 |
setBorder(BorderFactory.createEmptyBorder()); |
1012 |
} |
1013 |
} |
1014 |
} |