Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

step-sequencer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

step-sequencer - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.eslintrc

70

index.js

@@ -7,6 +7,13 @@ 'use strict';

function play() {
if (this._playing) return;
this.step = 0;
this._playing = true;
loop.call(this);
}
function loop() {
var self = this;
self.timer.setTimeout(function () {
self._advance.call(self);
advance.call(self);
if (self._playing) loop.call(self);

@@ -16,20 +23,3 @@ }, '', self.timeout);

function StepSequencer(tempo, division, sequence) {
if (tempo && typeof tempo !== 'number') throw new TypeError('Tempo must be a number');
if (division && typeof division !== 'number') throw new TypeError('Division must be a number');
if (sequence && !(sequence instanceof Array)) throw new TypeError('Sequence must be an array');
this.tempo = tempo || 120;
this.division = division || 4;
this.sequence = sequence || [];
this.step = 0;
this.timer = new NanoTimer();
this.timeout = Math.floor((60 / (this.tempo * this.division)) * 10e8) + 'n';
this._playing = false;
EventEmitter.call(this);
}
inherits(StepSequencer, EventEmitter);
StepSequencer.prototype._advance = function () {
function advance() {
this.emit('' + this.step, this.sequence[this.step]);

@@ -40,22 +30,15 @@ this.step = (this.step + 1);

StepSequencer.prototype.play = function () {
function resume() {
if (this._playing) return;
this.step = 0;
this._playing = true;
loop.call(this);
};
}
StepSequencer.prototype.resume = function () {
if (this._playing) return;
this._playing = true;
loop.call(this);
};
StepSequencer.prototype.stop = function () {
function stop() {
if (!this._playing) return;
this._playing = false;
this.timer.clearTimeout();
};
}
StepSequencer.prototype.setTempo = function (tempo) {
function setTempo(tempo) {
if (typeof tempo !== 'number') throw new TypeError('Tempo must be a number');

@@ -66,3 +49,3 @@ this.tempo = tempo;

StepSequencer.prototype.setSequence = function (division, sequence) {
function setSequence(division, sequence) {
if (typeof division !== 'number') throw new TypeError('Division must be a number');

@@ -76,2 +59,25 @@ if (!(sequence instanceof Array)) throw new TypeError('Sequence must be an array');

function StepSequencer(tempo, division, sequence) {
if (tempo && typeof tempo !== 'number') throw new TypeError('Tempo must be a number');
if (division && typeof division !== 'number') throw new TypeError('Division must be a number');
if (sequence && !(sequence instanceof Array)) throw new TypeError('Sequence must be an array');
this.tempo = tempo || 120;
this.division = division || 4;
this.sequence = sequence || [];
this.step = 0;
this.timer = new NanoTimer();
this.timeout = Math.floor((60 / (this.tempo * this.division)) * 10e8) + 'n';
this._playing = false;
EventEmitter.call(this);
}
inherits(StepSequencer, EventEmitter);
StepSequencer.prototype.play = play;
StepSequencer.prototype.resume = resume;
StepSequencer.prototype.stop = stop;
StepSequencer.prototype.setTempo = setTempo;
StepSequencer.prototype.setSequence = setSequence;
module.exports = StepSequencer;
{
"name": "step-sequencer",
"version": "0.1.0",
"version": "0.1.1",
"description": "A step-sequencer for Node.js",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha",
"lint": "eslint . || true"
},

@@ -30,4 +31,5 @@ "repository": {

"devDependencies": {
"eslint": "^1.10.3",
"mocha": "^2.4.5"
}
}

@@ -7,9 +7,7 @@ 'use strict';

describe('StepSequencer constructor', function () {
it('should throw when tempo is not a number', function () {
try {
var stepSequencer = new StepSequencer('120');
}
catch (e) {
stepSequencer.play();
} catch (e) {
return;

@@ -19,11 +17,9 @@ }

assert.fail();
});
it('should throw when division is not a number', function () {
try {
var stepSequencer = new StepSequencer(120, '4');
}
catch (e) {
stepSequencer.play();
} catch (e) {
return;

@@ -33,11 +29,9 @@ }

assert.fail();
});
it('should throw when sequence is not an array', function () {
try {
var stepSequencer = new StepSequencer(120, 4, {});
}
catch (e) {
stepSequencer.play();
} catch (e) {
return;

@@ -47,7 +41,5 @@ }

assert.fail();
});
it('should use correct defaults', function () {
var stepSequencer = new StepSequencer();

@@ -58,7 +50,5 @@

assert.equal(stepSequencer.sequence.length, 0);
});
it('should construct properly', function () {
var tempo = 160;

@@ -82,3 +72,2 @@ var division = 2;

// methods
assert.equal(typeof stepSequencer._advance, 'function');
assert.equal(typeof stepSequencer.play, 'function');

@@ -91,5 +80,3 @@ assert.equal(typeof stepSequencer.resume, 'function');

assert.equal(typeof stepSequencer.emit, 'function');
});
});

@@ -7,3 +7,2 @@ 'use strict';

describe('#play()', function () {
var tempo = 10000;

@@ -14,3 +13,2 @@ var division = 4;

it('should emit all of the steps', function (done) {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -23,12 +21,12 @@

stepSequencer.on('0', function (data) {
stepSequencer.on('0', function () {
zero = true;
})
.on('1', function (data) {
.on('1', function () {
one = true;
})
.on('2', function (data) {
.on('2', function () {
two = true;
})
.on('3', function (data) {
.on('3', function () {
three = true;

@@ -43,7 +41,5 @@

stepSequencer.play();
});
it('should emit the steps in order', function (done) {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -72,7 +68,5 @@

stepSequencer.play();
});
it('should emit the correct data at each step', function (done) {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -97,7 +91,5 @@

stepSequencer.play();
});
it('should set the internal state correctly', function () {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -110,5 +102,3 @@

stepSequencer.stop();
});
});

@@ -7,3 +7,2 @@ 'use strict';

describe('#resume()', function () {
var tempo = 10000;

@@ -14,6 +13,5 @@ var division = 4;

it('should resume correctly', function (done) {
var stepSequencer = new StepSequencer(tempo, division, sequence);
stepSequencer.on('0', function (data) {
stepSequencer.on('0', function () {
stepSequencer.stop();

@@ -27,3 +25,3 @@

})
.on('1', function (data) {
.on('1', function () {
stepSequencer.stop();

@@ -37,3 +35,3 @@

})
.on('2', function (data) {
.on('2', function () {
stepSequencer.stop();

@@ -47,3 +45,3 @@

})
.on('3', function (data) {
.on('3', function () {
stepSequencer.stop();

@@ -59,7 +57,5 @@

stepSequencer.play();
});
it('should set the internal state correctly', function () {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -72,5 +68,3 @@

assert(stepSequencer._playing);
});
});

@@ -7,5 +7,3 @@ 'use strict';

describe('#setSequence()', function () {
it('should throw when division is not a number', function () {
var stepSequencer = new StepSequencer();

@@ -15,4 +13,3 @@

stepSequencer.setSequence('2');
}
catch (e) {
} catch (e) {
return;

@@ -22,7 +19,5 @@ }

assert.fail();
});
it('should throw when sequence is not an array', function () {
var stepSequencer = new StepSequencer();

@@ -32,4 +27,3 @@

stepSequencer.setSequence(2, {});
}
catch (e) {
} catch (e) {
return;

@@ -39,7 +33,5 @@ }

assert.fail();
});
it('should set the division and sequence correctly', function () {
var stepSequencer = new StepSequencer();

@@ -54,5 +46,3 @@

assert.equal(stepSequencer.timeout, '250000000n');
});
});

@@ -7,5 +7,3 @@ 'use strict';

describe('#setTempo()', function () {
it('should throw when tempo is not a number', function () {
var stepSequencer = new StepSequencer();

@@ -15,4 +13,3 @@

stepSequencer.setTempo('100');
}
catch (e) {
} catch (e) {
return;

@@ -22,7 +19,5 @@ }

assert.fail();
});
it('should set the tempo correctly', function () {
var stepSequencer = new StepSequencer();

@@ -34,5 +29,3 @@

assert.equal(stepSequencer.timeout, '150000000n');
});
});

@@ -7,3 +7,2 @@ 'use strict';

describe('#stop()', function () {
var tempo = 10000;

@@ -14,3 +13,2 @@ var division = 4;

it('should stop correctly', function (done) {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -20,3 +18,3 @@

stepSequencer.on('0', function (data) {
stepSequencer.on('0', function () {
stepSequencer.stop();

@@ -31,3 +29,3 @@ stopped = true;

})
.on('1', function (data) {
.on('1', function () {
stopped = false;

@@ -37,7 +35,5 @@ });

stepSequencer.play();
});
it('should set the internal state correctly', function () {
var stepSequencer = new StepSequencer(tempo, division, sequence);

@@ -49,5 +45,3 @@

assert(!stepSequencer._playing);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc