Skip to content

Commit

Permalink
use javascript standard style
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckegg committed Jul 5, 2015
1 parent e4f607a commit 2792770
Show file tree
Hide file tree
Showing 55 changed files with 354 additions and 382 deletions.
19 changes: 10 additions & 9 deletions browser-entry.js
Expand Up @@ -15,42 +15,43 @@ var lastElement = null
var lastView = null
var lastLesson = null

watch(state, function refreshView() {
watch(state, function refreshView () {
var element = null
if (state.view() === 'lesson') {
if (lastLesson !== state.selectedLesson() || lastView !== 'lesson') {
lastLesson = state.selectedLesson()
var lesson = state.getLesson(state.selectedLesson())
if (lesson) {
var element = LessonView(state, lesson)
element = LessonView(state, lesson)
setView(element)
} else {
state.view.set('index')
}
}
} else if (state.view() !== lastView) {
var element = IndexView(state)
element = IndexView(state)
setView(element)
scrollSelectedIntoView()
}
lastView = state.view()
})

function scrollSelectedIntoView() {
function scrollSelectedIntoView () {
var selected = document.querySelector('.-selected')
if (selected) {
if (selected.scrollIntoViewIfNeeded) {
selected.scrollIntoViewIfNeeded()
selected.scrollIntoViewIfNeeded()
} else if (selected.scrollIntoView) {
selected.scrollIntoView(false)
selected.scrollIntoView(false)
}
}
}

function setView(element) {
function setView (element) {
if (lastElement) {
lastElement.destroy&&lastElement.destroy()
lastElement.destroy && lastElement.destroy()
lastElement.remove()
}
document.body.appendChild(element)
lastElement = element
}
}
@@ -1,4 +1,4 @@
//# duration=2
// # duration=2

var audioContext = new AudioContext()

Expand Down
@@ -1,4 +1,4 @@
//# duration=2
// # duration=2

var audioContext = new AudioContext()

Expand Down
@@ -1,21 +1,21 @@
//# duration=3
// # duration=3

var audioContext = new AudioContext()

play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

var oscillator = audioContext.createOscillator()
oscillator.connect(audioContext.destination)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime)
}
}
Expand Up @@ -4,8 +4,8 @@ play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

}
}
@@ -1,4 +1,4 @@
//# duration=3
// # duration=3

var audioContext = new AudioContext()

Expand All @@ -11,16 +11,16 @@ play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

var oscillator = audioContext.createOscillator()
oscillator.connect(filter)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime)
}
}
Expand Up @@ -4,16 +4,16 @@ play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

var oscillator = audioContext.createOscillator()
oscillator.connect(audioContext.destination)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime)
}
}
@@ -1,12 +1,12 @@
//# duration=3
// # duration=3

var audioContext = new AudioContext()

play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

Expand All @@ -22,8 +22,8 @@ function play(delay, pitch, duration) {
oscillator.connect(filter)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime)
}
}
Expand Up @@ -4,7 +4,7 @@ play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

Expand All @@ -17,8 +17,8 @@ function play(delay, pitch, duration) {
oscillator.connect(filter)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime)
}
}
@@ -1,12 +1,12 @@
//# duration=4.5
// # duration=4.5

var audioContext = new AudioContext()

play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

Expand All @@ -20,8 +20,8 @@ function play(delay, pitch, duration) {
oscillator.connect(envelope)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime + 2)
}
}
8 changes: 4 additions & 4 deletions lessons/1. Subtractive Synthesis/06. Add an envelope/start.js
Expand Up @@ -4,16 +4,16 @@ play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

var oscillator = audioContext.createOscillator()
oscillator.connect(audioContext.destination)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime)
}
}
8 changes: 4 additions & 4 deletions lessons/1. Subtractive Synthesis/07. Vibrato/answer.js
@@ -1,12 +1,12 @@
//# duration=4
// # duration=4

