protected void processAction(TGActionContext context) {
   TGSong song = ((TGSong) context.getAttribute(TGDocumentContextAttributes.ATTRIBUTE_SONG));
   TGTrack track = getSongManager(context).getLastTrack(song);
   if (track != null) {
     TablatureEditor.getInstance(getContext()).getTablature().getCaret().update(track.getNumber());
   }
 }
 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 addSong(TGSong song) {
    int trackCount = song.countTracks();
    if (this.settings.isTrackGroupEnabled() && trackCount > 1) {
      this.writer.println("\\score {");
      if (this.settings.getTrack() == LilypondSettings.ALL_TRACKS) {
        this.writer.println(indent(1) + "<<");
      }
    }

    for (int i = 0; i < trackCount; i++) {
      TGTrack track = song.getTrack(i);
      if (this.settings.getTrack() == LilypondSettings.ALL_TRACKS
          || this.settings.getTrack() == track.getNumber()) {
        if (!this.settings.isTrackGroupEnabled() || trackCount == 1) {
          this.writer.println("\\score {");
        }
        this.writer.println(indent(1) + "\\" + this.trackID(i, "StaffGroup"));
        if (!this.settings.isTrackGroupEnabled() || trackCount == 1) {
          this.addHeader(song, track.getName(), 1);
          this.writer.println("}");
        }
      }
    }

    if (this.settings.isTrackGroupEnabled() && trackCount > 1) {
      if (this.settings.getTrack() == LilypondSettings.ALL_TRACKS) {
        this.writer.println(indent(1) + ">>");
      }
      this.addHeader(song, null, 1);
      this.writer.println("}");
    }
  }
 private void updateTrack(TGTrack track) {
   try {
     getSequencer().setMute(track.getNumber(), track.isMute());
     getSequencer().setSolo(track.getNumber(), track.isSolo());
   } catch (MidiPlayerException e) {
     e.printStackTrace();
   }
 }
 protected int execute(TypedEvent e) {
   Caret caret = getEditor().getTablature().getCaret();
   TGTrack track = getSongManager().getTrack(caret.getTrack().getNumber() + 1);
   if (track != null) {
     caret.update(track.getNumber());
   }
   return 0;
 }
 private Clef getClef(TGTrack track) {
   if (!track.isPercussionTrack()) {
     for (final TGString string : track.getStrings()) {
       if (string.getValue() <= 34) {
         return Clef.BASS;
       }
     }
   }
   return Clef.TREBLE;
 }
  public void updateTracks() {
    this.anySolo = false;

    Iterator tracksIt = this.songManager.getSong().getTracks();
    while (tracksIt.hasNext()) {
      TGTrack track = (TGTrack) tracksIt.next();
      this.updateTrack(track);
      this.anySolo = ((!this.anySolo) ? track.isSolo() : this.anySolo);
    }

    this.afterUpdate();
  }
 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;
 }
