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;
 }
 public void playBeat(TGTrack track, final List notes) {
   TGChannel tgChannel = this.songManager.getChannel(track.getChannelId());
   if (tgChannel != null) {
     int channelId = tgChannel.getChannelId();
     int bank = tgChannel.getBank();
     int program = tgChannel.getProgram();
     int volume = (int) ((this.getVolume() / 10.00) * tgChannel.getVolume());
     int balance = tgChannel.getBalance();
     int chorus = tgChannel.getChorus();
     int reverb = tgChannel.getReverb();
     int phaser = tgChannel.getPhaser();
     int tremolo = tgChannel.getTremolo();
     int size = notes.size();
     int[][] beat = new int[size][2];
     for (int i = 0; i < size; i++) {
       TGNote note = (TGNote) notes.get(i);
       beat[i][0] =
           track.getOffset()
               + (note.getValue()
                   + ((TGString) track.getStrings().get(note.getString() - 1)).getValue());
       beat[i][1] = note.getVelocity();
     }
     playBeat(channelId, bank, program, volume, balance, chorus, reverb, phaser, tremolo, beat);
   }
 }
  private void addBeat(int key, TGBeat beat) {
    if (beat.isRestBeat()) {
      this.writer.print("r");
      this.addDuration(beat.getDuration());
    } else {
      int size = beat.countNotes();
      if (size > 1) {
        this.writer.print("<");
      }
      for (int i = 0; i < size; i++) {
        TGNote note = beat.getNote(i);

        int note_value =
            (note.getBeat().getMeasure().getTrack().getString(note.getString()).getValue()
                + note.getValue());
        this.addKey(key, note_value);
        if (!(size > 1)) {
          this.addDuration(beat.getDuration());
        }
        this.addString(note.getString());
        if (this.isAnyTiedTo(note)) {
          this.writer.print("~");
        }

        if (size > 1) {
          this.writer.print(" ");
        }
      }
      if (size > 1) {
        this.writer.print(">");
        this.addDuration(beat.getDuration());
      }

      if (beat.isChordBeat()) {
        this.writer.print("-\\tag #'chords ^\\markup \\fret-diagram #\"");
        TGChord chord = beat.getChord();
        for (int i = 0; i < chord.countStrings(); i++) {
          this.writer.print((i + 1) + "-" + getLilypondChordFret(chord.getFretValue(i)) + ";");
        }
        this.writer.print("\"");
      }

      if (beat.isTextBeat()) {
        this.writer.print("-\\tag #'texts ^\\markup {" + beat.getText().getValue() + "}");
      }

      if (beat.getMeasure().getTrack().getLyrics().getFrom() > beat.getMeasure().getNumber()) {
        this.temp.addSkippedLyricBeat(getLilypondDuration(beat.getDuration()));
      }

      this.writer.print(" ");
    }
  }
  private void writeNote(int header, TGNote note) {
    // escribo el valor
    writeByte(note.getValue());

    // escribo la cuerda
    writeByte(note.getString());

    // escribo el velocity
    if (((header & NOTE_VELOCITY) != 0)) {
      writeByte(note.getVelocity());
    }

    // escribo los efectos
    if (((header & NOTE_EFFECT) != 0)) {
      writeNoteEffect(note.getEffect());
    }
  }
  private void writeNotes(TGVoice voice, TGBeatData data) {
    for (int i = 0; i < voice.countNotes(); i++) {
      TGNote note = voice.getNote(i);

      int header = (i + 1 < voice.countNotes() ? NOTE_HAS_NEXT : 0);
      header = (note.isTiedNote()) ? header |= NOTE_TIED : header;
      if (note.getVelocity() != data.getVelocity()) {
        data.setVelocity(note.getVelocity());
        header |= NOTE_VELOCITY;
      }
      header = (note.getEffect().hasAnyEffect()) ? header |= NOTE_EFFECT : header;

      writeHeader(header);

      writeNote(header, note);
    }
  }
 private int getTiedNoteValue(int string, TGTrack track) {
   int measureCount = track.countMeasures();
   if (measureCount > 0) {
     for (int m = measureCount - 1; m >= 0; m--) {
       TGMeasure measure = track.getMeasure(m);
       for (int b = measure.countBeats() - 1; b >= 0; b--) {
         TGBeat beat = measure.getBeat(b);
         TGVoice voice = beat.getVoice(0);
         for (int n = 0; n < voice.countNotes(); n++) {
           TGNote note = voice.getNote(n);
           if (note.getString() == string) {
             return note.getValue();
           }
         }
       }
     }
   }
   return -1;
 }
  @Override
  protected int execute(ActionData actionData) {
    TGNote note = getEditor().getTablature().getCaret().getSelectedNote();
    if (note != null) {
      // comienza el undoable
      UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();

      if (getSongManager()
          .getMeasureManager()
          .moveSemitoneDown(
              getEditor().getTablature().getCaret().getMeasure(),
              note.getVoice().getBeat().getStart(),
              note.getString())) {
        // termia el undoable
        addUndoableEdit(undoable.endUndo());
        TuxGuitar.instance().getFileHistory().setUnsavedFile();
      }
      updateTablature();
    }
    return 0;
  }
 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 isAnyTiedTo(TGNote note) {
   TGMeasure measure = note.getBeat().getMeasure();
   TGBeat beat = this.manager.getMeasureManager().getNextBeat(measure.getBeats(), note.getBeat());
   while (measure != null) {
     while (beat != null) {
       // If is a rest beat, all voice sounds must be stopped.
       if (beat.isRestBeat()) {
         return false;
       }
       // Check if is there any note at same string.
       Iterator it = beat.getNotes().iterator();
       while (it.hasNext()) {
         TGNote current = (TGNote) it.next();
         if (current.getString() == note.getString()) {
           return current.isTiedNote();
         }
       }
       beat = this.manager.getMeasureManager().getNextBeat(measure.getBeats(), beat);
     }
     measure = this.manager.getTrackManager().getNextMeasure(measure);
     if (measure != null) {
       beat = this.manager.getMeasureManager().getFirstBeat(measure.getBeats());
     }
   }
   return false;
 }
