npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pd-fileutils

v0.4.0

Published

A set of utilities for Pure Data files : parser, image generator.

Downloads

22

Readme

Pure Data file utilities

Build Status

This library is a set of tools for handling pure data files.

pd-fileutils allows you to parse Pd files to a JavaScript object which is easy to modify. Of course, you can also create a patch from scratch. A patch can then be rendered to pd format, or to SVG if you want an image of it.

Demos

  • Random drone generator : generate random droning patches (you know ... robot sounds), listen to them online, and download the pd file if you like it.

Usage in the browser

First download the latest (or latest stable) browser build from dist/ and include it in your page :

  <script src="js/pd-fileutils.js"></script>

Then you can use pd-fileutils :

<div id="svg"></div>
<script>
    var patch = pdfu.parse('#N canvas 778 17 450 300 10;\n#X obj 14 13 loadbang;\n#X obj 14 34 print bla;\n#X connect 0 0 1 0;')
    var rendered = pdfu.renderSvg(patch, {svgFile: false})
    $('#svg').html(rendered)
</script>

Usage on node.js

Installation

Obviously, you will need node.js.

Installation is easier with the node package manager npm :

npm install pd-fileutils

To install the command-line tool globally, you might want to run npm with the -g option. Note that in this case you might need admin rights :

npm install -g pd-fileutils

Command-line tool

At the moment, the only thing you can do is render .pd files to .svg, for example :

pd-fileutils myPatch.pd > myPatch.svg

API documentation

Patch objects

pd-fileutils deals with JavaScript objects representing patches.

Specification

Patch object :

{
    nodes: [<node1>, ..., <nodeN>],
    connections: [<connection1>, ..., <connectionN>],
    args: [<arg1>, ..., <argN>],
    layout: {<key>: <value>},
}

Where <nodeK> is with format :

{
    id: <id>,
    proto: <object type>,
    args:  [<arg1>, ..., <argN>],
    layout: {<key>: <value>},
    data: [<number1>, ..., <numberN>],
    subpatch: <a patch object>
}
  • layout : a map containing all the layout properties of the object/patch.
  • args : an array of the creation arguments of the object/patch. Those can be only strings or numbers.
  • data : [only for tables] a list of numbers.
  • subpatch : [only for subpatches] contains the whole subpatch's graph.

And <connectionK> :

{
    source: {
        id: <source object id>,
        port: <outlet>
    },
    sink: {
        id: <sink object id>,
        port: <inlet>
    }
}

parse(pdFile)

Parses the string pdFile to a patch object. Example usage on Node.js :

var pdfu = require('pd-fileutils')
  , fs = require('fs')
  , patchStr, patch

// Read the file
patchStr = fs.readFileSync('./simple.pd').toString()

// Parse the read file
patch = pdfu.parse(patchStr)

renderPd(patch)

Renders the patch object to a string in the Pd file format.

renderSvg(patch)

Renders the patch object to a string in SVG format

Contributions

Are most welcome. There is still a lot of work to do there. Fork the project, make your changes and send me a pull request.

Running the tests

Running tests require mocha. Run with :

npm test

Building from source to dist/

npm run build

History

0.4

  • update all dependencies + move to webpack

0.3.4

  • parsing handles infos after the comma on a object definition line

0.3

  • parsing separates layout from model data
  • SVG rendering of all controls
  • basic pd rendering

0.2

  • SVG rendering + command-line tool
  • parsing supports most of the format

0.1

  • basic parsing