2
* Created on 17-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.actions.note;
9
import java.util.Iterator;
11
import org.eclipse.swt.events.TypedEvent;
12
import org.herac.tuxguitar.gui.TuxGuitar;
13
import org.herac.tuxguitar.gui.actions.Action;
14
import org.herac.tuxguitar.gui.editors.tab.Caret;
15
import org.herac.tuxguitar.gui.undo.undoables.measure.UndoableMeasureGeneric;
16
import org.herac.tuxguitar.song.models.TGBeat;
17
import org.herac.tuxguitar.song.models.TGDuration;
18
import org.herac.tuxguitar.song.models.TGMeasure;
19
import org.herac.tuxguitar.song.models.TGNote;
24
* TODO To change the template for this generated type comment go to
25
* Window - Preferences - Java - Code Style - Code Templates
27
public class ChangeTiedNoteAction extends Action{
28
public static final String NAME = "action.note.general.tied";
30
public ChangeTiedNoteAction() {
31
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
34
protected int execute(TypedEvent e){
35
Caret caret = getEditor().getTablature().getCaret();
36
if(caret.getSelectedNote() != null){
37
//comienza el undoable
38
UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
40
getSongManager().getMeasureManager().changeTieNote(caret.getSelectedNote());
43
addUndoableEdit(undoable.endUndo());
45
TGNote note = getSongManager().getFactory().newNote();
47
note.setVelocity(caret.getVelocity());
48
note.setString(caret.getSelectedString().getNumber());
49
note.setTiedNote(true);
51
TGDuration duration = getSongManager().getFactory().newDuration();
52
caret.getDuration().copy(duration);
54
setTiedNoteValue(note,caret);
56
//comienza el undoable
57
UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
59
getSongManager().getMeasureManager().addNote(caret.getSelectedBeat(),note,duration);
62
addUndoableEdit(undoable.endUndo());
64
TuxGuitar.instance().getFileHistory().setUnsavedFile();
69
private void setTiedNoteValue(TGNote note,Caret caret){
70
TGMeasure measure = caret.getMeasure();
71
TGBeat beat = getSongManager().getMeasureManager().getPreviousBeat( measure.getBeats(), caret.getSelectedBeat());
72
while( measure != null){
73
while( beat != null ){
74
if(beat.isRestBeat()){
78
// Check if is there any note at same string.
79
Iterator it = beat.getNotes().iterator();
80
while( it.hasNext() ){
81
TGNote current = (TGNote) it.next();
82
if(current.getString() == note.getString()){
83
note.setValue( current.getValue() );
87
beat = getSongManager().getMeasureManager().getPreviousBeat( measure.getBeats(), beat);
89
measure = getSongManager().getTrackManager().getPrevMeasure(measure);
90
if( measure != null ){
91
beat = getSongManager().getMeasureManager().getLastBeat( measure.getBeats() );
96
private void setTiedNoteValue(TGNote note,Caret caret){
97
TGMeasure measure = caret.getMeasure();
98
TGNote previous = null;
99
while(measure != null){
100
previous = getSongManager().getMeasureManager().getPreviousNote(measure,caret.getPosition(),caret.getSelectedString().getNumber());
101
if(previous != null){
102
note.setValue(previous.getValue());
105
measure = getSongManager().getTrackManager().getPrevMeasure(measure);
110
public void updateTablature() {
111
fireUpdate(getEditor().getTablature().getCaret().getMeasure().getNumber());