1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 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.std; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.ButtonGroup; |
37 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JCheckBox; |
40 |
import javax.swing.JComboBox; |
41 |
import javax.swing.JFileChooser; |
42 |
import javax.swing.JLabel; |
43 |
import javax.swing.JPanel; |
44 |
import javax.swing.JRadioButton; |
45 |
import javax.swing.JSlider; |
46 |
import javax.swing.JSpinner; |
47 |
import javax.swing.JTextField; |
48 |
import javax.swing.SpinnerNumberModel; |
49 |
|
50 |
import javax.swing.event.DocumentEvent; |
51 |
import javax.swing.event.DocumentListener; |
52 |
|
53 |
import net.sf.juife.Wizard; |
54 |
|
55 |
import net.sf.juife.wizard.DefaultWizardModel; |
56 |
import net.sf.juife.wizard.UserInputPage; |
57 |
import net.sf.juife.wizard.WizardPage; |
58 |
|
59 |
import org.jsampler.CC; |
60 |
import org.jsampler.Instrument; |
61 |
import org.jsampler.JSPrefs; |
62 |
import org.jsampler.MidiInstrumentMap; |
63 |
import org.jsampler.OrchestraModel; |
64 |
|
65 |
import org.linuxsampler.lscp.MidiInstrumentEntry; |
66 |
import org.linuxsampler.lscp.MidiInstrumentInfo; |
67 |
import org.linuxsampler.lscp.SamplerEngine; |
68 |
|
69 |
import static org.jsampler.view.std.StdI18n.i18n; |
70 |
|
71 |
|
72 |
/** |
73 |
* A wizard for mapping new MIDI instrument. |
74 |
* @author Grigor Iliev |
75 |
*/ |
76 |
public class JSNewMidiInstrumentWizard extends Wizard { |
77 |
/** |
78 |
* Creates a new instance of <code>JSNewMidiInstrumentWizard</code>. |
79 |
*/ |
80 |
public |
81 |
JSNewMidiInstrumentWizard(ImageIcon iconBrowse) { |
82 |
this(iconBrowse, null); |
83 |
} |
84 |
|
85 |
/** |
86 |
* Creates a new instance of <code>JSNewMidiInstrumentWizard</code>. |
87 |
*/ |
88 |
public |
89 |
JSNewMidiInstrumentWizard(ImageIcon iconBrowse, MidiInstrumentMap defaultMap) { |
90 |
super(CC.getMainFrame(), i18n.getLabel("JSNewMidiInstrumentWizard.title")); |
91 |
setModel(new NewMidiInstrumentWizardModel(iconBrowse, defaultMap)); |
92 |
} |
93 |
|
94 |
} |
95 |
|
96 |
class NewMidiInstrumentWizardModel extends DefaultWizardModel { |
97 |
private final InstrLocationMethodWizardPage instrLocationMethodWizardPage; |
98 |
private final OrchestraSelectWizardPage orchestraSelectWizardPage; |
99 |
private final ManualSelectWizardPage manualSelectWizardPage; |
100 |
private final InstrumentMappingWizardPage instrumentMappingWizardPage; |
101 |
|
102 |
private MidiInstrumentMap defaultMap; |
103 |
|
104 |
NewMidiInstrumentWizardModel(ImageIcon iconBrowse, MidiInstrumentMap defaultMap) { |
105 |
this.defaultMap = defaultMap; |
106 |
instrLocationMethodWizardPage = new InstrLocationMethodWizardPage(); |
107 |
orchestraSelectWizardPage = new OrchestraSelectWizardPage(); |
108 |
manualSelectWizardPage = new ManualSelectWizardPage(iconBrowse); |
109 |
instrumentMappingWizardPage = new InstrumentMappingWizardPage(this); |
110 |
|
111 |
addPage(instrLocationMethodWizardPage); |
112 |
addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step1")); |
113 |
|
114 |
addPage(manualSelectWizardPage); |
115 |
addPage(orchestraSelectWizardPage); |
116 |
addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step2"), 2); |
117 |
|
118 |
addPage(instrumentMappingWizardPage); |
119 |
addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step3")); |
120 |
} |
121 |
|
122 |
public String |
123 |
getInstrumentName() { |
124 |
if(!instrLocationMethodWizardPage.isOrchestraMethodSelected()) return null; |
125 |
Instrument instr = orchestraSelectWizardPage.getInstrument(); |
126 |
if(instr == null) return null; |
127 |
return instr.getName(); |
128 |
} |
129 |
|
130 |
/** |
131 |
* Moves to the next page in the wizard. |
132 |
* @return The next page in the wizard. |
133 |
*/ |
134 |
public WizardPage |
135 |
next() { |
136 |
InstrLocationMethodWizardPage p1 = instrLocationMethodWizardPage; |
137 |
WizardPage p2 = manualSelectWizardPage; |
138 |
|
139 |
if(getCurrentPage() == p1 && p1.isOrchestraMethodSelected()) { |
140 |
super.next(); |
141 |
} else if(getCurrentPage() == manualSelectWizardPage) { |
142 |
super.next(); |
143 |
} |
144 |
|
145 |
return super.next(); |
146 |
} |
147 |
|
148 |
/** |
149 |
* Moves to the previous page in the wizard. |
150 |
* @return The previous page in the wizard. |
151 |
* @see #hasPrevious |
152 |
*/ |
153 |
public WizardPage |
154 |
previous() { |
155 |
InstrLocationMethodWizardPage p1 = instrLocationMethodWizardPage; |
156 |
WizardPage p2 = instrumentMappingWizardPage; |
157 |
|
158 |
if(getCurrentPage() == orchestraSelectWizardPage) { |
159 |
super.previous(); |
160 |
} else if(getCurrentPage() == p2 && !p1.isOrchestraMethodSelected()) { |
161 |
super.previous(); |
162 |
} |
163 |
|
164 |
return super.previous(); |
165 |
} |
166 |
|
167 |
public void |
168 |
mapInstrument() { |
169 |
MidiInstrumentInfo instr = new MidiInstrumentInfo(); |
170 |
if(instrLocationMethodWizardPage.isOrchestraMethodSelected()) { |
171 |
Instrument i = orchestraSelectWizardPage.getInstrument(); |
172 |
instr.setFilePath(i.getPath()); |
173 |
instr.setInstrumentIndex(i.getInstrumentIndex()); |
174 |
instr.setEngine(i.getEngine()); |
175 |
instr.setLoadMode(orchestraSelectWizardPage.getLoadMode()); |
176 |
} else { |
177 |
instr.setFilePath(manualSelectWizardPage.getSelectedFile()); |
178 |
instr.setInstrumentIndex(manualSelectWizardPage.getInstrumentIndex()); |
179 |
instr.setEngine(manualSelectWizardPage.getEngine()); |
180 |
instr.setLoadMode(manualSelectWizardPage.getLoadMode()); |
181 |
} |
182 |
|
183 |
int map = instrumentMappingWizardPage.getMapId(); |
184 |
int bank = instrumentMappingWizardPage.getMidiBank(); |
185 |
int prog = instrumentMappingWizardPage.getMidiProgram(); |
186 |
|
187 |
instr.setName(instrumentMappingWizardPage.getInstrumentName()); |
188 |
instr.setVolume(instrumentMappingWizardPage.getVolume()); |
189 |
|
190 |
CC.getSamplerModel().mapBackendMidiInstrument(map, bank, prog, instr); |
191 |
} |
192 |
|
193 |
public MidiInstrumentMap |
194 |
getDefaultMap() { return defaultMap; } |
195 |
|
196 |
public void |
197 |
setDefaultMap(MidiInstrumentMap map) { defaultMap = map; } |
198 |
} |
199 |
|
200 |
class InstrLocationMethodWizardPage extends UserInputPage { |
201 |
private final static String INSTR_LOCATION_METHOD = "InstrLocationMethod"; |
202 |
private final static String NEW_MIDI_INSTR_WIZARD_SKIP1 = "NewMidiInstrumentWizard.skip1"; |
203 |
|
204 |
private final JRadioButton rbManual = |
205 |
new JRadioButton(i18n.getLabel("InstrLocationMethodWizardPage.rbManual")); |
206 |
|
207 |
private final JRadioButton rbOrchestra = |
208 |
new JRadioButton(i18n.getLabel("InstrLocationMethodWizardPage.rbOrchestra")); |
209 |
|
210 |
private final JCheckBox checkSkip = |
211 |
new JCheckBox(i18n.getLabel("InstrLocationMethodWizardPage.checkSkip")); |
212 |
|
213 |
InstrLocationMethodWizardPage() { |
214 |
super(i18n.getLabel("InstrLocationMethodWizardPage.subtitle")); |
215 |
|
216 |
String s = i18n.getLabel("InstrLocationMethodWizardPage.mainInstructions"); |
217 |
setMainInstructions(s); |
218 |
|
219 |
JPanel p = new JPanel(); |
220 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
221 |
|
222 |
ButtonGroup group = new ButtonGroup(); |
223 |
group.add(rbManual); |
224 |
group.add(rbOrchestra); |
225 |
rbManual.setSelected(true); |
226 |
|
227 |
p.add(rbManual); |
228 |
p.add(rbOrchestra); |
229 |
|
230 |
JPanel p2 = new JPanel(); |
231 |
p2.setLayout(new BorderLayout()); |
232 |
p2.add(p, BorderLayout.NORTH); |
233 |
p2.add(checkSkip, BorderLayout.SOUTH); |
234 |
setMainPane(p2); |
235 |
|
236 |
switch(preferences().getIntProperty(INSTR_LOCATION_METHOD)) { |
237 |
case 0: |
238 |
rbManual.setSelected(true); |
239 |
break; |
240 |
case 1: |
241 |
rbOrchestra.setSelected(true); |
242 |
} |
243 |
|
244 |
checkSkip.setSelected(preferences().getBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1)); |
245 |
|
246 |
rbManual.addActionListener(new ActionListener() { |
247 |
public void |
248 |
actionPerformed(ActionEvent e) { |
249 |
if(rbManual.isSelected()) { |
250 |
preferences().setIntProperty(INSTR_LOCATION_METHOD, 0); |
251 |
} |
252 |
} |
253 |
}); |
254 |
|
255 |
rbOrchestra.addActionListener(new ActionListener() { |
256 |
public void |
257 |
actionPerformed(ActionEvent e) { |
258 |
if(rbOrchestra.isSelected()) { |
259 |
preferences().setIntProperty(INSTR_LOCATION_METHOD, 1); |
260 |
} |
261 |
} |
262 |
}); |
263 |
|
264 |
checkSkip.addActionListener(new ActionListener() { |
265 |
public void |
266 |
actionPerformed(ActionEvent e) { |
267 |
boolean b = checkSkip.isSelected(); |
268 |
preferences().setBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1, b); |
269 |
} |
270 |
}); |
271 |
} |
272 |
|
273 |
protected JSPrefs |
274 |
preferences() { return CC.getViewConfig().preferences(); } |
275 |
|
276 |
/** |
277 |
* Determines whether the user selected an orchestra location method. |
278 |
*/ |
279 |
public boolean |
280 |
isOrchestraMethodSelected() { return rbOrchestra.isSelected(); } |
281 |
} |
282 |
|
283 |
class OrchestraSelectWizardPage extends UserInputPage { |
284 |
private final JLabel lOrchestras = |
285 |
new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lOrchestras")); |
286 |
|
287 |
private final JLabel lInstruments = |
288 |
new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lInstruments")); |
289 |
|
290 |
private final JLabel lLoadMode = |
291 |
new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lLoadMode")); |
292 |
|
293 |
private final JComboBox cbOrchestras = new JComboBox(); |
294 |
private final JComboBox cbInstruments = new JComboBox(); |
295 |
private final JComboBox cbLoadMode = new JComboBox(); |
296 |
|
297 |
OrchestraSelectWizardPage() { |
298 |
super(i18n.getLabel("OrchestraSelectWizardPage.subtitle")); |
299 |
setMainInstructions(i18n.getLabel("OrchestraSelectWizardPage.mainInstructions")); |
300 |
|
301 |
GridBagLayout gridbag = new GridBagLayout(); |
302 |
GridBagConstraints c = new GridBagConstraints(); |
303 |
|
304 |
JPanel p = new JPanel(); |
305 |
|
306 |
p.setLayout(gridbag); |
307 |
|
308 |
c.fill = GridBagConstraints.NONE; |
309 |
|
310 |
c.gridx = 0; |
311 |
c.gridy = 0; |
312 |
c.anchor = GridBagConstraints.EAST; |
313 |
c.insets = new Insets(0, 0, 6, 16); |
314 |
gridbag.setConstraints(lOrchestras, c); |
315 |
p.add(lOrchestras); |
316 |
|
317 |
c.gridx = 0; |
318 |
c.gridy = 1; |
319 |
gridbag.setConstraints(lInstruments, c); |
320 |
p.add(lInstruments); |
321 |
|
322 |
c.gridx = 0; |
323 |
c.gridy = 2; |
324 |
c.insets = new Insets(12, 0, 6, 16); |
325 |
gridbag.setConstraints(lLoadMode, c); |
326 |
p.add(lLoadMode); |
327 |
|
328 |
c.gridx = 1; |
329 |
c.gridy = 0; |
330 |
c.weightx = 1.0; |
331 |
c.insets = new Insets(0, 0, 6, 48); |
332 |
c.fill = GridBagConstraints.HORIZONTAL; |
333 |
c.anchor = GridBagConstraints.NORTH; |
334 |
gridbag.setConstraints(cbOrchestras, c); |
335 |
p.add(cbOrchestras); |
336 |
|
337 |
c.gridx = 1; |
338 |
c.gridy = 1; |
339 |
gridbag.setConstraints(cbInstruments, c); |
340 |
p.add(cbInstruments); |
341 |
|
342 |
c.gridx = 1; |
343 |
c.gridy = 2; |
344 |
c.insets = new Insets(12, 0, 6, 48); |
345 |
gridbag.setConstraints(cbLoadMode, c); |
346 |
p.add(cbLoadMode); |
347 |
|
348 |
JPanel p2 = new JPanel(); |
349 |
p2.setOpaque(false); |
350 |
c.gridx = 0; |
351 |
c.gridy = 3; |
352 |
c.fill = GridBagConstraints.VERTICAL; |
353 |
c.weightx = 0.0; |
354 |
c.weighty = 1.0; |
355 |
gridbag.setConstraints(p2, c); |
356 |
p.add(p2); |
357 |
|
358 |
setMainPane(p); |
359 |
|
360 |
int orchIdx = |
361 |
preferences().getIntProperty("OrchestraSelectWizardPage.OrchestraIndex", 0); |
362 |
|
363 |
cbOrchestras.addActionListener(new ActionListener() { |
364 |
public void |
365 |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
366 |
}); |
367 |
|
368 |
for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) { |
369 |
cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i)); |
370 |
} |
371 |
|
372 |
if(CC.getOrchestras().getOrchestraCount() > orchIdx) { |
373 |
cbOrchestras.setSelectedIndex(orchIdx); |
374 |
} |
375 |
|
376 |
cbInstruments.addActionListener(new ActionListener() { |
377 |
public void |
378 |
actionPerformed(ActionEvent e) { instrumentChanged(); } |
379 |
}); |
380 |
|
381 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT); |
382 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
383 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
384 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
385 |
|
386 |
int i = preferences().getIntProperty("std.midiInstrument.loadMode", 0); |
387 |
if(cbLoadMode.getItemCount() > i) cbLoadMode.setSelectedIndex(i); |
388 |
|
389 |
cbLoadMode.addActionListener(new ActionListener() { |
390 |
public void |
391 |
actionPerformed(ActionEvent e) { |
392 |
int j = cbLoadMode.getSelectedIndex(); |
393 |
if(j < 0) return; |
394 |
preferences().setIntProperty("std.midiInstrument.loadMode", j); |
395 |
} |
396 |
}); |
397 |
} |
398 |
|
399 |
protected JSPrefs |
400 |
preferences() { return CC.getViewConfig().preferences(); } |
401 |
|
402 |
private void |
403 |
orchestraChanged() { |
404 |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
405 |
String s = om == null ? null : om.getDescription(); |
406 |
if(s != null && s.length() == 0) s = null; |
407 |
cbOrchestras.setToolTipText(s); |
408 |
|
409 |
s = "OrchestraSelectWizardPage.OrchestraIndex"; |
410 |
int orchIdx = cbOrchestras.getSelectedIndex(); |
411 |
if(orchIdx >= 0) preferences().setIntProperty(s, orchIdx); |
412 |
|
413 |
cbInstruments.removeAllItems(); |
414 |
if(om == null || om.getInstrumentCount() == 0) { |
415 |
cbInstruments.setEnabled(false); |
416 |
return; |
417 |
} |
418 |
|
419 |
cbInstruments.setEnabled(true); |
420 |
|
421 |
for(int i = 0; i < om.getInstrumentCount(); i++) { |
422 |
cbInstruments.addItem(om.getInstrument(i)); |
423 |
} |
424 |
} |
425 |
|
426 |
private void |
427 |
instrumentChanged() { |
428 |
Instrument instr = (Instrument)cbInstruments.getSelectedItem(); |
429 |
String s = instr == null ? null : instr.getDescription(); |
430 |
if(s != null && s.length() == 0) s = null; |
431 |
cbInstruments.setToolTipText(s); |
432 |
|
433 |
getWizard().enableNextButton(instr != null); |
434 |
} |
435 |
|
436 |
public void |
437 |
postinitPage() { |
438 |
getWizard().enableNextButton(cbInstruments.getSelectedItem() != null); |
439 |
} |
440 |
|
441 |
/** |
442 |
* Gets the selected instrument. |
443 |
*/ |
444 |
public Instrument |
445 |
getInstrument() { return (Instrument)cbInstruments.getSelectedItem(); } |
446 |
|
447 |
/** |
448 |
* Gets the selected load mode. |
449 |
*/ |
450 |
public MidiInstrumentInfo.LoadMode |
451 |
getLoadMode() { return (MidiInstrumentInfo.LoadMode) cbLoadMode.getSelectedItem(); } |
452 |
} |
453 |
|
454 |
class ManualSelectWizardPage extends UserInputPage { |
455 |
private final JLabel lFilename = |
456 |
new JLabel(i18n.getLabel("ManualSelectWizardPage.lFilename")); |
457 |
|
458 |
private final JLabel lIndex = new JLabel(i18n.getLabel("ManualSelectWizardPage.lIndex")); |
459 |
|
460 |
private final JLabel lEngine = new JLabel(i18n.getLabel("ManualSelectWizardPage.lEngine")); |
461 |
|
462 |
private final JLabel lLoadMode = |
463 |
new JLabel(i18n.getLabel("ManualSelectWizardPage.lLoadMode")); |
464 |
|
465 |
private final JComboBox cbFilename = new JComboBox(); |
466 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
467 |
|
468 |
private final JButton btnBrowse; |
469 |
|
470 |
private final JComboBox cbEngine = new JComboBox(); |
471 |
private final JComboBox cbLoadMode = new JComboBox(); |
472 |
|
473 |
ManualSelectWizardPage(ImageIcon iconBrowse) { |
474 |
super(i18n.getLabel("ManualSelectWizardPage.subtitle")); |
475 |
setMainInstructions(i18n.getLabel("ManualSelectWizardPage.mainInstructions")); |
476 |
|
477 |
GridBagLayout gridbag = new GridBagLayout(); |
478 |
GridBagConstraints c = new GridBagConstraints(); |
479 |
|
480 |
JPanel mainPane = new JPanel(); |
481 |
|
482 |
mainPane.setLayout(gridbag); |
483 |
|
484 |
c.fill = GridBagConstraints.NONE; |
485 |
|
486 |
c.gridx = 0; |
487 |
c.gridy = 0; |
488 |
c.anchor = GridBagConstraints.EAST; |
489 |
c.insets = new Insets(3, 3, 3, 3); |
490 |
gridbag.setConstraints(lFilename, c); |
491 |
mainPane.add(lFilename); |
492 |
|
493 |
c.gridx = 0; |
494 |
c.gridy = 1; |
495 |
gridbag.setConstraints(lIndex, c); |
496 |
mainPane.add(lIndex); |
497 |
|
498 |
c.gridx = 0; |
499 |
c.gridy = 2; |
500 |
c.insets = new Insets(12, 3, 3, 3); |
501 |
gridbag.setConstraints(lEngine, c); |
502 |
mainPane.add(lEngine); |
503 |
|
504 |
c.gridx = 0; |
505 |
c.gridy = 3; |
506 |
c.insets = new Insets(3, 3, 3, 3); |
507 |
gridbag.setConstraints(lLoadMode, c); |
508 |
mainPane.add(lLoadMode); |
509 |
|
510 |
btnBrowse = new JButton(iconBrowse); |
511 |
btnBrowse.setMargin(new Insets(0, 0, 0, 0)); |
512 |
btnBrowse.setToolTipText(i18n.getLabel("ManualSelectWizardPage.btnBrowse")); |
513 |
c.gridx = 2; |
514 |
c.gridy = 0; |
515 |
gridbag.setConstraints(btnBrowse, c); |
516 |
mainPane.add(btnBrowse); |
517 |
|
518 |
c.fill = GridBagConstraints.HORIZONTAL; |
519 |
c.gridx = 1; |
520 |
c.gridy = 0; |
521 |
c.weightx = 1.0; |
522 |
c.anchor = GridBagConstraints.WEST; |
523 |
gridbag.setConstraints(cbFilename, c); |
524 |
mainPane.add(cbFilename); |
525 |
|
526 |
c.gridx = 1; |
527 |
c.gridy = 1; |
528 |
gridbag.setConstraints(spinnerIndex, c); |
529 |
mainPane.add(spinnerIndex); |
530 |
|
531 |
c.gridx = 1; |
532 |
c.gridy = 2; |
533 |
c.insets = new Insets(12, 3, 3, 64); |
534 |
gridbag.setConstraints(cbEngine, c); |
535 |
mainPane.add(cbEngine); |
536 |
|
537 |
c.gridx = 1; |
538 |
c.gridy = 3; |
539 |
c.insets = new Insets(3, 3, 3, 64); |
540 |
gridbag.setConstraints(cbLoadMode, c); |
541 |
mainPane.add(cbLoadMode); |
542 |
|
543 |
JPanel p2 = new JPanel(); |
544 |
p2.setOpaque(false); |
545 |
c.gridx = 0; |
546 |
c.gridy = 4; |
547 |
c.fill = GridBagConstraints.VERTICAL; |
548 |
c.weightx = 0.0; |
549 |
c.weighty = 1.0; |
550 |
gridbag.setConstraints(p2, c); |
551 |
mainPane.add(p2); |
552 |
|
553 |
setMainPane(mainPane); |
554 |
|
555 |
cbFilename.setEditable(true); |
556 |
String[] files = preferences().getStringListProperty("recentInstrumentFiles"); |
557 |
for(String s : files) cbFilename.addItem(s); |
558 |
cbFilename.setSelectedItem(null); |
559 |
|
560 |
cbFilename.addActionListener(new ActionListener() { |
561 |
public void |
562 |
actionPerformed(ActionEvent e) { updateState(); } |
563 |
}); |
564 |
|
565 |
btnBrowse.addActionListener(new ActionListener() { |
566 |
public void |
567 |
actionPerformed(ActionEvent e) { onBrowse(); } |
568 |
}); |
569 |
|
570 |
for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e); |
571 |
|
572 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT); |
573 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
574 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
575 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
576 |
|
577 |
int i = preferences().getIntProperty("std.midiInstrument.loadMode", 0); |
578 |
if(cbLoadMode.getItemCount() > i) cbLoadMode.setSelectedIndex(i); |
579 |
|
580 |
cbLoadMode.addActionListener(new ActionListener() { |
581 |
public void |
582 |
actionPerformed(ActionEvent e) { |
583 |
int j = cbLoadMode.getSelectedIndex(); |
584 |
if(j < 0) return; |
585 |
preferences().setIntProperty("std.midiInstrument.loadMode", j); |
586 |
} |
587 |
}); |
588 |
} |
589 |
|
590 |
protected JSPrefs |
591 |
preferences() { return CC.getViewConfig().preferences(); } |
592 |
|
593 |
private void |
594 |
onBrowse() { |
595 |
String s = preferences().getStringProperty("lastInstrumentLocation"); |
596 |
JFileChooser fc = new JFileChooser(s); |
597 |
int result = fc.showOpenDialog(this); |
598 |
if(result != JFileChooser.APPROVE_OPTION) return; |
599 |
|
600 |
cbFilename.setSelectedItem(fc.getSelectedFile().getPath()); |
601 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
602 |
preferences().setStringProperty("lastInstrumentLocation", path); |
603 |
} |
604 |
|
605 |
private void |
606 |
updateState() { |
607 |
boolean b = false; |
608 |
Object o = cbFilename.getSelectedItem(); |
609 |
if(o == null) b = false; |
610 |
else b = o.toString().length() > 0; |
611 |
getWizard().enableNextButton(b); |
612 |
} |
613 |
|
614 |
public void |
615 |
postinitPage() { |
616 |
updateState(); |
617 |
} |
618 |
|
619 |
/** |
620 |
* Gets the name of the instrument file. |
621 |
* @return The name of the instrument file. |
622 |
*/ |
623 |
public String |
624 |
getSelectedFile() { return cbFilename.getSelectedItem().toString(); } |
625 |
|
626 |
/** |
627 |
* Gets the index of the instrument in the instrument file. |
628 |
* @return The index of the instrument in the instrument file. |
629 |
*/ |
630 |
public int |
631 |
getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); } |
632 |
|
633 |
/** |
634 |
* Gets the selected engine. |
635 |
*/ |
636 |
public String |
637 |
getEngine() { return ((SamplerEngine)cbEngine.getSelectedItem()).getName(); } |
638 |
|
639 |
/** |
640 |
* Gets the selected load mode. |
641 |
*/ |
642 |
public MidiInstrumentInfo.LoadMode |
643 |
getLoadMode() { return (MidiInstrumentInfo.LoadMode)cbLoadMode.getSelectedItem(); } |
644 |
|
645 |
private final Handler eventHandler = new Handler(); |
646 |
|
647 |
private Handler |
648 |
getHandler() { return eventHandler; } |
649 |
|
650 |
private class Handler implements DocumentListener { |
651 |
// DocumentListener |
652 |
public void |
653 |
insertUpdate(DocumentEvent e) { updateState(); } |
654 |
|
655 |
public void |
656 |
removeUpdate(DocumentEvent e) { updateState(); } |
657 |
|
658 |
public void |
659 |
changedUpdate(DocumentEvent e) { updateState(); } |
660 |
} |
661 |
} |
662 |
|
663 |
class InstrumentMappingWizardPage extends WizardPage { |
664 |
private final JLabel lName = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lName")); |
665 |
private final JLabel lMap = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lMap")); |
666 |
private final JLabel lBank = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lBank")); |
667 |
private final JLabel lProgram = |
668 |
new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lProgram")); |
669 |
|
670 |
private final JLabel lVolume = |
671 |
new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lVolume")); |
672 |
|
673 |
private final JTextField tfName = new JTextField(); |
674 |
private final JComboBox cbMap = new JComboBox(); |
675 |
private final JSpinner spinnerBank = new JSpinner(new SpinnerNumberModel(0, 0, 16383, 1)); |
676 |
private final JComboBox cbProgram = new JComboBox(); |
677 |
private final JSlider slVolume = new JSlider(0, 100, 100); |
678 |
|
679 |
private final NewMidiInstrumentWizardModel wizardModel; |
680 |
|
681 |
InstrumentMappingWizardPage(NewMidiInstrumentWizardModel wizardModel) { |
682 |
super(i18n.getLabel("InstrumentMappingWizardPage.subtitle")); |
683 |
this.wizardModel = wizardModel; |
684 |
|
685 |
setPageType(Type.CONFIRMATION_PAGE); |
686 |
|
687 |
GridBagLayout gridbag = new GridBagLayout(); |
688 |
GridBagConstraints c = new GridBagConstraints(); |
689 |
|
690 |
setLayout(gridbag); |
691 |
|
692 |
c.fill = GridBagConstraints.NONE; |
693 |
|
694 |
c.gridx = 0; |
695 |
c.gridy = 0; |
696 |
c.anchor = GridBagConstraints.EAST; |
697 |
c.insets = new Insets(24, 3, 3, 0); |
698 |
gridbag.setConstraints(lName, c); |
699 |
add(lName); |
700 |
|
701 |
c.gridx = 0; |
702 |
c.gridy = 2; |
703 |
c.insets = new Insets(3, 3, 3, 0); |
704 |
gridbag.setConstraints(lMap, c); |
705 |
add(lMap); |
706 |
|
707 |
c.gridx = 0; |
708 |
c.gridy = 3; |
709 |
gridbag.setConstraints(lBank, c); |
710 |
add(lBank); |
711 |
|
712 |
c.gridx = 0; |
713 |
c.gridy = 4; |
714 |
gridbag.setConstraints(lProgram, c); |
715 |
add(lProgram); |
716 |
|
717 |
c.gridx = 0; |
718 |
c.gridy = 1; |
719 |
c.insets = new Insets(3, 3, 24, 0); |
720 |
gridbag.setConstraints(lVolume, c); |
721 |
add(lVolume); |
722 |
|
723 |
c.fill = GridBagConstraints.HORIZONTAL; |
724 |
c.gridx = 1; |
725 |
c.gridy = 0; |
726 |
c.weightx = 1.0; |
727 |
c.insets = new Insets(24, 12, 3, 36); |
728 |
c.anchor = GridBagConstraints.WEST; |
729 |
gridbag.setConstraints(tfName, c); |
730 |
add(tfName); |
731 |
|
732 |
c.gridx = 1; |
733 |
c.gridy = 2; |
734 |
c.insets = new Insets(3, 12, 3, 36); |
735 |
gridbag.setConstraints(cbMap, c); |
736 |
add(cbMap); |
737 |
|
738 |
c.gridx = 1; |
739 |
c.gridy = 3; |
740 |
gridbag.setConstraints(spinnerBank, c); |
741 |
add(spinnerBank); |
742 |
|
743 |
c.gridx = 1; |
744 |
c.gridy = 4; |
745 |
gridbag.setConstraints(cbProgram, c); |
746 |
add(cbProgram); |
747 |
|
748 |
c.gridx = 1; |
749 |
c.gridy = 1; |
750 |
c.insets = new Insets(3, 12, 24, 36); |
751 |
gridbag.setConstraints(slVolume, c); |
752 |
add(slVolume); |
753 |
|
754 |
JPanel p2 = new JPanel(); |
755 |
p2.setOpaque(false); |
756 |
c.gridx = 0; |
757 |
c.gridy = 5; |
758 |
c.insets = new Insets(0, 0, 0, 0); |
759 |
c.fill = GridBagConstraints.VERTICAL; |
760 |
c.weightx = 0.0; |
761 |
c.weighty = 1.0; |
762 |
gridbag.setConstraints(p2, c); |
763 |
add(p2); |
764 |
|
765 |
cbMap.addActionListener(new ActionListener() { |
766 |
public void |
767 |
actionPerformed(ActionEvent e) { updateState(); } |
768 |
}); |
769 |
|
770 |
for(MidiInstrumentMap m : CC.getSamplerModel().getMidiInstrumentMaps()) { |
771 |
cbMap.addItem(m); |
772 |
} |
773 |
|
774 |
tfName.getDocument().addDocumentListener(getHandler()); |
775 |
|
776 |
cbMap.setEnabled(cbMap.getItemCount() > 0); |
777 |
|
778 |
|
779 |
for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i)); |
780 |
|
781 |
cbMap.addActionListener(new ActionListener() { |
782 |
public void |
783 |
actionPerformed(ActionEvent e) { updateMapping(); } |
784 |
}); |
785 |
|
786 |
updateMapping(); |
787 |
} |
788 |
|
789 |
protected JSPrefs |
790 |
preferences() { return CC.getViewConfig().preferences(); } |
791 |
|
792 |
private void |
793 |
updateState() { |
794 |
cbMap.setEnabled(cbMap.getItemCount() > 0); |
795 |
boolean b = cbMap.getSelectedItem() != null; |
796 |
spinnerBank.setEnabled(b); |
797 |
cbProgram.setEnabled(b); |
798 |
|
799 |
b = tfName.getText().length() > 0 && cbMap.getSelectedItem() != null; |
800 |
b = b && cbProgram.getSelectedItem() != null; |
801 |
if(getWizard() != null) getWizard().enableFinishButton(b); |
802 |
} |
803 |
|
804 |
private void |
805 |
updateMapping() { |
806 |
if(cbMap.getSelectedItem() == null) return; |
807 |
MidiInstrumentMap map = (MidiInstrumentMap)cbMap.getSelectedItem(); |
808 |
MidiInstrumentEntry entry = map.getAvailableEntry(); |
809 |
if(entry == null) return; |
810 |
spinnerBank.setValue(entry.getMidiBank()); |
811 |
cbProgram.setSelectedIndex(entry.getMidiProgram()); |
812 |
} |
813 |
|
814 |
public void |
815 |
postinitPage() { |
816 |
String s = wizardModel.getInstrumentName(); |
817 |
if(s != null) tfName.setText(s); |
818 |
if(wizardModel.getDefaultMap() != null) { |
819 |
cbMap.setSelectedItem(wizardModel.getDefaultMap()); |
820 |
} |
821 |
updateState(); |
822 |
} |
823 |
|
824 |
/** |
825 |
* Invoked when the user clicks the 'Finish' button |
826 |
* while this page is the current page of the wizard. |
827 |
* @return <code>true</code> |
828 |
*/ |
829 |
public boolean |
830 |
mayFinish() { |
831 |
((NewMidiInstrumentWizardModel)getWizardModel()).mapInstrument(); |
832 |
preferences().setIntProperty("lastUsedMidiBank", getMidiBank()); |
833 |
return true; |
834 |
} |
835 |
|
836 |
/** |
837 |
* Gets the ID of the selected MIDI instrument map. |
838 |
*/ |
839 |
public int |
840 |
getMapId() { return ((MidiInstrumentMap)cbMap.getSelectedItem()).getMapId(); } |
841 |
|
842 |
/** |
843 |
* Gets the selected MIDI bank. |
844 |
*/ |
845 |
public int |
846 |
getMidiBank() { return Integer.parseInt(spinnerBank.getValue().toString()); } |
847 |
|
848 |
/** |
849 |
* Gets the selected MIDI program. |
850 |
*/ |
851 |
public int |
852 |
getMidiProgram() { return cbProgram.getSelectedIndex(); } |
853 |
|
854 |
/** |
855 |
* Gets the chosen name for the new MIDI instrument. |
856 |
* @return The chosen name for the new MIDI instrument. |
857 |
*/ |
858 |
public String |
859 |
getInstrumentName() { return tfName.getText(); } |
860 |
|
861 |
/** |
862 |
* Returns the volume level of the new MIDI instrument. |
863 |
* @return The volume level of the new MIDI instrument. |
864 |
*/ |
865 |
public float |
866 |
getVolume() { |
867 |
float f = slVolume.getValue(); |
868 |
f /= 100; |
869 |
return f; |
870 |
} |
871 |
|
872 |
private final Handler eventHandler = new Handler(); |
873 |
|
874 |
private Handler |
875 |
getHandler() { return eventHandler; } |
876 |
|
877 |
private class Handler implements DocumentListener { |
878 |
// DocumentListener |
879 |
public void |
880 |
insertUpdate(DocumentEvent e) { updateState(); } |
881 |
|
882 |
public void |
883 |
removeUpdate(DocumentEvent e) { updateState(); } |
884 |
|
885 |
public void |
886 |
changedUpdate(DocumentEvent e) { updateState(); } |
887 |
} |
888 |
} |