mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){"use strict";var load=require("audio-loader");var player=require("sample-player");function instrument(ac,name,options){if(arguments.length===1)return function(n,o){return instrument(ac,n,o)};var opts=options||{};var isUrl=opts.isSoundfontURL||isSoundfontURL;var toUrl=opts.nameToUrl||nameToUrl;var url=isUrl(name)?name:toUrl(name,opts.soundfont,opts.format);return load(ac,url,{only:opts.only||opts.notes}).then(function(buffers){var p=player(ac,buffers,opts).connect(ac.destination);p.url=url;p.name=name;return p})}function isSoundfontURL(name){return/\.js(\?.*)?$/i.test(name)}function nameToUrl(name,sf,format){format=format==="ogg"?format:"mp3";sf=sf==="FluidR3_GM"?sf:"MusyngKite";return"https://gleitz.github.io/midi-js-soundfonts/"+sf+"/"+name+"-"+format+".js"}var Soundfont=require("./legacy");Soundfont.instrument=instrument;Soundfont.nameToUrl=nameToUrl;if(typeof module==="object"&&module.exports)module.exports=Soundfont;if(typeof window!=="undefined")window.Soundfont=Soundfont},{"./legacy":2,"audio-loader":5,"sample-player":8}],2:[function(require,module,exports){"use strict";var parser=require("note-parser");function Soundfont(ctx,nameToUrl){console.warn("new Soundfont() is deprected");console.log("Please use Soundfont.instrument() instead of new Soundfont().instrument()");if(!(this instanceof Soundfont))return new Soundfont(ctx);this.nameToUrl=nameToUrl||Soundfont.nameToUrl;this.ctx=ctx;this.instruments={};this.promises=[]}Soundfont.prototype.onready=function(callback){console.warn("deprecated API");console.log("Please use Promise.all(Soundfont.instrument(), Soundfont.instrument()).then() instead of new Soundfont().onready()");Promise.all(this.promises).then(callback)};Soundfont.prototype.instrument=function(name,options){console.warn("new Soundfont().instrument() is deprecated.");console.log("Please use Soundfont.instrument() instead.");var ctx=this.ctx;name=name||"default";if(name in this.instruments)return this.instruments[name];var inst={name:name,play:oscillatorPlayer(ctx,options)};this.instruments[name]=inst;if(name!=="default"){var promise=Soundfont.instrument(ctx,name,options).then(function(instrument){inst.play=instrument.play;return inst});this.promises.push(promise);inst.onready=function(cb){console.warn("onready is deprecated. Use Soundfont.instrument().then()");promise.then(cb)}}else{inst.onready=function(cb){console.warn("onready is deprecated. Use Soundfont.instrument().then()");cb()}}return inst};function loadBuffers(ac,name,options){console.warn("Soundfont.loadBuffers is deprecate.");console.log("Use Soundfont.instrument(..) and get buffers properties from the result.");return Soundfont.instrument(ac,name,options).then(function(inst){return inst.buffers})}Soundfont.loadBuffers=loadBuffers;function oscillatorPlayer(ctx,defaultOptions){defaultOptions=defaultOptions||{};return function(note,time,duration,options){console.warn("The oscillator player is deprecated.");console.log("Starting with version 0.9.0 you will have to wait until the soundfont is loaded to play sounds.");var midi=note>0&¬e<129?+note:parser.midi(note);var freq=midi?parser.midiToFreq(midi,440):null;if(!freq)return;duration=duration||.2;options=options||{};var destination=options.destination||defaultOptions.destination||ctx.destination;var vcoType=options.vcoType||defaultOptions.vcoType||"sine";var gain=options.gain||defaultOptions.gain||.4;var vco=ctx.createOscillator();vco.type=vcoType;vco.frequency.value=freq;var vca=ctx.createGain();vca.gain.value=gain;vco.connect(vca);vca.connect(destination);vco.start(time);if(duration>0)vco.stop(time+duration);return vco}}S
|