Exemple #9
0
  private TGTrack readTrack(int number, TGSong song) {
    // header
    int header = readHeader();

    TGTrack track = this.factory.newTrack();

    track.setNumber(number);

    // leo el nombre
    track.setName(readUnsignedByteString());

    // leo el solo
    track.setSolo((header & TRACK_SOLO) != 0);

    // leo el mute
    track.setMute((header & TRACK_MUTE) != 0);

    // leo el canal
    readChannel(song, track);

    // leo la cantidad de compases
    int measureCount = song.countMeasureHeaders();

    // leo los compases
    TGMeasure lastMeasure = null;
    for (int i = 0; i < measureCount; i++) {
      TGMeasure measure = readMeasure(song.getMeasureHeader(i), lastMeasure);
      track.addMeasure(measure);
      lastMeasure = measure;
    }

    // leo la cantidad de cuerdas
    int stringCount = readByte();

    // leo las cuerdas
    for (int i = 0; i < stringCount; i++) {
      track.getStrings().add(readInstrumentString(i + 1));
    }

    // leo el offset
    track.setOffset(TGTrack.MIN_OFFSET + readByte());

    // leo el color
    readRGBColor(track.getColor());

    // leo el lyrics
    if (((header & TRACK_LYRICS) != 0)) {
      readLyrics(track.getLyrics());
    }

    return track;
  }
 private void addStaffGroup(TGTrack track, String id) {
   this.writer.println(id + "StaffGroup = \\new StaffGroup <<");
   if (this.addTrackTitleOnGroup(track.getSong())) {
     this.writer.println(
         indent(1) + "\\set StaffGroup.instrumentName = #\"" + track.getName() + "\"");
   }
   if (this.settings.isScoreEnabled()) {
     this.writer.println(indent(1) + "\\" + id + "Staff");
   }
   if (this.settings.isTablatureEnabled()) {
     this.writer.println(indent(1) + "\\" + id + "TabStaff");
   }
   this.writer.println(">>");
 }
 private TGTrack readTrack(int number, List<TGChannel> channels, TGLyric lyrics)
     throws IOException {
   readUnsignedByte();
   if (number == 1 || getVersionIndex() == 0) {
     skip(1);
   }
   TGTrack track = new TGTrackImpl();
   track.setNumber(number);
   track.setLyrics(lyrics);
   track.setName(readStringByte(40));
   int stringCount = readInt();
   for (int i = 0; i < 7; i++) {
     int tuning = readInt();
     if (stringCount > i) {
       track.getStrings().add(new TGString(i + 1, tuning));
     }
   }
   readInt();
   final TGChannel newChannel = this.readChannel(channels);
   if (newChannel != null) {
     track.setChannel(newChannel);
   }
   // readChannel(track.getChannel(), channels);
   readInt();
   track.setOffset(readInt());
   track.setColor(readColor());
   skip((getVersionIndex() > 0) ? 49 : 44);
   if (getVersionIndex() > 0) {
     readStringByteSizeOfInteger();
     readStringByteSizeOfInteger();
   }
   return track;
 }