var audioContext = new AudioContext()

play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

Expand All @@ -20,7 +20,7 @@ function play(delay, pitch, duration) {
oscillator.connect(envelope)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

var vibrato = audioContext.createGain()
vibrato.gain.value = 30
Expand All @@ -34,4 +34,4 @@ function play(delay, pitch, duration) {
oscillator.start(startTime)
oscillator.stop(endTime + 2)

}
}
6 changes: 3 additions & 3 deletions lessons/1. Subtractive Synthesis/07. Vibrato/start.js
Expand Up @@ -4,7 +4,7 @@ play(0, 3, 0.5)
play(1, 10, 0.5)
play(2, 15, 0.5)

function play(delay, pitch, duration) {
function play (delay, pitch, duration) {
var startTime = audioContext.currentTime + delay
var endTime = startTime + duration

Expand All @@ -18,8 +18,8 @@ function play(delay, pitch, duration) {
oscillator.connect(envelope)

oscillator.type = 'sawtooth'
oscillator.detune.value = pitch * 100
oscillator.detune.value = pitch * 100

oscillator.start(startTime)
oscillator.stop(endTime + 2)
}
}
@@ -1,22 +1,22 @@
//# duration=8.4
// # duration=8.4

var audioContext = new AudioContext()

// wait 100ms for sample to download/decode
var startTime = audioContext.currentTime + 0.2

getSample('zara1.ogg', function play(buffer) {
getSample('zara1.ogg', function play (buffer) {
var player = audioContext.createBufferSource()
player.buffer = buffer
player.connect(audioContext.destination)
player.start(startTime)
})
function getSample(url, cb) {

function getSample (url, cb) {
var request = new XMLHttpRequest()
request.open('GET', url)
request.responseType = 'arraybuffer'
request.onload = function() {
request.onload = function () {
audioContext.decodeAudioData(request.response, cb)
}
request.send()
Expand Down
Expand Up @@ -3,15 +3,13 @@ var audioContext = new AudioContext()
// wait 100ms for sample to download/decode
var startTime = audioContext.currentTime + 0.2

getSample('zara1.ogg', function play(buffer) {
getSample('zara1.ogg', function play (buffer) {})

})

function getSample(url, cb) {
function getSample (url, cb) {
var request = new XMLHttpRequest()
request.open('GET', url)
request.responseType = 'arraybuffer'
request.onload = function() {
request.onload = function () {
audioContext.decodeAudioData(request.response, cb)
}
request.send()
Expand Down
@@ -1,20 +1,20 @@
//# duration=2.2
// # duration=2.2

var audioContext = new AudioContext()
var startTime = audioContext.currentTime + 0.2

getSample('zara1.ogg', function play(buffer) {
getSample('zara1.ogg', function play (buffer) {
var player = audioContext.createBufferSource()
player.buffer = buffer
player.connect(audioContext.destination)
player.start(startTime, 2.5, 2)
})
function getSample(url, cb) {

function getSample (url, cb) {
var request = new XMLHttpRequest()
request.open('GET', url)
request.responseType = 'arraybuffer'
request.onload = function() {
request.onload = function () {
audioContext.decodeAudioData(request.response, cb)
}
request.send()
Expand Down
@@ -1,18 +1,18 @@
var audioContext = new AudioContext()
var startTime = audioContext.currentTime + 0.2

getSample('zara1.ogg', function play(buffer) {
getSample('zara1.ogg', function play (buffer) {
var player = audioContext.createBufferSource()
player.buffer = buffer
player.connect(audioContext.destination)
player.start(startTime)
})
function getSample(url, cb) {

function getSample (url, cb) {
var request = new XMLHttpRequest()
request.open('GET', url)
request.responseType = 'arraybuffer'
request.onload = function() {
request.onload = function () {
audioContext.decodeAudioData(request.response, cb)
}
request.send()
Expand Down

0 comments on commit 2792770

Please sign in to comment.