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;
  }
 public void redrawLocked() {
   if (!TuxGuitar.instance().isLocked()) {
     TuxGuitar.instance().lock();
     this.redraw();
     TuxGuitar.instance().unlock();
   }
 }
  public void show() {
    this.config = new MatrixConfig();
    this.config.load();

    this.dialog =
        DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.RESIZE);
    this.dialog.setText(TuxGuitar.getProperty("matrix.editor"));
    this.dialog.setImage(TuxGuitar.instance().getIconManager().getAppIcon());
    this.dialog.setLayout(new GridLayout());
    this.dialog.addDisposeListener(new DisposeListenerImpl());
    this.bufferDisposer = new BufferDisposer();

    this.composite = new Composite(this.dialog, SWT.NONE);
    this.composite.setLayout(new GridLayout());
    this.composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    this.initToolBar();
    this.initEditor();
    this.loadIcons();

    this.addListeners();
    this.dialog.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            removeListeners();
            TuxGuitar.instance().updateCache(true);
          }
        });
    DialogUtils.openDialog(this.dialog, DialogUtils.OPEN_STYLE_CENTER);
  }
 public void addListeners() {
   TuxGuitar.instance().getkeyBindingManager().appendListenersTo(this.toolbar);
   TuxGuitar.instance().getkeyBindingManager().appendListenersTo(this.editor);
   TuxGuitar.instance().getIconManager().addLoader(this);
   TuxGuitar.instance().getLanguageManager().addLoader(this);
   TuxGuitar.instance().getEditorManager().addRedrawListener(this);
 }
 private void initFretSearch(Composite parent) {
   Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
   group.setLayout(new GridLayout(4, false));
   group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
   group.setText(TuxGuitar.getProperty("chord.settings.search-frets"));
   this.minFret =
       makeSpinner(
           group,
           TuxGuitar.getProperty("chord.settings.minimum-fret"),
           ChordSettings.instance().getFindChordsMin(),
           0,
           15);
   this.maxFret =
       makeSpinner(
           group,
           TuxGuitar.getProperty("chord.settings.maximum-fret"),
           ChordSettings.instance().getFindChordsMax(),
           2,
           25);
   this.minFret.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           checkMinimumFretValue();
         }
       });
   this.maxFret.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           checkMaximumFretValue();
         }
       });
 }
  public void redrawPlayingMode() {
    if (!isDisposed()
        && !TuxGuitar.instance().isLocked()
        && TuxGuitar.instance().getPlayer().isRunning()) {
      // TuxGuitar.instance().lock();

      TGMeasure measure = TuxGuitar.instance().getEditorCache().getPlayMeasure();
      TGBeat beat = TuxGuitar.instance().getEditorCache().getPlayBeat();
      if (measure != null && beat != null) {
        int currentMeasure = measure.getNumber();
        int currentTrack = measure.getTrack().getNumber();
        boolean changed =
            (currentMeasure != this.playedMeasure || currentTrack != this.playedTrack);
        if (changed) {
          this.resetPlayed();
          this.editor.redraw();
        } else {
          TGPainter painter = new TGPainterImpl(new GC(this.editor));
          int scrollX = this.editor.getHorizontalBar().getSelection();
          int scrollY = this.editor.getVerticalBar().getSelection();
          if (this.playedBeat != null) {
            this.paintBeat(
                painter, measure, this.playedBeat, (-scrollX), (BORDER_HEIGHT - scrollY));
          }
          this.paintBeat(painter, measure, beat, (-scrollX), (BORDER_HEIGHT - scrollY));
          painter.dispose();
        }
        this.playedMeasure = currentMeasure;
        this.playedTrack = currentTrack;
        this.playedBeat = beat;
      }
      // TuxGuitar.instance().unlock();
    }
  }
 protected void processAction(TGActionContext context) {
   if (TuxGuitar.instance().getBrowser().isDisposed()) {
     TuxGuitar.instance().getBrowser().show();
   } else {
     TuxGuitar.instance().getBrowser().dispose();
   }
 }
  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);
        }
      }
    }
  }
 protected void afterAction() {
   TuxGuitar.instance()
       .getTablatureEditor()
       .getTablature()
       .updateMeasure(getMeasure().getNumber());
   TuxGuitar.instance().updateCache(true);
   this.editor.redraw();
 }
