Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

visualiser.js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

visualiser.js

An audio visualiser interface & plugin system.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Visualiser.js

An audio visualiser interface & plugin system.

Readme todo
  • Tutorial to make a plugin
  • Actual documentation of classes

How to use

Visualiser.js is an ES6 Module, so you can

import Visualiser from './visualiser/Visualiser.js'
const visualiser = new Visualiser({width: 1920, height: 1080})

and you're almost up and running!

Layers

Visualiser.js runs plugins (think 'visual components') on layers (think like photoshop). These layers have to be defined as 2D or 3D content and is done like so

import { default as Visualiser, Layer2D, Layer3D } from './visualiser/Visualiser.js'
import Bar from './plugins/Bar.js'

const width = 1920
const height = 1080

const visualiser = new Visualiser({width, height})

const layer = new Layer2D({width, height})
visualiser.addLayer(layer)

const bar = new Bar({width, height, color: '#FF897E'})
layer.addPlugin(bar)

Rendering

Now you have a visualiser that will actually make something when fed an audio source, but first it must be added to the page

document.body.appendChild(visualiser.canvas)

and fed some audio!

const audioElement = document.createElement('audio')
const source = visualiser.audioElementToSource(audioElement);
visualiser.connectAudioSource(source);
audioElement.src = 'audio.webm'
audioElement.play()

but you might notice the nothing happens, this is due to the web browser blocking auto-playing audio. This is a great thing but means we must wait for user interaction using window.addEventListener

All together now!

<script type="module">
  import { default as Visualiser, Layer2D, Layer3D } from './visualiser/Visualiser.js'
  import Bar from './plugins/Bar.js'

  const width = 1920
  const height = 1080
  const audioPath = 'audio.webm'

  window.addEventListener('click', ()=>{

    const visualiser = new Visualiser({width, height})

    const layer = new Layer2D({width, height})
    visualiser.addLayer(layer)

    const bar = new Bar({width, height, color: '#FF897E'})
    layer.addPlugin(bar)  

    document.body.appendChild(visualiser.canvas)

    const audioElement = document.createElement('audio')
    const source = visualiser.audioElementToSource(audioElement);
    visualiser.connectAudioSource(source);
    audioElement.src = audioPath
    audioElement.play()

  }, {once: true})
</script>

Keywords

FAQs

Package last updated on 03 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc