Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Fix safari issues #32

Merged
merged 4 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/boombap.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ function boombap () {
['2.4.51', '4Q', 40, 80, -96]
);

boombapPattern
bap.clock.sequence = boombapPattern
.kit(1, drumKit)
.kit(2, plongKit)
.kit(3, stringKit)
.kit(4, bassKit)
.start();
.kit(4, bassKit);
}

module.exports = boombap;
38 changes: 38 additions & 0 deletions examples/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
// @license http://opensource.org/licenses/MIT
// copyright Paul Irish 2015


// Date.now() is supported everywhere except IE8. For IE8 we use the Date.now polyfill
// github.com/Financial-Times/polyfill-service/blob/master/polyfills/Date.now/polyfill.js
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values

// if you want values similar to what you'd get with real perf.now, place this towards the head of the page
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed


(function(){

if ("performance" in window == false) {
window.performance = {};
}

Date.now = (Date.now || function () { // thanks IE8
return new Date().getTime();
});

if ("now" in window.performance == false){

var nowOffset = Date.now();

if (performance.timing && performance.timing.navigationStart){
nowOffset = performance.timing.navigationStart
}

window.performance.now = function now(){
return Date.now() - nowOffset;
}
}

})();


var bap = require('../index');
var metronome = require('./metronome');
var boombap = require('./boombap');
Expand Down
2 changes: 1 addition & 1 deletion examples/metronome.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function metronome () {
['*.2%1.01', '1W']
);

pattern.kit(kit).start();
bap.clock.sequence = pattern.kit(kit);
}

module.exports = metronome;
2 changes: 1 addition & 1 deletion examples/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function sequences () {
mainLoop
);

arrangedBeat.start();
bap.clock.sequence = arrangedBeat;
}

module.exports = sequences;
5 changes: 2 additions & 3 deletions examples/slices.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ function slices () {
['2.4.49', '2T', 48]
);

pattern
bap.clock.sequence = pattern
.kit(1, sampleKit)
.kit(2, breakKit)
.start();
.kit(2, breakKit);
}

module.exports = slices;
19 changes: 17 additions & 2 deletions lib/Clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ var instanceOfType = require('./types/instanceOfType');
var debounce = require('lodash.debounce');
var memoize = require('lodash.memoize');

var inited = false;
function init () {
inited = true;
var source = bap.clock.context.createBufferSource();
source.buffer = bap.clock.context.createBuffer(1, 22050, 44100);
source.start(0);
}

var Clock = PositionModel.extend({

type: 'clock',
Expand Down Expand Up @@ -53,6 +61,13 @@ var Clock = PositionModel.extend({

start: function (sequence) {

if (!inited) {
init();
return setTimeout(function () {
this.start(sequence);
}.bind(this), 100);
}

if (!this._canStartPlaying()) {
return setTimeout(function () {
this.start(sequence);
Expand Down Expand Up @@ -85,7 +100,7 @@ var Clock = PositionModel.extend({
if (!sequence || sequence === this.sequence) {
this.engine.pause();
this.playing = false;
this.tempo = 0;
// this.tempo = 0;
this._lastQueuedPosition = '0.0.00';
}
},
Expand All @@ -95,7 +110,7 @@ var Clock = PositionModel.extend({
this.engine.stop();
this.playing = false;
this.position = '1.1.01';
this.tempo = 0;
// this.tempo = 0;
this._lastQueuedPosition = '0.0.00';
}
},
Expand Down
9 changes: 4 additions & 5 deletions lib/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Layer = Model.extend(triggerParams, volumeParams, {
var source = this._source(params);

if (source) {
var out = source.gain = this._createGain(params, source);
var out = source._gain = this._createGain(params, source);
out = this._configureAttack(time, params, out);
out = this._configurePan(params, out);
source.connect(out);
Expand Down Expand Up @@ -72,11 +72,10 @@ var Layer = Model.extend(triggerParams, volumeParams, {
}

sources.forEach(function (source) {
if (source.gain) {
this._configureRelease(time, params, source.gain);
if (source._gain) {
this._configureRelease(time, params, source._gain);
}
this._stopSource(time, params, source);
source.stop(time + params.release);
this._stopSource(time + params.release, params, source);
}.bind(this));
},

Expand Down