Skip to content

Commit

Permalink
light up pads while sample is playing
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegraham committed Jan 28, 2012
1 parent 73b9d60 commit 8184fa8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
30 changes: 26 additions & 4 deletions app/jpc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions coffeescripts/jpc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ $(document).ready ->
audioContext = new webkitAudioContext

class AudioPlayer
constructor: ->
constructor: (@view)->

play: ->
if @buffer
@source = audioContext.createBufferSource()
@source.buffer = @buffer
@source.connect audioContext.destination
@source.noteOn 0
@triggerView()

stop: ->
if @buffer && @source
@source.noteOff 0


triggerView: ->
@view.lightOn()
window.clearTimeout @timer
timeOut = (@buffer.length / @buffer.sampleRate) * 1000
@timer = window.setTimeout @view.lightOff, timeOut

load_file: (file) ->
reader = new FileReader
self = this
Expand All @@ -34,7 +42,12 @@ $(document).ready ->

class PadView extends Backbone.View
initialize: ->
@audio_player = new AudioPlayer
@el = $(@el)
@audio_player = new AudioPlayer this

lightOn: -> @el.addClass 'active'

lightOff: => @el.removeClass 'active'

triggerSample: ->
chokeGroup.select(this)
Expand Down

0 comments on commit 8184fa8

Please sign in to comment.