示例#10
0
 public void paintControl(PaintEvent e) {
   if (!TuxGuitar.instance().isLocked()) {
     TuxGuitar.instance().lock();
     TGPainter painter = new TGPainterImpl(e.gc);
     paintEditor(painter);
     TuxGuitar.instance().unlock();
   }
 }
 protected void addPlugin() throws TGPluginException {
   if (!this.loaded) {
     TuxGuitar.instance().getActionManager().addAction(this.toolAction);
     TGCustomToolManager.instance().addCustomTool(this.tool);
     TuxGuitar.instance().getItemManager().createMenu();
     this.loaded = true;
   }
 }
 protected void removePlugin() throws TGPluginException {
   if (this.loaded) {
     TGCustomToolManager.instance().removeCustomTool(this.tool);
     TuxGuitar.instance().getActionManager().removeAction(this.tool.getAction());
     TuxGuitar.instance().getItemManager().createMenu();
     this.loaded = false;
   }
 }
示例#13
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;
  }
示例#14
0
 protected TGMeasure getMeasure() {
   if (TuxGuitar.instance().getPlayer().isRunning()) {
     TGMeasure measure = TuxGuitar.instance().getEditorCache().getPlayMeasure();
     if (measure != null) {
       return measure;
     }
   }
   return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getMeasure();
 }
示例#15
0
 public void loadIcons() {
   if (!isDisposed()) {
     this.dialog.setImage(TuxGuitar.instance().getIconManager().getAppIcon());
     this.settings.setImage(TuxGuitar.instance().getIconManager().getSettings());
     this.loadDurationImage(true);
     this.layout();
     this.redraw();
   }
 }
示例#16
0
 private void initTypeCombo(Composite parent) {
   this.newLabel(parent, TuxGuitar.getProperty("chord.settings.type"));
   this.typeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
   this.typeCombo.setLayoutData(getGridData());
   this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.most-common"));
   this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.inversions"));
   this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.close-voiced"));
   this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.open-voiced"));
   this.typeCombo.select(ChordSettings.instance().getChordTypeIndex());
 }
示例#17
0
 public void loadProperties() {
   if (!isDisposed()) {
     this.dialog.setText(TuxGuitar.getProperty("matrix.editor"));
     this.gridsLabel.setText(TuxGuitar.getProperty("matrix.grids"));
     this.settings.setToolTipText(TuxGuitar.getProperty("settings"));
     this.disposeBuffer();
     this.layout();
     this.redraw();
   }
 }
示例#18
0
 protected void setMenuItemTextAndAccelerator(MenuItem menuItem, String key, String action) {
   String text = TuxGuitar.getProperty(key);
   if (action != null) {
     KeyBinding keyBinding =
         TuxGuitar.instance().getKeyBindingManager().getKeyBindingForAction(action);
     if (keyBinding != null) {
       text += "\t" + keyBinding.toString() + "\u0000";
     }
   }
   menuItem.setText(text);
 }
示例#19
0
 public void update() {
   boolean running = TuxGuitar.instance().getPlayer().isRunning();
   if (this.lastEdit != TuxGuitar.instance().getCustomChordManager().getLastEdit()) {
     this.addItems();
     this.lastEdit = TuxGuitar.instance().getCustomChordManager().getLastEdit();
   }
   this.insertChord.setEnabled(!running);
   for (int i = 0; i < this.subMenuItems.length; i++) {
     this.subMenuItems[i].setEnabled(!running);
   }
 }
 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());
     }
   }
 }
 public void openDirectoryDialog(
     final ImageExporterSettings settings,
     final TGSongStreamContext context,
     final Runnable callback) {
   DirectoryDialog dialog = new DirectoryDialog(TuxGuitar.getInstance().getShell());
   dialog.setText(TuxGuitar.getProperty("tuxguitar-image.directory-dialog.title"));
   settings.setPath(dialog.open());
   if (settings.getPath() != null) {
     context.setAttribute(ImageExporterSettings.class.getName(), settings);
     callback.run();
   }
 }
