Giter Club home page Giter Club logo

audiodrop's Introduction

AudioDrop

AudioDrop is a utility that enables drag-and-drop loading of Audio Buffers. Simply specify an element to be designated as a drop zone and provide a callback that determines how to handle the newly-created audio buffer.

For use with the Web Audio API: If you're looking for a general drag-and-drop utility you may want to check out dropzone. Audiodrop makes use of the Web Audio API to decode audio files into AudioBuffer objects.

API

AudioDrop(options)

Call AudioDrop with an options object. Required options are context, elements, and drop.

AudioDrop({

  // the web audio context (required)
  context: myAudioContext,

  // a DOM Element or an array of DOM Elements (required)
  elements: document.querySelector('#dropzone'),

  // the callback to handle each file (required)
  drop: function(buffer, file) {
    window[file.name] = buffer;
    console.log('Added the buffer ' + file.name + ' to the window.');
  },

  // DOM Events

  // called when there is a file being dragged into the dropzone
  dragEnter: function(e) { },

  // called repeatedly while a file is being dragged on the dropzone
  dragOver: function(e) { },

  // called when there is a file being dragged out of the dropzone
  dragLeave: function(e) { },
})

AudioDrop.isValidVariableName(String)

A convenience function for determining whether or not a string, if turned into a variable name, would violate a reserved keyword. This is useful if you are planning to attach the variable to the window, as in the example below.

Examples

Attach the audio buffer to the window.

AudioDrop({
  context: new AudioContext(),
  elements: window.document.body,
  drop: function(buffer, file) {
    var name = file.name.replace(/\.[^/.]+$/, "");
    if( AudioDrop.isValidVariableName(name) ) {
      window[name] = buffer;
      console.log('Added the variable "' + name + '"" to the window.');
    } else {
      window[name + '-sample'] = buffer;
      console.log('Added the variable window["' + name + '-sample"] to the window.');
    }
  }
});

AudioDrop was created for Lissajous.

audiodrop's People

Contributors

crochetfeve0251 avatar kylestetz avatar odub avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.