Exemplo n.º 1
0
  private boolean removeNote(TGBeat beat, int value) {
    Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
    TGMeasure measure = getMeasure();

    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.getRealValue() == value) {
          caret.update(measure.getTrack().getNumber(), beat.getStart(), note.getString());

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

          TGSongManager manager = TuxGuitar.instance().getSongManager();
          manager.getMeasureManager().removeNote(note);

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

          this.afterAction();

          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 2
0
  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;
  }
Exemplo n.º 3
0
  protected void paintBeat(
      TGPainter painter, TGMeasure measure, TGBeat beat, float fromX, float fromY) {
    if (this.clientArea != null) {
      int minimumY = BORDER_HEIGHT;
      int maximumY = (this.clientArea.height - BORDER_HEIGHT);

      for (int v = 0; v < beat.countVoices(); v++) {
        TGVoice voice = beat.getVoice(v);
        for (int i = 0; i < voice.countNotes(); i++) {
          TGNoteImpl note = (TGNoteImpl) voice.getNote(i);
          float x1 =
              (fromX
                  + this.leftSpacing
                  + (((beat.getStart() - measure.getStart())
                          * (this.timeWidth * measure.getTimeSignature().getNumerator()))
                      / measure.getLength())
                  + 1);
          float y1 =
              (fromY
                  + (((this.maxNote - this.minNote) - (note.getRealValue() - this.minNote))
                      * this.lineHeight)
                  + 1);
          float x2 =
              (x1
                  + ((voice.getDuration().getTime() * this.timeWidth)
                      / measure.getTimeSignature().getDenominator().getTime())
                  - 2);
          float y2 = (y1 + this.lineHeight - 2);

          if (y1 >= maximumY || y2 <= minimumY) {
            continue;
          }

          y1 = (y1 < minimumY ? minimumY : y1);
          y2 = (y2 > maximumY ? maximumY : y2);

          if ((x2 - x1) > 0 && (y2 - y1) > 0) {
            painter.setBackground(
                new TGColorImpl(
                    (note.getBeatImpl()
                            .isPlaying(
                                TuxGuitar.instance()
                                    .getTablatureEditor()
                                    .getTablature()
                                    .getViewLayout())
                        ? this.config.getColorPlay()
                        : this.config.getColorNote())));
            painter.initPath(TGPainter.PATH_FILL);
            painter.setAntialias(false);
            painter.addRectangle(x1, y1, (x2 - x1), (y2 - y1));
            painter.closePath();
          }
        }
      }
    }
  }