示例#22
0
 private void loadDurationImage(boolean force) {
   int duration =
       TuxGuitar.instance()
           .getTablatureEditor()
           .getTablature()
           .getCaret()
           .getDuration()
           .getValue();
   if (force || this.duration != duration) {
     this.duration = duration;
     this.durationLabel.setImage(TuxGuitar.instance().getIconManager().getDuration(this.duration));
   }
 }
示例#23
0
  public void addItems() {
    this.disposeItems();
    this.subMenuItems = new MenuItem[TuxGuitar.instance().getCustomChordManager().countChords()];
    for (int i = 0; i < this.subMenuItems.length; i++) {
      TGChord chord = TuxGuitar.instance().getCustomChordManager().getChord(i);
      Map actionData = new HashMap();
      actionData.put(InsertChordAction.PROPERTY_CHORD, chord);

      this.subMenuItems[i] = new MenuItem(this.menu, SWT.PUSH);
      this.subMenuItems[i].setData(actionData);
      this.subMenuItems[i].setText(chord.getName());
      this.subMenuItems[i].addSelectionListener(new TGActionProcessor(InsertChordAction.NAME));
    }
  }
  @Override
  public void undo() throws CannotUndoException {
    if (!canUndo()) {
      throw new CannotUndoException();
    }
    TGSongManager manager = TuxGuitar.instance().getSongManager();
    manager.changeAlternativeRepeat(this.position, this.undoRepeatAlternative);
    TGMeasure measure =
        manager.getTrackManager().getMeasureAt(manager.getFirstTrack(), this.position);
    TuxGuitar.instance().getTablatureEditor().getTablature().updateMeasure(measure.getNumber());
    this.undoCaret.update();

    this.doAction = REDO_ACTION;
  }
示例#25
0
 public void loadIcons() {
   this.whole.setImage(TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.WHOLE));
   this.half.setImage(TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.HALF));
   this.quarter.setImage(TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.QUARTER));
   this.eighth.setImage(TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.EIGHTH));
   this.sixteenth.setImage(
       TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.SIXTEENTH));
   this.thirtySecond.setImage(
       TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.THIRTY_SECOND));
   this.sixtyFourth.setImage(
       TuxGuitar.getInstance().getIconManager().getDuration(TGDuration.SIXTY_FOURTH));
   this.dotted.setImage(TuxGuitar.getInstance().getIconManager().getDurationDotted());
   this.doubleDotted.setImage(TuxGuitar.getInstance().getIconManager().getDurationDoubleDotted());
   this.division.setImage(TuxGuitar.getInstance().getIconManager().getDivisionType());
 }
示例#26
0
  protected void paintSelection(TGPainter painter, float fromX, float fromY) {
    if (!this.selectionPaintDisabled
        && this.clientArea != null
        && !TuxGuitar.instance().getPlayer().isRunning()) {
      selectionFinish();
      if (this.selection >= 0) {
        this.selectionPaintDisabled = true;

        int x = Math.round(fromX);
        int y = Math.round(fromY + ((this.maxNote - this.selection) * this.lineHeight));
        int width = Math.round(this.bufferWidth);
        int height = Math.round(this.lineHeight);

        TGImage selectionArea = new TGImageImpl(this.editor.getDisplay(), width, height);
        painter.copyArea(selectionArea, x, y);
        painter.setAlpha(100);
        painter.setBackground(new TGColorImpl(this.config.getColorLine(2)));
        painter.initPath(TGPainter.PATH_FILL);
        painter.setAntialias(false);
        painter.addRectangle(x, y, width, height);
        painter.closePath();

        this.selectionX = x;
        this.selectionY = y;
        this.selectionBackBuffer = selectionArea;
        this.selectionPaintDisabled = false;
      }
    }
  }
