/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSNewMidiInstrumentWizard.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/std/JSNewMidiInstrumentWizard.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1286 by iliev, Fri Aug 10 20:24:23 2007 UTC revision 1329 by iliev, Sat Sep 8 18:33:05 2007 UTC
# Line 62  import org.jsampler.JSPrefs; Line 62  import org.jsampler.JSPrefs;
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    
# Line 73  import static org.jsampler.view.std.StdI Line 74  import static org.jsampler.view.std.StdI
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  }  }
# Line 91  class NewMidiInstrumentWizardModel exten Line 99  class NewMidiInstrumentWizardModel exten
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"));
# Line 108  class NewMidiInstrumentWizardModel exten Line 119  class NewMidiInstrumentWizardModel exten
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           */           */
# Line 170  class NewMidiInstrumentWizardModel exten Line 189  class NewMidiInstrumentWizardModel exten
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 {
# Line 185  class InstrLocationMethodWizardPage exte Line 210  class InstrLocationMethodWizardPage exte
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");
# Line 208  class InstrLocationMethodWizardPage exte Line 233  class InstrLocationMethodWizardPage exte
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;
# Line 216  class InstrLocationMethodWizardPage exte Line 241  class InstrLocationMethodWizardPage exte
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                  });                  });
# Line 231  class InstrLocationMethodWizardPage exte Line 256  class InstrLocationMethodWizardPage exte
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                  });                  });
# Line 240  class InstrLocationMethodWizardPage exte Line 265  class InstrLocationMethodWizardPage exte
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           */           */
# Line 329  class OrchestraSelectWizardPage extends Line 357  class OrchestraSelectWizardPage extends
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(); }
# Line 338  class OrchestraSelectWizardPage extends Line 369  class OrchestraSelectWizardPage extends
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(); }
# Line 347  class OrchestraSelectWizardPage extends Line 382  class OrchestraSelectWizardPage extends
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();
# Line 356  class OrchestraSelectWizardPage extends Line 406  class OrchestraSelectWizardPage extends
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);
# Line 408  class ManualSelectWizardPage extends Use Line 462  class ManualSelectWizardPage extends Use
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;
# Line 466  class ManualSelectWizardPage extends Use Line 520  class ManualSelectWizardPage extends Use
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;
# Line 498  class ManualSelectWizardPage extends Use Line 552  class ManualSelectWizardPage extends Use
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
# Line 511  class ManualSelectWizardPage extends Use Line 573  class ManualSelectWizardPage extends Use
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() {
# Line 535  class ManualSelectWizardPage extends Use Line 621  class ManualSelectWizardPage extends Use
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.
# Line 590  class InstrumentMappingWizardPage extend Line 676  class InstrumentMappingWizardPage extend
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();
# Line 687  class InstrumentMappingWizardPage extend Line 777  class InstrumentMappingWizardPage extend
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);
# Line 701  class InstrumentMappingWizardPage extend Line 801  class InstrumentMappingWizardPage extend
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                    
# Line 714  class InstrumentMappingWizardPage extend Line 829  class InstrumentMappingWizardPage extend
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                    

Legend:
Removed from v.1286  
changed lines
  Added in v.1329

  ViewVC Help
Powered by ViewVC