/** * 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); } } }