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

spaghetti-audio

v1.1.3

Published

The musical instrument nobody asked for

Downloads

23

Readme

Spaghetti Audio

The musical instrument nobody asked for

Spaghetti Audio

Spaghetti Audio combines the Web Audio API via Tone.js and an interactive canvas to let you draw and strum strings

The longer the string, the lower the pitch, just like an elastic band... or, erm, spaghetti?

On touch devices, draw strings with two fingers and strum with one

Usage

If Spaghetti Audio is exactly what you've been searching for, you too can enjoy the sonic taste of spaghetti sound waves by following these steps:

  1. Install via npm or yarn

    npm i spaghetti-audio
  2. Create some spaghetti

    import SpaghettiAudio from 'spaghetti-audio'
    
    const spaghettiAudio = new SpaghettiAudio()
    
    // All the spaghetti goodness is rendered to a canvas element, so append that to the DOM
    document.body.appendChild(spaghettiAudio.canvas)
  3. To properly clean up Spaghetti Audio (e.g. when navigating to another page in a SPA) call the destroy method. This removes event listeners and cancels animation frame requests.

    spaghettiAudio.destroy()

Appending to a wrapper

Rather than sticking the spaghetti canvas straight in the <body> and taking up the full window width, you can attach it to another element. This example attaches the spaghetti canvas to a wrapper with id "spaghetti-wrapper".

import SpaghettiAudio from 'spaghetti-audio'

const wrapper = document.querySelector('#spaghetti-wrapper')
const spaghettiAudio = new SpaghettiAudio({ wrapper })

wrapper.appendChild(spaghettiAudio.canvas)

Usage with React

Spaghetti Audio is UI framework agnostic and the mounting process is similar for React, Vue.js and other frameworks. You can think of Spaghetti Audio more like a game with a render loop rather than a reactive component. This means we need to instantiate it, attach it to a component and destroy it when that component unmounts. Here's how that looks in React:

function SpaghettiAudioWrapper() {
  const wrapperRef = useRef()

  useEffect(() => {
    const spaghettiAudio = new SpaghettiAudio({ wrapper: wrapperRef.current })

    wrapperRef.current.appendChild(spaghettiAudio.canvas)

    return () => spaghettiAudio.destroy()
  }, [])

  return <div className="spaghetti-wrapper" ref={wrapperRef} />
}

Local development

  1. Clone this repo and cd spaghetti-audio

  2. Install dependencies with npm or yarn

    npm i
  3. Spin up the dev server

    npm run start
  4. The dev server is now running at http://localhost:8080

 Settings

The following settings can be used to customise the spaghetti experience, use these when initialising spaghetti audio, e.g. new SpaghettiAudio({ damping: 0.05 })

export interface Settings {
  /** How fast motion dies down. The higher the number, the less oscillation and more al dente the spaghetti. */
  damping?: number
  /** Show the hitboxes and other helpful debugger annotations on the canvas. */
  debug?: boolean
  /** The frequency range of the keyboard. */
  hiRange?: { start: number; end: number }
  /** The key to store the spaghetti strings under in local storage. */
  localStorageKey?: string
  /** It's spaghetti, not scialatelli, so let's set a minimum length. */
  minStringLength?: number
  /** The space around the spaghetti that's interactive. */
  hitboxSize?: number
  /** Spaghetti color. */
  spaghettiColor?: string
  /** Spaghetti width. */
  spaghettiWidth?: number
  /** The total interactive points along each spaghetti string. Minimum is 3 – Two anchor points on each end, and one interactive wobbly point in the middle. */
  totalPoints?: number
  /** How quickly the spaghetti oscillates back to center. The higher the number, the stickier or more molasses-like the spaghetti. */
  viscosity?: number
  /** Show a clear button to clear all the strings. */
  withClearButton?: boolean
  /** Store the spaghetti strings in local storage. */
  withLocalStorage?: boolean
  /** A HTML element, if the spaghetti canvas is attached to a wrapper. */
  wrapper?: HTMLElement
}