private void readBeatEffects(TGBeat beat, TGNoteEffect noteEffect) throws IOException {
   int flags1 = readUnsignedByte();
   int flags2 = readUnsignedByte();
   noteEffect.setFadeIn(((flags1 & 0x10) != 0));
   noteEffect.setVibrato(((flags1 & 0x02) != 0));
   if ((flags1 & 0x20) != 0) {
     int effect = readUnsignedByte();
     noteEffect.setTapping(effect == 1);
     noteEffect.setSlapping(effect == 2);
     noteEffect.setPopping(effect == 3);
   }
   if ((flags2 & 0x04) != 0) {
     readTremoloBar(noteEffect);
   }
   if ((flags1 & 0x40) != 0) {
     int strokeDown = readByte();
     int strokeUp = readByte();
     if (strokeDown > 0) {
       beat.getStroke().setDirection(TGStroke.STROKE_DOWN);
       beat.getStroke().setValue(toStrokeValue(strokeDown));
     } else if (strokeUp > 0) {
       beat.getStroke().setDirection(TGStroke.STROKE_UP);
       beat.getStroke().setValue(toStrokeValue(strokeUp));
     }
   }
   if ((flags2 & 0x02) != 0) {
     readByte();
   }
 }
 public void readTremoloPicking(TGNoteEffect effect) throws IOException {
   int value = readUnsignedByte();
   TGEffectTremoloPicking tp = getFactory().newEffectTremoloPicking();
   if (value == 1) {
     tp.getDuration().setValue(TGDuration.EIGHTH);
     effect.setTremoloPicking(tp);
   } else if (value == 2) {
     tp.getDuration().setValue(TGDuration.SIXTEENTH);
     effect.setTremoloPicking(tp);
   } else if (value == 3) {
     tp.getDuration().setValue(TGDuration.THIRTY_SECOND);
     effect.setTremoloPicking(tp);
   }
 }
 private void readTrill(TGNoteEffect effect) throws IOException {
   byte fret = readByte();
   byte period = readByte();
   TGEffectTrill trill = new TGEffectTrill();
   trill.setFret(fret);
   if (period == 1) {
     trill.getDuration().setValue(TGDuration.SIXTEENTH);
     effect.setTrill(trill);
   } else if (period == 2) {
     trill.getDuration().setValue(TGDuration.THIRTY_SECOND);
     effect.setTrill(trill);
   } else if (period == 3) {
     trill.getDuration().setValue(TGDuration.SIXTY_FOURTH);
     effect.setTrill(trill);
   }
 }
  private void readArtificialHarmonic(TGNoteEffect effect) throws IOException {
    int type = readByte();

    HarmonicEffect harmonic = null;

    switch (type) {
      case 1:
        harmonic = HarmonicEffect.NATURAL;
        break;
      case 2:
        skip(3);
        harmonic = HarmonicEffect.ARTIFICIAL;
        break;
      case 3:
        skip(1);
        harmonic = HarmonicEffect.TAPPED;
        break;
      case 4:
        harmonic = HarmonicEffect.PINCH;
        break;
      case 5:
        harmonic = HarmonicEffect.SEMI;
        break;
    }

    harmonic.setData(0);
    effect.setHarmonic(harmonic);
  }
 private void readGrace(TGNoteEffect effect) throws IOException {
   int fret = readUnsignedByte();
   int dynamic = readUnsignedByte();
   int transition = readByte();
   int duration = readUnsignedByte();
   int flags = readUnsignedByte();
   TGEffectGrace grace = new TGEffectGrace();
   grace.setFret(fret);
   grace.setDynamic(
       (TGVelocities.MIN_VELOCITY + (TGVelocities.VELOCITY_INCREMENT * dynamic))
           - TGVelocities.VELOCITY_INCREMENT);
   grace.setDuration(duration);
   grace.setDead((flags & 0x01) != 0);
   grace.setOnBeat((flags & 0x02) != 0);
   if (transition == 0) {
     grace.setTransition(Transition.NONE);
   } else if (transition == 1) {
     grace.setTransition(Transition.SLIDE);
   } else if (transition == 2) {
     grace.setTransition(Transition.BEND);
   } else if (transition == 3) {
     grace.setTransition(Transition.HAMMER);
   }
   effect.setGrace(grace);
 }
 private void readNoteEffects(TGNoteEffect noteEffect) throws IOException {
   int flags1 = readUnsignedByte();
   int flags2 = readUnsignedByte();
   if ((flags1 & 0x01) != 0) {
     readBend(noteEffect);
   }
   if ((flags1 & 0x10) != 0) {
     readGrace(noteEffect);
   }
   if ((flags2 & 0x04) != 0) {
     readTremoloPicking(noteEffect);
   }
   if ((flags2 & 0x08) != 0) {
     noteEffect.setSlide(true);
     readByte();
   }
   if ((flags2 & 0x10) != 0) {
     readArtificialHarmonic(noteEffect);
   }
   if ((flags2 & 0x20) != 0) {
     readTrill(noteEffect);
   }
   noteEffect.setHammer(((flags1 & 0x02) != 0));
   noteEffect.setLetRing(((flags1 & 0x08) != 0));
   noteEffect.setVibrato(((flags2 & 0x40) != 0) || noteEffect.isVibrato());
   noteEffect.setPalmMute(((flags2 & 0x02) != 0));
   noteEffect.setStaccato(((flags2 & 0x01) != 0));
 }
  private void readNoteEffect(TGNoteEffect effect) {
    // leo el vibrato
    effect.setVibrato(readBoolean());

    // leo el bend
    if (readBoolean()) {
      effect.setBend(readBendEffect());
    }

    // leo la nota muerta
    effect.setDeadNote(readBoolean());

    // leo el slide
    effect.setSlide(readBoolean());

    // leo el hammer
    effect.setHammer(readBoolean());
  }
  private long readBeat(long start, TGMeasure measure, TGTrack track, TGTempo tempo, int voiceIndex)
      throws IOException {
    int flags = readUnsignedByte();

    TGBeat beat = getBeat(measure, start);
    TGVoice voice = beat.getVoice(voiceIndex);
    if ((flags & 0x40) != 0) {
      int beatType = readUnsignedByte();
      voice.setEmpty((beatType & 0x02) == 0);
    }
    TGDuration duration = readDuration(flags);
    TGNoteEffect effect = new TGNoteEffect();
    if ((flags & 0x02) != 0) {
      readChord(track.stringCount(), beat);
    }
    if ((flags & 0x04) != 0) {
      readText(beat);
    }
    if ((flags & 0x08) != 0) {
      readBeatEffects(beat, effect);
    }
    if ((flags & 0x10) != 0) {
      readMixChange(tempo);
    }
    int stringFlags = readUnsignedByte();
    for (int i = 6; i >= 0; i--) {
      if ((stringFlags & (1 << i)) != 0 && (6 - i) < track.stringCount()) {
        TGString string = track.getString((6 - i) + 1).clone();
        TGNote note = readNote(string, track, effect.clone());
        voice.addNote(note);
      }
      voice.setDuration(duration.clone());
    }

    skip(1);

    int read = readByte();
    // if (read == 8 || read == 10 || read == 24 ) {
    if ((read & 0x08) != 0) {
      skip(1);
    }

    return (!voice.isEmpty() ? duration.getTime() : 0);
  }
  private long readBeat(long start, TGMeasure measure, TGTrack track, TGTempo tempo)
      throws IOException {
    int flags = readUnsignedByte();
    if ((flags & 0x40) != 0) {
      readUnsignedByte();
    }

    TGBeat beat = getFactory().newBeat();
    TGVoice voice = beat.getVoice(0);
    TGDuration duration = readDuration(flags);
    TGNoteEffect effect = getFactory().newEffect();
    if ((flags & 0x02) != 0) {
      readChord(track.stringCount(), beat);
    }
    if ((flags & 0x04) != 0) {
      readText(beat);
    }
    if ((flags & 0x08) != 0) {
      readBeatEffects(beat, effect);
    }
    if ((flags & 0x10) != 0) {
      readMixChange(tempo);
    }
    int stringFlags = readUnsignedByte();
    for (int i = 6; i >= 0; i--) {
      if ((stringFlags & (1 << i)) != 0 && (6 - i) < track.stringCount()) {
        TGString string = track.getString((6 - i) + 1).clone(getFactory());
        TGNote note = readNote(string, track, effect.clone(getFactory()));
        voice.addNote(note);
      }
    }
    beat.setStart(start);
    voice.setEmpty(false);
    duration.copy(voice.getDuration());
    measure.addBeat(beat);

    return duration.getTime();
  }
  private void readTremoloBar(TGNoteEffect effect) throws IOException {
    skip(5);
    BendingEffect tremoloBar = new BendingEffect();
    int numPoints = readInt();
    for (int i = 0; i < numPoints; i++) {
      int position = readInt();
      int value = readInt();
      readByte();

      int pointPosition = Math.round(position * EffectPoint.MAX_POSITION_LENGTH / GP_BEND_POSITION);
      int pointValue = Math.round(value / (GP_BEND_SEMITONE * 2f));
      tremoloBar.addPoint(pointPosition, pointValue);
    }
    if (!tremoloBar.getPoints().isEmpty()) {
      effect.setTremoloBar(tremoloBar);
    }
  }
  private void readBend(TGNoteEffect effect) throws IOException {
    TGEffectBend bend = getFactory().newEffectBend();
    skip(5);
    int points = readInt();
    for (int i = 0; i < points; i++) {
      int position = readInt();
      int value = readInt();
      readByte();

      int pointPosition =
          Math.round(position * TGEffectBend.MAX_POSITION_LENGTH / GP_BEND_POSITION);
      int pointValue = Math.round(value * TGEffectBend.SEMITONE_LENGTH / GP_BEND_SEMITONE);
      bend.addPoint(pointPosition, pointValue);
    }
    if (!bend.getPoints().isEmpty()) {
      effect.setBend(bend);
    }
  }
  private void readBend(TGNoteEffect effect) throws IOException {
    skip(5);
    BendingEffect bend = new BendingEffect();
    int numPoints = readInt();
    for (int i = 0; i < numPoints; i++) {
      int bendPosition = readInt();
      int bendValue = readInt();
      readByte();

      int pointPosition =
          Math.round(bendPosition * EffectPoint.MAX_POSITION_LENGTH / GP_BEND_POSITION);
      int pointValue = Math.round(bendValue * EffectPoint.SEMITONE_LENGTH / GP_BEND_SEMITONE);
      bend.addPoint(pointPosition, pointValue);
    }
    if (!bend.getPoints().isEmpty()) {
      effect.setBend(bend);
    }
  }
 private void readGrace(TGNoteEffect effect) throws IOException {
   int fret = readUnsignedByte();
   TGEffectGrace grace = getFactory().newEffectGrace();
   grace.setOnBeat(false);
   grace.setDead((fret == 255));
   grace.setFret(((!grace.isDead()) ? fret : 0));
   grace.setDynamic(
       (TGVelocities.MIN_VELOCITY + (TGVelocities.VELOCITY_INCREMENT * readUnsignedByte()))
           - TGVelocities.VELOCITY_INCREMENT);
   int transition = readUnsignedByte();
   if (transition == 0) {
     grace.setTransition(TGEffectGrace.TRANSITION_NONE);
   } else if (transition == 1) {
     grace.setTransition(TGEffectGrace.TRANSITION_SLIDE);
   } else if (transition == 2) {
     grace.setTransition(TGEffectGrace.TRANSITION_BEND);
   } else if (transition == 3) {
     grace.setTransition(TGEffectGrace.TRANSITION_HAMMER);
   }
   grace.setDuration(readUnsignedByte());
   effect.setGrace(grace);
 }
 private void readNoteEffects(TGNoteEffect noteEffect) throws IOException {
   int flags1 = readUnsignedByte();
   int flags2 = readUnsignedByte();
   noteEffect.setHammer(((flags1 & 0x02) != 0));
   noteEffect.setLetRing(((flags1 & 0x08) != 0));
   noteEffect.setVibrato(((flags2 & 0x40) != 0) || noteEffect.isVibrato());
   noteEffect.setPalmMute(((flags2 & 0x02) != 0));
   noteEffect.setStaccato(((flags2 & 0x01) != 0));
   if ((flags1 & 0x01) != 0) {
     readBend(noteEffect);
   }
   if ((flags1 & 0x10) != 0) {
     readGrace(noteEffect);
   }
   if ((flags2 & 0x04) != 0) {
     readTremoloPicking(noteEffect);
   }
   if ((flags2 & 0x08) != 0) {
     noteEffect.setSlide(true);
     readByte();
   }
   if ((flags2 & 0x10) != 0) {
     TGEffectHarmonic harmonic = getFactory().newEffectHarmonic();
     int type = readByte();
     if (type == 1) {
       harmonic.setType(TGEffectHarmonic.TYPE_NATURAL);
     } else if (type == 3) {
       harmonic.setType(TGEffectHarmonic.TYPE_TAPPED);
     } else if (type == 4) {
       harmonic.setType(TGEffectHarmonic.TYPE_PINCH);
     } else if (type == 5) {
       harmonic.setType(TGEffectHarmonic.TYPE_SEMI);
     } else if (type == 15) {
       harmonic.setType(TGEffectHarmonic.TYPE_ARTIFICIAL);
       harmonic.setData(2);
     } else if (type == 17) {
       harmonic.setType(TGEffectHarmonic.TYPE_ARTIFICIAL);
       harmonic.setData(3);
     } else if (type == 22) {
       harmonic.setType(TGEffectHarmonic.TYPE_ARTIFICIAL);
       harmonic.setData(0);
     }
     noteEffect.setHarmonic(harmonic);
   }
   if ((flags2 & 0x20) != 0) {
     byte fret = readByte();
     byte period = readByte();
     TGEffectTrill trill = getFactory().newEffectTrill();
     trill.setFret(fret);
     if (period == 1) {
       trill.getDuration().setValue(TGDuration.SIXTEENTH);
       noteEffect.setTrill(trill);
     } else if (period == 2) {
       trill.getDuration().setValue(TGDuration.THIRTY_SECOND);
       noteEffect.setTrill(trill);
     } else if (period == 3) {
       trill.getDuration().setValue(TGDuration.SIXTY_FOURTH);
       noteEffect.setTrill(trill);
     }
   }
 }
  private void writeNoteEffect(TGNoteEffect effect) {
    int header = 0;

    header = (effect.isBend()) ? header |= EFFECT_BEND : header;
    header = (effect.isTremoloBar()) ? header |= EFFECT_TREMOLO_BAR : header;
    header = (effect.isHarmonic()) ? header |= EFFECT_HARMONIC : header;
    header = (effect.isGrace()) ? header |= EFFECT_GRACE : header;
    header = (effect.isTrill()) ? header |= EFFECT_TRILL : header;
    header = (effect.isTremoloPicking()) ? header |= EFFECT_TREMOLO_PICKING : header;
    header = (effect.isVibrato()) ? header |= EFFECT_VIBRATO : header;
    header = (effect.isDeadNote()) ? header |= EFFECT_DEAD : header;
    header = (effect.isSlide()) ? header |= EFFECT_SLIDE : header;
    header = (effect.isHammer()) ? header |= EFFECT_HAMMER : header;
    header = (effect.isGhostNote()) ? header |= EFFECT_GHOST : header;
    header = (effect.isAccentuatedNote()) ? header |= EFFECT_ACCENTUATED : header;
    header = (effect.isHeavyAccentuatedNote()) ? header |= EFFECT_HEAVY_ACCENTUATED : header;
    header = (effect.isPalmMute()) ? header |= EFFECT_PALM_MUTE : header;
    header = (effect.isStaccato()) ? header |= EFFECT_STACCATO : header;
    header = (effect.isTapping()) ? header |= EFFECT_TAPPING : header;
    header = (effect.isSlapping()) ? header |= EFFECT_SLAPPING : header;
    header = (effect.isPopping()) ? header |= EFFECT_POPPING : header;
    header = (effect.isFadeIn()) ? header |= EFFECT_FADE_IN : header;

    writeHeader(header, 3);

    // escribo el bend
    if (((header & EFFECT_BEND) != 0)) {
      writeBendEffect(effect.getBend());
    }

    // leo el tremolo bar
    if (((header & EFFECT_TREMOLO_BAR) != 0)) {
      writeTremoloBarEffect(effect.getTremoloBar());
    }

    // leo el harmonic
    if (((header & EFFECT_HARMONIC) != 0)) {
      writeHarmonicEffect(effect.getHarmonic());
    }

    // leo el grace
    if (((header & EFFECT_GRACE) != 0)) {
      writeGraceEffect(effect.getGrace());
    }

    // leo el trill
    if (((header & EFFECT_TRILL) != 0)) {
      writeTrillEffect(effect.getTrill());
    }

    // leo el tremolo picking
    if (((header & EFFECT_TREMOLO_PICKING) != 0)) {
      writeTremoloPickingEffect(effect.getTremoloPicking());
    }
  }
