public void write(long time, Instrument instrument1, Instrument instrument2) {
    double bid1 = instrument1.getBid();
    double ask1 = instrument1.getAsk();
    double bid2 = instrument2.getBid();
    double ask2 = instrument2.getAsk();

    if (bid1 > 0 && ask1 > 0 && bid2 > 0 && ask2 > 0) {
      StringBuilder sb = new StringBuilder();
      sb.append(dateFormat.format(new Date(time))).append(",");
      sb.append(decimalFormat.format(bid1)).append(",");
      sb.append(decimalFormat.format(ask1)).append(",");
      sb.append(decimalFormat.format(bid2)).append(",");
      sb.append(decimalFormat.format(ask2));

      writer.println(sb);
      writer.flush();
    }
  }
Exemple #2
0
  public void readInstrument(BufferedInputStream in, Instrument instr) throws IOException {
    // Instrument size
    int size = make32Bit(read(in, 4));

    // Instrument name
    read(in, 22);

    // Instrument type (always 0)
    // Note: not always 0 but it says so in the documents...
    in.read();

    // Number of samples in instrument
    Sample[] sample = new Sample[make16Bit(read(in, 2))];

    if (sample.length == 0) {
      read(in, size - 29);
    } else {
      // Sample header size
      int ssize = make32Bit(read(in, 4));
      if (ssize != 40) {
        throw new IOException("samplesize != 40!");
      }

      // Sample number for all notes
      instr.setSampleForNote(read(in, 96));

      // Points for volume envelope
      byte[] volEnvData = read(in, 48);

      // Points for panning envelope
      byte[] panEnvData = read(in, 48);

      // Number of volume points
      int points = in.read();
      Envelope volumeEnvelope = new Envelope();
      volumeEnvelope.setData(makeEnvelopePoints(points, volEnvData));

      // Number of panning points
      points = in.read();
      Envelope panningEnvelope = new Envelope();
      panningEnvelope.setData(makeEnvelopePoints(points, panEnvData));

      // Volume sustain point
      volumeEnvelope.setSustainPosition(in.read());

      // Volume loop start point
      volumeEnvelope.setLoopStart(in.read());

      // Volume loop end point
      volumeEnvelope.setLoopEnd(in.read());

      // Panning sustain point
      panningEnvelope.setSustainPosition(in.read());

      // Panning loop start point
      panningEnvelope.setLoopStart(in.read());

      // Panning loop end point
      panningEnvelope.setLoopEnd(in.read());

      // Volume type: bit 0: on; 1: Sustain; 2: Loop
      volumeEnvelope.setType(in.read());

      // Panning type: bit 0: on; 1: Sustain; 2: Loop
      panningEnvelope.setType(in.read());

      // Vibrato type
      Vibrato vibrato = new Vibrato();
      vibrato.setType(in.read());

      // Vibrato sweep
      vibrato.setSweep(in.read());

      // Vibrato depth
      vibrato.setDepth(in.read());

      // Vibrato rate
      vibrato.setRate(in.read());

      // Volume fadeout
      instr.setFadeout(make16Bit(read(in, 2)));

      // reserved
      read(in, 22);

      for (int i = 0; i < sample.length; i++) {
        sample[i] = new Sample();
        loadSample(in, sample[i]);
      }
      for (int i = 0; i < sample.length; i++) {
        loadSampleData(in, sample[i]);
      }

      instr.setPanningEnvelope(panningEnvelope);
      instr.setVolumeEnvelope(volumeEnvelope);
      instr.setVibrato(vibrato);
      instr.setSamples(sample);
    }
  }