示例#27
0
  protected void paintEditor(TGPainter painter) {
    if (!TuxGuitar.instance().getPlayer().isRunning()) {
      this.resetPlayed();
    }

    this.disposeSelectionBuffer();
    this.clientArea = this.editor.getClientArea();

    if (this.clientArea != null) {
      TGImage buffer = getBuffer();

      this.width = this.bufferWidth;
      this.height = (this.bufferHeight + (BORDER_HEIGHT * 2));

      this.updateScroll();
      int scrollX = this.editor.getHorizontalBar().getSelection();
      int scrollY = this.editor.getVerticalBar().getSelection();

      painter.drawImage(buffer, -scrollX, (BORDER_HEIGHT - scrollY));
      this.paintMeasure(painter, (-scrollX), (BORDER_HEIGHT - scrollY));
      this.paintBorders(painter, (-scrollX), 0);
      this.paintPosition(painter, (-scrollX), 0);

      this.paintSelection(painter, (-scrollX), (BORDER_HEIGHT - scrollY));
    }
  }
  /**
   * Creates the TGChord ArrayList out of StringValue's ArrayLists
   *
   * @param Highest rated StringValues
   * @return TGChord collection
   */
  private ArrayList createChords(ArrayList top) {
    if (!isValidProcess()) {
      return null;
    }

    ArrayList chords = new ArrayList(top.size());

    Iterator it = top.iterator();

    while (it.hasNext()) {
      TGChord chord =
          TuxGuitar.instance().getSongManager().getFactory().newChord(this.tuning.length);
      Iterator it2 = ((ArrayList) it.next()).iterator();

      while (it2.hasNext()) {
        StringValue stringValue = (StringValue) it2.next();
        int string = ((chord.getStrings().length - 1) - (stringValue.getString()));
        int fret = stringValue.getFret();
        chord.addFretValue(string, fret);
        chord.setName(this.chordName);
      }

      chords.add(chord);
    }
    return chords;
  }
示例#29
0
  protected void paintPosition(TGPainter painter, float fromX, float fromY) {
    if (this.clientArea != null && !TuxGuitar.instance().getPlayer().isRunning()) {
      Caret caret = getCaret();
      TGMeasure measure = getMeasure();
      TGBeat beat = caret.getSelectedBeat();
      if (beat != null) {
        float x =
            (((beat.getStart() - measure.getStart())
                    * (this.timeWidth * measure.getTimeSignature().getNumerator()))
                / measure.getLength());
        float width =
            ((beat.getVoice(caret.getVoice()).getDuration().getTime() * this.timeWidth)
                / measure.getTimeSignature().getDenominator().getTime());
        painter.setBackground(new TGColorImpl(this.config.getColorPosition()));
        painter.initPath(TGPainter.PATH_FILL);
        painter.setAntialias(false);
        painter.addRectangle(fromX + (this.leftSpacing + x), fromY, width, BORDER_HEIGHT);
        painter.closePath();

        painter.initPath(TGPainter.PATH_FILL);
        painter.setAntialias(false);
        painter.addRectangle(
            fromX + (this.leftSpacing + x),
            fromY + (this.clientArea.height - BORDER_HEIGHT),
            width,
            BORDER_HEIGHT);
        painter.closePath();
      }
    }
  }
示例#30
0
 private void initEmptyStringChords(Composite parent) {
   this.emptyStringChords = new Button(parent, SWT.CHECK);
   this.emptyStringChords.setSelection(ChordSettings.instance().isEmptyStringChords());
   this.emptyStringChords.setText(TuxGuitar.getProperty("chord.settings.open-chords"));
   this.emptyStringChords.setSize(100, 20);
   this.emptyStringChords.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
 }