-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
56,533 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.sass-cache/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard 'livereload' do | ||
watch(%r{/.+\.(css|js|html)}) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Sounder.Collections.Tracks extends Backbone.Collection | ||
model: Sounder.Models.Track | ||
url: 'http://api.shuffler.fm/v1/channels/artist:36376?api-key=zlspn5imm91ak2z7nk3g' | ||
# url: 'http://api.shuffler.fm/v1/artists/36376?api-key=zlspn5imm91ak2z7nk3g' | ||
# 36376 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
window.Sounder = | ||
Models: {} | ||
Collections: {} | ||
Views: {} | ||
Routers: {} | ||
|
||
init: -> | ||
|
||
# Init settings | ||
$.fx.interval = 20 | ||
|
||
|
||
# Initialize Routers | ||
@Routers.main = new Sounder.Routers.Main() | ||
Backbone.history.start() | ||
|
||
|
||
|
||
$ -> | ||
Sounder.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class Sounder.Models.Track extends Backbone.Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
class Player | ||
|
||
constructor: -> | ||
@audioPlayers = [] | ||
@currentPlaying = null | ||
@isPlaying = false | ||
@currentTrack = 0 | ||
@initEvents() | ||
|
||
@ | ||
|
||
|
||
initEvents: (el) -> | ||
$(@).on 'newAudio', (e, el) => | ||
console.log 'new source', el | ||
@audioPlayers.push el | ||
@renderPlaylist() | ||
|
||
$(@).on 'playLast', (e) => @playLast() | ||
|
||
$(@).on 'playIndex', (e, index) => | ||
if @currentTrack is index and @isPlaying | ||
@pauseCurrent() | ||
else | ||
@currentTrack = index | ||
@playCurrent() | ||
|
||
|
||
renderPlaylist: -> | ||
$('#playlist').html '' | ||
for player in @audioPlayers | ||
do (player) => | ||
# index = @audioPlayers.indexOf player | ||
# console.log index ,$(player).data 'index' | ||
# $(player).data 'index', "#{index}" | ||
# console.log 'toucher', player | ||
# tmpl = "<a class='play' data-index='#{index}' href='#'>track-#{index}</a>" | ||
# $('#playlist').append tmpl | ||
|
||
|
||
pauseCurrent: -> | ||
current = _.filter @audioPlayers, (a) -> | ||
a.paused is false | ||
|
||
for audio in current | ||
do (audio) -> | ||
audio.pause() | ||
|
||
$(Sounder.renderer).trigger 'pause' | ||
@isPlaying = false | ||
|
||
|
||
playLast: -> | ||
if @isPlaying | ||
@pauseCurrent() | ||
|
||
last = @audioPlayers[@audioPlayers.length - 1] | ||
last.play() | ||
|
||
$(Sounder.renderer).trigger 'start' | ||
@isPlaying = true | ||
|
||
|
||
|
||
playCurrent: () -> | ||
if @isPlaying | ||
@pauseCurrent() | ||
i = @audioPlayers.indexOf @currentTrack | ||
# current = @audioPlayers[@currentTrack] | ||
current = @audioPlayers[i] | ||
current.play() | ||
|
||
$(Sounder.renderer).trigger 'start' | ||
@isPlaying = true | ||
|
||
|
||
|
||
(-> | ||
Sounder.player = new Player | ||
)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
class Renderer | ||
|
||
OFFSET: 100 | ||
BARS: 104 | ||
BARWIDTH: 60 | ||
BARSOFFSET: 0 | ||
activeShader: "paper" | ||
hue: 0 | ||
theI:0 | ||
hueDirection: "up" | ||
runRenderer: true | ||
points: [] | ||
path: null | ||
changeHue: false | ||
smooth: true | ||
|
||
constructor: -> | ||
@freqByteData = new Uint8Array(Sounder.control.analyser.frequencyBinCount) | ||
@initEvents() | ||
@initPaper() | ||
@ | ||
|
||
|
||
initPaper: -> | ||
paper.setup $('canvas')[0] | ||
@bg = new paper.Rectangle(paper.view.bounds) | ||
paper.view.fillColor = 'rgb(255,2555,233)' | ||
@path = new paper.Path() | ||
@path.strokeColor = 'black' | ||
# @path.fillColor = '#000000' | ||
@path.strokeWidth = 1 | ||
|
||
console.log 'started ', paper ,'engine on ', @path | ||
|
||
@TOTALWIDTH = paper.view.size.width | ||
@TOTALHEIGHT = paper.view.size.height | ||
console.log @TOTALWIDTH, @TOTALHEIGHT | ||
@POINTSGAP = ( @TOTALWIDTH / @BARS ) | ||
@PI = Math.PI | ||
@GOLDEN = 1.618 | ||
@initPoints() | ||
console.log "each point is ", @POINTSGAP, "apart from each other" | ||
paper.view.draw() | ||
|
||
initPoints: -> | ||
console.log @BARS | ||
i = 0 | ||
while i <= @BARS | ||
w = @TOTALWIDTH - (@POINTSGAP * i) | ||
point = new paper.Point w, @TOTALHEIGHT | ||
@path.add point | ||
i += 1 | ||
console.log @path.segments[0].point.x, @path.segments[@path.segments.length - 1].point.x | ||
|
||
|
||
|
||
updatePos: -> | ||
oldHeight = @TOTALHEIGHT | ||
@TOTALWIDTH = paper.view.size.width | ||
@TOTALHEIGHT = paper.view.size.height | ||
@POINTSGAP = ( @TOTALWIDTH / @BARS ) | ||
|
||
# i = 0 | ||
# | ||
# | ||
for i in [0...@BARS] by 1 | ||
# while i <= @BARS | ||
w = @TOTALWIDTH - (@POINTSGAP * i) | ||
@path.segments[i].point.x = w | ||
@path.segments[i].point.y = @TOTALHEIGHT if @path.segments[i].point.y is oldHeight | ||
# i += 1 | ||
|
||
initEvents: -> | ||
|
||
$(@).on 'drawPoints', => | ||
|
||
|
||
$(@).on 'pause', => | ||
@runRenderer = false | ||
# @hueChanger false | ||
|
||
$(@).on 'start', => | ||
@runRenderer = true | ||
@render() | ||
# @hueChanger() | ||
|
||
$(@).on 'changeShader', (e, shader) => | ||
$('body').attr('style', ''); | ||
@activeShader = shader | ||
|
||
# trigger for window resize | ||
debouncedresize = _.debounce ( => @updatePos() ), 10 | ||
$(window).resize => | ||
debouncedresize() | ||
|
||
# constructor: -> | ||
# @init() | ||
# @ | ||
|
||
shader: (value) -> | ||
# if @activeShader is "solid" | ||
# $("body").css "background-color", => | ||
# "hsl(#{@hue},#{(value[@OFFSET] /10)}%,10%)" | ||
|
||
|
||
# if @activeShader is "paper" | ||
# i = 0 | ||
|
||
|
||
for i in [1..@path.segments.length - 2] by 1 | ||
|
||
# while i < (@path.segments.length - 2) | ||
|
||
magnitude = value[Math.round(i * (@PI * 0.9))] * @GOLDEN | ||
|
||
# unless i is 0 | ||
@path.segments[(@path.segments.length - 1) - i].point.y = (@TOTALHEIGHT) - magnitude | ||
# i += 1 | ||
|
||
@bg.fillColor = "hsla(#{ 255 - (value[@OFFSET] % 255)},30%,80%, 0.1)" | ||
@path.strokeColor = "hsla(#{255 - (value[@OFFSET] % 255)},20%,60%, 0.2)" | ||
# @path.strokeWidth = 100 | ||
@path.smooth() if @smooth | ||
|
||
paper.view.draw() | ||
|
||
$("body").css "background-color", => | ||
"hsla(#{ (value[@OFFSET] % 255)},10%,90%, 1)" | ||
|
||
|
||
|
||
|
||
|
||
hueChanger: (looping=true) -> | ||
if Sounder.renderer.changeHue | ||
window.webkitRequestAnimationFrame Sounder.renderer.hueChanger | ||
|
||
if Sounder.renderer.hueDirection is "up" then Sounder.renderer.hue = Sounder.renderer.hue + 1 | ||
else if Sounder.renderer.hueDirection is "down" then Sounder.renderer.hue = Sounder.renderer.hue - 1 | ||
|
||
if Sounder.renderer.hue > 250 then Sounder.renderer.hueDirection = "down" | ||
else if Sounder.renderer.hue < 10 then Sounder.renderer.hueDirection = "up" | ||
|
||
|
||
|
||
render: -> | ||
if Sounder.renderer.runRenderer | ||
window.webkitRequestAnimationFrame Sounder.renderer.render | ||
Sounder.control.analyser.getByteFrequencyData Sounder.renderer.freqByteData | ||
Sounder.renderer.shader Sounder.renderer.freqByteData | ||
|
||
(-> | ||
Sounder.renderer = new Renderer | ||
)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Sounder.Routers.Main extends Backbone.Router | ||
|
||
view: null | ||
|
||
routes: | ||
'': 'home' | ||
':key':'home' | ||
|
||
|
||
home: (key) -> | ||
@view = new Sounder.Views.Home(key) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class SounderControl | ||
|
||
|
||
init: -> | ||
@initEvents() | ||
@context = new window.webkitAudioContext() | ||
@analyser = @context.createAnalyser() | ||
@_plug @analyser, @context.destination | ||
console.log 'welcome to ', @context, @analyser | ||
@getTracks() | ||
|
||
|
||
constructor: -> | ||
@loaded = false | ||
@source = undefined | ||
@audio = undefined | ||
|
||
# Sounder.player = new Player() | ||
|
||
@init() | ||
|
||
|
||
initEvents: -> | ||
$(@).on 'newTrack', (e, track) => @plugOne track | ||
|
||
|
||
plugMany: -> | ||
for plug in $('audio') | ||
do (plug) => | ||
source = @context.createMediaElementSource(plug) | ||
source.connect @analyser | ||
$(Sounder.player).trigger 'newAudio', plug | ||
|
||
|
||
plugOne: (el)-> | ||
source = @context.createMediaElementSource(el) | ||
source.connect @analyser | ||
$(Sounder.player).trigger 'newAudio', el | ||
# @audioSources.push source | ||
|
||
|
||
_plug: (input, output) -> | ||
input.connect output | ||
|
||
getTracks: -> | ||
# console.log Meteor | ||
# console.log @tracks | ||
@ | ||
|
||
|
||
(-> | ||
Sounder.control = new SounderControl | ||
)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
class Sounder.Views.Home extends Backbone.View | ||
|
||
template: JST['home'] | ||
|
||
# Define main element to attach to | ||
el: "#container" | ||
|
||
|
||
# events: | ||
# 'keyup #search-input' : 'search' | ||
# 'click #about-open, #about-close' : 'openAbout' | ||
|
||
initialize: (key) -> | ||
@tracks = new Sounder.Collections.Tracks() | ||
@tracks.fetch | ||
# data: | ||
dataType:'jsonp' | ||
success: => | ||
tracks = _.filter @tracks.models, (t) => | ||
console.log t | ||
t.attributes.object.stream.platform not in ['youtube', 'vimeo'] | ||
@tracks.models = [] | ||
@tracks.models = tracks | ||
console.log @tracks, tracks.length | ||
@render() | ||
@renderTracks() | ||
|
||
|
||
|
||
render: -> | ||
@$el.html(@template()) | ||
|
||
doPlay: -> | ||
Sounder.control.plugMany() | ||
$(Sounder.player).trigger 'playLast' | ||
|
||
renderTracks: -> | ||
i = 1 | ||
for t in @tracks.models | ||
t.trackIndex = i | ||
v = new Sounder.Views.Track(model:t) | ||
@$('#track-list').append v.$el | ||
i += 1 | ||
|
||
_.delay (=> | ||
@doPlay() | ||
|
||
console.log 'play' | ||
), 1000 | ||
|
Oops, something went wrong.