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 boolean isPercussionChannel(TGSong song, int channelId) {
   Iterator it = song.getChannels();
   while (it.hasNext()) {
     TGChannel channel = (TGChannel) it.next();
     if (channel.getChannelId() == channelId) {
       return channel.isPercussionChannel();
     }
   }
   return false;
 }
 public int getPercussionChannelId() {
   Iterator tgChannels = this.songManager.getSong().getChannels();
   while (tgChannels.hasNext()) {
     TGChannel tgChannel = (TGChannel) tgChannels.next();
     if (tgChannel.isPercussionChannel()) {
       return tgChannel.getChannelId();
     }
   }
   return -1;
 }
 public void updateParameters(TGChannel tgChannel) {
   Iterator parameters = tgChannel.getParameters();
   while (parameters.hasNext()) {
     TGChannelParameter tgChannelParameter = (TGChannelParameter) parameters.next();
     this.updateParameters(tgChannel, tgChannelParameter);
   }
 }
Example #5
0
  private TGChannel readChannel(List<TGChannel> channels) throws IOException {
    TGChannel result = null;

    int index = (readInt() - 1);
    int effectChannel = (readInt() - 1);
    if (index >= 0 && index < channels.size()) {
      result = channels.get(index).clone();
      if (result.getInstrument() < 0) {
        result.setInstrument((short) 0);
      }
      if (!result.isPercussionChannel()) {
        result.setEffectChannel((short) effectChannel);
      }
    }

    return result;
  }
 private List readChannels() throws IOException {
   List channels = new ArrayList();
   for (int i = 0; i < 64; i++) {
     TGChannel channel = getFactory().newChannel();
     channel.setChannel((short) i);
     channel.setEffectChannel((short) i);
     channel.setProgram((short) readInt());
     channel.setVolume(toChannelShort(readByte()));
     channel.setBalance(toChannelShort(readByte()));
     channel.setChorus(toChannelShort(readByte()));
     channel.setReverb(toChannelShort(readByte()));
     channel.setPhaser(toChannelShort(readByte()));
     channel.setTremolo(toChannelShort(readByte()));
     channels.add(channel);
     skip(2);
   }
   return channels;
 }
 private void updateDefaultControllers() {
   try {
     Iterator tgChannels = this.songManager.getSong().getChannels();
     while (tgChannels.hasNext()) {
       TGChannel tgChannel = (TGChannel) tgChannels.next();
       getOutputTransmitter()
           .sendControlChange(tgChannel.getChannelId(), MidiControllers.RPN_MSB, 0);
       getOutputTransmitter()
           .sendControlChange(tgChannel.getChannelId(), MidiControllers.RPN_LSB, 0);
       getOutputTransmitter()
           .sendControlChange(tgChannel.getChannelId(), MidiControllers.DATA_ENTRY_MSB, 12);
       getOutputTransmitter()
           .sendControlChange(tgChannel.getChannelId(), MidiControllers.DATA_ENTRY_LSB, 0);
     }
   } catch (MidiPlayerException e) {
     e.printStackTrace();
   }
 }
 public void updateParameters(TGChannel tgChannel, TGChannelParameter tgChannelParameter) {
   try {
     getOutputTransmitter()
         .sendParameter(
             tgChannel.getChannelId(), tgChannelParameter.getKey(), tgChannelParameter.getValue());
   } catch (MidiPlayerException e) {
     e.printStackTrace();
   }
 }
  private void updateController(TGChannel channel) {
    int volume = (int) ((this.getVolume() / 10.00) * channel.getVolume());
    int balance = channel.getBalance();
    int chorus = channel.getChorus();
    int reverb = channel.getReverb();
    int phaser = channel.getPhaser();
    int tremolo = channel.getTremolo();

    updateController(channel.getChannelId(), volume, balance, chorus, reverb, phaser, tremolo, 127);
  }
  public void updateChannels() throws MidiPlayerException {
    // Remove unused channels.
    List oldChannelIds = getChannelRouter().getMidiChannelIds();
    Iterator iterator = oldChannelIds.iterator();
    while (iterator.hasNext()) {
      int channelId = ((Integer) iterator.next()).intValue();

      boolean removableChannel = (this.songManager.getChannel(channelId) == null);
      if (!removableChannel) {
        MidiChannel midiChannel = getChannelRouter().getMidiChannel(channelId);
        if (midiChannel != null) {
          removableChannel = (!this.getSynthesizerProxy().isChannelOpen(midiChannel));
        }
      }

      if (removableChannel) {
        this.getSynthesizerProxy().closeChannel(getChannelRouter().getMidiChannel(channelId));
        this.getChannelRouter().removeMidiChannel(channelId);
      }
    }

    // Add channels
    List newChannelIds = getChannelRouter().getMidiChannelIds();
    Iterator tgChannels = this.songManager.getSong().getChannels();
    while (tgChannels.hasNext()) {
      TGChannel tgChannel = (TGChannel) tgChannels.next();
      if (!newChannelIds.contains(new Integer(tgChannel.getChannelId()))) {
        MidiChannel midiChannel = this.getSynthesizerProxy().openChannel(tgChannel.getChannelId());
        if (midiChannel != null) {
          this.getChannelRouter().addMidiChannel(tgChannel.getChannelId(), midiChannel);
        }
      }
    }

    this.updateParameters();
  }
  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());
    }
  }
Example #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());
  }
 private void updateProgram(TGChannel channel) {
   this.updateProgram(channel.getChannelId(), channel.getBank(), channel.getProgram());
 }