Skip to content

Commit

Permalink
Releasing version 1.0.1
Browse files Browse the repository at this point in the history
 - Using 'linearRampToValueAtTime' fade rather than requestAnimationFrame() - fixes #3
 - Removing requestAnimationFrame all together so music will loop while browser is in the background - fixes #21
  • Loading branch information
Cody Lundquist committed Jul 14, 2014
1 parent c90a651 commit c73e28d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BandJS",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/band.min.js",
"ignore": [
"**/.*",
Expand Down
41 changes: 21 additions & 20 deletions dist/band.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,28 +719,29 @@ function Player(conductor) {
if ('up' !== direction && 'down' !== direction) {
throw new Error('Direction must be either up or down.');
}

var fadeDuration = 0.2;

faded = direction === 'down';
var i = 100 * conductor.masterVolumeLevel,
fadeTimer = function() {
if (i > 0) {
i = i - 4;
i = i < 0 ? 0 : i;
var gain = 'up' === direction ? conductor.masterVolumeLevel * 100 - i : i;
conductor.masterVolume.gain.value = gain / 100;
requestAnimationFrame(fadeTimer);
} else {
if (typeof cb === 'function') {
cb.call(player);
}

if (resetVolume) {
faded = ! faded;
conductor.masterVolume.gain.value = conductor.masterVolumeLevel;
}
}
};
if (direction === 'up') {
conductor.masterVolume.gain.linearRampToValueAtTime(0, conductor.audioContext.currentTime);
conductor.masterVolume.gain.linearRampToValueAtTime(conductor.masterVolumeLevel, conductor.audioContext.currentTime + fadeDuration);
} else {
conductor.masterVolume.gain.linearRampToValueAtTime(conductor.masterVolumeLevel, conductor.audioContext.currentTime);
conductor.masterVolume.gain.linearRampToValueAtTime(0, conductor.audioContext.currentTime + fadeDuration);
}

fadeTimer();
setTimeout(function() {
if (typeof cb === 'function') {
cb.call(player);
}

if (resetVolume) {
faded = ! faded;
conductor.masterVolume.gain.linearRampToValueAtTime(conductor.masterVolumeLevel, conductor.audioContext.currentTime);
}
}, fadeDuration * 1000);
}

/**
Expand Down Expand Up @@ -835,7 +836,7 @@ function Player(conductor) {
}
} else {
updateTotalPlayTime();
requestAnimationFrame(totalPlayTimeCalculator);
setTimeout(totalPlayTimeCalculator, 1000 / 60);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/band.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BandJS",
"version": "1.0.0",
"version": "1.0.1",
"description": "Band.js - Music Composer - An interface for the Web Audio API that supports rhythms, multiple instruments, repeating sections, and complex time signatures.",
"main": "src/main.js",
"repository": {
Expand Down
41 changes: 21 additions & 20 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,29 @@ function Player(conductor) {
if ('up' !== direction && 'down' !== direction) {
throw new Error('Direction must be either up or down.');
}

var fadeDuration = 0.2;

faded = direction === 'down';
var i = 100 * conductor.masterVolumeLevel,
fadeTimer = function() {
if (i > 0) {
i = i - 4;
i = i < 0 ? 0 : i;
var gain = 'up' === direction ? conductor.masterVolumeLevel * 100 - i : i;
conductor.masterVolume.gain.value = gain / 100;
requestAnimationFrame(fadeTimer);
} else {
if (typeof cb === 'function') {
cb.call(player);
}

if (resetVolume) {
faded = ! faded;
conductor.masterVolume.gain.value = conductor.masterVolumeLevel;
}
}
};
if (direction === 'up') {
conductor.masterVolume.gain.linearRampToValueAtTime(0, conductor.audioContext.currentTime);
conductor.masterVolume.gain.linearRampToValueAtTime(conductor.masterVolumeLevel, conductor.audioContext.currentTime + fadeDuration);
} else {
conductor.masterVolume.gain.linearRampToValueAtTime(conductor.masterVolumeLevel, conductor.audioContext.currentTime);
conductor.masterVolume.gain.linearRampToValueAtTime(0, conductor.audioContext.currentTime + fadeDuration);
}

fadeTimer();
setTimeout(function() {
if (typeof cb === 'function') {
cb.call(player);
}

if (resetVolume) {
faded = ! faded;
conductor.masterVolume.gain.linearRampToValueAtTime(conductor.masterVolumeLevel, conductor.audioContext.currentTime);
}
}, fadeDuration * 1000);
}

/**
Expand Down Expand Up @@ -174,7 +175,7 @@ function Player(conductor) {
}
} else {
updateTotalPlayTime();
requestAnimationFrame(totalPlayTimeCalculator);
setTimeout(totalPlayTimeCalculator, 1000 / 60);
}
}
}
Expand Down

0 comments on commit c73e28d

Please sign in to comment.