Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

minor fixes

  • Loading branch information...
commit 8c92e099d74336b51089ed84dc20936771665a5a 1 parent 180de53
@sqren authored
Showing with 52 additions and 40 deletions.
  1. +25 −18 coffee/club.coffee
  2. +6 −3 coffee/player.coffee
  3. +21 −19 js/club.js
View
43 coffee/club.coffee
@@ -1,9 +1,12 @@
class @Club
constructor: (songs, commands, cheers) ->
+ # options
@commandProbability = 0.3 # higher means more often commands
- @clubNumber = 0 # the club to start from
- @setTimerSeconds 60 # number of seconds per club
- @paused = true # pause from beginning
+ @secondsPerClub = 60 # number of seconds per club
+
+ # initial setup
+ @clubNumber = 0 # the club to start from
+ @setTimerSeconds @secondsPerClub
# setup players
@songPlayer = new SongPlayer('songs/', songs);
@@ -18,11 +21,15 @@ class @Club
primary: "ui-icon-play"
.click => @toggleControls()
-
# countdown every second
setInterval (=>
- return false if @paused
+ return false if @songPlayer.current.paused
+
+ if @clubNumber > 100
+ $( ".controls" ).button "disable"
+ @pause()
+ alert "Er du fuld nu?"
# decrement second by one and update UI accordingly
@decrementSecond()
@@ -33,7 +40,7 @@ class @Club
# end of song; change to next
if @timerSeconds is 0
@songPlayer.next()
- @setTimerSeconds 60
+ @setTimerSeconds @secondsPerClub
@setCommand()
@incrementClubNumber()
@@ -44,7 +51,7 @@ class @Club
# play command
@commandPlayer.next( (duration) =>
- console.log "Duration from screen: " + duration
+
# increase volume for song again and pause command
setTimeout ( =>
@songPlayer.setVolume 1
@@ -59,7 +66,7 @@ class @Club
decrementSecond: ->
# calculations
@timerSeconds--
- progressBarWidth = (@timerSeconds / 60) * 100
+ progressBarWidth = (@timerSeconds / @secondsPerClub) * 100
# UI
$(".timer-seconds").html @timerSeconds
@@ -82,21 +89,21 @@ class @Club
console.log "Command will NOT be played"
resume: ->
- @paused = false
+ $( ".controls" ).button
+ icons:
+ primary: "ui-icon-pause"
+
@songPlayer.start()
pause: ->
- @paused = true
+ $( ".controls" ).button
+ icons:
+ primary: "ui-icon-play"
+
@songPlayer.pause()
toggleControls: ->
- if @paused is true
- $( ".controls" ).button
- icons:
- primary: "ui-icon-pause"
+ if @songPlayer.current.paused is true
@resume()
- else
- $( ".controls" ).button
- icons:
- primary: "ui-icon-play"
+ else
@pause()
View
9 coffee/player.coffee
@@ -3,11 +3,11 @@ class Player
@track_number = 0
@current = new Audio(@folder + @playlist[@track_number])
- start: ->
+ start: ->
@current.play()
pause: ->
- @current.pause() if @current.paused is false
+ @current.pause() if @current.paused is false
next: (callback) ->
# pause current track
@@ -25,6 +25,7 @@ class Player
# set track source
@current.src = @folder + filename
+ # start
@start()
console.log "Changed track to: " + filename
@@ -32,6 +33,7 @@ class Player
console.log "Volume change to: #{volume} "
@current.volume = volume
+# songplayer with specific label
class @SongPlayer extends Player
setLabel: (filename) ->
filename_human = filename.substring(0, filename.length - 4)
@@ -40,6 +42,7 @@ class @SongPlayer extends Player
super
@setLabel @playlist[@track_number]
+# commandplayer with own implementation of next for returning duration in a callback
class @CommandPlayer extends Player
next: (callback) ->
# pause current track
@@ -62,7 +65,7 @@ class @CommandPlayer extends Player
if @current.duration > 0
clearInterval(preload)
- #
+ # return duration of command to Club()
callback(@current.duration)
# start next song
View
40 js/club.js
@@ -5,9 +5,9 @@
function Club(songs, commands, cheers) {
var _this = this;
this.commandProbability = 0.3;
+ this.secondsPerClub = 60;
this.clubNumber = 0;
- this.setTimerSeconds(60);
- this.paused = true;
+ this.setTimerSeconds(this.secondsPerClub);
this.songPlayer = new SongPlayer('songs/', songs);
this.commandPlayer = new CommandPlayer('commands/', commands);
this.cheersPlayer = new CheersPlayer('cheers/', cheers);
@@ -20,19 +20,23 @@
return _this.toggleControls();
});
setInterval((function() {
- if (_this.paused) return false;
+ if (_this.songPlayer.current.paused) return false;
+ if (_this.clubNumber > 100) {
+ $(".controls").button("disable");
+ _this.pause();
+ alert("Er du fuld nu?");
+ }
_this.decrementSecond();
if (_this.timerSeconds === 1) _this.cheersPlayer.next();
if (_this.timerSeconds === 0) {
_this.songPlayer.next();
- _this.setTimerSeconds(60);
+ _this.setTimerSeconds(_this.secondsPerClub);
_this.setCommand();
_this.incrementClubNumber();
}
if (_this.timerSeconds === _this.commandSecond && _this.commandSecond > 0) {
_this.songPlayer.setVolume(0.2);
return _this.commandPlayer.next(function(duration) {
- console.log("Duration from screen: " + duration);
return setTimeout((function() {
_this.songPlayer.setVolume(1);
return _this.commandPlayer.pause();
@@ -49,7 +53,7 @@
Club.prototype.decrementSecond = function() {
var progressBarWidth;
this.timerSeconds--;
- progressBarWidth = (this.timerSeconds / 60) * 100;
+ progressBarWidth = (this.timerSeconds / this.secondsPerClub) * 100;
$(".timer-seconds").html(this.timerSeconds);
return $(".progress-bar-inside").css("width", progressBarWidth + "%");
};
@@ -76,29 +80,27 @@
};
Club.prototype.resume = function() {
- this.paused = false;
+ $(".controls").button({
+ icons: {
+ primary: "ui-icon-pause"
+ }
+ });
return this.songPlayer.start();
};
Club.prototype.pause = function() {
- this.paused = true;
+ $(".controls").button({
+ icons: {
+ primary: "ui-icon-play"
+ }
+ });
return this.songPlayer.pause();
};
Club.prototype.toggleControls = function() {
- if (this.paused === true) {
- $(".controls").button({
- icons: {
- primary: "ui-icon-pause"
- }
- });
+ if (this.songPlayer.current.paused === true) {
return this.resume();
} else {
- $(".controls").button({
- icons: {
- primary: "ui-icon-play"
- }
- });
return this.pause();
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.