gt:                     if (note.effects == null) {
context: package dguitar.codecs.guitarPro.version1;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import dguitar.codecs.guitarPro.GPBeat;
  import dguitar.codecs.guitarPro.GPBend;
  import dguitar.codecs.guitarPro.GPBendPoint;
  import dguitar.codecs.guitarPro.GPBendType;
  import dguitar.codecs.guitarPro.GPChordDiagram;
  import dguitar.codecs.guitarPro.GPChordNote;
  import dguitar.codecs.guitarPro.GPChordType;
  import dguitar.codecs.guitarPro.GPDuration;
  import dguitar.codecs.guitarPro.GPEffectsOnBeat;
  import dguitar.codecs.guitarPro.GPEffectsOnNote;
  import dguitar.codecs.guitarPro.GPFormatException;
  import dguitar.codecs.guitarPro.GPHarmonic;
  import dguitar.codecs.guitarPro.GPInputStream;
  import dguitar.codecs.guitarPro.GPKey;
  import dguitar.codecs.guitarPro.GPMIDIChannel;
  import dguitar.codecs.guitarPro.GPMeasure;
  import dguitar.codecs.guitarPro.GPMeasureTrackPair;
  import dguitar.codecs.guitarPro.GPNote;
  import dguitar.codecs.guitarPro.GPSlide;
  import dguitar.codecs.guitarPro.GPSong;
  import dguitar.codecs.guitarPro.GPTonalityType;
  import dguitar.codecs.guitarPro.GPTrack;
  import dguitar.codecs.guitarPro.GPVibrato;
  
  /**
   * The class GP1InputStream allows to parse an InputStream containing a GTP file
   * which is encoded in the 1, 1.01, 1.02, 1.03, 1.04 format.
   * 
   * @author Matthieu Wipliez
   */
  public class GP1InputStream extends GPInputStream {
      /**
       * The versions this parser supports.
       */
      private static final String supportedVersions[] = {
              "FICHIER GUITARE PRO v1", "FICHIER GUITARE PRO v1.01",
              "FICHIER GUITARE PRO v1.02", "FICHIER GUITARE PRO v1.03",
              "FICHIER GUITARE PRO v1.04" };
  
      /**
       * The number of tracks. In versions from 1 to 1.02 included, it is 1; it is
       * 8 for versions 1.03 and 1.04.
       */
      private int _numTracks;
  
      /**
       * The version number read from the stream. Allows the parser to take
       * different paths according to the file version.
       */
      private int _versionNumber;
  
      /**
       * Creates a new GP2InputStream from an existing stream.
       */
      public GP1InputStream(InputStream in) {
          super(in);
      }
  
      /**
       * Creates a new GP4InputStream by cloning an existing GPInputStream.
       * 
       * @param gpIn
       *            the original GPInputStream.
       */
      public GP1InputStream(GPInputStream gpIn) {
          super(gpIn);
      }
  
      /**
       * This method checks if the String version if supported.
       * 
       * @param version
       *            the version described by a string.
       * @return true if the version is supported.
       */
      public static boolean supportedVersion(String version) {
          int i;
          boolean correct;
  
          correct = false;
          for (i = 0; (i < supportedVersions.length) && (!correct); i++) {
              correct = version.equals(supportedVersions[i]);
          }
          return correct;
      }
  
      /**
       * This methods returns a String with the supported versions separated by
       * '\n'.
       * 
       * @return "FICHIER GUITARE PRO v1" <br />
       *         "FICHIER GUITARE PRO v1.01" <br />
       *         "FICHIER GUITARE PRO v1.02" <br />
       *         "FICHIER GUITARE PRO v1.03" <br />
       *         "FICHIER GUITARE PRO v1.04"
       */
      public static String supportedVersions() {
          int i;
          String s;
  
          s = "";
          for (i = 0; i < supportedVersions.length; i++) {
              s += supportedVersions[i];
              if (i + 1 < supportedVersions.length)
                  s += "\n";
          }
          return s;
      }
  
      /**
       * Reads a piece from the stream.
       * 
       * @return the GPSong read.
       * @throws IOException
       */
      public GPSong readPiece() throws IOException {
          GPSong piece = new GPSong();
          String s;
  
          // Version
          if (__version.equals("")) {
              __version = readStringByte(30);
          }
  
          piece.setVersion(__version);
  
          // Sets the version number, and attributes that depend of it.
          checkVersionNumber();
  
          // Title
          s = readStringByteMaxLengthPlusOne();
          piece.setTitle(s);
  
          // Author of the song
          s = readStringByteMaxLengthPlusOne();
          piece.setAuthorSong(s);
  
          // Instructions
          s = readStringByteMaxLengthPlusOne();
          piece.setInstruction(s);
  
          // Tempo
          piece.setTempo(readInt());
  
          // Triplet Feel
          piece.tripletFeel = (readInt() == 1);
  
          // Key (usually C)
          if (_versionNumber > 2) {
              GPKey key = GPKey.valueOf(readInt());
              piece.setKey(key);
          } else {
              piece.setKey(GPKey.C);
          }
  
          // No octave
          piece.setOctave(0);
  
          // Reads tracks' tuning
          List<GPTrack> tracks = piece.getTracks();
          for (int i = 0; i < _numTracks; i++) {
              GPTrack track = new GPTrack();
              tracks.add(track);
  
              int numStrings;
              if (_versionNumber > 1) {
                  numStrings = readInt();
              } else {
                  numStrings = 6;
              }
              track.setNumberOfStrings(numStrings);
  
              for (int j = 0; j < numStrings; j++) {
                  track.setStringsTuning(j, readInt());
              }
          }
  
          // Number of measures
          int numberOfMeasures = readInt();
  
          // Reads tracks' information
          for (int i = 0; i < _numTracks; i++) {
              GPTrack track = (GPTrack) tracks.get(i);
              track.setPort(1);
              track.setChannel(i + 1);
  
              GPMIDIChannel channel = readTrack(track);
              piece.setChannels(i, channel);
          }
          
          if (_versionNumber > 2) {
              // TODO: check what this information could be.
              // Dump infos
              skip(1); // assertBytesEqualTo(1, 1);
      
              // Status byte? Generally equals to 48.
              // If it equals 49 (bit 0 set), one track is solo.
              int b = readByte();
      
              // n often equals 45119 or 382679111
              int n = readInt();
      
              // The number of the solo track.
              int soloTrackNumber = readInt();
          }
  
          // Reads all measures
          List<GPMeasure> measures = piece.getMeasures();
          List<GPMeasureTrackPair> measuresTracksPairs = piece.getMeasuresTracksPairs();
          for (int i = 0; i < numberOfMeasures; i++) {
              GPMeasure measure = new GPMeasure();
              measure.setNumber(i + 1);
              measures.add(measure);
  
              readMeasureTrackPairs(tracks, measure, measuresTracksPairs);
          }
  
          // For fun
          int i = 0, numBytes = 1;
          boolean different = false;
          int b = read();
          while (b != -1) {
              i++;
              if (!different && i > 4) {
                  different = true;
              }
              b = read();
              numBytes++;
          }
  
          if (different) {
              System.err
                      .println("GP1InputStream: This GTP file has something special ("
                              + numBytes + " additional bytes)...");
          }
  
          return piece;
      }
  
      /**
       * Sets the _versionNumber attribute, according to the version read from the
       * file, and sets attributes that are version-dependant.
       */
      private void checkVersionNumber() {
          int index = __version.indexOf(".");
          if (index < 0) {
              _versionNumber = 0;
          } else {
              String sub = __version.substring(index + 1, index + 3);
              _versionNumber = Integer.parseInt(sub);
          }
  
          if (_versionNumber > 2) {
              _numTracks = 8;
          } else {
              _numTracks = 1;
          }
      }
      
      /**
       * Returns a beat read from a GP2 file.
       * 
       * @param trackNumberOfStrings
       *            the number of strings of the track we are currently reading.
       * @return a GPBeat read from a GP2 file.
       * @throws IOException
       */
      private GPBeat readBeat(int trackNumberOfStrings) throws IOException {
          GP1EffectsOnBeat gp1effects = new GP1EffectsOnBeat();
          GPBeat beat = new GPBeat();
  
          // An integer which is believed to correspond to
          // some duration or something.
          // The time for a whole is 1920 (and a eight is 240). When notes are dotted,
          // the half of the normal time is added.
          int beatDuration = readInt();
          GPDuration duration = GPDuration.valueOf(readByte());
          beat.setDuration(duration);
  
          // Effects on the beat
          int effectBeat = readUnsignedByte();
  
          // Some effects imply that the beat has no content, so we MUST NOT read
          // anything after the effects, and return immediatly.
          boolean returnNow = false;
  
          // Reads the effects on the beat
          if (effectBeat != 0) {
              // This beat is linked with the previous one
              if ((effectBeat & 0x40) != 0) {
                  List<GPNote> notes = beat.getNotes();
                  GPNote note = new GPNote();
                  note.setTieNote(true);
                  notes.add(note);
                  returnNow = true;
              }
  
              // Triplet
              if ((effectBeat & 0x20) != 0) {
                  beat.setNTuplet(3);
                  // The number of the note in the triplet...
                  // What is it used for?
                  int n = readUnsignedByte();
                  n += 0;
              }
  
              // Dotted beat
              if ((effectBeat & 0x10) != 0) {
                  beat.dottedNotes = true;
              }
  
              // Rest beat
              if ((effectBeat & 0x08) != 0) {
                  beat.setRestBeat(true);
                  returnNow = true;
              }
  
              // Effects on the beat
              if ((effectBeat & 0x04) != 0) {
                  readEffectsOnBeat(gp1effects, beat.effects);
              }
  
              // Presence of a chord diagram
              if ((effectBeat & 0x02) != 0) {
                  beat.chordDiagram = readChordDiagram();
              }
  
              // Presence of a text
              if ((effectBeat & 0x01) != 0) {
                  beat.text = readStringByte(0);
              }
          }
  
          // If the flag has been set, we return immediatly
          if (returnNow) {
              return beat;
          }
  
          // Finds out which strings are played
          // i = 0 => lowest string
          int stringsPlayed = readUnsignedByte();
  
          // Gets the effects header
          int effectsHeader = readUnsignedByte();
  
          // Gets the corresponding notes
          List<GPNote> notes = beat.getNotes();
          int numberOfStrings = 0;
          for (int i = 5; i >= 0; i--) {
              if ((stringsPlayed & (1 << i)) != 0) {
                  GPNote note = readNote();
                  notes.add(note);
  
                  // Effect set on this note
                  if ((effectsHeader & (1 << i)) != 0) {
                      note.effects = readEffectsOnNote();
                  }
  
                  // Adds effects on note if
                  if (gp1effects.hasEffects()) {
  