From 15f6ca8461ffb08a5f0bef1a24a6466252568851 Mon Sep 17 00:00:00 2001 From: hchiam Date: Tue, 19 Jan 2021 19:57:35 -0500 Subject: [PATCH 1/2] license link comment that stays after minification --- _2DNote.js | 2 ++ _2DNote.min.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/_2DNote.js b/_2DNote.js index 3b7d932..1e5c63b 100644 --- a/_2DNote.js +++ b/_2DNote.js @@ -1,3 +1,5 @@ +/*! LICENSE: https://github.com/hchiam/_2DNote/blob/master/LICENSE */ + // example usage: _2DNote.play(...) or _2DNote.update(...) var _2DNote = (function () { diff --git a/_2DNote.min.js b/_2DNote.min.js index 2e65a59..6da3131 100644 --- a/_2DNote.min.js +++ b/_2DNote.min.js @@ -1,2 +1,3 @@ -// _2DNote 1.12.3 +// _2DNote 1.13.0 +/*! LICENSE: https://github.com/hchiam/_2DNote/blob/master/LICENSE */ var _2DNote={audioContext:new(AudioContext||webkitAudioContext),note:null,viewXRange:[0,document.documentElement.clientWidth],viewYRange:[0,document.documentElement.clientHeight],comfyFrequencyRange:[150,400],comfyVolumeRange:[0,.5],panRange:[-1,1],setAs2DArea:function(e,t,n=!0){this.callbackUponUpdate=t;const i=e||document.body;i.addEventListener("mousedown",this.play.bind(this)),i.addEventListener("mouseup",this.stop.bind(this)),i.addEventListener("mousemove",this.update.bind(this)),i.addEventListener("touchstart",this.play.bind(this)),i.addEventListener("touchend",this.stop.bind(this)),i.addEventListener("touchmove",this.update.bind(this)),n&&this.setupExitedViewDetection(i)},play:function(e,t=!0){this.stop(),t&&this.setupExitedViewDetection(e);var n=this.getFrequency(e),i=this.getVolume(e),o=this.getPan(e),a=this.audioContext.createGain();a.connect(this.audioContext.destination),a.gain.value=isNaN(i)?.5:i;var s=this.audioContext.createOscillator();s.type="sine",s.frequency.value=isNaN(n)?400:n,s.connect(a);var r=this.audioContext.createStereoPanner();o&&(r.pan.value=o),a.connect(r),r.connect(this.audioContext.destination),s.start(),this.note={oscillator:s,volumeSetup:a,panner:r}},update:function(e,t){if(this.note){var n=this.getFrequency(e),i=this.getVolume(e),o=this.getPan(e);this.note.volumeSetup.gain.value=i,this.note.oscillator.frequency.value=n,this.note.panner.pan.value=o,t?t(i,n,o):this.callbackUponUpdate&&this.callbackUponUpdate(i,n,o)}},stop:function(){null!=this.note&&(this.note.oscillator.stop(this.audioContext.currentTime),this.note=null)},setupExitedViewDetection:function(e){const t=e||document.body;t.removeEventListener&&t.addEventListener&&(t.removeEventListener("mouseleave",this.warnExitedView),t.removeEventListener("touchcancel",this.warnExitedView),t.addEventListener("mouseleave",this.warnExitedView),t.addEventListener("touchcancel",this.warnExitedView))},warnExitedView:function(e){const t=e||document.body;var n={currentTarget:!0,clientX:t.clientWidth/2,clientY:t.clientHeight/2};_2DNote.play(n),setTimeout((function(){_2DNote.stop(),t.removeEventListener&&(t.removeEventListener("mouseleave",_2DNote.warnExitedView),t.removeEventListener("touchcancel",_2DNote.warnExitedView))}),100)},getFrequency:function(e){var t=this.getX(e);return this.normalize(t,this.viewXRange,this.comfyFrequencyRange)},getVolume:function(e){var t=this.getY(e);return this.normalize(t,this.viewYRange,this.comfyVolumeRange)},getPan:function(e){var t=this.getX(e);return this.normalize(t,this.viewXRange,this.panRange)},getX:function(e){var t=e.currentTarget&&e.clientX,n=e.touches;return t?e.clientX:n?e.touches[0].clientX:e.offsetLeft},getY:function(e){var t=e.currentTarget&&e.clientY,n=e.touches;return t?e.clientY:n?e.touches[0].clientY:e.offsetTop},normalize:function(e,[t,n],[i,o]){var a=(o-i)/(n-t)*(e-t)+i;return Math.min(Math.max(a,i),o)},copy:function(){return function e(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t)){var n=[];return t.forEach((function(t){n.push(e(t))})),n}var i={};for(var o in t)t.hasOwnProperty(o)&&("audioContext"===o?i.audioContext=new AudioContext:i[o]=e(t[o]));return i}(this)}};"undefined"!=typeof window&&(window._2DNote=_2DNote),"undefined"!=typeof module&&(module.exports=_2DNote); From 7640ae76632d8edfd0ba440cfbe438339fdddec9 Mon Sep 17 00:00:00 2001 From: hchiam Date: Tue, 19 Jan 2021 19:58:17 -0500 Subject: [PATCH 2/2] 1.13.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 20a2f88..62ac6ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hchiam/2dnote", - "version": "1.12.3", + "version": "1.13.0", "main": "_2DNote.js", "unpkg": "_2DNote.min.js", "author": "hchiam",