~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/actions/note/ChangeTiedNoteAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 17-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.actions.note;
 
8
 
 
9
import java.util.Iterator;
 
10
 
 
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;
 
20
 
 
21
/**
 
22
 * @author julian
 
23
 *
 
24
 * TODO To change the template for this generated type comment go to
 
25
 * Window - Preferences - Java - Code Style - Code Templates
 
26
 */
 
27
public class ChangeTiedNoteAction extends Action{
 
28
        public static final String NAME = "action.note.general.tied";
 
29
        
 
30
        public ChangeTiedNoteAction() {
 
31
                super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
 
32
        }
 
33
        
 
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();
 
39
                        
 
40
                        getSongManager().getMeasureManager().changeTieNote(caret.getSelectedNote());
 
41
                        
 
42
                        //termia el undoable
 
43
                        addUndoableEdit(undoable.endUndo());
 
44
                }else{
 
45
                        TGNote note = getSongManager().getFactory().newNote();
 
46
                        note.setValue(0);
 
47
                        note.setVelocity(caret.getVelocity());
 
48
                        note.setString(caret.getSelectedString().getNumber());
 
49
                        note.setTiedNote(true);
 
50
                        
 
51
                        TGDuration duration = getSongManager().getFactory().newDuration();
 
52
                        caret.getDuration().copy(duration);
 
53
                        
 
54
                        setTiedNoteValue(note,caret);
 
55
                        
 
56
                        //comienza el undoable
 
57
                        UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
 
58
                        
 
59
                        getSongManager().getMeasureManager().addNote(caret.getSelectedBeat(),note,duration);
 
60
                        
 
61
                        //termia el undoable
 
62
                        addUndoableEdit(undoable.endUndo());
 
63
                }
 
64
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
65
                updateTablature();
 
66
                return 0;
 
67
        }
 
68
        
 
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()){
 
75
                                        note.setValue(0);
 
76
                                        return;
 
77
                                }
 
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() );
 
84
                                                return;
 
85
                                        }
 
86
                                }
 
87
                                beat = getSongManager().getMeasureManager().getPreviousBeat( measure.getBeats(), beat);
 
88
                        }
 
89
                        measure = getSongManager().getTrackManager().getPrevMeasure(measure);
 
90
                        if( measure != null ){
 
91
                                beat = getSongManager().getMeasureManager().getLastBeat( measure.getBeats() );
 
92
                        }
 
93
                }
 
94
        }
 
95
        /*
 
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());
 
103
                                break;
 
104
                        }
 
105
                        measure = getSongManager().getTrackManager().getPrevMeasure(measure);
 
106
                }
 
107
        }
 
108
        */
 
109
        
 
110
        public void updateTablature() {
 
111
                fireUpdate(getEditor().getTablature().getCaret().getMeasure().getNumber());
 
112
        }
 
113
}