JSFiddle - React, Tailwind, and code Playground

by Thiago Figueiredo

JavaScript

/*! web-audio-daw 2016-04-11 */
!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.Wad=b()}):"object"==typeof exports?module.exports=b():a.Wad=b()}(this,function(){!function(a){var b="recorderWorker.js",c=function(a,c){var d=c||{},e=d.bufferLen||4096,f=d.numChannels||2;this.context=a.context,this.node=(this.context.createScriptProcessor||this.context.createJavaScriptNode).call(this.context,e,f,f);var g=new Worker(d.workerPath||b);g.postMessage({command:"init",config:{sampleRate:this.context.sampleRate,numChannels:f}});var h,i=!1;this.node.onaudioprocess=function(a){if(i){for(var b=[],c=0;f>c;c++)b.push(a.inputBuffer.getChannelData(c));g.postMessage({command:"record",buffer:b})}},this.configure=function(a){for(var b in a)a.hasOwnProperty(b)&&(d[b]=a[b])},this.record=function(){i=!0},this.stop=function(){i=!1},this.clear=function(){g.postMessage({command:"clear"})},this.getBuffer=function(a){h=a||d.callback,g.postMessage({command:"getBuffer"})},this.exportWAV=function(a,b){if(h=a||d.callback,b=b||d.type||"audio/wav",!h)throw new Error("Callback not set");g.postMessage({command:"exportWAV",type:b})},g.onmessage=function(a){var b=a.data;h(b)},a.connect(this.node),this.node.connect(this.context.destination)};c.forceDownload=function(b,c){var d=(a.URL||a.webkitURL).createObjectURL(b),e=a.document.createElement("a");e.href=d,e.download=c||"output.wav";var f=document.createEvent("Event");f.initEvent("click",!0,!0),e.dispatchEvent(f)},a.Recorder=c}(window),function(a){function b(){return c}function c(b){if(!(this instanceof c))return new c(b);if(a.AudioContext||(a.AudioContext=a.webkitAudioContext),b||(console.log("tuna.js: Missing audio context! Creating a new context for you."),b=a.AudioContext&&new a.AudioContext),!b)throw new Error("Tuna cannot initialize because this environment does not support web audio.");d(b),j=b,k=this}function d(a){function b(){var a=arguments[0];return...