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