コード例 #1
0
ファイル: Filter.java プロジェクト: harshalrio91/Pixelitor
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    Filter filter = (Filter) o;

    if (!getListName().equals(filter.getListName())) {
      return false;
    }

    return true;
  }
 @Override
 protected void doOKAction() {
   mySelectedClass = calcSelectedClass();
   if (mySelectedClass == null) return;
   if (!myClassFilter.isAccepted(mySelectedClass)) {
     Messages.showErrorDialog(
         myTabbedPane.getComponent(),
         SymbolPresentationUtil.getSymbolPresentableText(mySelectedClass) + " is not acceptable");
     return;
   }
   super.doOKAction();
 }
コード例 #3
0
ファイル: LaguerreDlg.java プロジェクト: ynohtna/FScape
  protected void process() {
    int i, j, len, ch, chunkLength;
    long progOff, progLen;
    float f1;

    // io
    AudioFile inF = null;
    AudioFile outF = null;
    AudioFileDescr inStream;
    AudioFileDescr outStream;
    FloatFile[] floatF = null;
    File tempFile[] = null;

    // buffers
    float[][] inBuf, outBuf;
    float[] win;
    float[] convBuf1, convBuf2;
    float[] tempFlt;

    int inChanNum, inLength, inputStep, outputStep, winSize;
    int transLen, skip, inputLen, outputLen, fltLen;
    int framesRead, framesWritten;
    float warp, a1, b0, b1, x0, x1, y0, y1, b0init;

    Param ampRef = new Param(1.0, Param.ABS_AMP); // transform-Referenz
    Param peakGain;
    float gain = 1.0f; // gain abs amp
    float maxAmp = 0.0f;

    PathField ggOutput;

    topLevel:
    try {

      // ---- open input, output ----

      // input
      inF = AudioFile.openAsRead(new File(pr.text[PR_INPUTFILE]));
      inStream = inF.getDescr();
      inChanNum = inStream.channels;
      inLength = (int) inStream.length;
      // this helps to prevent errors from empty files!
      if ((inLength * inChanNum) < 1) throw new EOFException(ERR_EMPTY);
      // .... check running ....
      if (!threadRunning) break topLevel;

      // output
      ggOutput = (PathField) gui.getItemObj(GG_OUTPUTFILE);
      if (ggOutput == null) throw new IOException(ERR_MISSINGPROP);
      outStream = new AudioFileDescr(inStream);
      ggOutput.fillStream(outStream);
      outF = AudioFile.openAsWrite(outStream);
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ---- parameter inits ----

      warp =
          Math.max(-0.98f, Math.min(0.98f, (float) (pr.para[PR_WARP].val / 100))); // DAFx2000 'b'
      f1 = (1.0f - warp) / (1.0f + warp); // DAFx2000 (25)
      winSize = 32 << pr.intg[PR_FRAMESIZE]; // DAFx2000 'N'
      j = winSize >> 1;
      transLen = (int) (f1 * winSize + 0.5f); // DAFx2000 'P' (26)
      i = pr.intg[PR_OVERLAP] + 1;
      while (((float) transLen / (float) i) > j) i++;
      inputStep = (int) (((float) transLen / (float) i) + 0.5f); // DAFx2000 'L'
      fltLen = Math.max(winSize, transLen);
      // System.out.println( "inputStep "+inputStep+"; winSize "+winSize+"; transLen "+transLen+";
      // fltLen "+fltLen+"; warp "+warp+"; � "+f1 );
      win = Filter.createFullWindow(winSize, Filter.WIN_HANNING); // DAFx2000 (27)
      outputStep = inputStep;

      b0init = (float) Math.sqrt(1.0f - warp * warp);

      progOff = 0;
      progLen = (long) inLength * (2 + inChanNum); // + winSize;

      tempFlt = new float[fltLen];
      inputLen = winSize + inputStep;
      inBuf = new float[inChanNum][inputLen];
      outputLen = transLen + outputStep;
      outBuf = new float[inChanNum][outputLen];

      // normalization requires temp files
      if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) {
        tempFile = new File[inChanNum];
        floatF = new FloatFile[inChanNum];
        for (ch = 0; ch < inChanNum; ch++) { // first zero them because an exception might be thrown
          tempFile[ch] = null;
          floatF[ch] = null;
        }
        for (ch = 0; ch < inChanNum; ch++) {
          tempFile[ch] = IOUtil.createTempFile();
          floatF[ch] = new FloatFile(tempFile[ch], GenericFile.MODE_OUTPUT);
        }
        progLen += (long) inLength;
      } else {
        gain = (float) ((Param.transform(pr.para[PR_GAIN], Param.ABS_AMP, ampRef, null)).val);
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ----==================== the real stuff ====================----

      framesRead = 0;
      framesWritten = 0;
      skip = 0;

      while (threadRunning && (framesWritten < inLength)) {

        chunkLength = Math.min(inputLen, inLength - framesRead + skip);
        // ---- read input chunk ----
        len = Math.max(0, chunkLength - skip);
        inF.readFrames(inBuf, skip, len);
        framesRead += len;
        progOff += len;
        //				off			+= len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
        // .... check running ....
        if (!threadRunning) break topLevel;

        // zero padding
        if (chunkLength < inputLen) {
          for (ch = 0; ch < inChanNum; ch++) {
            convBuf1 = inBuf[ch];
            for (i = chunkLength; i < convBuf1.length; i++) {
              convBuf1[i] = 0.0f;
            }
          }
        }

        for (ch = 0; threadRunning && (ch < inChanNum); ch++) {
          convBuf1 = inBuf[ch];
          convBuf2 = outBuf[ch];

          for (i = 0, j = fltLen; i < winSize; i++) {
            tempFlt[--j] = convBuf1[i] * win[i];
          }
          while (j > 0) {
            tempFlt[--j] = 0.0f;
          }

          a1 = -warp; // inital allpass
          b0 = b0init;
          b1 = 0.0f;
          for (j = 0; j < transLen; j++) {
            x1 = 0.0f;
            y1 = 0.0f;

            //						for( i = 0; i < transLen; i++ ) {		// DAFx2000 (2 resp. 3)
            for (i = 0; i < fltLen; i++) { // DAFx2000 (2 resp. 3)
              x0 = tempFlt[i];
              y0 = b0 * x0 + b1 * x1 - a1 * y1;
              tempFlt[i] = y0; // (work with double precision while computing cascades)
              y1 = y0;
              x1 = x0;
            }

            a1 = -warp; // cascaded allpasses
            b0 = -warp;
            b1 = 1.0f;

            convBuf2[j] += (float) y1;
          }
          // .... progress ....
          progOff += chunkLength - skip;
          setProgression((float) progOff / (float) progLen);
        } // for channels
        // .... check running ....
        if (!threadRunning) break topLevel;

        chunkLength = Math.min(outputStep, inLength - framesWritten);
        // ---- write output chunk ----
        if (floatF != null) {
          for (ch = 0; ch < inChanNum; ch++) {
            floatF[ch].writeFloats(outBuf[ch], 0, chunkLength);
          }
          progOff += chunkLength;
          //					off			  += len;
          framesWritten += chunkLength;
          // .... progress ....
          setProgression((float) progOff / (float) progLen);

        } else {
          for (ch = 0; ch < inChanNum; ch++) {
            Util.mult(outBuf[ch], 0, chunkLength, gain);
          }
          outF.writeFrames(outBuf, 0, chunkLength);
          progOff += chunkLength;
          //					off			  += len;
          framesWritten += chunkLength;
          // .... progress ....
          setProgression((float) progOff / (float) progLen);
        }
        // .... check running ....
        if (!threadRunning) break topLevel;

        // check max amp
        for (ch = 0; ch < inChanNum; ch++) {
          convBuf1 = outBuf[ch];
          for (i = 0; i < chunkLength; i++) {
            f1 = Math.abs(convBuf1[i]);
            if (f1 > maxAmp) {
              maxAmp = f1;
            }
          }
        }

        // overlaps
        skip = winSize;
        for (ch = 0; ch < inChanNum; ch++) {
          System.arraycopy(inBuf[ch], inputStep, inBuf[ch], 0, winSize);
          convBuf1 = outBuf[ch];
          System.arraycopy(convBuf1, outputStep, convBuf1, 0, transLen);
          for (i = transLen; i < outputLen; ) {
            convBuf1[i++] = 0.0f;
          }
        }
      } // until framesWritten == outLength
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ----==================== normalize output ====================----

      if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) {
        peakGain = new Param((double) maxAmp, Param.ABS_AMP);
        gain =
            (float)
                (Param.transform(
                        pr.para[PR_GAIN],
                        Param.ABS_AMP,
                        new Param(1.0 / peakGain.val, peakGain.unit),
                        null))
                    .val;
        normalizeAudioFile(floatF, outF, inBuf, gain, 1.0f);
        maxAmp *= gain;

        for (ch = 0; ch < inChanNum; ch++) {
          floatF[ch].cleanUp();
          floatF[ch] = null;
          tempFile[ch].delete();
          tempFile[ch] = null;
        }
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ---- Finish ----

      outF.close();
      outF = null;
      outStream = null;
      inF.close();
      inF = null;
      inStream = null;
      inBuf = null;

      // inform about clipping/ low level
      handleClipping(maxAmp);
    } catch (IOException e1) {
      setError(e1);
    } catch (OutOfMemoryError e2) {
      inStream = null;
      outStream = null;
      inBuf = null;
      convBuf1 = null;
      convBuf2 = null;
      System.gc();

      setError(new Exception(ERR_MEMORY));
      ;
    }

    // ---- cleanup (topLevel) ----
    if (inF != null) {
      inF.cleanUp();
      inF = null;
    }
    if (outF != null) {
      outF.cleanUp();
      outF = null;
    }
    if (floatF != null) {
      for (ch = 0; ch < floatF.length; ch++) {
        if (floatF[ch] != null) {
          floatF[ch].cleanUp();
          floatF[ch] = null;
        }
        if (tempFile[ch] != null) {
          tempFile[ch].delete();
          tempFile[ch] = null;
        }
      }
    }
  } // process()
