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

Commit

Permalink
Initial commit. With ABC notation converter.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Nov 9, 2013
0 parents commit 1702d87
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .bob.json
@@ -0,0 +1,21 @@
{
"build": "clean lint complexity test coverage test-integration doc",
"lint": {
"type": "jshint"
},
"complexity": {
"type": "plato"
},
"test": {
"type": "buster"
},
"coverage": {
"type": "buster-istanbul"
},
"test-integration": {
"type": "buster"
},
"doc": {
"type": "dox-foundation"
}
}
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.bob
.DS_Store
node_modules
npm-debug.log
3 changes: 3 additions & 0 deletions .jshintrc
@@ -0,0 +1,3 @@
{
"esnext": true
}
14 changes: 14 additions & 0 deletions .npmignore
@@ -0,0 +1,14 @@
.bob
.bob.json
.DS_Store
.git
.gitignore
.jshintrc
.npmignore
.travis.yml
avatar.jpg
node_modules
npm-debug.log
screenshots
test
test-integration
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "0.11"
- "0.10"
before_install: "npm install -g bob --loglevel error"
script: "bob build"
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,2 @@
### 0.0.1
* Initial version
23 changes: 23 additions & 0 deletions README.md
@@ -0,0 +1,23 @@
<img align="right" src="https://raw.github.com/cliffano/roombox/master/avatar.jpg" alt="Avatar"/>

