private JPanel getMixerOptionsPanel() {
    if (mixerOptionsPanel == null) {
      mixerOptionsPanel = new JPanel();
      mixerOptionsPanel.setBorder(
          BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Mixer"));

      mixerOptionsPanel.setLayout(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();

      c.anchor = GridBagConstraints.NORTHWEST;
      c.fill = GridBagConstraints.NONE;
      c.weightx = 1;

      c.insets = new Insets(8, 4, 0, 0);
      mixerOptionsPanel.add(new JLabel("Select mixer:"), c);

      c.gridy = 1;
      mixerOptionsPanel.add(getMixerComboBox(), c);

      c.gridy = 2;
      mixerOptionsPanel.add(getMixerDefaultButton(), c);

      c.insets = new Insets(16, 4, 0, 0);
      c.gridy = 3;
      mixerOptionsPanel.add(new JLabel("Enable mixer features:"), c);

      c.insets = new Insets(6, 0, 0, 0);
      c.gridy = 4;
      mixerOptionsPanel.add(getEnableMixerVolumeCheckBox(), c);

      c.insets = new Insets(0, 0, 0, 0);
      c.gridy = 5;
      mixerOptionsPanel.add(getEnableMixerPanCheckBox(), c);

      if (AudioSystem.getMixerInfo().length == 0) {
        for (Component child : mixerOptionsPanel.getComponents()) {
          child.setEnabled(false);
        }
      }
    }
    return mixerOptionsPanel;
  }
  private JPanel getSoundOptionsPanel() {
    if (soundOptionsPanel == null) {
      soundOptionsPanel = new JPanel();
      soundOptionsPanel.setBorder(
          BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Sound Effects"));

      soundOptionsPanel.setLayout(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();

      c.fill = 1;
      c.weightx = 1;
      c.anchor = GridBagConstraints.NORTHWEST;

      c.gridwidth = GridBagConstraints.REMAINDER;
      soundOptionsPanel.add(getEnableSoundCheckBox(), c);
      soundOptionsPanel.add(getEnableGunshotCheckBox(), c);
      soundOptionsPanel.add(getEnableBulletHitCheckBox(), c);
      soundOptionsPanel.add(getEnableRobotDeathCheckBox(), c);
      soundOptionsPanel.add(getEnableWallCollisionCheckBox(), c);
      soundOptionsPanel.add(getEnableRobotCollisionCheckBox(), c);

      c.insets = new Insets(10, 0, 0, 10);
      c.gridwidth = 1;
      c.fill = 0;
      c.weighty = 1;
      c.weightx = 0;
      soundOptionsPanel.add(getEnableAllSoundsButton(), c);
      c.weightx = 1;
      c.gridwidth = GridBagConstraints.REMAINDER;
      soundOptionsPanel.add(getDisableAllSoundsButton(), c);

      if (AudioSystem.getMixerInfo().length == 0) {
        for (Component child : soundOptionsPanel.getComponents()) {
          child.setEnabled(false);
        }
      }
    }
    return soundOptionsPanel;
  }
예제 #3
0
  private ArrayList<SoundSample> getSampleAsArrayList(Selection selection, Component c) {
    ArrayList<SoundSample> points = new ArrayList<SoundSample>();

    // System.err.println(c.getHeight());
    int sampleBeginIndex = selection.getBegin();
    int sampleEndIndex = selection.getEnd();

    if (!checkRange(sampleBeginIndex, sampleEndIndex)) {
      System.err.println(
          "The range of sample ("
              + sampleBeginIndex
              + " , "
              + sampleEndIndex
              + ") you are trying to visualize is invalid");
    } else {
      int selectionLength = sampleEndIndex - sampleBeginIndex + 1;
      float maxValue = myHelper.getMaxSampleValue();
      samplePerPixel = selectionLength * 1.0 / frameWidth;
      if (DEBUG) System.err.println("getSamples: sample per pixel " + samplePerPixel);

      if (selectionLength
          < frameWidth) { // if every sample can be displayed (i.e at least 1 pixel per sample)
        if (DEBUG) System.err.println("getSamples: Everything can be displayed " + selectionLength);
        int ratio = (int) Math.floor(frameWidth / selectionLength);
        if (DEBUG) System.err.println("getSamples: ratio " + ratio);
        int occupyPixels = ratio * selectionLength;
        selectionLength =
            selectionLength
                + (frameWidth - occupyPixels)
                    / ratio; // fill up the display space with a few more samples

        if (DEBUG) System.err.println("getSamples: selection length " + selectionLength);

        if (selectionLength + sampleBeginIndex - 1 > data.size()) {
          selectionLength -= selectionLength + sampleBeginIndex - 1 - data.size();
        }
        if (DEBUG) System.err.println("getSamples: Final selection length " + selectionLength);
        for (int i = 0; i < selectionLength; i++) {
          float sampleValue = data.get(sampleBeginIndex + i - 1);
          float y = ((float) Math.floor(c.getHeight() / 2) * (1 - sampleValue / maxValue));
          points.add(
              new SoundSample(new Point2D.Float(i * ratio, y), sampleValue, sampleBeginIndex + i));
        }
      } else if (selectionLength / 2 < frameWidth) { // we can sample at Nyquist rate
        // System.err.println("Sample begin " + sampleBeginIndex );

        int start = sampleBeginIndex;
        for (int pixel = 0; pixel < frameWidth; pixel++) {
          // System.err.println("Sample index " + (start+ samplePerPixel * pixel) );

          int sampleValue = data.get((int) Math.floor(start + samplePerPixel * pixel));
          // int sampleValue = findMax(start, end);
          float y =
              ((float) Math.floor(c.getHeight() / 2)
                  - (sampleValue * ((float) Math.floor(c.getHeight() / 2) / maxValue)));
          points.add(new SoundSample(new Point2D.Float(pixel, y), sampleValue, pixel));
        }
      } else { // show general contour
        int start = sampleBeginIndex;
        int end = (int) (sampleBeginIndex + this.samplePerPixel);
        int baseLine = c.getHeight() / 2;
        for (int pixel = 0; pixel < frameWidth; pixel++) {
          ArrayList<Integer> minMax = findMinMax(start, end);
          // System.err.println(minMax);
          float y = baseLine - (minMax.get(0) * 0.9f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(0), pixel));

          y = baseLine - (minMax.get(0) * 0.7f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(0) / 2, pixel));

          // System.err.print("Min y: " + y + " ");

          y = baseLine - (minMax.get(1) * 0.9f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(1) / 2, pixel));
          y = baseLine - (minMax.get(1) * 0.7f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(1), pixel));

          //					if (y > c.getHeight())
          //						System.err.println("not right");
          start = end + 1;
          end = (int) (end + samplePerPixel);
        }
      }
    }
    return points;
  }