ambience mode done?
This commit is contained in:
parent
7239b3dcd4
commit
6e2b32ab08
2 changed files with 69 additions and 43 deletions
|
|
@ -502,58 +502,78 @@ export default Em.Component.extend(helperMixin, visualizerMixin, {
|
||||||
this.set('oldBeatPrefCache', newOldBeatPrefCache);
|
this.set('oldBeatPrefCache', newOldBeatPrefCache);
|
||||||
},
|
},
|
||||||
|
|
||||||
onAmbienceModeChange: function() {
|
doAmbienceLightChange: function(justOneLight){
|
||||||
var activeLights = this.get('activeLights'),
|
var activeLights = this.get('activeLights'),
|
||||||
workedLights = [],
|
lightsData = this.get('lightsData'),
|
||||||
|
workedLights = this.get('ambienceWorkedLights'),
|
||||||
|
ambienceWorkedLightsHandles = this.get('ambienceWorkedLightsHandles'),
|
||||||
lightOff = (light)=>{
|
lightOff = (light)=>{
|
||||||
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
if(this.get('ambienceMode')){
|
||||||
data: JSON.stringify({'on': false, 'transitiontime': 20}),
|
|
||||||
contentType: 'application/json',
|
|
||||||
type: 'PUT'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if(this.get('ambienceMode') && this.get('playing')) {
|
|
||||||
activeLights.forEach((light)=>{
|
|
||||||
lightOff(light);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.set('ambienceModeHandle', setInterval(()=> {
|
|
||||||
var lights = [],
|
|
||||||
transitionTime = Math.floor(Math.random()*30 + 4);
|
|
||||||
|
|
||||||
for(let i=0; i < activeLights.length/2; i++){
|
|
||||||
let l = activeLights[Math.floor(Math.random()*activeLights.length)];
|
|
||||||
if(!lights.contains(l) && !workedLights.contains(l)){
|
|
||||||
lights.push(l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lights.forEach((light)=>{
|
|
||||||
workedLights.push(light);
|
|
||||||
|
|
||||||
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
||||||
data: JSON.stringify({'on': true, 'hue': Math.floor(Math.random()*65535), 'bri': Math.floor(Math.random()*200) + 1, 'transitiontime': transitionTime}),
|
data: JSON.stringify({'on': false, 'transitiontime': 20}),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
type: 'PUT'
|
type: 'PUT'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
lights = [],
|
||||||
|
transitionTime = Math.floor(Math.random()*20),
|
||||||
|
iterations = justOneLight ? 1 : activeLights.length/2;
|
||||||
|
|
||||||
setTimeout(()=>{
|
// pick some random lights
|
||||||
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
for(let i=0; i < iterations; i++){
|
||||||
data: JSON.stringify({'hue': Math.floor(Math.random()*65535), 'bri': Math.floor(Math.random()*204) + 51, 'transitiontime': transitionTime}),
|
let l = activeLights[Math.floor(Math.random()*activeLights.length)];
|
||||||
contentType: 'application/json',
|
|
||||||
type: 'PUT'
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(()=>{
|
if(!lights.contains(l) && !workedLights.contains(l)){
|
||||||
lightOff(light);
|
lights.push(l);
|
||||||
workedLights.removeObject(light);
|
workedLights.push(l);
|
||||||
}, transitionTime * 100);
|
} else if(justOneLight && workedLights.length !== activeLights.length){ // work a light if we only need one
|
||||||
}, transitionTime*100);
|
while(workedLights.contains(l)){
|
||||||
});
|
l = activeLights[Math.floor(Math.random()*activeLights.length)];
|
||||||
}, 2000));
|
}
|
||||||
|
|
||||||
|
lights.push(l);
|
||||||
|
workedLights.push(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lights.forEach((light)=>{
|
||||||
|
var options = {'hue': Math.floor(Math.random()*65535), 'bri': Math.floor(Math.random()*200) + 1, 'transitiontime': transitionTime};
|
||||||
|
|
||||||
|
if(lightsData[light].state.on === false){
|
||||||
|
options.on = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
||||||
|
data: JSON.stringify(options),
|
||||||
|
contentType: 'application/json',
|
||||||
|
type: 'PUT'
|
||||||
|
});
|
||||||
|
|
||||||
|
// stop the light from turning off
|
||||||
|
if(ambienceWorkedLightsHandles[light]){
|
||||||
|
clearTimeout(ambienceWorkedLightsHandles[light]);
|
||||||
|
delete ambienceWorkedLightsHandles[light];
|
||||||
|
}
|
||||||
|
|
||||||
|
// turn the light off after it's been idle for a while
|
||||||
|
ambienceWorkedLightsHandles[light] = setTimeout(()=>{
|
||||||
|
lightOff(light);
|
||||||
|
workedLights.removeObject(light);
|
||||||
|
delete ambienceWorkedLightsHandles[light];
|
||||||
|
}, transitionTime * 100 + 1000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onAmbienceModeChange: function() {
|
||||||
|
if(this.get('ambienceMode') && this.get('playing')) {
|
||||||
|
this.set('ambienceModeHandle', setInterval(()=> {this.doAmbienceLightChange();}, 5000));
|
||||||
|
this.setProperties({
|
||||||
|
'colorloopMode': false,
|
||||||
|
'flashingTransitions': false
|
||||||
|
});
|
||||||
} else if(this.get('ambienceModeHandle')) {
|
} else if(this.get('ambienceModeHandle')) {
|
||||||
activeLights.forEach((light)=>{
|
this.get('activeLights').forEach((light)=>{
|
||||||
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
|
||||||
data: JSON.stringify({'on': true}),
|
data: JSON.stringify({'on': true}),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
|
|
@ -725,6 +745,10 @@ export default Em.Component.extend(helperMixin, visualizerMixin, {
|
||||||
this.set('paused', false);
|
this.set('paused', false);
|
||||||
}, 150);
|
}, 150);
|
||||||
|
|
||||||
|
if(this.get('ambienceMode') && activeLights.length > 0){
|
||||||
|
this.doAmbienceLightChange(true);
|
||||||
|
}
|
||||||
|
|
||||||
//work the music beat area - simulate the speaker vibration by running a CSS animation on it
|
//work the music beat area - simulate the speaker vibration by running a CSS animation on it
|
||||||
Em.$('#beatSpeakerCenterOuter').removeClass('vibrateOuter').prop('offsetWidth', Em.$('#beatSpeakerCenterOuter').prop('offsetWidth')).addClass('vibrateOuter');
|
Em.$('#beatSpeakerCenterOuter').removeClass('vibrateOuter').prop('offsetWidth', Em.$('#beatSpeakerCenterOuter').prop('offsetWidth')).addClass('vibrateOuter');
|
||||||
Em.$('#beatSpeakerCenterInner').removeClass('vibrateInner').prop('offsetWidth', Em.$('#beatSpeakerCenterInner').prop('offsetWidth')).addClass('vibrateInner');
|
Em.$('#beatSpeakerCenterInner').removeClass('vibrateInner').prop('offsetWidth', Em.$('#beatSpeakerCenterInner').prop('offsetWidth')).addClass('vibrateInner');
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,8 @@ export default Em.Mixin.create({
|
||||||
oldBeatPrefCache: null,
|
oldBeatPrefCache: null,
|
||||||
storage: null,
|
storage: null,
|
||||||
firstVisit: true,
|
firstVisit: true,
|
||||||
|
ambienceWorkedLights: [],
|
||||||
|
ambienceWorkedLightsHandles: {},
|
||||||
|
|
||||||
largeArtworkPic: function(){
|
largeArtworkPic: function(){
|
||||||
var pic = null,
|
var pic = null,
|
||||||
|
|
|
||||||
Reference in a new issue