private TGNote readNote(TGString string, TGTrack track, TGNoteEffect effect) throws IOException {
   int flags = readUnsignedByte();
   TGNote note = getFactory().newNote();
   note.setString(string.getNumber());
   note.setEffect(effect);
   note.getEffect().setAccentuatedNote(((flags & 0x40) != 0));
   note.getEffect().setGhostNote(((flags & 0x04) != 0));
   if ((flags & 0x20) != 0) {
     int noteType = readUnsignedByte();
     note.setTiedNote((noteType == 0x02));
     note.getEffect().setDeadNote((noteType == 0x03));
   }
   if ((flags & 0x01) != 0) {
     skip(2);
   }
   if ((flags & 0x10) != 0) {
     note.setVelocity(
         (TGVelocities.MIN_VELOCITY + (TGVelocities.VELOCITY_INCREMENT * readByte()))
             - TGVelocities.VELOCITY_INCREMENT);
   }
   if ((flags & 0x20) != 0) {
     int fret = readByte();
     int value = (note.isTiedNote() ? getTiedNoteValue(string.getNumber(), track) : fret);
     note.setValue(value >= 0 && value < 100 ? value : 0);
   }
   if ((flags & 0x80) != 0) {
     skip(2);
   }
   if ((flags & 0x08) != 0) {
     readNoteEffects(note.getEffect());
   }
   return note;
 }
  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 Clef getClef(TGTrack track) {
   if (!track.isPercussionTrack()) {
     for (final TGString string : track.getStrings()) {
       if (string.getValue() <= 34) {
         return Clef.BASS;
       }
     }
   }
   return Clef.TREBLE;
 }
 private void addTuning(TGTrack track, int indent) {
   this.writer.print(indent(indent) + "\\set TabStaff.stringTunings = #'(");
   Iterator strings = track.getStrings().iterator();
   while (strings.hasNext()) {
     TGString string = (TGString) strings.next();
     // Lilypond relates string tuning to MIDI middle C (note 60)
     this.writer.print((string.getValue() - 60) + " ");
   }
   this.writer.println(")");
 }