Exemple #12
0
  private void readChannel(TGSong song, TGTrack track) {
    TGChannel channel = this.factory.newChannel();
    TGChannelParameter gmChannel1Param = this.factory.newChannelParameter();
    TGChannelParameter gmChannel2Param = this.factory.newChannelParameter();

    // leo el canal
    int channel1 = (readByte() & 0xff);
    gmChannel1Param.setKey(GMChannelRoute.PARAMETER_GM_CHANNEL_1);
    gmChannel1Param.setValue(Integer.toString(channel1));

    // leo el canal de efectos
    int channel2 = (readByte() & 0xff);
    gmChannel2Param.setKey(GMChannelRoute.PARAMETER_GM_CHANNEL_2);
    gmChannel2Param.setValue(Integer.toString(channel2));

    // Parseo el banco de sonidos
    channel.setBank(channel1 == 9 ? TGChannel.DEFAULT_PERCUSSION_BANK : TGChannel.DEFAULT_BANK);

    // leo el instrumento
    channel.setProgram(readByte());

    // leo el volumen
    channel.setVolume(readByte());

    // leo el balance
    channel.setBalance(readByte());

    // leo el chorus
    channel.setChorus(readByte());

    // leo el reverb
    channel.setReverb(readByte());

    // leo el phaser
    channel.setPhaser(readByte());

    // leo el tremolo
    channel.setTremolo(readByte());

    // ------------------------------------------//
    for (int i = 0; i < song.countChannels(); i++) {
      TGChannel channelAux = song.getChannel(i);
      for (int n = 0; n < channelAux.countParameters(); n++) {
        TGChannelParameter channelParameter = channelAux.getParameter(n);
        if (channelParameter.getKey().equals(GMChannelRoute.PARAMETER_GM_CHANNEL_1)) {
          if (Integer.toString(channel1).equals(channelParameter.getValue())) {
            channel.setChannelId(channelAux.getChannelId());
          }
        }
      }
    }
    if (channel.getChannelId() <= 0) {
      channel.setChannelId(song.countChannels() + 1);
      channel.setName(("#" + channel.getChannelId()));
      channel.addParameter(gmChannel1Param);
      channel.addParameter(gmChannel2Param);
      song.addChannel(channel);
    }
    track.setChannelId(channel.getChannelId());
  }
  public static TGUndoableCloneTrack startUndo(TGContext context, TGTrack track) {
    TGUndoableCloneTrack undoable = new TGUndoableCloneTrack(context);
    undoable.doAction = UNDO_ACTION;
    undoable.trackNumber = track.getNumber();

    return undoable;
  }
  private void readChannel(TGSong song, TGTrack track, List channels) throws IOException {
    int index = (readInt() - 1);
    int effectChannel = (readInt() - 1);
    if (index >= 0 && index < channels.size()) {
      TGChannel channel = getFactory().newChannel();

      ((TGChannel) channels.get(index)).copy(channel);
      if (channel.getProgram() < 0) {
        channel.setProgram((short) 0);
      }
      if (!channel.isPercussionChannel()) {
        channel.setEffectChannel((short) effectChannel);
      }

      // ------------------------------------------//
      for (int i = 0; i < song.countChannels(); i++) {
        TGChannel channelAux = song.getChannel(i);
        if (channelAux.getChannel() == channel.getChannel()) {
          channel.setChannelId(channelAux.getChannelId());
        }
      }
      if (channel.getChannelId() <= 0) {
        channel.setChannelId(song.countChannels() + 1);
        channel.setName(("#" + channel.getChannelId()));
        song.addChannel(channel);
      }
      track.setChannelId(channel.getChannelId());
    }
  }
  private void addTabStaff(TGTrack track, String id) {
    boolean addLyrics = (this.settings.isLyricsEnabled() && !track.getLyrics().isEmpty());
    boolean addChordDiagrams =
        (this.settings.isChordDiagramEnabled() && !this.settings.isScoreEnabled());
    boolean addTexts = (this.settings.isTextEnabled() && !this.settings.isScoreEnabled());

    this.writer.println(
        id
            + "TabStaff = \\new "
            + (addLyrics ? "TabVoice = \"" + id + "TabStaff\" <<" : "TabStaff {"));

    this.addTuning(track, 1);

    if (!addChordDiagrams) {
      this.writer.println(indent(1) + "\\removeWithTag #'chords");
    }
    if (!addTexts) {
      this.writer.println(indent(1) + "\\removeWithTag #'texts");
    }
    this.writer.println(indent(1) + "\\" + id + "Music #" + getLilypondBoolean(true));
    if (addLyrics) {
      this.writer.println(
          indent(1) + "\\new Lyrics \\lyricsto \"" + id + "TabStaff\" \\" + id + "Lyrics");
    }
    this.writer.println((addLyrics ? ">>" : "}"));
  }
 private void addMusic(TGTrack track, String id) {
   this.writer.println(id + "Music = #(define-music-function (parser location inTab) (boolean?)");
   this.writer.println("#{");
   TGMeasure previous = null;
   int count = track.countMeasures();
   for (int i = 0; i < count; i++) {
     TGMeasure measure = track.getMeasure(i);
     int measureFrom = this.settings.getMeasureFrom();
     int measureTo = this.settings.getMeasureTo();
     if ((measureFrom <= measure.getNumber() || measureFrom == LilypondSettings.FIRST_MEASURE)
         && (measureTo >= measure.getNumber() || measureTo == LilypondSettings.LAST_MEASURE)) {
       this.addMeasure(measure, previous, 1, (i == (count - 1)));
       previous = measure;
     }
   }
   this.writer.println(indent(1) + "\\pageBreak");
   this.writer.println("#})");
 }
 private void readMeasures(TGSong song, int measures, int tracks, int tempoValue)
     throws IOException {
   TGTempo tempo = getFactory().newTempo();
   tempo.setValue(tempoValue);
   long start = TGDuration.QUARTER_TIME;
   for (int i = 0; i < measures; i++) {
     TGMeasureHeader header = song.getMeasureHeader(i);
     header.setStart(start);
     for (int j = 0; j < tracks; j++) {
       TGTrack track = song.getTrack(j);
       TGMeasure measure = getFactory().newMeasure(header);
       track.addMeasure(measure);
       readMeasure(measure, track, tempo);
     }
     tempo.copy(header.getTempo());
     start += header.getLength();
   }
 }
  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 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;
 }
 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(")");
 }
  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 addLyrics(TGTrack track, String id) {
   this.writer.println(id + "Lyrics = \\lyricmode {");
   this.writer.println(indent(1) + "\\set ignoreMelismata = #" + getLilypondBoolean(true));
   int skippedCount = this.temp.getSkippedLyricBeats().size();
   if (skippedCount > 0) {
     this.writer.print(indent(1));
     for (int i = 0; i < skippedCount; i++) {
       this.writer.print("\\skip " + ((String) this.temp.getSkippedLyricBeats().get(i)) + " ");
     }
     this.writer.println();
   }
   this.writer.println(indent(1) + track.getLyrics().getLyrics());
   this.writer.println(indent(1) + "\\unset ignoreMelismata");
   this.writer.println("}");
 }
  private void writeTrack(TGTrack track) {
    // header
    int header = 0;
    if (!track.getLyrics().isEmpty()) {
      header |= TRACK_LYRICS;
    }
    writeHeader(header);

    // escribo el nombre
    writeUnsignedByteString(track.getName());

    // escribo el canal
    writeChannel(track);

    // escribo los compases
    TGMeasure lastMeasure = null;
    for (TGMeasure measure : track.getMeasures()) {
      writeMeasure(measure, lastMeasure);
      lastMeasure = measure;
    }

    // escribo la cantidad de cuerdas
    writeByte(track.getStrings().size());

    // escribo las cuerdas
    for (TGString string : track.getStrings()) {
      writeInstrumentString(string);
    }

    // escribo el offset
    writeByte(track.getOffset() - TGTrack.MIN_OFFSET);

    // escribo el color
    writeRGBColor(track.getColor());

    // escribo el lyrics
    if (((header & TRACK_LYRICS) != 0)) {
      writeLyrics(track.getLyrics());
    }
  }
 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 TGTrack readTrack(TGSong song) {
    TGTrack track = this.factory.newTrack();

    // leo el numero
    track.setNumber((int) readLong());

    // leo el nombre
    track.setName(readString());

    // leo el canal
    readChannel(track);

    // leo la cantidad de compases
    int measureCount = readInt();

    if (song.countMeasureHeaders() == 0) {
      for (int i = 0; i < measureCount; i++) {
        TGMeasureHeader header = this.factory.newHeader();
        song.addMeasureHeader(header);
      }
    }

    // leo los compases
    for (int i = 0; i < measureCount; i++) {
      track.addMeasure(readMeasure(song.getMeasureHeader(i)));
    }

    // leo la cantidad de cuerdas
    int stringCount = readInt();

    // leo las cuerdas
    for (int i = 0; i < stringCount; i++) {
      track.getStrings().add(readInstrumentString());
    }

    // leo el color
    readColor(track.getColor());

    return track;
  }
  private void readChannel(TGTrack track) {
    // leo el canal
    track.getChannel().setChannel(readShort());

    // leo el canal de efectos
    track.getChannel().setEffectChannel(readShort());

    // leo el instrumento
    track.getChannel().setInstrument(readShort());

    // leo el volumen
    track.getChannel().setVolume(readShort());

    // leo el balance
    track.getChannel().setBalance(readShort());

    // leo el chorus
    track.getChannel().setChorus(readShort());

    // leo el reverb
    track.getChannel().setReverb(readShort());

    // leo el phaser
    track.getChannel().setPhaser(readShort());

    // leo el tremolo
    track.getChannel().setTremolo(readShort());

    // leo el solo
    track.setSolo(readBoolean());

    // leo el mute
    track.setMute(readBoolean());
  }
 private static TGTrack cloneTrack(TGTrack track) {
   return track.clone(
       TuxGuitar.instance().getSongManager().getFactory(),
       TuxGuitar.instance().getSongManager().getSong());
 }
  private void writeChannel(TGTrack track) {
    int header = 0;
    header = (track.isSolo()) ? header |= CHANNEL_SOLO : header;
    header = (track.isMute()) ? header |= CHANNEL_MUTE : header;
    writeHeader(header);

    // escribo el canal
    writeByte(track.getChannel().getChannel());

    // escribo el canal de efectos
    writeByte(track.getChannel().getEffectChannel());

    // escribo el instrumento
    writeByte(track.getChannel().getInstrument());

    // escribo el volumen
    writeByte(track.getChannel().getVolume());

    // escribo el balance
    writeByte(track.getChannel().getBalance());

    // escribo el chorus
    writeByte(track.getChannel().getChorus());

    // escribo el reverb
    writeByte(track.getChannel().getReverb());

    // escribo el phaser
    writeByte(track.getChannel().getPhaser());

    // escribo el tremolo
    writeByte(track.getChannel().getTremolo());
  }