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