saving song beat preferences

This commit is contained in:
Egor Philippov 2015-10-07 16:55:18 -07:00
parent c51d297c14
commit 3482659949
6 changed files with 97 additions and 56 deletions

View file

@ -8,7 +8,6 @@ Music awesomeness for hue lights.
- app intro with intro.js - app intro with intro.js
- music visualizations with three.js - music visualizations with three.js
- integrate with soundcloud - integrate with soundcloud
- display player time when hovering over seek bar
## BUGS ## BUGS
- can't create groups anymore - can't create groups anymore
@ -18,3 +17,4 @@ Music awesomeness for hue lights.
- help, contact, about, youtube video ??? - help, contact, about, youtube video ???
- beat settings by interval - beat settings by interval
- auto beat detection mode - auto beat detection mode
- display player time when hovering over seek bar

View file

@ -20,6 +20,20 @@ export default Em.Component.extend({
activeLights.removeObject(light); activeLights.removeObject(light);
} else { } else {
activeLights.pushObject(light); activeLights.pushObject(light);
// sync the current light settings to the newly added light
var options = {on: this.get('lightsOn'), bri: this.get('lightsBrightness'), effect: this.get('colorLoopOn') ? 'colorloop' : 'none'},
rgb = this.get('rgb');
if(rgb[0] !== 255 && rgb[1] !== 255 && rgb[2] !== 255) {
options['xy'] = this.rgbToXy(rgb[0], rgb[1], rgb[2]);
}
Em.$.ajax(this.get('apiURL') + '/lights/' + light + '/state', {
data: JSON.stringify(options),
contentType: 'application/json',
type: 'PUT'
});
} }
}, },
toggleColorpicker() { toggleColorpicker() {
@ -175,7 +189,6 @@ export default Em.Component.extend({
return this.get('colorLoopOn') ? 'On' : 'Off'; return this.get('colorLoopOn') ? 'On' : 'Off';
}.property('colorLoopOn'), }.property('colorLoopOn'),
// **************** STROBE LIGHT START **************** // **************** STROBE LIGHT START ****************
strobeOn: false, strobeOn: false,

View file

@ -50,8 +50,6 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
this.$('#playerBottom').slideToggle(); this.$('#playerBottom').slideToggle();
this.changePlayerControl('playerBottomDisplayed', !this.get('playerBottomDisplayed')); this.changePlayerControl('playerBottomDisplayed', !this.get('playerBottomDisplayed'));
}, },
saveSongSettings() {
},
goToSong(index, playSong){ goToSong(index, playSong){
var dancer = this.get('dancer'), audio = new Audio(); var dancer = this.get('dancer'), audio = new Audio();
audio.src = this.get('playQueue')[index].url; audio.src = this.get('playQueue')[index].url;
@ -66,6 +64,8 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
timeElapsed: 0 timeElapsed: 0
}); });
this.loadSongBeatPreferences();
if(playSong){ if(playSong){
this.send('play'); this.send('play');
} }
@ -199,6 +199,9 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
} }
} }
}, },
addAudio: function () {
Em.$('#fileInput').click();
},
shuffleChanged(value) { shuffleChanged(value) {
this.changePlayerControl('shuffle', Em.isNone(value) ? !this.get('shuffle') : value); this.changePlayerControl('shuffle', Em.isNone(value) ? !this.get('shuffle') : value);
}, },
@ -220,28 +223,13 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
frequencyChanged(value){ frequencyChanged(value){
this.changePlayerControl('frequency', value, true); this.changePlayerControl('frequency', value, true);
}, },
addAudio: function () {
Em.$('#fileInput').click();
},
playListAreaAddAudio(){ playListAreaAddAudio(){
this.send('addAudio'); this.send('addAudio');
}, },
speakerViewedChanged(value){
this.set('speakerViewed', value);
},
randomTransitionChanged(value){
this.set('randomTransition', value);
},
onBeatBriAndColorChanged(value){
this.set('onBeatBriAndColor', value);
},
dimmerEnabledChanged(value){
this.set('dimmerEnabled', value);
},
audioModeChanged(value){ audioModeChanged(value){
if(value === 1) { if(value === 1) {
this.startUsingMic(); this.startUsingMic();
} else if(value === 3) { } else if(value === 0) {
this.send('useLocalAudio'); this.send('useLocalAudio');
} else { } else {
this.set('audioMode', value); this.set('audioMode', value);
@ -268,10 +256,9 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
playQueue = this.get('playQueue'), playQueue = this.get('playQueue'),
updatePlayQueue = function(){ updatePlayQueue = function(){
var tags = ID3.getAllTags("local"); var tags = ID3.getAllTags("local");
playQueue.push({filename: this.name.replace(/\.[^/.]+$/, ""), url: URL.createObjectURL(this), artist: tags.artist, title: tags.title }); playQueue.pushObject({filename: this.name.replace(/\.[^/.]+$/, ""), url: URL.createObjectURL(this), artist: tags.artist, title: tags.title });
ID3.clearAll(); ID3.clearAll();
self.notifyPropertyChange('playQueue');
// make sure to init the first song // make sure to init the first song
if(playQueue.length > 0 && self.get('playQueuePointer') === -1){ if(playQueue.length > 0 && self.get('playQueuePointer') === -1){
@ -293,6 +280,52 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
} }
}, },
changePlayerControl(name, value, isOption, skipSaveBeatPrefs){
this.set(name, value);
if(isOption){
var options = {};
options[name] = value;
if(this.get('usingLocalAudio') && this.get('playQueuePointer') !== -1 && skipSaveBeatPrefs !== true) {
this.saveSongBeatPreferences();
}
this.get('kick').set(options);
}
localStorage.setItem('huegasm.' + name, value);
},
incrementElapseTime(){
this.incrementProperty('timeElapsed');
if(this.get('timeElapsed') === this.get('timeTotal')){
this.send('next');
}
},
saveSongBeatPreferences() {
var song = this.get('playQueue')[this.get('playQueuePointer')],
title = Em.isEmpty(song.artist) ? song.filename : song.artist + '-' + song.title,
songBeatPreferences = this.get('songBeatPreferences');
songBeatPreferences[title] = {threshold: this.get('threshold'), decay: this.get('decay'), frequency: this.get('frequency') };
localStorage.setItem('huegasm.songBeatPreferences', JSON.stringify(songBeatPreferences));
},
loadSongBeatPreferences() {
var song = this.get('playQueue')[this.get('playQueuePointer')],
title = Em.isEmpty(song.artist) ? song.filename : song.artist + '-' + song.title,
songBeatPreferences = this.get('songBeatPreferences'),
preference = songBeatPreferences[title];
if(!Em.isNone(preference)) {
this.changePlayerControl('threshold', preference.threshold, true, true);
this.changePlayerControl('decay', preference.decay, true, true);
this.changePlayerControl('frequency', preference.frequency, true, true);
}
},
startUsingMic() { startUsingMic() {
navigator.getUserMedia( navigator.getUserMedia(
{audio: true}, {audio: true},
@ -504,18 +537,25 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
this.set('usingMicSupported', false); this.set('usingMicSupported', false);
} }
['volume', 'shuffle', 'repeat', 'volumeMuted', 'threshold', 'decay', 'frequency', 'speakerViewed', 'transitionTime', 'randomTransition', 'playerBottomDisplayed', 'onBeatBriAndColor', 'audioMode', 'dimmerEnabled'].forEach(function (item) { ['volume', 'shuffle', 'repeat', 'volumeMuted', 'threshold', 'decay', 'frequency', 'speakerViewed', 'transitionTime', 'randomTransition', 'playerBottomDisplayed', 'onBeatBriAndColor', 'audioMode', 'dimmerEnabled', 'songBeatPreferences'].forEach(function (item) {
if (localStorage.getItem('huegasm.' + item)) { if (localStorage.getItem('huegasm.' + item)) {
var itemVal = localStorage.getItem('huegasm.' + item); var itemVal = localStorage.getItem('huegasm.' + item);
if (item === 'repeat' || item === 'volume' || item === 'decay' || item === 'threshold' || item === 'transitionTime' || item === 'audioMode') { if (item === 'repeat' || item === 'volume' || item === 'decay' || item === 'threshold' || item === 'transitionTime' || item === 'audioMode') {
itemVal = Number(itemVal); itemVal = Number(itemVal);
} else if(item === 'frequency') { } else if(item === 'frequency') {
itemVal = itemVal.split(',').map(function(val){return Number(val);}); itemVal = itemVal.split(',').map(function(val){return Number(val);});
} else if(item === 'songBeatPreferences') {
itemVal = JSON.parse(itemVal);
} else { } else {
itemVal = (itemVal === 'true'); itemVal = (itemVal === 'true');
} }
self.send(item+'Changed', itemVal); if(Em.isNone(self.actions[item+'Changed'])){
self.set(item, itemVal);
} else {
self.send(item + 'Changed', itemVal);
}
} }
}); });
}, },

View file

@ -120,6 +120,7 @@ export default Em.Mixin.create({
// audio: playing or paused // audio: playing or paused
playing: false, playing: false,
fadeOutNotification: false, fadeOutNotification: false,
songBeatPreferences: {},
speakerViewed: true, speakerViewed: true,
speakerLabel: function() { speakerLabel: function() {
@ -148,24 +149,7 @@ export default Em.Mixin.create({
} }
}.property('onBeatBriAndColor'), }.property('onBeatBriAndColor'),
changePlayerControl(name, value, isOption){
if(isOption){
var options = {};
options[name] = value;
this.get('kick').set(options);
}
this.set(name, value);
localStorage.setItem('huegasm.' + name, value);
},
incrementElapseTimeHandle: null, incrementElapseTimeHandle: null,
incrementElapseTime(){
this.incrementProperty('timeElapsed');
if(this.get('timeElapsed') === this.get('timeTotal')){
this.send('next');
}
},
micIcon: function () { micIcon: function () {
if (this.get('usingMicAudio')) { if (this.get('usingMicAudio')) {
@ -261,15 +245,6 @@ export default Em.Mixin.create({
} }
}.property('volumeMuted', 'volume'), }.property('volumeMuted', 'volume'),
onDimmerEnabledChange: function(){
if(!this.get('dimmerEnabled')){
this.set('dimmerOn', false);
} else if(this.get('playing')){
this.set('dimmerOn', true);
}
}.observes('dimmerEnabled'),
onDimmerOnChange: function() { onDimmerOnChange: function() {
var opacity = 0; var opacity = 0;
@ -301,6 +276,22 @@ export default Em.Mixin.create({
this.changeTooltipText(type, tooltipTxt); this.changeTooltipText(type, tooltipTxt);
}.observes('repeat').on('init'), }.observes('repeat').on('init'),
onDimmerEnabledChange: function () {
var tooltipTxt = 'Dim on play', type = 'dimmerEnabled';
if (this.get(type)) {
tooltipTxt = 'Stop dimming';
}
if(!this.get(type)){
this.set('dimmerOn', false);
} else if(this.get('playing')){
this.set('dimmerOn', true);
}
this.changeTooltipText(type, tooltipTxt);
}.observes('dimmerEnabled').on('init'),
onShuffleChange: function () { onShuffleChange: function () {
var tooltipTxt = 'Shuffle', type = 'shuffle'; var tooltipTxt = 'Shuffle', type = 'shuffle';

View file

@ -23,7 +23,7 @@
{{/if}} {{/if}}
<span class="pull-right"> <span class="pull-right">
<span data-toggle="tooltip" data-placement="top" class="bootstrapTooltip" data-title="Dim on play" {{action "toggleDimming"}}>{{paper-icon icon="brightness-high" class=dimmingClass}} <span data-toggle="tooltip" data-placement="top" class="bootstrapTooltip" id="dimmerEnabledTooltip" data-title={{dimmerEnabledTooltipTxt}} {{action "toggleDimming"}}>{{paper-icon icon="brightness-high" class=dimmingClass}}
</span> </span>
<span data-toggle="tooltip" data-placement="top" class="bootstrapTooltip" data-title="Visualizations" {{action "toggleVisualizations"}}>{{paper-icon icon="remove-red-eye" class="playerControllIcon"}} <span data-toggle="tooltip" data-placement="top" class="bootstrapTooltip" data-title="Visualizations" {{action "toggleVisualizations"}}>{{paper-icon icon="remove-red-eye" class="playerControllIcon"}}
</span> </span>
@ -140,9 +140,6 @@
<div id="playerButtonGroup" class="row"> <div id="playerButtonGroup" class="row">
{{#paper-button raised=true warn=true action="defaultControls"}}Default{{/paper-button}} {{#paper-button raised=true warn=true action="defaultControls"}}Default{{/paper-button}}
{{#if usingLocalAudio}}
{{#paper-button raised=true action="saveSongSettings"}}Save Song Settings{{/paper-button}}
{{/if}}
</div> </div>
</div> </div>

View file

@ -7,7 +7,7 @@ $playerBackColor: #F12B24;
$playerHeight: 400px; $playerHeight: 400px;
$playerDefaultIconColor: #BBBBBB; $playerDefaultIconColor: #BBBBBB;
$footerHeight: 40px; $footerHeight: 40px;
$playerBottomHeight: 390px; $playerBottomHeight: 380px;
// BRIDGE FINDER // BRIDGE FINDER
html { html {
@ -696,7 +696,7 @@ md-switch.md-default-theme.md-checked .md-thumb {
} }
#beatOptionButtonGroup { #beatOptionButtonGroup {
margin: 20px 0; margin: 20px 0 10px 0;
} }
.beatOption { .beatOption {