mirror of
https://github.com/bvanroll/rpiRadio.git
synced 2025-08-30 20:42:44 +00:00
71 lines
6.4 KiB
JavaScript
71 lines
6.4 KiB
JavaScript
var assert = require('assert');
|
|
var MidiPlayer = require('../module/midiplayer');
|
|
var zelda = 'data:audio/midi;base64,TVRoZAAAAAYAAQACAIBNVHJrAAADoQDAAQCQRn+CAIBGfwCQRn9AgEZ/AJBBf0CAQX8AkEF/QIBBfwCQRn9AgEZ/AJBEfyCARH8AkEJ/IIBCfwCQRH+DAIBEf0CQRn+CAIBGfwCQRn9AgEZ/AJBBf0CAQX8AkEF/QIBBfwCQRn9AgEZ/AJBFfyCARX8AkEN/IIBDfwCQRX+BQIBFf4IAkEUBhACARQGEAJBGf4EAgEZ/AJBBf4FAgEF/AJBGf0CARn8AkEZ/IIBGfwCQSH8ggEh/AJBKfyCASn8AkEt/IIBLfwCQTX+CAIBNf0CQTX9AgE1/AJBNf0CATX8AkE5/IIBOfwCQUH8ggFB/AJBSf4IAgFJ/QJBSf0CAUn8AkFJ/QIBSfwCQUH8ggFB/AJBOfyCATn8AkFB/YIBQfwCQTn8ggE5/AJBNf4IAgE1/AJBNf4EAgE1/AJBLf2CAS38AkE1/IIBNfwCQTn+CAIBOfwCQTX9AgE1/AJBLf0CAS38AkEl/YIBJfwCQS38ggEt/AJBNf4IAgE1/AJBLf0CAS38AkEl/QIBJfwCQSH9ggEh/AJBKfyCASn8AkEx/ggCATH8AkE9/gQCAT38AkE1/QIBNfwCQQX8ggEF/AJBBfyCAQX8AkEF/QIBBfwCQQX8ggEF/AJBBfyCAQX8AkEF/QIBBfwCQQX8ggEF/AJBBfyCAQX8AkEF/QIBBfwCQQX9AgEF/AJBGf4EAgEZ/AJBBf4FAgEF/AJBGf0CARn8AkEZ/IIBGfwCQSH8ggEh/AJBKfyCASn8AkEt/IIBLfwCQTX+CAIBNf0CQTX9AgE1/AJBNf0CATX8AkE5/IIBOfwCQUH8ggFB/AJBSf4MAgFJ/AJBVf4EAgFV/AJBUf4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AqQACQKkBAgCpAAJAqQCCAKkAAkCpAIIAqQACQKkBAgCpAAJAqQCCAKkAAkCpAIIAqQACQKkAggCpAAJAqQCCAKkAAkCpAIIAqQACQKkAggCpAAJApQECAKUAAkClAIIApQACQKUAggClAAJApQECAKUAAkClAIIApQACQKUAggClAAJApQECAKUAAkClAIIApQACQKUAggClAAJApQCCAKUAAkClAIIApQACQKUAggClAAJApQCCAKUAAkChAQIAoQACQKEAggChAAJAoQCCAKEAAkChAQIAoQACQKEAggChAAJAoQCCAKEAAkChAQIAoQACQKEAggChAAJAoQCCAKEAAkChAIIAoQACQKEAggChAAJAoQCCAKEAAkChAIIAoQACQKUBAgClAAJApQCCAKUAAkClAIIApQACQKUBAgClAAJApQCCAKUAAkClAIIApQACQKUBAgClAAJApQCCAKUAAkClAIIApQACQKUAggClAAJApQCCAKUAAkClAIIApQACQKUAggClAAJAoQECAKEAAkChAIIAoQACQKEAggChAAJAoQECAKEAAkChAIIAoQACQKEAggChAAJAoQECAKEAAkChAIIAoQACQKEAggChAAJAoQCCAKEAAkChAIIAoQACQKEAggChAAJAoQCCAKEAAkClAQIApQACQKUAggClAAJApQCCAKUAAkClAQIApQACQKUAggClAAJApQCCAKUAAkClAQIApQACQKUAggClAAJApQCCAKUAAkClAIIApQACQKUAggClAAJApQCCAKUAAkClAIIApQACQL0BAgC9AAJAvQCCAL0AAkC9AIIAvQACQL0BAgC9AAJAvQCCAL0AAkC9AIIAvQACQL0BAgC9AAJAvQCCAL0AAkC9AIIAvQACQL0AggC9AAJAvQCCAL0AAkC9AIIAvQACQL0AggC9AAJAuQECALkAAkC5AIIAuQACQLkAggC5AAJAuQECALkAAkC5AIIAuQACQLkAggC5AAJAuQECALkAAkC5AIIAuQACQLkAggC5AAJAuQCCALkAAkC5AIIAuQACQLkAggC5AAJAuQCCALkAAkDBAQIAwQACQMEAggDBAAJAwQCCAMEAAkDBAQIAwQACQMEAggDBAAJAwQCCAMEAAkDBAQIAwQACQMEAggDBAAJAwQCCAMEAAkDBAIIAwQACQMEAggDBAAJAwQCCAMEAAkDBAIIAwQACQKUBAgClAAJA5QCCAOUAAkDlAIIA5QACQOEBAgDhAAJA4QCCAOEAAkDhAIIA4QACQN0BAgDdAAJA3QCCAN0AAkDdAIIA3QACQNkBAgDZAAJApQECAKUAA/y8A';
|
|
|
|
describe('MidiPlayerJS', function() {
|
|
describe('#Utils', function () {
|
|
describe('#byteToHex()', function () {
|
|
it('should return hex value from byte.', function () {
|
|
assert.equal('7f', MidiPlayer.Utils.byteToHex(127));
|
|
});
|
|
});
|
|
|
|
describe('#bytesToHex()', function () {
|
|
it('should return hex value from array of bytes.', function () {
|
|
assert.equal('7f3a', MidiPlayer.Utils.bytesToHex([127, 58]));
|
|
});
|
|
});
|
|
|
|
describe('#hexToNumber()', function () {
|
|
it('should return base 10 value from hex string.', function () {
|
|
assert.equal(254, MidiPlayer.Utils.hexToNumber('fe'));
|
|
});
|
|
});
|
|
|
|
describe('#bytesToNumber()', function () {
|
|
it('should return base 10 value from array of bytes.', function () {
|
|
assert.equal(923139, MidiPlayer.Utils.bytesToNumber([14, 22, 3]));
|
|
});
|
|
});
|
|
|
|
describe('#bytesToLetters()', function () {
|
|
it('should return string from array of bytes.', function () {
|
|
assert.equal('Mthd', MidiPlayer.Utils.bytesToLetters([77, 116, 104, 100]));
|
|
});
|
|
});
|
|
|
|
describe('#decToBinary()', function () {
|
|
it('should return binary value from decimal.', function () {
|
|
assert.equal('10110', MidiPlayer.Utils.decToBinary(22));
|
|
});
|
|
});
|
|
|
|
describe('#readVarInt()', function () {
|
|
it('should return binary value from decimal.', function () {
|
|
assert.equal(42, MidiPlayer.Utils.readVarInt([128, 42]));
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
describe('#Player', function () {
|
|
describe('#loadFile()', function () {
|
|
it('should load file correctly.', function () {
|
|
var Player = new MidiPlayer.Player();
|
|
Player.loadFile('demo/midi/zelda.mid');
|
|
assert.equal(3330, Player.buffer.length);
|
|
assert.equal(2, Player.tracks.length);
|
|
});
|
|
});
|
|
|
|
describe('#loadDataUri()', function () {
|
|
it('should load data correctly from data uri.', function () {
|
|
var Player = new MidiPlayer.Player();
|
|
Player.loadDataUri(zelda);
|
|
assert.equal(3330, Player.buffer.length);
|
|
assert.equal(2, Player.tracks.length);
|
|
});
|
|
});
|
|
|
|
});
|
|
}); |