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

react-native-pure-data

v0.0.1-alpha.1

Published

🔈 ⚡ Synthesize algorithmic sound at runtime in React Native.

Downloads

33

Readme

react-native-pure-data

A native wrapper for libpd-ios and libpd-android, which enables you to rapidly prototype DSP algorithms described using Pure Data, an industry standard open source visual programming language capable of synthesising audiovisual effects.

react-native-pure-data enables the synthesis of generative audio, which helps developers achieve dynamic sound at runtime. This is useful for games, music production and communications.

Key Features

  • Patches in Pure Data can be interacted with via React component props.
  • Simultaneous patch execution.
  • Supports hot reloading, so DSP algorithms can be prototyped directly using Pure Data's interface and then executed concurrently on an Android/iOS device or emulator.
  • Loaded patches respect the Component Lifecycle, so they can be mounted or unmounted as expected.

⚠️ Warning

Please be extremely cautious when prototyping using this library.

Pd is capable of generating high amplitude sound waves, which can damage your hearing if you choose to listen using headphones.

Please take care to minimize the risk of hearing damage or loss as much as possible by playing back on external speakers at a reduced volume whenever prototyping with new patches or props. In addition, you must always consider the volume of the end user's device.

And remember,

With great power, comes great responsibility. - Linus Torvalds

🚀 Getting Started

1. Installing

Using npm:

npm install --save react-native-pure-data

Using yarn:

yarn add react-native-pure-data

For versions of React Native less than 0.60, after installation has complete you must execute react-native link to make the native library dependencies visible to your compiled application.

2. Update metro.config.js

Once installed, you'll need to update your metro.config.js to help the Metro Bundler load your patches:

+const metroDefault = require('metro-config/src/defaults/defaults.js');

 module.exports = {
   resolver: {
+    assetExts: metroDefault.assetExts.concat(['pd']),
   },
 };

This will enable hot loading, so you can modify your patches even whilst they're being rendered by the app.

After making this change, you'll need to restart the bundler.

3. Runtime Specific

3.1 iOS

After installing this library, you'll need reinstall the iOS cocoapods. First, enter your app's /ios directory. Then use:

pod install # update cocoapods
cd ..
react-native run-ios

3.2 Android

Android is not yet supported, but will be released this weekend.

✍️ Example

react-native-pure-data exposes just two Components; AudioController and Patch. The former is used for general sound output configuration, and the latter is used to load and interact with a patch written in Pure Data.

The simplest example is a patch which does not rely on any data from your App.js; you'll see here, that all we need to do is define an <AudioController /> at the root of the application, and declare the Patch's file source.

import React from "react";
import {AudioController, Patch} from "react-native-pure-data";

import SomePatch from "./patches/some-patch.pd";

export default () => (
  <AudioController
    active
  >
    <Patch
      source={SomePatch}
    />
  </AudioController>
);

However, Pure Data is uses an asynchronous, message-driven protocol. This normally means that imported patches will need to be either triggered or configured by your runtime logic.

To communicate with a loaded patch from your app, all you have to do is specify additional props on the Patch component. These will be synchronously routed to corresponding receivers in the Pure Data patch whenever the component is re-rendered:

import React, {useState, useEffect} from "react";
import {AudioController, Patch} from "react-native-pure-data";

import SomePatch from "./patches/some-patch.pd";

export default () => {
  const [frequency, setFrequency] = useState(440);
  useEffect(
    () => {
      /* every 1000ms, set a new frequency */
      const i = setInterval(
        () => setFrequency(Math.random() * 1000),
        1000,
      );
      return () => clearInterval(i);
    },
    [],
  );
  return (
    <AudioController
      active
    >
      <Patch
        source={SomePatch}
        nextFrequency={frequency}
      />
    </AudioController>
  );
};

In the example above, a random frequency will be calculated and transmitted to the corresponding receiver on the diagram. In this case, the receiver would be called "nextFrequency", which would be declared using a Pure Data Object with the definition [r nextFrequency]:

The convention used here is that for every numeric prop, the name of that prop corresponds to the message receiver within the patch.

Therefore, if we defined an additional prop named someOtherFrequency={Math.random()}, whenever the component is re-rendered we would send a message to the receiver [r someOtherFrequency] that existed within the patch. If the receiver does not exist, this is a noop.

Please check out the Example App for further details.

✨ Resources

✌️ Licence

MIT