From 65d9da19fb7362bb26e17a49af6c1da75898142d Mon Sep 17 00:00:00 2001 From: Egor Philippov Date: Mon, 2 Nov 2015 16:59:16 -0800 Subject: [PATCH] removing interval, hopefully better beat detection, bug fixes --- .../components/bridge-finder/component.js | 12 +++--- app/pods/components/hue-controls/component.js | 7 ++-- app/pods/components/music-tab/component.js | 16 ++++---- .../components/music-tab/mixins/helpers.js | 17 +------- .../components/music-tab/mixins/visualizer.js | 6 ++- app/pods/components/music-tab/template.hbs | 7 +--- app/styles/app.scss | 2 +- config/environment.js | 2 +- vendor/dancer.js | 41 ++++++++++++------- 9 files changed, 51 insertions(+), 59 deletions(-) diff --git a/app/pods/components/bridge-finder/component.js b/app/pods/components/bridge-finder/component.js index d3eb6fb..6b68fd1 100644 --- a/app/pods/components/bridge-finder/component.js +++ b/app/pods/components/bridge-finder/component.js @@ -31,7 +31,7 @@ export default Em.Component.extend({ }, findBridgeByIp() { - var manualBridgeIp = this.get('manualBridgeIp'), self = this; + var manualBridgeIp = this.get('manualBridgeIp'); if (manualBridgeIp.toLowerCase() === 'trial' || manualBridgeIp.toLowerCase() === 'offline') { this.setProperties({ @@ -44,11 +44,11 @@ export default Em.Component.extend({ data: JSON.stringify({"devicetype": "huegasm"}), contentType: 'application/json', type: 'POST' - }).fail(function () { - self.set('manualBridgeIpNotFound', true); - setTimeout(function(){ self.set('manualBridgeIpNotFound', false); }, 5000); - }).then(function () { - self.set('bridgeIp', manualBridgeIp); + }).fail(() => { + this.set('manualBridgeIpNotFound', true); + setTimeout(() => { this.set('manualBridgeIpNotFound', false); }, 5000); + }).then(() => { + this.set('bridgeIp', manualBridgeIp); }); } } diff --git a/app/pods/components/hue-controls/component.js b/app/pods/components/hue-controls/component.js index 43f8e42..570e15b 100644 --- a/app/pods/components/hue-controls/component.js +++ b/app/pods/components/hue-controls/component.js @@ -63,7 +63,7 @@ export default Em.Component.extend({ 'Beat Interval - The minimum amount of time between each registered beat
' + 'Frequency Range - The frequency range of the sound to listen on for the beat
' + 'Transition Time - The time it takes for a light to change color or brightness

' + - 'TIP: Beat settings are saved per song as indicated by the red star icon in the top left corner. These settings they will be restored if you ever listen to the same song again.', + 'TIP: Beat detection settings are saved per song as indicated by the red star icon in the top left corner. These settings they will be restored if you ever listen to the same song again.', position: 'top' }, { @@ -109,8 +109,6 @@ export default Em.Component.extend({ // it's VERY ugly but it works intro.onchange((element) => { - this.set('dimmerOn', false); - if(element.id === 'musicTab' || element.id === 'playlist' || element.id === 'playerArea' || element.id === 'beatOptionRow' || element.id === 'beatOptionButtonGroup' || element.id === 'beatContainer' || element.id === 'usingMicAudioTooltip'){ Em.$('#musicTab').removeClass('hidden'); Em.$('#lightsTab').addClass('hidden'); @@ -156,7 +154,8 @@ export default Em.Component.extend({ // skip hidden/missing elements intro.onafterchange((element)=>{ - if(Em.$(element).hasClass('introjsFloatingElement')){ + var elem = Em.$(element); + if(elem.hasClass('introjsFloatingElement') || elem.html() === ''){ Em.$('.introjs-nextbutton').click(); } }).onexit(onFinish).oncomplete(onFinish).start(); diff --git a/app/pods/components/music-tab/component.js b/app/pods/components/music-tab/component.js index c8b407b..503a1f6 100644 --- a/app/pods/components/music-tab/component.js +++ b/app/pods/components/music-tab/component.js @@ -357,9 +357,6 @@ export default Em.Component.extend(helperMixin, visualizerMixin, { repeatChanged(value) { this.changePlayerControl('repeat', Em.isNone(value) ? (this.get('repeat') + 1) % 3 : value); }, - transitionTimeChanged(value) { - this.changePlayerControl('transitionTime', value); - }, playerBottomDisplayedChanged(value) { this.changePlayerControl('playerBottomDisplayed', value); }, @@ -580,9 +577,11 @@ export default Em.Component.extend(helperMixin, visualizerMixin, { this.set('dragLeaveTimeoutHandle', setTimeout(function(){ self.set('dragging', false); }, 500)); }, - simulateKick() { + simulateKick(mag, ratioKick) { + console.log(mag + ',' + ratioKick); + var activeLights = this.get('activeLights'), - transitionTime = this.get('transitionTime') * 10, + transitionTime = 100, onBeatBriAndColor = this.get('onBeatBriAndColor'), lightsData = this.get('lightsData'), color = null, @@ -651,11 +650,10 @@ export default Em.Component.extend(helperMixin, visualizerMixin, { var dancer = new Dancer(), storage = this.get('storage'), kick = dancer.createKick({ - frequency: [0,100], threshold: this.get('threshold'), - onKick: (mag) => { + onKick: (mag, ratioKick) => { if (this.get('paused') === false) { - this.simulateKick(mag); + this.simulateKick(mag, ratioKick); } } }); @@ -671,7 +669,7 @@ export default Em.Component.extend(helperMixin, visualizerMixin, { this.set('usingMicSupported', false); } - ['volume', 'shuffle', 'repeat', 'volumeMuted', 'threshold', 'transitionTime', 'playerBottomDisplayed', 'onBeatBriAndColor', 'audioMode', 'songBeatPreferences', 'firstVisit', 'currentVisName', 'playQueue', 'playQueuePointer', 'micBoost'].forEach((item)=>{ + ['volume', 'shuffle', 'repeat', 'volumeMuted', 'threshold', 'playerBottomDisplayed', 'onBeatBriAndColor', 'audioMode', 'songBeatPreferences', 'firstVisit', 'currentVisName', 'playQueue', 'playQueuePointer', 'micBoost'].forEach((item)=>{ if (!Em.isNone(storage.get('huegasm.' + item))) { var itemVal = storage.get('huegasm.' + item); diff --git a/app/pods/components/music-tab/mixins/helpers.js b/app/pods/components/music-tab/mixins/helpers.js index ee7babd..f48af76 100644 --- a/app/pods/components/music-tab/mixins/helpers.js +++ b/app/pods/components/music-tab/mixins/helpers.js @@ -11,7 +11,7 @@ export default Em.Mixin.create({ beatOptions: { threshold: { - range: {min: 0, max: 1.0}, + range: {min: 0, max: 0.6}, step: 0.01, defaultValue: 0.3, pips: { @@ -24,20 +24,6 @@ export default Em.Mixin.create({ } } }, - transitionTime: { - range: {min: 0, max: 0.5}, - step: 0.1, - defaultValue: 0.1, - pips: { - mode: 'positions', - values: [0,20,40,60,80,100], - density: 10, - format: { - to: function ( value ) {return value;}, - from: function ( value ) { return value; } - } - } - }, micBoost: { range: {min: 1, max: 11}, step: 0.5, @@ -54,7 +40,6 @@ export default Em.Mixin.create({ } }, - transitionTime: 0.1, threshold: 0.3, micBoost: 5, oldThreshold: null, diff --git a/app/pods/components/music-tab/mixins/visualizer.js b/app/pods/components/music-tab/mixins/visualizer.js index 60d7039..ea958e4 100644 --- a/app/pods/components/music-tab/mixins/visualizer.js +++ b/app/pods/components/music-tab/mixins/visualizer.js @@ -41,9 +41,11 @@ export default Em.Mixin.create({ dancer.bind('update', () => { var currentVisName = this.get('currentVisName'), - gradient = ctx.createLinearGradient(0, 0, 0, h); + gradient = ctx.createLinearGradient(0, 0, 0, h), + pageHidden = document.hidden || document.msHidden || document.webkitHidden || document.mozHidden; - if(currentVisName === 'None'){ + // dont do anything if the page is hidden or no visualization + if(currentVisName === 'None' || pageHidden){ return; } diff --git a/app/pods/components/music-tab/template.hbs b/app/pods/components/music-tab/template.hbs index ee7a501..68783cf 100644 --- a/app/pods/components/music-tab/template.hbs +++ b/app/pods/components/music-tab/template.hbs @@ -152,16 +152,11 @@ {{/if}}
-
+
Sensitivity {{range-slider start=threshold orientation="vertical" step=beatOptions.threshold.step range=beatOptions.threshold.range slide="thresholdChanged" pips=beatOptions.threshold.pips}}
-
- Transition Time - {{range-slider start=transitionTime orientation="vertical" step=beatOptions.transitionTime.step range=beatOptions.transitionTime.range slide="transitionTimeChanged" pips=beatOptions.transitionTime.pips}} -
-
{{#paper-switch checked=onBeatBriAndColor disabled=trial}}= this.currentThreshold && - magnitude >= this.threshold ) { + var magnitude = this.maxAmplitude(this.frequency); + + if (magnitude >= this.currentThreshold && magnitude >= this.threshold) { this.currentThreshold = magnitude; - this.onKick && this.onKick.call( this.dancer, magnitude ); - console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxKICK:' + magnitude); + this.onKick && this.onKick.call(this.dancer, magnitude); + this.canUseRatio = false; + + if(this.canUseRatioHandle) { + clearTimeout(this.canUseRatioHandle); + this.canUseRatioHandle = null; + } + + var self = this; + this.canUseRatioHandle = setTimeout(function(){ + self.canUseRatio = true; + }, 2000); } else { - this.offKick && this.offKick.call( this.dancer, magnitude ); + if(magnitude/this.previousMag > this.threshold*5 && magnitude>0.1 && this.canUseRatio) { + this.onKick && this.onKick.call(this.dancer, magnitude, magnitude/this.previousMag); + } else { + this.offKick && this.offKick.call(this.dancer, magnitude); + } + this.currentThreshold -= this.decay; + this.previousMag = (magnitude > 0) ? magnitude : 0.0001; } }, maxAmplitude : function ( frequency ) { @@ -361,15 +380,11 @@ SAMPLE_RATE = 44100; var adapter = function ( dancer ) { - var context = new AudioContext();//, filter = context.createBiquadFilter(); - - //filter.type = "lowpass"; - //filter.frequency.value = 440; + var context = new AudioContext(); this.dancer = dancer; this.audio = new Audio(); this.context = context; - //this.filter = filter; }; adapter.prototype = { @@ -498,10 +513,8 @@ this.source.connect(this.proc); this.source.connect(this.gain); - //this.source.connect( this.filter ); this.gain.connect(this.context.destination); this.proc.connect(this.context.destination); - //this.filter.connect( this.context.destination ); this.isLoaded = true; this.progress = 1;