/*
* Created on 17-dic-2005
*
* TODO To change the template for this generated file go to Window -
* Preferences - Java - Code Style - Code Templates
*/
package org.herac.tuxguitar.gui.actions.effects;
import org.eclipse.swt.events.TypedEvent;
import org.herac.tuxguitar.gui.TuxGuitar;
import org.herac.tuxguitar.gui.actions.Action;
import org.herac.tuxguitar.gui.editors.tab.Caret;
import org.herac.tuxguitar.gui.editors.tab.TGNoteImpl;
import org.herac.tuxguitar.gui.undo.undoables.measure.UndoableMeasureGeneric;
import org.herac.tuxguitar.song.models.TGDuration;
import org.herac.tuxguitar.song.models.TGNote;
/**
* @author julian
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ChangeDeadNoteAction extends Action {
public static final String NAME = "action.note.effect.change-dead";
public ChangeDeadNoteAction() {
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING
| KEY_BINDING_AVAILABLE);
}
@Override
protected int execute(TypedEvent e) {
// comienza el undoable
UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
Caret caret = getEditor().getTablature().getCaret();
TGNote note = caret.getSelectedNote();
if (note == null) {
note = new TGNoteImpl();
note.setValue(0);
note.setVelocity(caret.getVelocity());
note.setString(caret.getSelectedString().getNumber());
TGDuration duration = caret.getDuration().clone();
getSongManager().getMeasureManager().addNote(caret.getMeasure(),
caret.getPosition(), note, duration, caret.getVoice());
}
getSongManager().getMeasureManager().changeDeadNote(note);
TuxGuitar.instance().getFileHistory().setUnsavedFile();
updateTablature();
// termia el undoable
addUndoableEdit(undoable.endUndo());
return 0;
}
@Override
public void updateTablature() {
fireUpdate(getEditor().getTablature().getCaret().getMeasure().getNumber());
}
}