From acf5759021ea23b60b2aebf459f8c6f808389982 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 31 Jan 2015 14:00:09 -0800 Subject: [PATCH] Abstract setBalance --- js/main-window.js | 4 +++- js/media.js | 6 ++++++ js/winamp.js | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/js/main-window.js b/js/main-window.js index e4c10233..285a444e 100644 --- a/js/main-window.js +++ b/js/main-window.js @@ -197,6 +197,7 @@ MainWindow = { window.addEventListener('titleUpdated', function() { self.updateTitle(); }); window.addEventListener('channelCountUpdated', function() { self.updateChannelCount(); }); window.addEventListener('volumeChanged', function() { self.updateVolume(); }); + window.addEventListener('balanceChanged', function() { self.setBalance(); }); window.addEventListener('doubledModeToggled', function() { self.toggleDoubledMode(); }); this.nodes.window.addEventListener('dragenter', this.dragenter.bind(this)); @@ -307,7 +308,8 @@ MainWindow = { this.nodes.volume.value = volume; }, - setBalance: function(balance) { + setBalance: function() { + var balance = this.winamp.getBalance(); var string = ''; if(balance == 0) { string = 'Balance: Center'; diff --git a/js/media.js b/js/media.js index 878059dd..c0ec94f7 100644 --- a/js/media.js +++ b/js/media.js @@ -12,6 +12,7 @@ Media = { }, _startTime: 0, _position: 0, + _balance: 0, _playing: false, _loop: false, autoPlay: false, @@ -200,6 +201,11 @@ Media = { this._leftGain.gain.value = 1; this._rightGain.gain.value = 1; } + this._balance = balance; + }, + + getBalance: function() { + return this._balance; }, toggleRepeat: function() { diff --git a/js/winamp.js b/js/winamp.js index 0eae5680..0d09c51e 100755 --- a/js/winamp.js +++ b/js/winamp.js @@ -23,6 +23,7 @@ Winamp = { titleUpdated: new Event('titleUpdated'), channelCountUpdated: new Event('channelCountUpdated'), volumeChanged: new Event('volumeChanged'), + balanceChanged: new Event('balanceChanged'), doubledModeToggled: new Event('doubledModeToggled'), } @@ -167,7 +168,11 @@ Winamp = { // From -100 to 100 setBalance: function(balance) { this.media.setBalance(balance); - this.mainWindow.setBalance(balance); + window.dispatchEvent(this.events.balanceChanged); + }, + + getBalance: function() { + return this.media.getBalance(); }, seekForwardBy: function(seconds) {