/** * Shows a dialog that enables the user to select audio input devices. * * @param multipleSelectionAllowed if <code>true</code>, indicates that more than one output * device can be selected. * @return The selected <code>AudioDeviceDescriptor</code>s as an array, or <code>null</code> if * the dialog was cancelled. */ public static AudioDeviceDescriptor[] showSelectAudioInputDeviceDialog( boolean multipleSelectionAllowed) { JList list = new JList( SgEngine.getInstance() .getProperties() .getAudioInputDeviceList() .getDeviceDescriptors()); list.setSelectionMode( multipleSelectionAllowed ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION); Object[] message = new Object[] {new JScrollPane(list)}; int option = JOptionPane.showConfirmDialog( getMainFrame(), message, SgEngine.getInstance().getResourceBundle().getString("device.select.input.audio"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION) { Object[] o = list.getSelectedValues(); AudioDeviceDescriptor[] result = new AudioDeviceDescriptor[o.length]; for (int i = 0; i < o.length; i++) { result[i] = (AudioDeviceDescriptor) o[i]; } return result; } return null; }
/** * Shows an edit midi event dialog. * * @param event The events to be edited. * @return <code>true</code> if the dialog has been shown. */ public static boolean showEditShortMessageEventDialog( MidiEvent event, TrackProxy track, MidiDescriptor midiDescriptor) { MidiEditPanel mep = new MidiEditPanel( track, event, SgEngine.getInstance().getResourceBundle().getString("midi.event.edit.event")); Object[] message = new Object[] {mep}; int option = JOptionPane.showConfirmDialog( getMainFrame(), message, SgEngine.getInstance().getResourceBundle().getString("midi.event.edit.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION && mep.hasChanged()) { try { // create change edit and perform changes Object changeObj = new Object(); ChangeEventsEdit edit = new ChangeEventsEdit(track, new MidiEvent[] {event}, midiDescriptor, null, changeObj); mep.applyChanges(changeObj); edit.perform(); midiDescriptor.getUndoManager().addEdit(edit); } catch (InvalidMidiDataException imdex) { JOptionPane.showMessageDialog( getMainFrame(), imdex.getMessage(), SgEngine.getInstance().getResourceBundle().getString("error.invalidMidiData"), JOptionPane.ERROR_MESSAGE); } } return true; }
/** * Shows a dialog that allows the user to select an Audio Unit from list that displays all * AudioUnits that are available in the system. * * @param preSelection The pre-selected element. * @return An <code>AudioUnitDescriptor</code> if the user selcted one, or <code>null</code> if * the user selected none or cancelled the dialog. */ public static AudioUnitDescriptor showSelectAudioUnitDialog(AudioUnitDescriptor preSelection) { AudioUnitDescriptor[] audioUnits = AUContainer.getInstance().getAllAudioUnitDescriptors(); AuItem[] items = new AuItem[audioUnits.length]; AuItem sel = null; for (int i = 0; i < audioUnits.length; i++) { items[i] = new AuItem(audioUnits[i]); if (audioUnits[i] == preSelection) { sel = items[i]; } } JList list = new JList(items); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (sel != null) { list.setSelectedValue(sel, true); } Object[] message = new Object[] {new JScrollPane(list)}; int option = JOptionPane.showConfirmDialog( getMainFrame(), message, SgEngine.getInstance().getResourceBundle().getString("audiounit.select"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION) { Object[] o = list.getSelectedValues(); if (o != null && o.length > 0) { AudioUnitDescriptor result = ((AuItem) o[0]).audioUnit; return result; } } return null; }
/** * Shows a dialog that allows the user to select a VST plugin from list that displays all * VSTPlugins that are available in the system. * * @param preSelection The pre-selected element. * @return A <code>VstPlugin</code> if the user selcted one, or <code>null</code> if the user * selected none or cancelled the dialog. */ public static VstPluginDescriptor showSelectVstPluginDialog(VstPluginDescriptor preSelection) { VstPluginDescriptor[] vstPlugins = VstContainer.getInstance().getAllVstPluginDescriptors(); VstItem[] items = new VstItem[vstPlugins.length]; VstItem sel = null; for (int i = 0; i < vstPlugins.length; i++) { items[i] = new VstItem(vstPlugins[i]); if (vstPlugins[i] == preSelection) { sel = items[i]; } } JList list = new JList(items); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (sel != null) { list.setSelectedValue(sel, true); } Object[] message = new Object[] {new JScrollPane(list)}; int option = JOptionPane.showConfirmDialog( getMainFrame(), message, SgEngine.getInstance().getResourceBundle().getString("vstplugin.select"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION) { Object[] o = list.getSelectedValues(); if (o != null && o.length > 0) { VstPluginDescriptor result = ((VstItem) o[0]).vstPlugin; return result; } } return null; }
/** * Gets a <code>KeyStroke</code> for the given resource key. * * @param resourceKey The key to the keystroke value in the resource bundle. A keystroke resource * value shall have the format <code>keystroke "|" alternat_keystroke</code>, e.g. <code> * ctrl c | meta c</code> * @return The corresponding <code>KeyStroke</code>. If an alternate keystroke is defined, it will * be returned on Mac systems. */ public static KeyStroke getKeyStroke(String resourceKey) { String s = SgEngine.getInstance().getResourceBundle().getString(resourceKey); if (s != null) { StringTokenizer st = new StringTokenizer(s, "|"); String key = st.nextToken(); if (isMacOs() && st.hasMoreTokens()) { return KeyStroke.getKeyStroke(st.nextToken().trim()); } return KeyStroke.getKeyStroke(key.trim()); } return null; }
/** * Shows a dialog where the user can input an audio format based on the given default format. * * @param format The default format. <code>null</code> indicates that the SoundsGood default audio * format shall be used. * @return The adjusted audio format, or <code>null</code> if the user canceled the dialog. */ public static AudioFormat showAudioFormatDialog(AudioFormat format) { AudioFormatPanel p = new AudioFormatPanel(format); int option = JOptionPane.showConfirmDialog( getMainFrame(), p, SgEngine.getInstance().getResourceBundle().getString("audio.format"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION) { return p.getAudioFormat(); } return null; }
/** * Displays a dialog that allows the user to set the number of repeatings of the given MIDI note * on the given MIDI track. If the user confirms, an undoable edit is created and added to the * provided <code>MidiDescriptor</code>'s <code>UndoManager</code>. * * @param midiDescriptor The <code>MidiDescriptor</code>. * @param track The MIDI track. It is assumed that this track belongs to the given <code> * MidiDescriptor</code>'s <code>SgMidiSequence</code>. * @param events The events that describe the note to be repeated. It is assumed that these events * belong to the given MIDI track. */ public static void showRepeatNoteDialog( MidiDescriptor midiDescriptor, TrackProxy track, MidiEvent[] events) { ResourceBundle rb = SgEngine.getInstance().getResourceBundle(); SgMidiSequence sequence = null; try { sequence = midiDescriptor.getSequence(); } catch (InvalidMidiDataException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (sequence == null) { return; } RepeatNotePanel repeatNotePanel = new RepeatNotePanel(1, 4); Object[] message = new Object[] { repeatNotePanel, }; int option = JOptionPane.showConfirmDialog( getMainFrame(), message, rb.getString("midi.note.repeat.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION) { int tactCount = repeatNotePanel.getTactCountValue(); int countPerTact = repeatNotePanel.getCountPerTactValue(); MidiEvent[] addedEvents = MidiToolkit.repeatEvents(sequence, events, countPerTact, tactCount); AddEventsEdit undoableEdit = new AddEventsEdit( track, addedEvents, midiDescriptor, rb.getString("edit.repeatEventsEdit"), UiToolkit.class); undoableEdit.perform(); midiDescriptor.getUndoManager().addEdit(undoableEdit); } }
/** * Displays a dialog where the user can set the tempo (in BPM or MPQ). * * @param midiDescriptor The <code>MidiDescriptor</code> for which the tempo is to be changed. * Must not be <code>null</code>. * @param tick The tick position where the tempo shall be set. Default is 0 (track tempo). */ public static void showSetTempoDialog(MidiDescriptor midiDescriptor, long tick) { ResourceBundle rb = SgEngine.getInstance().getResourceBundle(); SgMidiSequence seq = null; try { seq = midiDescriptor.getSequence(); } catch (InvalidMidiDataException e) { } catch (IOException e) { } if (seq == null) { return; } TrackProxy[] tracks = seq.getTrackProxies(); MidiEvent event = null; TrackProxy track = null; for (int i = 0; event == null && i < tracks.length; i++) { event = tracks[i].getTempoEvent(); track = tracks[i]; } if (event == null) { int option = JOptionPane.showConfirmDialog( getMainFrame(), rb.getString("midi.tempo.noTempoSet.message"), rb.getString("midi.tempo.noTempoSet.title"), JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE); if (option == JOptionPane.YES_OPTION) { TrackProxy tempTrack = null; try { tempTrack = midiDescriptor.getSequence().getSelectedTrackProxy(); } catch (InvalidMidiDataException e) { } catch (IOException e) { } if (tempTrack != null) { track = tempTrack; float mpq = MidiToolkit.bpmToMPQ(SgEngine.getInstance().getProperties().getDefaultMidiTempo()); event = MidiToolkit.createTempoEvent(mpq); final MidiDescriptor descriptor = midiDescriptor; AddEventsEdit edit = new AddEventsEdit( track, new MidiEvent[] {event}, midiDescriptor, rb.getString("midi.tempo.addTempoEvent"), UiToolkit.class) { private static final long serialVersionUID = 1; public void perform() { super.perform(); float mpq = MidiToolkit.getTempoInMPQ((MetaMessage) events[0].getMessage()); descriptor.setTempoInMpq(mpq); } public void undo() { super.undo(); descriptor.setTempoInMpq(-1); } }; edit.perform(); midiDescriptor.getUndoManager().addEdit(edit); } } } if (event != null) { float mpq = MidiToolkit.getTempoInMPQ((MetaMessage) event.getMessage()); final SetTempoPanel tempoPanel = new SetTempoPanel(mpq); Object[] message = new Object[] { tempoPanel, }; JOptionPane pane = new JOptionPane( message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, tempoPanel); JDialog d = pane.createDialog(UiToolkit.getMainFrame(), rb.getString("midi.tempo.title")); d.addComponentListener( new ComponentAdapter() { public void componentShown(ComponentEvent e) { tempoPanel.requestFocus(); } }); d.setVisible(true); Integer selectedValue = (Integer) pane.getValue(); if (selectedValue != null && selectedValue.intValue() == JOptionPane.OK_OPTION && tempoPanel.hasChanged()) { // TODO: improve this! float mpqVal = tempoPanel.getMPQValue(); ChangeTempoEdit undoableEdit = new ChangeTempoEdit(midiDescriptor, track, event, mpqVal, UiToolkit.class); undoableEdit.perform(); midiDescriptor.getUndoManager().addEdit(undoableEdit); } } }
/** * Displays a dialog that allows the user to edit the name of the given MIDI track. * * @param changeObj The change object for the undoable edit that is automatically created. * @param midiDescriptor The MIDI descriptor containing the sequence that contains the given * track. * @param track The track. * @param parent The component that shall be the parent of the created dialog. * @return The new track name, or <code>null</code> if the user chose not to set a track name at * all or aborted the dialog. */ public static String showEditTrackNameDialog( Object changeObj, MidiDescriptor midiDescriptor, TrackProxy track, Component parent) { if (track == null) { return null; } String trackName = track.getTrackName(); JCheckBox cb = new JCheckBox( SgEngine.getInstance() .getResourceBundle() .getString("midi.track.editTrackName.storeNameInTrack"), (trackName != null)); cb.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JComponent c = (JComponent) e.getSource(); c = (JComponent) c.getParent(); Component[] comps = ((JComponent) c.getParent()).getComponents(); for (int i = 0; i < comps.length; i++) { if (comps[i] instanceof JPanel && comps[i] != c) { if (((JPanel) comps[i]).getComponent(0) instanceof JTextField) { ((JTextField) ((JPanel) comps[i]).getComponent(0)) .setEnabled(((JCheckBox) e.getSource()).isSelected()); } } } } }); JPanel panel = new JPanel(new BorderLayout()); JPanel cbPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); cbPanel.add(cb); cbPanel.setBorder( new TitledBorder( SgEngine.getInstance() .getResourceBundle() .getString("midi.track.editTrackName.setName"))); panel.add(cbPanel, BorderLayout.NORTH); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); JTextField textField = new JTextField((trackName != null ? trackName : ""), 30); textField.setEnabled(cb.isSelected()); textField.selectAll(); p.add(textField); p.setBorder( new TitledBorder( SgEngine.getInstance() .getResourceBundle() .getString("midi.track.editTrackName.trackName"))); panel.add(p); Object[] message = new Object[] { panel, }; int option = JOptionPane.showConfirmDialog( parent, message, SgEngine.getInstance().getResourceBundle().getString("midi.track.editTrackName.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if (option == JOptionPane.OK_OPTION) { String name; if (cb.isSelected()) { name = textField.getText(); } else { name = null; } if (name == null && trackName == null || name != null && name.equals(trackName)) { System.out.println("track name left unchanged!"); // nothing to do... } else { ChangeTrackNameEdit edit = new ChangeTrackNameEdit(track, name, midiDescriptor, changeObj); edit.perform(); midiDescriptor.getUndoManager().addEdit(edit); return name; } } return null; }