62 |
import org.jsampler.MidiInstrumentMap; |
import org.jsampler.MidiInstrumentMap; |
63 |
import org.jsampler.OrchestraModel; |
import org.jsampler.OrchestraModel; |
64 |
|
|
65 |
|
import org.linuxsampler.lscp.MidiInstrumentEntry; |
66 |
import org.linuxsampler.lscp.MidiInstrumentInfo; |
import org.linuxsampler.lscp.MidiInstrumentInfo; |
67 |
import org.linuxsampler.lscp.SamplerEngine; |
import org.linuxsampler.lscp.SamplerEngine; |
68 |
|
|
74 |
* @author Grigor Iliev |
* @author Grigor Iliev |
75 |
*/ |
*/ |
76 |
public class JSNewMidiInstrumentWizard extends Wizard { |
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>. |
* Creates a new instance of <code>JSNewMidiInstrumentWizard</code>. |
87 |
*/ |
*/ |
88 |
public |
public |
89 |
JSNewMidiInstrumentWizard(JSPrefs prefs, ImageIcon iconBrowse) { |
JSNewMidiInstrumentWizard(ImageIcon iconBrowse, MidiInstrumentMap defaultMap) { |
90 |
super(CC.getMainFrame(), i18n.getLabel("JSNewMidiInstrumentWizard.title")); |
super(CC.getMainFrame(), i18n.getLabel("JSNewMidiInstrumentWizard.title")); |
91 |
setModel(new NewMidiInstrumentWizardModel(prefs, iconBrowse)); |
setModel(new NewMidiInstrumentWizardModel(iconBrowse, defaultMap)); |
92 |
} |
} |
93 |
|
|
94 |
} |
} |
99 |
private final ManualSelectWizardPage manualSelectWizardPage; |
private final ManualSelectWizardPage manualSelectWizardPage; |
100 |
private final InstrumentMappingWizardPage instrumentMappingWizardPage; |
private final InstrumentMappingWizardPage instrumentMappingWizardPage; |
101 |
|
|
102 |
NewMidiInstrumentWizardModel(JSPrefs prefs, ImageIcon iconBrowse) { |
private MidiInstrumentMap defaultMap; |
103 |
instrLocationMethodWizardPage = new InstrLocationMethodWizardPage(prefs); |
|
104 |
|
NewMidiInstrumentWizardModel(ImageIcon iconBrowse, MidiInstrumentMap defaultMap) { |
105 |
|
this.defaultMap = defaultMap; |
106 |
|
instrLocationMethodWizardPage = new InstrLocationMethodWizardPage(); |
107 |
orchestraSelectWizardPage = new OrchestraSelectWizardPage(); |
orchestraSelectWizardPage = new OrchestraSelectWizardPage(); |
108 |
manualSelectWizardPage = new ManualSelectWizardPage(iconBrowse); |
manualSelectWizardPage = new ManualSelectWizardPage(iconBrowse); |
109 |
instrumentMappingWizardPage = new InstrumentMappingWizardPage(); |
instrumentMappingWizardPage = new InstrumentMappingWizardPage(this); |
110 |
|
|
111 |
addPage(instrLocationMethodWizardPage); |
addPage(instrLocationMethodWizardPage); |
112 |
addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step1")); |
addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step1")); |
119 |
addStep(i18n.getLabel("JSNewMidiInstrumentWizard.step3")); |
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. |
* Moves to the next page in the wizard. |
132 |
* @return The next page in the wizard. |
* @return The next page in the wizard. |
133 |
*/ |
*/ |
189 |
|
|
190 |
CC.getSamplerModel().mapBackendMidiInstrument(map, bank, prog, instr); |
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 { |
class InstrLocationMethodWizardPage extends UserInputPage { |
210 |
private final JCheckBox checkSkip = |
private final JCheckBox checkSkip = |
211 |
new JCheckBox(i18n.getLabel("InstrLocationMethodWizardPage.checkSkip")); |
new JCheckBox(i18n.getLabel("InstrLocationMethodWizardPage.checkSkip")); |
212 |
|
|
213 |
InstrLocationMethodWizardPage(final JSPrefs prefs) { |
InstrLocationMethodWizardPage() { |
214 |
super(i18n.getLabel("InstrLocationMethodWizardPage.subtitle")); |
super(i18n.getLabel("InstrLocationMethodWizardPage.subtitle")); |
215 |
|
|
216 |
String s = i18n.getLabel("InstrLocationMethodWizardPage.mainInstructions"); |
String s = i18n.getLabel("InstrLocationMethodWizardPage.mainInstructions"); |
233 |
p2.add(checkSkip, BorderLayout.SOUTH); |
p2.add(checkSkip, BorderLayout.SOUTH); |
234 |
setMainPane(p2); |
setMainPane(p2); |
235 |
|
|
236 |
switch(prefs.getIntProperty(INSTR_LOCATION_METHOD)) { |
switch(preferences().getIntProperty(INSTR_LOCATION_METHOD)) { |
237 |
case 0: |
case 0: |
238 |
rbManual.setSelected(true); |
rbManual.setSelected(true); |
239 |
break; |
break; |
241 |
rbOrchestra.setSelected(true); |
rbOrchestra.setSelected(true); |
242 |
} |
} |
243 |
|
|
244 |
checkSkip.setSelected(prefs.getBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1)); |
checkSkip.setSelected(preferences().getBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1)); |
245 |
|
|
246 |
rbManual.addActionListener(new ActionListener() { |
rbManual.addActionListener(new ActionListener() { |
247 |
public void |
public void |
248 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
249 |
if(rbManual.isSelected()) { |
if(rbManual.isSelected()) { |
250 |
prefs.setIntProperty(INSTR_LOCATION_METHOD, 0); |
preferences().setIntProperty(INSTR_LOCATION_METHOD, 0); |
251 |
} |
} |
252 |
} |
} |
253 |
}); |
}); |
256 |
public void |
public void |
257 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
258 |
if(rbOrchestra.isSelected()) { |
if(rbOrchestra.isSelected()) { |
259 |
prefs.setIntProperty(INSTR_LOCATION_METHOD, 1); |
preferences().setIntProperty(INSTR_LOCATION_METHOD, 1); |
260 |
} |
} |
261 |
} |
} |
262 |
}); |
}); |
265 |
public void |
public void |
266 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
267 |
boolean b = checkSkip.isSelected(); |
boolean b = checkSkip.isSelected(); |
268 |
prefs.setBoolProperty(NEW_MIDI_INSTR_WIZARD_SKIP1, b); |
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. |
* Determines whether the user selected an orchestra location method. |
278 |
*/ |
*/ |
357 |
|
|
358 |
setMainPane(p); |
setMainPane(p); |
359 |
|
|
360 |
|
int orchIdx = |
361 |
|
preferences().getIntProperty("OrchestraSelectWizardPage.OrchestraIndex", 0); |
362 |
|
|
363 |
cbOrchestras.addActionListener(new ActionListener() { |
cbOrchestras.addActionListener(new ActionListener() { |
364 |
public void |
public void |
365 |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
369 |
cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i)); |
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() { |
cbInstruments.addActionListener(new ActionListener() { |
377 |
public void |
public void |
378 |
actionPerformed(ActionEvent e) { instrumentChanged(); } |
actionPerformed(ActionEvent e) { instrumentChanged(); } |
382 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
383 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
384 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
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 |
private void |
403 |
orchestraChanged() { |
orchestraChanged() { |
404 |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
406 |
if(s != null && s.length() == 0) s = null; |
if(s != null && s.length() == 0) s = null; |
407 |
cbOrchestras.setToolTipText(s); |
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(); |
cbInstruments.removeAllItems(); |
414 |
if(om == null || om.getInstrumentCount() == 0) { |
if(om == null || om.getInstrumentCount() == 0) { |
415 |
cbInstruments.setEnabled(false); |
cbInstruments.setEnabled(false); |
462 |
private final JLabel lLoadMode = |
private final JLabel lLoadMode = |
463 |
new JLabel(i18n.getLabel("ManualSelectWizardPage.lLoadMode")); |
new JLabel(i18n.getLabel("ManualSelectWizardPage.lLoadMode")); |
464 |
|
|
465 |
private final JTextField tfFilename = new JTextField(); |
private final JComboBox cbFilename = new JComboBox(); |
466 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
467 |
|
|
468 |
private final JButton btnBrowse; |
private final JButton btnBrowse; |
520 |
c.gridy = 0; |
c.gridy = 0; |
521 |
c.weightx = 1.0; |
c.weightx = 1.0; |
522 |
c.anchor = GridBagConstraints.WEST; |
c.anchor = GridBagConstraints.WEST; |
523 |
gridbag.setConstraints(tfFilename, c); |
gridbag.setConstraints(cbFilename, c); |
524 |
mainPane.add(tfFilename); |
mainPane.add(cbFilename); |
525 |
|
|
526 |
c.gridx = 1; |
c.gridx = 1; |
527 |
c.gridy = 1; |
c.gridy = 1; |
552 |
|
|
553 |
setMainPane(mainPane); |
setMainPane(mainPane); |
554 |
|
|
555 |
tfFilename.getDocument().addDocumentListener(getHandler()); |
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() { |
btnBrowse.addActionListener(new ActionListener() { |
566 |
public void |
public void |
573 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
574 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
575 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
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 |
private void |
594 |
onBrowse() { |
onBrowse() { |
595 |
JFileChooser fc = new JFileChooser(); |
String s = preferences().getStringProperty("lastInstrumentLocation"); |
596 |
|
JFileChooser fc = new JFileChooser(s); |
597 |
int result = fc.showOpenDialog(this); |
int result = fc.showOpenDialog(this); |
598 |
if(result == JFileChooser.APPROVE_OPTION) { |
if(result != JFileChooser.APPROVE_OPTION) return; |
599 |
tfFilename.setText(fc.getSelectedFile().getPath()); |
|
600 |
} |
cbFilename.setSelectedItem(fc.getSelectedFile().getPath()); |
601 |
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
602 |
|
preferences().setStringProperty("lastInstrumentLocation", path); |
603 |
} |
} |
604 |
|
|
605 |
private void |
private void |
606 |
updateState() { getWizard().enableNextButton(tfFilename.getText().length() != 0); } |
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 |
public void |
615 |
postinitPage() { |
postinitPage() { |
621 |
* @return The name of the instrument file. |
* @return The name of the instrument file. |
622 |
*/ |
*/ |
623 |
public String |
public String |
624 |
getSelectedFile() { return tfFilename.getText(); } |
getSelectedFile() { return cbFilename.getSelectedItem().toString(); } |
625 |
|
|
626 |
/** |
/** |
627 |
* Gets the index of the instrument in the instrument file. |
* Gets the index of the instrument in the instrument file. |
676 |
private final JComboBox cbProgram = new JComboBox(); |
private final JComboBox cbProgram = new JComboBox(); |
677 |
private final JSlider slVolume = new JSlider(0, 100, 100); |
private final JSlider slVolume = new JSlider(0, 100, 100); |
678 |
|
|
679 |
InstrumentMappingWizardPage() { |
private final NewMidiInstrumentWizardModel wizardModel; |
680 |
|
|
681 |
|
InstrumentMappingWizardPage(NewMidiInstrumentWizardModel wizardModel) { |
682 |
super(i18n.getLabel("InstrumentMappingWizardPage.subtitle")); |
super(i18n.getLabel("InstrumentMappingWizardPage.subtitle")); |
683 |
|
this.wizardModel = wizardModel; |
684 |
|
|
685 |
setPageType(Type.CONFIRMATION_PAGE); |
setPageType(Type.CONFIRMATION_PAGE); |
686 |
|
|
687 |
GridBagLayout gridbag = new GridBagLayout(); |
GridBagLayout gridbag = new GridBagLayout(); |
777 |
|
|
778 |
|
|
779 |
for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i)); |
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 |
private void |
793 |
updateState() { |
updateState() { |
794 |
cbMap.setEnabled(cbMap.getItemCount() > 0); |
cbMap.setEnabled(cbMap.getItemCount() > 0); |
801 |
if(getWizard() != null) getWizard().enableFinishButton(b); |
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 |
public void |
815 |
postinitPage() { |
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(); |
updateState(); |
822 |
} |
} |
823 |
|
|
829 |
public boolean |
public boolean |
830 |
mayFinish() { |
mayFinish() { |
831 |
((NewMidiInstrumentWizardModel)getWizardModel()).mapInstrument(); |
((NewMidiInstrumentWizardModel)getWizardModel()).mapInstrument(); |
832 |
|
preferences().setIntProperty("lastUsedMidiBank", getMidiBank()); |
833 |
return true; |
return true; |
834 |
} |
} |
835 |
|
|