Example #1
0
 /**
  * Makes the given class visitor visit this field.
  *
  * @param cv a class visitor.
  */
 public void accept(final ClassVisitor cv) {
   FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
   if (fv == null) {
     return;
   }
   int i, n;
   n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = visibleAnnotations.get(i);
     an.accept(fv.visitAnnotation(an.desc, true));
   }
   n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = invisibleAnnotations.get(i);
     an.accept(fv.visitAnnotation(an.desc, false));
   }
   n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = visibleTypeAnnotations.get(i);
     an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
   }
   n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
     an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
   }
   n = attrs == null ? 0 : attrs.size();
   for (i = 0; i < n; ++i) {
     fv.visitAttribute(attrs.get(i));
   }
   fv.visitEnd();
 }
Example #2
0
 public SoundbankResource[] getResources() {
   SoundbankResource[] resources = new SoundbankResource[layers.size() + samples.size()];
   int j = 0;
   for (int i = 0; i < layers.size(); i++) resources[j++] = layers.get(i);
   for (int i = 0; i < samples.size(); i++) resources[j++] = samples.get(i);
   return resources;
 }
Example #3
0
  /**
   * Method itemX509Data
   *
   * @param i
   * @return the asked X509Data element, null if the index is too big
   * @throws XMLSecurityException
   */
  public X509Data itemX509Data(int i) throws XMLSecurityException {
    if (x509Datas != null) {
      return x509Datas.get(i);
    }
    Element e =
        XMLUtils.selectDsNode(this.constructionElement.getFirstChild(), Constants._TAG_X509DATA, i);

    if (e != null) {
      return new X509Data(e, this.baseURI);
    }
    return null;
  }
Example #4
0
  /**
   * Method itemEncryptedKey
   *
   * @param i
   * @return the asked EncryptedKey element, null if the index is too big
   * @throws XMLSecurityException
   */
  public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException {
    if (encryptedKeys != null) {
      return encryptedKeys.get(i);
    }
    Element e =
        XMLUtils.selectXencNode(
            this.constructionElement.getFirstChild(), EncryptionConstants._TAG_ENCRYPTEDKEY, i);

    if (e != null) {
      XMLCipher cipher = XMLCipher.getInstance();
      cipher.init(XMLCipher.UNWRAP_MODE, null);
      return cipher.loadEncryptedKey(e);
    }
    return null;
  }
