private void setTiedNoteValue(TGNote note, Caret caret) {
   TGMeasure measure = caret.getMeasure();
   TGVoice voice =
       getSongManager()
           .getMeasureManager()
           .getPreviousVoice(measure.getBeats(), caret.getSelectedBeat(), caret.getVoice());
   while (measure != null) {
     while (voice != null) {
       if (voice.isRestVoice()) {
         note.setValue(0);
         return;
       }
       // Check if is there any note at same string.
       Iterator it = voice.getNotes().iterator();
       while (it.hasNext()) {
         TGNote current = (TGNote) it.next();
         if (current.getString() == note.getString()) {
           note.setValue(current.getValue());
           return;
         }
       }
       voice =
           getSongManager()
               .getMeasureManager()
               .getPreviousVoice(measure.getBeats(), voice.getBeat(), caret.getVoice());
     }
     measure = getSongManager().getTrackManager().getPrevMeasure(measure);
     if (measure != null) {
       voice =
           getSongManager().getMeasureManager().getLastVoice(measure.getBeats(), caret.getVoice());
     }
   }
 }
  private boolean addNote(TGBeat beat, long start, int value) {
    if (beat != null) {
      TGMeasure measure = getMeasure();
      Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();

      List strings = measure.getTrack().getStrings();
      for (int i = 0; i < strings.size(); i++) {
        TGString string = (TGString) strings.get(i);
        if (value >= string.getValue()) {
          boolean emptyString = true;

          for (int v = 0; v < beat.countVoices(); v++) {
            TGVoice voice = beat.getVoice(v);
            Iterator it = voice.getNotes().iterator();
            while (it.hasNext()) {
              TGNoteImpl note = (TGNoteImpl) it.next();
              if (note.getString() == string.getNumber()) {
                emptyString = false;
                break;
              }
            }
          }
          if (emptyString) {
            TGSongManager manager = TuxGuitar.instance().getSongManager();

            // comienza el undoable
            UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();

            TGNote note = manager.getFactory().newNote();
            note.setValue((value - string.getValue()));
            note.setVelocity(caret.getVelocity());
            note.setString(string.getNumber());

            TGDuration duration = manager.getFactory().newDuration();
            caret.getDuration().copy(duration);

            manager.getMeasureManager().addNote(beat, note, duration, start, caret.getVoice());

            caret.moveTo(
                caret.getTrack(), caret.getMeasure(), note.getVoice().getBeat(), note.getString());

            // termia el undoable
            TuxGuitar.instance().getUndoableManager().addEdit(undoable.endUndo());
            TuxGuitar.instance().getFileHistory().setUnsavedFile();

            // reprodusco las notas en el pulso
            TuxGuitar.instance().playBeat(caret.getSelectedBeat());

            this.afterAction();

            return true;
          }
        }
      }
    }
    return false;
  }
  public static UndoableChangeAlternativeRepeat startUndo() {
    UndoableChangeAlternativeRepeat undoable = new UndoableChangeAlternativeRepeat();
    Caret caret = getCaret();
    undoable.doAction = UNDO_ACTION;
    undoable.undoCaret = new UndoableCaretHelper();
    undoable.position = caret.getPosition();
    undoable.undoRepeatAlternative = caret.getMeasure().getHeader().getRepeatAlternative();

    return undoable;
  }
 private void moveToNext() {
   if (TuxGuitar.instance().getPlayer().isRunning()) {
     TuxGuitar.instance().getTransport().gotoNext();
   } else {
     Caret caret = getEditor().getTablature().getCaret();
     TGTrackImpl track = caret.getTrack();
     TGMeasure measure = getSongManager().getTrackManager().getNextMeasure(caret.getMeasure());
     if (track != null && measure != null) {
       caret.update(track.getNumber(), measure.getStart(), caret.getSelectedString().getNumber());
     }
   }
 }
  protected int execute(TypedEvent e) {
    // comienza el undoable
    UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();

    Caret caret = getEditor().getTablature().getCaret();
    getSongManager()
        .getMeasureManager()
        .changePopping(
            caret.getMeasure(), caret.getPosition(), caret.getSelectedString().getNumber());
    TuxGuitar.instance().getFileHistory().setUnsavedFile();
    updateTablature();

    // termia el undoable
    addUndoableEdit(undoable.endUndo());

    return 0;
  }
  protected void setTripletFeel(int tripletFeel, boolean toEnd) {
    // comienza el undoable
    UndoableChangeTripletFeel undoable = UndoableChangeTripletFeel.startUndo();

    Caret caret = getEditor().getTablature().getCaret();
    TGMeasureImpl measure = caret.getMeasure();

    getSongManager().changeTripletFeel(measure.getStart(), tripletFeel, toEnd);

    TuxGuitar.instance().getFileHistory().setUnsavedFile();

    // actualizo la tablatura
    updateTablature();

    // termia el undoable
    addUndoableEdit(undoable.endUndo(tripletFeel, toEnd));
  }
  protected void processAction(TGActionContext context) {
    Caret caret = getEditor().getTablature().getCaret();
    // si es el ultimo compas, agrego uno nuevo
    if (getSongManager().getTrackManager().isLastMeasure(caret.getMeasure())) {
      int number = (getSongManager().getSong().countMeasureHeaders() + 1);

      // comienza el undoable
      UndoableAddMeasure undoable = UndoableAddMeasure.startUndo(number);

      this.getSongManager().addNewMeasure(number);
      this.fireUpdate(number);
      this.moveToNext();

      // termia el undoable
      this.addUndoableEdit(undoable.endUndo());
    } else {
      this.moveToNext();
    }
  }