Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Various Fixes #1

Open
wants to merge 8 commits into from

1 participant

@gjacobrobertson

I noticed that local settings would get overridden by default settings every time the app was loaded, theme songs would start from the beginning of the song (rather than the beginning of the range), and not aways stop after the allotted amount of time. So I fixed those things, and changed the range formatting to MM:SS instead of milliseconds. Just figured I'd see if you guys wanted my changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 82 additions and 126 deletions.
  1. +36 −53 coffee/shipify.coffee
  2. +3 −4 index.haml
  3. +2 −5 index.html
  4. +41 −64 js/shipify.js
View
89 coffee/shipify.coffee
@@ -2,7 +2,7 @@ window.S ||= {} # initialized in settings.js
# Format is github_username: ['spotify_track_uri', start_in_ms, stop_in_ms]
S.defaultThemes =
- nottombrown: ['spotify:track:0GugYsbXWlfLOgsmtsdxzg', 12000, 50000]
+ nottombrown: ['spotify:track:0GugYsbXWlfLOgsmtsdxzg', 12000, 54000]
facedog: ['spotify:track:2BY7ALEWdloFHgQZG6VMLA', 12000, 44000]
waxman: ['spotify:track:3MrRksHupTVEQ7YbA0FsZK', 12000, 44000]
@@ -39,95 +39,63 @@ $ ->
localStorage.setItem('themeList', JSON.stringify(@toJSON()))
renderThemeViews: =>
- console.log TL.toJSON()
$('.themesongs tbody').empty()
@themes = {}
for username, song of TL.toJSON()
do ( username, song) =>
- @themes[username] = new ThemeView(song[0], song[1], song[2], username)
+ track_uri = song[0]
+ start = song[1]
+ stop = song[2]
+ @themes[username] = new ThemeView(track_uri, new Date(start), new Date(stop), username)
# Initialize Themelist
Boot = JSON.parse localStorage.getItem('themeList')
- Boot = S.defaultThemes
-
+ Boot ||= S.defaultThemes
- TL = new ThemeList(Boot)
- # TL.persist()
+ TL = new ThemeList(Boot)
class ThemeView extends Backbone.View
constructor: (track_uri, start, stop, username) ->
+ @track_uri = track_uri + '#' + start.getMinutes() + ':' + start.getSeconds()
@track = models.Track.fromURI(track_uri)
@start = start
@stop = stop
@username = username
- @fadeTime = 1500
@render()
render: =>
@el = $ themeTemplate
username: @username
themesong: @track
- range: "#{@start/1000}s - #{@stop/1000}s"
+ range: "#{@start.getMinutes()}:#{@start.getSeconds()} - #{@stop.getMinutes()}:#{@stop.getSeconds()}"
@el.find('.preview').click =>
@play()
@el.find('.remove').click =>
@remove()
+
@el.appendTo $('.themesongs tbody')
remove: =>
- console.log "Removed"
TL.unset(@username)
- console.log TL
@el.hide()
play: =>
- S.playingTheme = true
- player.track = @track
- setTimeout @end, (@stop-@start)
+ if !S.playingTheme
+ S.playingTheme = true
- setCorrectPosition = =>
- # Give us some time to load the new track
- if player.track.name != @track.name
- setTimeout ->
- setCorrectPosition()
- , 100
- else
- player.position = @start
+ player.play(@track_uri)
+ setTimeout @end, (@stop-@start)
- setCorrectPosition()
end: =>
- player.track = S.track
-
- # Give us some time to load the new track
- setCorrectPosition = =>
- player.position = S.position
-
- if player.track.name != S.track.name
- setTimeout ->
- setCorrectPosition()
- , 100
- else
- S.playingTheme = false
-
- setCorrectPosition()
-
- fadeOut: (callback=->)=>
- # Volume changing does not currently work
- # http://stackoverflow.com/questions/10822979/change-volume-with-spotify-app-api
- timeInterval = @fadeTime/10
- for level in [10..1]
- do (level) =>
- setTimeout =>
- player.volume = 0.1*level
- console.log 0.1*level
- , timeInterval*level
- setTimeout callback, @fadeTime
+ if S.playingTheme
+ S.playingTheme = false
+ player.playing = false
# Rendering
#
@@ -140,14 +108,15 @@ $ ->
#
#
updateCurrentlyPlaying = ->
- if !S.playingTheme
+ if S.playingTheme
currentTrack = player.track
- S.position = player.position
S.track = currentTrack
if currentTrack?
$("#np").html "#{currentTrack}"
+ else
+ $("#np").empty()
setInterval updateCurrentlyPlaying, 200
@@ -189,12 +158,26 @@ $ ->
#
$("#new button").click (e) ->
console.log "New theme"
+
+ parseTime = (time) ->
+ timeRegexp = /(\d{1,2}):(\d{2})/g
+ match = timeRegexp.exec(time)
+ if not match
+ return null
+ console.log(match[1])
+ console.log(match[2])
+ console.log(1000 * ( 60 * parseInt(match[1]) + parseInt(match[2]) ))
+ return 1000 * ( 60 * parseInt(match[1]) + parseInt(match[2]) )
+
theme =
username: $("#new .username").val()
uri: $("#new .uri").val()
- start: parseInt $("#new .start").val()
- stop: parseInt $("#new .stop").val()
+ start: parseTime $("#new .start").val()
+ stop: parseTime $("#new .stop").val()
+ if theme.start == null or theme.stop == null
+ e.preventDefault()
+ return false
TL.set(theme.username, [theme.uri, theme.start, theme.stop])
TL.renderThemeViews()
e.preventDefault()
View
7 index.haml
@@ -52,11 +52,10 @@
.control-group
%label.control-label Start and Stop
.controls
- %input.start.input-small{ :placeholder => 22000, :value => 22000}
+ %input.start.input-small{ :placeholder => 0:22, :value => 0:22}
= "-"
- %input.stop.input-small{ :placeholder => 54000, :value => 54000 }
- %p
- In milliseconds. Leave blank to play the entire song
+ %input.stop.input-small{ :placeholder => 0:54, :value => 0:54 }
+
%button.btn{ :style => "margin-left: 305px"} Create Themesong
View
7 index.html
@@ -66,12 +66,9 @@ <h2 style='text-align: center'>
<div class='control-group'>
<label class='control-label'>Start and Stop</label>
<div class='controls'>
- <input class='start input-small' placeholder='22000' value='22000'>
+ <input class='start input-small' placeholder='0:22' value='0:22'>
-
- <input class='stop input-small' placeholder='54000' value='54000'>
- <p>
- In milliseconds. Leave blank to play the entire song
- </p>
+ <input class='stop input-small' placeholder='0:54' value='0:54'>
</div>
</div>
<button class='btn' style='margin-left: 305px'>Create Themesong</button>
View
105 js/shipify.js
@@ -1,13 +1,13 @@
-// Generated by CoffeeScript 1.3.1
+// Generated by CoffeeScript 1.4.0
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.S || (window.S = {});
S.defaultThemes = {
- nottombrown: ['spotify:track:0GugYsbXWlfLOgsmtsdxzg', 12000, 50000],
+ nottombrown: ['spotify:track:0GugYsbXWlfLOgsmtsdxzg', 12000, 54000],
facedog: ['spotify:track:2BY7ALEWdloFHgQZG6VMLA', 12000, 44000],
waxman: ['spotify:track:3MrRksHupTVEQ7YbA0FsZK', 12000, 44000]
};
@@ -43,7 +43,6 @@
ThemeList.prototype.renderThemeViews = function() {
var song, username, _ref, _results,
_this = this;
- console.log(TL.toJSON());
$('.themesongs tbody').empty();
this.themes = {};
_ref = TL.toJSON();
@@ -51,7 +50,11 @@
for (username in _ref) {
song = _ref[username];
_results.push((function(username, song) {
- return _this.themes[username] = new ThemeView(song[0], song[1], song[2], username);
+ var start, stop, track_uri;
+ track_uri = song[0];
+ start = song[1];
+ stop = song[2];
+ return _this.themes[username] = new ThemeView(track_uri, new Date(start), new Date(stop), username);
})(username, song));
}
return _results;
@@ -61,15 +64,13 @@
})(Backbone.Model);
Boot = JSON.parse(localStorage.getItem('themeList'));
- Boot = S.defaultThemes;
+ Boot || (Boot = S.defaultThemes);
TL = new ThemeList(Boot);
ThemeView = (function(_super) {
__extends(ThemeView, _super);
function ThemeView(track_uri, start, stop, username) {
- this.fadeOut = __bind(this.fadeOut, this);
-
this.end = __bind(this.end, this);
this.play = __bind(this.play, this);
@@ -77,11 +78,11 @@
this.remove = __bind(this.remove, this);
this.render = __bind(this.render, this);
+ this.track_uri = track_uri + '#' + start.getMinutes() + ':' + start.getSeconds();
this.track = models.Track.fromURI(track_uri);
this.start = start;
this.stop = stop;
this.username = username;
- this.fadeTime = 1500;
this.render();
}
@@ -90,7 +91,7 @@
this.el = $(themeTemplate({
username: this.username,
themesong: this.track,
- range: "" + (this.start / 1000) + "s - " + (this.stop / 1000) + "s"
+ range: "" + (this.start.getMinutes()) + ":" + (this.start.getSeconds()) + " - " + (this.stop.getMinutes()) + ":" + (this.stop.getSeconds())
}));
this.el.find('.preview').click(function() {
return _this.play();
@@ -102,64 +103,23 @@
};
ThemeView.prototype.remove = function() {
- console.log("Removed");
TL.unset(this.username);
- console.log(TL);
return this.el.hide();
};
ThemeView.prototype.play = function() {
- var setCorrectPosition,
- _this = this;
- S.playingTheme = true;
- player.track = this.track;
- setTimeout(this.end, this.stop - this.start);
- setCorrectPosition = function() {
- if (player.track.name !== _this.track.name) {
- return setTimeout(function() {
- return setCorrectPosition();
- }, 100);
- } else {
- return player.position = _this.start;
- }
- };
- return setCorrectPosition();
+ if (!S.playingTheme) {
+ S.playingTheme = true;
+ player.play(this.track_uri);
+ return setTimeout(this.end, this.stop - this.start);
+ }
};
ThemeView.prototype.end = function() {
- var setCorrectPosition,
- _this = this;
- player.track = S.track;
- setCorrectPosition = function() {
- player.position = S.position;
- if (player.track.name !== S.track.name) {
- return setTimeout(function() {
- return setCorrectPosition();
- }, 100);
- } else {
- return S.playingTheme = false;
- }
- };
- return setCorrectPosition();
- };
-
- ThemeView.prototype.fadeOut = function(callback) {
- var level, timeInterval, _fn, _i,
- _this = this;
- if (callback == null) {
- callback = function() {};
- }
- timeInterval = this.fadeTime / 10;
- _fn = function(level) {
- return setTimeout(function() {
- player.volume = 0.1 * level;
- return console.log(0.1 * level);
- }, timeInterval * level);
- };
- for (level = _i = 10; _i >= 1; level = --_i) {
- _fn(level);
+ if (S.playingTheme) {
+ S.playingTheme = false;
+ return player.playing = false;
}
- return setTimeout(callback, this.fadeTime);
};
return ThemeView;
@@ -168,13 +128,14 @@
TL.renderThemeViews();
updateCurrentlyPlaying = function() {
var currentTrack;
- if (!S.playingTheme) {
+ if (S.playingTheme) {
currentTrack = player.track;
- S.position = player.position;
S.track = currentTrack;
if (currentTrack != null) {
return $("#np").html("" + currentTrack);
}
+ } else {
+ return $("#np").empty();
}
};
setInterval(updateCurrentlyPlaying, 200);
@@ -201,14 +162,30 @@
tabs();
models.application.observe(models.EVENT.ARGUMENTSCHANGED, tabs);
$("#new button").click(function(e) {
- var theme;
+ var parseTime, theme;
console.log("New theme");
+ parseTime = function(time) {
+ var match, timeRegexp;
+ timeRegexp = /(\d{1,2}):(\d{2})/g;
+ match = timeRegexp.exec(time);
+ if (!match) {
+ return null;
+ }
+ console.log(match[1]);
+ console.log(match[2]);
+ console.log(1000 * (60 * parseInt(match[1]) + parseInt(match[2])));
+ return 1000 * (60 * parseInt(match[1]) + parseInt(match[2]));
+ };
theme = {
username: $("#new .username").val(),
uri: $("#new .uri").val(),
- start: parseInt($("#new .start").val()),
- stop: parseInt($("#new .stop").val())
+ start: parseTime($("#new .start").val()),
+ stop: parseTime($("#new .stop").val())
};
+ if (theme.start === null || theme.stop === null) {
+ e.preventDefault();
+ return false;
+ }
TL.set(theme.username, [theme.uri, theme.start, theme.stop]);
TL.renderThemeViews();
e.preventDefault();
Something went wrong with that request. Please try again.