Example #5
0
  private void readPdtaChunk(RIFFReader riff) throws IOException {

    List<SF2Instrument> presets = new ArrayList<SF2Instrument>();
    List<Integer> presets_bagNdx = new ArrayList<Integer>();
    List<SF2InstrumentRegion> presets_splits_gen = new ArrayList<SF2InstrumentRegion>();
    List<SF2InstrumentRegion> presets_splits_mod = new ArrayList<SF2InstrumentRegion>();

    List<SF2Layer> instruments = new ArrayList<SF2Layer>();
    List<Integer> instruments_bagNdx = new ArrayList<Integer>();
    List<SF2LayerRegion> instruments_splits_gen = new ArrayList<SF2LayerRegion>();
    List<SF2LayerRegion> instruments_splits_mod = new ArrayList<SF2LayerRegion>();

    while (riff.hasNextChunk()) {
      RIFFReader chunk = riff.nextChunk();
      String format = chunk.getFormat();
      if (format.equals("phdr")) {
        // Preset Header / Instrument
        if (chunk.available() % 38 != 0) throw new RIFFInvalidDataException();
        int count = chunk.available() / 38;
        for (int i = 0; i < count; i++) {
          SF2Instrument preset = new SF2Instrument(this);
          preset.name = chunk.readString(20);
          preset.preset = chunk.readUnsignedShort();
          preset.bank = chunk.readUnsignedShort();
          presets_bagNdx.add(chunk.readUnsignedShort());
          preset.library = chunk.readUnsignedInt();
          preset.genre = chunk.readUnsignedInt();
          preset.morphology = chunk.readUnsignedInt();
          presets.add(preset);
          if (i != count - 1) this.instruments.add(preset);
        }
      } else if (format.equals("pbag")) {
        // Preset Zones / Instruments splits
        if (chunk.available() % 4 != 0) throw new RIFFInvalidDataException();
        int count = chunk.available() / 4;

        // Skip first record
        {
          int gencount = chunk.readUnsignedShort();
          int modcount = chunk.readUnsignedShort();
          while (presets_splits_gen.size() < gencount) presets_splits_gen.add(null);
          while (presets_splits_mod.size() < modcount) presets_splits_mod.add(null);
          count--;
        }

        int offset = presets_bagNdx.get(0);
        // Offset should be 0 (but just case)
        for (int i = 0; i < offset; i++) {
          if (count == 0) throw new RIFFInvalidDataException();
          int gencount = chunk.readUnsignedShort();
          int modcount = chunk.readUnsignedShort();
          while (presets_splits_gen.size() < gencount) presets_splits_gen.add(null);
          while (presets_splits_mod.size() < modcount) presets_splits_mod.add(null);
          count--;
        }

        for (int i = 0; i < presets_bagNdx.size() - 1; i++) {
          int zone_count = presets_bagNdx.get(i + 1) - presets_bagNdx.get(i);
          SF2Instrument preset = presets.get(i);
          for (int ii = 0; ii < zone_count; ii++) {
            if (count == 0) throw new RIFFInvalidDataException();
            int gencount = chunk.readUnsignedShort();
            int modcount = chunk.readUnsignedShort();
            SF2InstrumentRegion split = new SF2InstrumentRegion();
            preset.regions.add(split);
            while (presets_splits_gen.size() < gencount) presets_splits_gen.add(split);
            while (presets_splits_mod.size() < modcount) presets_splits_mod.add(split);
            count--;
          }
        }
      } else if (format.equals("pmod")) {
        // Preset Modulators / Split Modulators
        for (int i = 0; i < presets_splits_mod.size(); i++) {
          SF2Modulator modulator = new SF2Modulator();
          modulator.sourceOperator = chunk.readUnsignedShort();
          modulator.destinationOperator = chunk.readUnsignedShort();
          modulator.amount = chunk.readShort();
          modulator.amountSourceOperator = chunk.readUnsignedShort();
          modulator.transportOperator = chunk.readUnsignedShort();
          SF2InstrumentRegion split = presets_splits_mod.get(i);
          if (split != null) split.modulators.add(modulator);
        }
      } else if (format.equals("pgen")) {
        // Preset Generators / Split Generators
        for (int i = 0; i < presets_splits_gen.size(); i++) {
          int operator = chunk.readUnsignedShort();
          short amount = chunk.readShort();
          SF2InstrumentRegion split = presets_splits_gen.get(i);
          if (split != null) split.generators.put(operator, amount);
        }
      } else if (format.equals("inst")) {
        // Instrument Header / Layers
        if (chunk.available() % 22 != 0) throw new RIFFInvalidDataException();
        int count = chunk.available() / 22;
        for (int i = 0; i < count; i++) {
          SF2Layer layer = new SF2Layer(this);
          layer.name = chunk.readString(20);
          instruments_bagNdx.add(chunk.readUnsignedShort());
          instruments.add(layer);
          if (i != count - 1) this.layers.add(layer);
        }
      } else if (format.equals("ibag")) {
        // Instrument Zones / Layer splits
        if (chunk.available() % 4 != 0) throw new RIFFInvalidDataException();
        int count = chunk.available() / 4;

        // Skip first record
        {
          int gencount = chunk.readUnsignedShort();
          int modcount = chunk.readUnsignedShort();
          while (instruments_splits_gen.size() < gencount) instruments_splits_gen.add(null);
          while (instruments_splits_mod.size() < modcount) instruments_splits_mod.add(null);
          count--;
        }

        int offset = instruments_bagNdx.get(0);
        // Offset should be 0 (but just case)
        for (int i = 0; i < offset; i++) {
          if (count == 0) throw new RIFFInvalidDataException();
          int gencount = chunk.readUnsignedShort();
          int modcount = chunk.readUnsignedShort();
          while (instruments_splits_gen.size() < gencount) instruments_splits_gen.add(null);
          while (instruments_splits_mod.size() < modcount) instruments_splits_mod.add(null);
          count--;
        }

        for (int i = 0; i < instruments_bagNdx.size() - 1; i++) {
          int zone_count = instruments_bagNdx.get(i + 1) - instruments_bagNdx.get(i);
          SF2Layer layer = layers.get(i);
          for (int ii = 0; ii < zone_count; ii++) {
            if (count == 0) throw new RIFFInvalidDataException();
            int gencount = chunk.readUnsignedShort();
            int modcount = chunk.readUnsignedShort();
            SF2LayerRegion split = new SF2LayerRegion();
            layer.regions.add(split);
            while (instruments_splits_gen.size() < gencount) instruments_splits_gen.add(split);
            while (instruments_splits_mod.size() < modcount) instruments_splits_mod.add(split);
            count--;
          }
        }

      } else if (format.equals("imod")) {
        // Instrument Modulators / Split Modulators
        for (int i = 0; i < instruments_splits_mod.size(); i++) {
          SF2Modulator modulator = new SF2Modulator();
          modulator.sourceOperator = chunk.readUnsignedShort();
          modulator.destinationOperator = chunk.readUnsignedShort();
          modulator.amount = chunk.readShort();
          modulator.amountSourceOperator = chunk.readUnsignedShort();
          modulator.transportOperator = chunk.readUnsignedShort();
          SF2LayerRegion split = instruments_splits_gen.get(i);
          if (split != null) split.modulators.add(modulator);
        }
      } else if (format.equals("igen")) {
        // Instrument Generators / Split Generators
        for (int i = 0; i < instruments_splits_gen.size(); i++) {
          int operator = chunk.readUnsignedShort();
          short amount = chunk.readShort();
          SF2LayerRegion split = instruments_splits_gen.get(i);
          if (split != null) split.generators.put(operator, amount);
        }
      } else if (format.equals("shdr")) {
        // Sample Headers
        if (chunk.available() % 46 != 0) throw new RIFFInvalidDataException();
        int count = chunk.available() / 46;
        for (int i = 0; i < count; i++) {
          SF2Sample sample = new SF2Sample(this);
          sample.name = chunk.readString(20);
          long start = chunk.readUnsignedInt();
          long end = chunk.readUnsignedInt();
          sample.data = sampleData.subbuffer(start * 2, end * 2, true);
          if (sampleData24 != null) sample.data24 = sampleData24.subbuffer(start, end, true);
          /*
          sample.data = new ModelByteBuffer(sampleData, (int)(start*2),
                  (int)((end - start)*2));
          if (sampleData24 != null)
              sample.data24 = new ModelByteBuffer(sampleData24,
                      (int)start, (int)(end - start));
           */
          sample.startLoop = chunk.readUnsignedInt() - start;
          sample.endLoop = chunk.readUnsignedInt() - start;
          if (sample.startLoop < 0) sample.startLoop = -1;
          if (sample.endLoop < 0) sample.endLoop = -1;
          sample.sampleRate = chunk.readUnsignedInt();
          sample.originalPitch = chunk.readUnsignedByte();
          sample.pitchCorrection = chunk.readByte();
          sample.sampleLink = chunk.readUnsignedShort();
          sample.sampleType = chunk.readUnsignedShort();
          if (i != count - 1) this.samples.add(sample);
        }
      }
    }

    Iterator<SF2Layer> liter = this.layers.iterator();
    while (liter.hasNext()) {
      SF2Layer layer = liter.next();
      Iterator<SF2LayerRegion> siter = layer.regions.iterator();
      SF2Region globalsplit = null;
      while (siter.hasNext()) {
        SF2LayerRegion split = siter.next();
        if (split.generators.get(SF2LayerRegion.GENERATOR_SAMPLEID) != null) {
          int sampleid = split.generators.get(SF2LayerRegion.GENERATOR_SAMPLEID);
          split.generators.remove(SF2LayerRegion.GENERATOR_SAMPLEID);
          split.sample = samples.get(sampleid);
        } else {
          globalsplit = split;
        }
      }
      if (globalsplit != null) {
        layer.getRegions().remove(globalsplit);
        SF2GlobalRegion gsplit = new SF2GlobalRegion();
        gsplit.generators = globalsplit.generators;
        gsplit.modulators = globalsplit.modulators;
        layer.setGlobalZone(gsplit);
      }
    }

    Iterator<SF2Instrument> iiter = this.instruments.iterator();
    while (iiter.hasNext()) {
      SF2Instrument instrument = iiter.next();
      Iterator<SF2InstrumentRegion> siter = instrument.regions.iterator();
      SF2Region globalsplit = null;
      while (siter.hasNext()) {
        SF2InstrumentRegion split = siter.next();
        if (split.generators.get(SF2LayerRegion.GENERATOR_INSTRUMENT) != null) {
          int instrumentid = split.generators.get(SF2InstrumentRegion.GENERATOR_INSTRUMENT);
          split.generators.remove(SF2LayerRegion.GENERATOR_INSTRUMENT);
          split.layer = layers.get(instrumentid);
        } else {
          globalsplit = split;
        }
      }

      if (globalsplit != null) {
        instrument.getRegions().remove(globalsplit);
        SF2GlobalRegion gsplit = new SF2GlobalRegion();
        gsplit.generators = globalsplit.generators;
        gsplit.modulators = globalsplit.modulators;
        instrument.setGlobalZone(gsplit);
      }
    }
  }