Exemple #5
0
  private TGString readInstrumentString(int number) {
    TGString string = this.factory.newString();

    string.setNumber(number);

    // leo el valor
    string.setValue(readByte());

    return string;
  }
  private TGString readInstrumentString() {
    TGString string = this.factory.newString();

    // leo el numero
    string.setNumber(readInt());

    // leo el valor
    string.setValue(readInt());

    return string;
  }
 private int getClef(TGTrack track) {
   if (!isPercussionChannel(track.getSong(), track.getChannelId())) {
     Iterator it = track.getStrings().iterator();
     while (it.hasNext()) {
       TGString string = (TGString) it.next();
       if (string.getValue() <= 34) {
         return TGMeasure.CLEF_BASS;
       }
     }
   }
   return TGMeasure.CLEF_TREBLE;
 }
 private TGTrack readTrack(TGSong song, int number, List channels, TGLyric lyrics)
     throws IOException {
   TGTrack track = getFactory().newTrack();
   track.setNumber(number);
   track.setLyrics(lyrics);
   readUnsignedByte();
   track.setName(readStringByte(40));
   int stringCount = readInt();
   for (int i = 0; i < 7; i++) {
     int tuning = readInt();
     if (stringCount > i) {
       TGString string = getFactory().newString();
       string.setNumber(i + 1);
       string.setValue(tuning);
       track.getStrings().add(string);
     }
   }
   readInt();
   readChannel(song, track, channels);
   readInt();
   track.setOffset(readInt());
   readColor(track.getColor());
   return track;
 }
 private void writeInstrumentString(TGString string) {
   // escribo el valor
   writeByte(string.getValue());
 }
  protected TGImage getBuffer() {
    if (this.clientArea != null) {
      this.bufferDisposer.update(this.clientArea.width, this.clientArea.height);
      if (this.buffer == null || this.buffer.isDisposed()) {
        String[] names = null;
        TGMeasure measure = getMeasure();
        this.maxNote = 0;
        this.minNote = 127;
        if (TuxGuitar.instance()
            .getSongManager()
            .isPercussionChannel(measure.getTrack().getChannelId())) {
          names = new String[PERCUSSIONS.length];
          for (int i = 0; i < names.length; i++) {
            this.minNote = Math.min(this.minNote, PERCUSSIONS[i].getValue());
            this.maxNote = Math.max(this.maxNote, PERCUSSIONS[i].getValue());
            names[i] = PERCUSSIONS[names.length - i - 1].getName();
          }
        } else {
          for (int sNumber = 1; sNumber <= measure.getTrack().stringCount(); sNumber++) {
            TGString string = measure.getTrack().getString(sNumber);
            this.minNote = Math.min(this.minNote, string.getValue());
            this.maxNote = Math.max(this.maxNote, (string.getValue() + 20));
          }
          names = new String[this.maxNote - this.minNote + 1];
          for (int i = 0; i < names.length; i++) {
            names[i] = (NOTE_NAMES[(this.maxNote - i) % 12] + ((this.maxNote - i) / 12));
          }
        }

        int minimumNameWidth = 110;
        int minimumNameHeight = 0;
        TGPainter painter = new TGPainterImpl(new GC(this.dialog.getDisplay()));
        painter.setFont(new TGFontImpl(this.config.getFont()));
        for (int i = 0; i < names.length; i++) {
          int fmWidth = painter.getFMWidth(names[i]);
          if (fmWidth > minimumNameWidth) {
            minimumNameWidth = fmWidth;
          }
          int fmHeight = painter.getFMHeight();
          if (fmHeight > minimumNameHeight) {
            minimumNameHeight = fmHeight;
          }
        }
        painter.dispose();

        int cols = measure.getTimeSignature().getNumerator();
        int rows = (this.maxNote - this.minNote);

        this.leftSpacing = minimumNameWidth + 10;
        this.lineHeight =
            Math.max(
                minimumNameHeight,
                ((this.clientArea.height - (BORDER_HEIGHT * 2.0f)) / (rows + 1.0f)));
        this.timeWidth =
            Math.max(
                (10
                    * (TGDuration.SIXTY_FOURTH
                        / measure.getTimeSignature().getDenominator().getValue())),
                ((this.clientArea.width - this.leftSpacing) / cols));
        this.bufferWidth = this.leftSpacing + (this.timeWidth * cols);
        this.bufferHeight = (this.lineHeight * (rows + 1));
        this.buffer =
            new TGImageImpl(
                this.editor.getDisplay(),
                Math.round(this.bufferWidth),
                Math.round(this.bufferHeight));

        painter = this.buffer.createPainter();
        painter.setFont(new TGFontImpl(this.config.getFont()));
        painter.setForeground(new TGColorImpl(this.config.getColorForeground()));
        for (int i = 0; i <= rows; i++) {
          painter.setBackground(new TGColorImpl(this.config.getColorLine(i % 2)));
          painter.initPath(TGPainter.PATH_FILL);
          painter.setAntialias(false);
          painter.addRectangle(0, (i * this.lineHeight), this.bufferWidth, this.lineHeight);
          painter.closePath();
          painter.drawString(
              names[i],
              5,
              (Math.round((i * this.lineHeight))
                  + Math.round((this.lineHeight - minimumNameHeight) / 2)));
        }
        for (int i = 0; i < cols; i++) {
          float colX = this.leftSpacing + (i * this.timeWidth);
          float divisionWidth = (this.timeWidth / this.grids);
          for (int j = 0; j < this.grids; j++) {
            if (j == 0) {
              painter.setLineStyleSolid();
            } else {
              painter.setLineStyleDot();
            }
            painter.initPath();
            painter.setAntialias(false);
            painter.moveTo(Math.round(colX + (j * divisionWidth)), 0);
            painter.lineTo(Math.round(colX + (j * divisionWidth)), this.bufferHeight);
            painter.closePath();
          }
        }
        painter.dispose();
      }
    }
    return this.buffer;
  }
Exemple #11
0
 public void copy(TGString string) {
   string.setNumber(getNumber());
   string.setValue(getValue());
 }
Exemple #12
0
 public boolean isEqual(TGString string) {
   return (this.getNumber() == string.getNumber() && this.getValue() == string.getValue());
 }
Exemple #13
0
 protected int getTrackString(int number) {
   TGString string = ChordList.this.beat.getMeasure().getTrack().getString(number);
   return string.getValue();
 }