Exemple #16
0
  private void readNoteEffect(TGNoteEffect effect) {
    int header = readHeader(3);

    // leo el bend
    if (((header & EFFECT_BEND) != 0)) {
      effect.setBend(readBendEffect());
    }

    // leo el tremolo bar
    if (((header & EFFECT_TREMOLO_BAR) != 0)) {
      effect.setTremoloBar(readTremoloBarEffect());
    }

    // leo el harmonic
    if (((header & EFFECT_HARMONIC) != 0)) {
      effect.setHarmonic(readHarmonicEffect());
    }

    // leo el grace
    if (((header & EFFECT_GRACE) != 0)) {
      effect.setGrace(readGraceEffect());
    }

    // leo el trill
    if (((header & EFFECT_TRILL) != 0)) {
      effect.setTrill(readTrillEffect());
    }

    // leo el tremolo picking
    if (((header & EFFECT_TREMOLO_PICKING) != 0)) {
      effect.setTremoloPicking(readTremoloPickingEffect());
    }

    // vibrato
    effect.setVibrato(((header & EFFECT_VIBRATO) != 0));

    // dead note
    effect.setDeadNote(((header & EFFECT_DEAD) != 0));

    // slide
    effect.setSlide(((header & EFFECT_SLIDE) != 0));

    // hammer-on/pull-off
    effect.setHammer(((header & EFFECT_HAMMER) != 0));

    // ghost note
    effect.setGhostNote(((header & EFFECT_GHOST) != 0));

    // accentuated note
    effect.setAccentuatedNote(((header & EFFECT_ACCENTUATED) != 0));

    // heavy accentuated note
    effect.setHeavyAccentuatedNote(((header & EFFECT_HEAVY_ACCENTUATED) != 0));

    // palm mute
    effect.setPalmMute(((header & EFFECT_PALM_MUTE) != 0));

    // staccato
    effect.setStaccato(((header & EFFECT_STACCATO) != 0));

    // tapping
    effect.setTapping(((header & EFFECT_TAPPING) != 0));

    // slapping
    effect.setSlapping(((header & EFFECT_SLAPPING) != 0));

    // popping
    effect.setPopping(((header & EFFECT_POPPING) != 0));

    // fade in
    effect.setFadeIn(((header & EFFECT_FADE_IN) != 0));
  }