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