Beispiel #10
0
  private void readNote(int header, TGVoice voice, TGBeatData data) {
    TGNote note = this.factory.newNote();

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

    // leo la cuerda
    note.setString(readByte());

    // leo la ligadura
    note.setTiedNote((header & NOTE_TIED) != 0);

    // leo el velocity
    if (((header & NOTE_VELOCITY) != 0)) {
      data.getVoice(voice.getIndex()).setVelocity(readByte());
    }
    note.setVelocity(data.getVoice(voice.getIndex()).getVelocity());

    // leo los efectos
    if (((header & NOTE_EFFECT) != 0)) {
      readNoteEffect(note.getEffect());
    }

    voice.addNote(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;
  }
  protected int execute(TypedEvent e) {
    Caret caret = getEditor().getTablature().getCaret();
    if (caret.getSelectedNote() != null) {
      // comienza el undoable
      UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();

      getSongManager().getMeasureManager().changeTieNote(caret.getSelectedNote());

      // termia el undoable
      addUndoableEdit(undoable.endUndo());
    } else {
      TGNote note = getSongManager().getFactory().newNote();
      note.setValue(0);
      note.setVelocity(caret.getVelocity());
      note.setString(caret.getSelectedString().getNumber());
      note.setTiedNote(true);

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

      setTiedNoteValue(note, caret);

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

      getSongManager()
          .getMeasureManager()
          .addNote(caret.getSelectedBeat(), note, duration, caret.getVoice());

      // termia el undoable
      addUndoableEdit(undoable.endUndo());
    }
    TuxGuitar.instance().getFileHistory().setUnsavedFile();
    updateTablature();
    return 0;
  }
  private TGBeat readNote(TGMeasure measure, TGBeat previous) {
    TGBeat beat = previous;

    // leo el valor
    int value = readInt();

    // leo el start
    long start = (TGDuration.QUARTER_TIME * readLong() / 1000);
    if (beat == null || beat.getStart() != start) {
      beat = this.factory.newBeat();
      beat.setStart(start);
      measure.addBeat(beat);
    }
    TGVoice voice = beat.getVoice(0);
    voice.setEmpty(false);

    // leo la duracion
    readDuration(voice.getDuration());

    TGNote note = this.factory.newNote();

    note.setValue(value);

    // leo el velocity
    note.setVelocity(readInt());

    // leo la cuerda
    note.setString(readInt());

    // leo la ligadura
    note.setTiedNote(readBoolean());

    // leo los efectos
    readNoteEffect(note.getEffect());

    voice.addNote(note);
    return beat;
  }