protected void hit(float x, float y) {
    if (!TuxGuitar.instance().getPlayer().isRunning()) {
      TGMeasure measure = getMeasure();
      Caret caret = getCaret();
      int value = getValueAt(y);
      long start = getStartAt(x);

      if (start >= measure.getStart() && start < (measure.getStart() + measure.getLength())) {
        caret.update(caret.getTrack().getNumber(), start, caret.getStringNumber());
        TuxGuitar.instance().updateCache(true);
      }
      if (value >= this.minNote || value <= this.maxNote) {
        if (start >= measure.getStart()) {
          TGVoice voice =
              TuxGuitar.instance()
                  .getSongManager()
                  .getMeasureManager()
                  .getVoiceIn(measure, start, caret.getVoice());
          if (voice != null) {
            if (!removeNote(voice.getBeat(), value)) {
              addNote(voice.getBeat(), start, value);
            }
          }
        } else {
          play(value);
        }
      }
    }
  }
  public void cleanMeasures(int m1, int m2) {
    if (m1 > 0 && m1 <= m2) {
      // comienza el undoable
      UndoableJoined undoable = new UndoableJoined();

      Caret caret = getEditor().getTablature().getCaret();
      for (int number = m1; number <= m2; number++) {
        TGMeasure measure = getSongManager().getTrackManager().getMeasure(caret.getTrack(), number);
        if (measure != null) {
          // comienza el undoable
          UndoableMeasureGeneric mUndoable = UndoableMeasureGeneric.startUndo(measure);

          getSongManager().getMeasureManager().cleanMeasure(measure);

          // termia el undoable
          undoable.addUndoableEdit(mUndoable.endUndo(measure));
        }
      }

      // termia el undoable
      if (!undoable.isEmpty()) {
        addUndoableEdit(undoable.endUndo());
      }
      TuxGuitar.instance().getFileHistory().setUnsavedFile();

      updateTablature();
    }
  }
  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;
  }
 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(ActionData actionData) {
    // comienza el undoable
    UndoableCloneTrack undoable = UndoableCloneTrack.startUndo();
    TuxGuitar.instance().getFileHistory().setUnsavedFile();

    Caret caret = getEditor().getTablature().getCaret();

    getSongManager().cloneTrack(caret.getTrack());
    updateTablature();

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

    return 0;
  }
  protected void processAction(TGActionContext context) {
    // comienza el undoable
    UndoableMoveTrackUp undoable = UndoableMoveTrackUp.startUndo();

    Caret caret = getEditor().getTablature().getCaret();
    TGTrack track = caret.getTrack();

    if (getSongManager().moveTrackUp(track)) {
      updateTablature();

      // termia el undoable
      addUndoableEdit(undoable.endUndo(track));
      TuxGuitar.instance().getFileHistory().setUnsavedFile();
    }
  }