[![Build Status](https://secure.travis-ci.org/cliffano/roombox.png?branch=master)](http://travis-ci.org/cliffano/roombox)
[![Dependencies Status](https://david-dm.org/cliffano/roombox.png)](http://david-dm.org/cliffano/roombox)
[![Published Version](https://badge.fury.io/js/roombox.png)](http://badge.fury.io/js/roombox)
<br/>
[![npm Badge](https://nodei.co/npm/roombox.png)](http://npmjs.org/package/roombox)

Roombox
-------

Roombox is a Roomba boombox.

This is handy when you want to turn your [Roomba vacuum cleaner](http://en.wikipedia.org/wiki/Roomba) into a boombox.

Installation
------------

npm install -g roombox

Usage
-----

43 changes: 43 additions & 0 deletions lib/converters/abc.js
@@ -0,0 +1,43 @@
var abcnode = require('abcnode');

// reasonably pleasant Roomba song notes between note numbers 60 - 83
const BASE = 60,
ROOMBA_NOTES = [
'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B',
'c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b'
],
SANITISE = ['!', '\\\\', 'Z:.+'];

function convert(data) {

SANITISE.forEach(function (pattern) {
data = data.replace(new RegExp(pattern), '');
});

var parsed = abcnode.parse(data),
song = {
title: parsed.header.title,
by: parsed.header.composer,
notes: []
};

parsed.song.forEach(function (x) {
x.forEach(function (y) {
y.forEach(function (z) {
z.chords.forEach(function (chord) {
chord.notes.forEach(function (note) {
var number = ROOMBA_NOTES.indexOf(note.note);
if (number !== -1) {
song.notes.push(number + BASE);
song.notes.push(note.duration);
}
});
});
});
});
});

return song;
}

exports.convert = convert;
Empty file added lib/playlist.js
Empty file.
Empty file added lib/roombox.js
Empty file.
51 changes: 51 additions & 0 deletions package.json
@@ -0,0 +1,51 @@
{
"name": "roombox",
"description": "Roomba boombox",
"keywords": [
"roomba",
"boombox",
"abc notation",
"music"
],
"version": "0.0.1",
"homepage": "http://github.com/cliffano/roombox",
"author": "Cliffano Subagio <blah@cliffano.com> (http://blog.cliffano.com)",
"contributors": [
"All contributors (https://github.com/cliffano/roombox/graphs/contributors)"
],
"main": "./lib/roombox",
"bin": {
"roombox": "./bin/roombox"
},
"preferGlobal": false,
"repository": {
"type": "git",
"url": "http://github.com/cliffano/roombox.git"
},
"bugs": {
"url": "http://github.com/cliffano/roombox/issues"
},
"directories": {
"bin": "./bin",
"lib": "./lib",
"test": "./test"
},
"dependencies": {
"abcnode": "http://github.com/cliffano/abcnode/tarball/master",
"roomba": "~0.0.1"
},
"devDependencies": {
"buster-node": "~0.7.0",
"referee": "~1.0.1"
},
"scripts": {},
"engines": {
"node": ">= 0.8.0"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/cliffano/roombox/raw/master/LICENSE"
}
]
}
57 changes: 57 additions & 0 deletions test/converters/abc.js
@@ -0,0 +1,57 @@
var buster = require('buster-node'),
abc = require('../../lib/converters/abc'),
referee = require('referee'),
assert = referee.assert;

buster.testCase('abc - convert', {
'should convert abc notation to Roomba song data': function () {
var data = [
'X:1',
'T:Hey Jude',
'C:The Beatles',
'L:1/8',
'Q:140',
'M:4/4',
'K:C',
'z6G2|[E2C,2]C,2[zC,]E[GC,]A|[D2G,2]G,2[z2G,2][DG,]E|[F2G,2][c2G,2]G,c[BG,]G|[AF,]G/F/[E2C,2]C,2[zC,]G|[AF,]AF,A[d/F,/]cB/F,/c/A|[G2C,2]C,2[CC,]D[EC,]A|'
];
var song = abc.convert(data.join('\n'));
assert.equals(song.title, 'Hey Jude');
assert.equals(song.by, 'The Beatles');
assert.equals(song.notes, [67, 64, 64, 64, 64, 32, 67, 32, 69, 32, 62, 64, 62, 32, 64, 32, 65, 64, 72, 64, 72, 32, 71, 32, 67, 32, 69, 32, 67, 16, 65, 16, 64, 64, 67, 32, 69, 32, 69, 32, 69, 32, 74, 16, 72, 32, 71, 16, 72, 16, 69, 32, 67, 64, 60, 32, 62, 32, 64, 32, 69, 32]);
},
'should sanitise invalid ABC 1.6 data': function () {
var data = [
'X:1',
'T:Hey Jude!',
'C:The Beatles',
'L:1/8',
'Q:140',
'M:4/4',
'K:C',
'z6G2|[E2C,2]C,2[zC,]E[GC,]A|[D2G,2]G,2[z2G,2][DG,]E|[F2G,2][c2G,2]G,c[BG,]G|[AF,]G/F/[E2C,2]C,2[zC,]G|[AF,]AF,A[d/F,/]cB/F,/c/A|[G2C,2]C,2[CC,]D[EC,]A|\\',
'Z: edited by'
];
var song = abc.convert(data.join('\n'));
assert.equals(song.title, 'Hey Jude');
assert.equals(song.by, 'The Beatles');
assert.equals(song.notes, [67, 64, 64, 64, 64, 32, 67, 32, 69, 32, 62, 64, 62, 32, 64, 32, 65, 64, 72, 64, 72, 32, 71, 32, 67, 32, 69, 32, 67, 16, 65, 16, 64, 64, 67, 32, 69, 32, 69, 32, 69, 32, 74, 16, 72, 32, 71, 16, 72, 16, 69, 32, 67, 64, 60, 32, 62, 32, 64, 32, 69, 32]);
},
'should throw error when there is invalid syntax': function () {
var data = [
'X:1',
'T:Hey Jude!',
'C:The Beatles',
'L:1/8',
'Q:140',
'M:4/4',
'K:C',
'z6G2|[E2C,|\\'
];
try {
abc.convert(data.join('\n'));
} catch (e) {
assert.match(e, 'SyntaxError');
}
}
});

0 comments on commit 1702d87

Please sign in to comment.