コード例 #4
0
ファイル: InputFrame.java プロジェクト: raniaics/sip-creator
/**
 * This frame shows an input record's XML in the form of a tree, with an added ability to copy the
 * values from any node for other purposes. There are controls to create selection criteria for
 * choosing particular records as the scan proceeds, and buttons for going to the first or the next
 * record.
 *
 * @author Gerald de Jong <*****@*****.**>
 */
public class InputFrame extends FrameBase {
  private static final DefaultTreeModel EMPTY_MODEL =
      new DefaultTreeModel(new DefaultMutableTreeNode("No input"));
  private JTree recordTree;
  private JComboBox filterBox = new JComboBox(Filter.values());
  private JTextField filterField = new JTextField();

  private enum Filter {
    REGEX("Regex"),
    MODULO("Modulo");

    private String name;

    private Filter(String name) {
      this.name = name;
    }

    @Override
    public String toString() {
      return name;
    }
  }

  public InputFrame(SipModel sipModel) {
    super(Which.INPUT, sipModel, "Input");
    sipModel.addParseListener(
        new SipModel.ParseListener() {
          @Override
          public void updatedRecord(MetadataRecord metadataRecord) {
            exec(new RecordSetter(metadataRecord));
          }
        });
    recordTree =
        new JTree(EMPTY_MODEL) {
          @Override
          public String getToolTipText(MouseEvent evt) {
            TreePath treePath = recordTree.getPathForLocation(evt.getX(), evt.getY());
            return treePath != null
                ? ((GroovyTreeNode) treePath.getLastPathComponent()).toolTip
                : "";
          }
        };
    recordTree.setToolTipText("Input Record");
    recordTree.setCellRenderer(new Renderer());
    recordTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    recordTree.setTransferHandler(new TreeTransferHandler());
    filterField.addActionListener(rewind);
  }

  @Override
  protected void buildContent(Container content) {
    content.add(scrollVH(recordTree), BorderLayout.CENTER);
    content.add(createRecordButtonPanel(), BorderLayout.SOUTH);
  }

  private JPanel createRecordButtonPanel() {
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createTitledBorder("Filter"));
    p.add(filterBox, BorderLayout.WEST);
    p.add(filterField, BorderLayout.CENTER);
    p.add(createButtonPanel(), BorderLayout.SOUTH);
    return p;
  }

  private JPanel createButtonPanel() {
    JPanel p = new JPanel(new GridLayout(1, 0));
    p.add(new JButton(rewind));
    p.add(new JButton(play));
    return p;
  }

  private class RecordSetter implements Swing {
    private MetadataRecord metadataRecord;

    private RecordSetter(MetadataRecord metadataRecord) {
      this.metadataRecord = metadataRecord;
    }

    @Override
    public void run() {
      if (metadataRecord == null) {
        recordTree.setModel(EMPTY_MODEL);
      } else {
        GroovyTreeNode root = new GroovyTreeNode(metadataRecord);
        recordTree.setModel(new DefaultTreeModel(root));
        root.expand();
      }
    }
  }

  private class GroovyTreeNode implements TreeNode, Comparable<GroovyTreeNode> {
    private static final int MAX_LENGTH = 40;
    private MetadataRecord metadataRecord;
    private GroovyTreeNode parent;
    private String attrKey, attrValue;
    private GroovyNode node;
    private Vector<GroovyTreeNode> children = new Vector<GroovyTreeNode>();
    private String string;
    private String toolTip;

    private GroovyTreeNode(MetadataRecord metadataRecord) {
      this(null, metadataRecord.getRootNode());
      this.metadataRecord = metadataRecord;
    }

    private GroovyTreeNode(GroovyTreeNode parent, String attrKey, String attrValue) {
      this.parent = parent;
      this.attrKey = attrKey;
      this.attrValue = attrValue;
      string = String.format("<html><b>%s</b> = %s</html>", attrKey, attrValue);
      toolTip = string; // todo
    }

    private GroovyTreeNode(GroovyTreeNode parent, GroovyNode node) {
      this.parent = parent;
      this.node = node;
      for (Map.Entry<String, String> entry : node.attributes().entrySet()) {
        children.add(new GroovyTreeNode(this, entry.getKey(), entry.getValue()));
      }
      if (node.getNodeValue() instanceof List) {
        string = node.getNodeName();
        toolTip = String.format("Size: %d", ((List) node.getNodeValue()).size());
      } else {
        String truncated = node.text();
        if (truncated.contains("\n") || truncated.length() >= MAX_LENGTH) {
          int index = truncated.indexOf('\n');
          if (index > 0) truncated = truncated.substring(0, index);
          if (truncated.length() >= MAX_LENGTH) truncated = truncated.substring(0, MAX_LENGTH);
          string = String.format("<html><b>%s</b> = %s ...</html>", node.getNodeName(), truncated);
          toolTip = tameTooltipText(node.text());
        } else {
          string = String.format("<html><b>%s</b> = %s</html>", node.getNodeName(), truncated);
          toolTip = truncated;
        }
      }
      if (this.node.getNodeValue() instanceof List) {
        for (Object sub : ((List) this.node.getNodeValue())) {
          GroovyNode subnode = (GroovyNode) sub;
          children.add(new GroovyTreeNode(this, subnode));
        }
        Collections.sort(children);
      }
    }

    @Override
    public TreeNode getChildAt(int i) {
      return children.elementAt(i);
    }

    @Override
    public int getChildCount() {
      return children.size();
    }

    @Override
    public TreeNode getParent() {
      return parent;
    }

    @Override
    public int getIndex(TreeNode treeNode) {
      return children.indexOf(treeNode);
    }

    @Override
    public boolean getAllowsChildren() {
      return !children.isEmpty();
    }

    @Override
    public boolean isLeaf() {
      return children.isEmpty();
    }

    @Override
    public Enumeration children() {
      return children.elements();
    }

    @Override
    public String toString() {
      return metadataRecord != null
          ? String.format("record %d", metadataRecord.getRecordNumber())
          : string;
    }

    public void expand() {
      if (!isLeaf()) {
        Timer timer =
            new Timer(
                50,
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    recordTree.expandPath(getTreePath());
                    for (TreeNode sub : children) {
                      ((GroovyTreeNode) sub).expand();
                    }
                  }
                });
        timer.setRepeats(false);
        timer.start();
      }
    }

    public TreePath getTreePath() {
      List<TreeNode> list = new ArrayList<TreeNode>();
      compilePathList(list);
      return new TreePath(list.toArray());
    }

    private void compilePathList(List<TreeNode> list) {
      if (parent != null) parent.compilePathList(list);
      list.add(this);
    }

    private String tameTooltipText(String text) {
      List<String> lines = new ArrayList<String>();
      while (text.length() > MAX_LENGTH) {
        int pos = text.indexOf(' ', MAX_LENGTH - 10);
        if (pos < 0) break;
        if (pos > MAX_LENGTH + 5) pos = MAX_LENGTH;
        lines.add(text.substring(0, pos).trim());
        text = text.substring(pos).trim();
      }
      if (!text.trim().isEmpty()) lines.add(text);
      StringBuilder html = new StringBuilder("<html>");
      for (String line : lines) html.append(line).append("<br/>\n");
      return html.toString();
    }

    @Override
    public int compareTo(GroovyTreeNode gtn) {
      if (attrKey != null && gtn.attrKey == null) return -1;
      if (attrKey == null && gtn.attrKey != null) return 1;
      if (attrKey != null && gtn.attrKey != null) return attrKey.compareTo(gtn.attrKey);
      return node.getNodeName().compareTo(gtn.node.getNodeName());
    }
  }

  public static class Renderer extends DefaultTreeCellRenderer {

    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      Component component =
          super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
      if (value instanceof GroovyTreeNode) {
        GroovyTreeNode node = (GroovyTreeNode) value;
        if (node.attrKey != null) {
          setIcon(SwingHelper.ICON_ATTRIBUTE);
        } else if (!node.isLeaf()) {
          setIcon(SwingHelper.ICON_COMPOSITE);
        } else {
          setIcon(SwingHelper.ICON_VALUE);
        }
      } else {
        setIcon(SwingHelper.ICON_COMPOSITE);
      }
      return component;
    }
  }

  private RewindAction rewind = new RewindAction();

  private class RewindAction extends AbstractAction {
    private RewindAction() {
      super("First");
      putValue(Action.SMALL_ICON, SwingHelper.ICON_REWIND);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      sipModel.seekReset();
      play.actionPerformed(actionEvent);
    }
  }

  private PlayAction play = new PlayAction();

  private class PlayAction extends AbstractAction {
    private PlayAction() {
      super("Next");
      putValue(Action.SMALL_ICON, SwingHelper.ICON_PLAY);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      setEnabled(false);
      sipModel.seekRecord(
          createPredicate(),
          new Swing() {
            @Override
            public void run() {
              setEnabled(true);
            }
          });
    }
  }

  private SipModel.ScanPredicate createPredicate() {
    final String filterString = filterField.getText().trim();
    switch ((Filter) filterBox.getSelectedItem()) {
      case REGEX:
        return new SipModel.ScanPredicate() {
          @Override
          public boolean accept(MetadataRecord record) {
            return record.contains(Pattern.compile(filterString));
          }
        };
      case MODULO:
        int modulo;
        try {
          modulo = Integer.parseInt(filterString);
        } catch (NumberFormatException e) {
          modulo = 1;
        }
        if (modulo <= 0) modulo = 1;
        final int recordNumberModulo = modulo;
        return new SipModel.ScanPredicate() {
          @Override
          public boolean accept(MetadataRecord record) {
            return recordNumberModulo == 1 || record.getRecordNumber() % recordNumberModulo == 0;
          }
        };
      default:
        throw new RuntimeException();
    }
  }

  private static class TreeTransferHandler extends TransferHandler {

    protected Transferable createTransferable(JComponent c) {
      JTree tree = (JTree) c;
      TreePath[] paths = tree.getSelectionPaths();
      if (paths == null || paths.length != 1) return null;
      TreePath path = tree.getSelectionPath();
      GroovyTreeNode groovyTreeNode = (GroovyTreeNode) path.getLastPathComponent();
      return new StringTransferable((String) (groovyTreeNode.node.getNodeValue()));
    }

    public int getSourceActions(JComponent c) {
      return COPY;
    }
  }

  private static class StringTransferable implements Transferable {
    private String string;

    private static final DataFlavor[] flavors = {DataFlavor.stringFlavor};

    private StringTransferable(String string) {
      this.string = string;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
      return flavors;
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
      return flavor.equals(flavors[0]);
    }

    @Override
    public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
      return string;
    }
  }
}