jam is shortcut for Jazz AngularJS MongoDB
API reference is available at http://jazz-soft.net/doc/Jazz-Plugin/reference.html
Questions and comments are welcome at http://jazz-soft.org/
npm install jam-midi
node jam
and point your browser to localhost:3003 or use localhost:3003/jam.html to view all messages with zoom:
var jazz = require('jazz-midi')
, Jazz = new jazz.MIDI()
, MongoClient = require('mongodb').MongoClient
, express = require('express')
, http = require('http')
, path = require('path');
var out = Jazz.MidiOutOpen(0);
var list = Jazz.MidiOutList();
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
app.use(express.favicon('public/images/favicon.ico'));
var db, song, Song;
MongoClient.connect('mongodb://localhost:27017/npm', function(err, database) {
if(err) throw err;
db = database;
http.createServer(app).listen(3003, function () {
console.log("Express server listening on port 3003");
});
});
/*Handling the AngularJS post request*/
app.post('/post', function (req, res) {
var msg = req.body.msg;
Jazz.MidiOutLong(msg);
res.send(msg);
var timestamp = req.body.timestamp;
if (!timestamp) song = false;
var midi = { '_id' : timestamp, 'msg' : msg };
if (song) insert(song, midi);
});
app.post('/list', function (req, res) {
res.send(list);
});
app.post('/songs', function (req, res) {
db.collections(function(err, collections){
var colls = collections.map(function(obj){
return obj.collectionName === "system.indexes" ? null : obj.collectionName;
});
res.send(colls);
});
});
app.post('/rec', function (req, res) {
if (req.body.song) song = req.body.song;
var msg = req.body.msg;
Jazz.MidiOutLong(msg);
res.send(song);
db.dropCollection(song, function(err, result){});
console.dir("db." + song + " cleaned");
});
app.post('/play', function (req, res) {
var id = req.body;
if (Song) db.collection(Song).findOne(id, function(err, row) {
if(err) throw err;
if (row) {
var msg = row.msg;
Jazz.MidiOutLong(msg);
res.send(msg);
}
});
});
app.post('/drop', function (req, res) {
if (req.body.song)
song = req.body.song;
db.dropCollection(song, function(err, result){});
Song = null;
console.log('drop: ' + song);
res.send('drop: ' + song);
});
app.post('/out', function (req, res) {
var out = req.body.out;
Jazz.MidiOutOpen(out);
var msg = req.body.msg;
Jazz.MidiOutLong(msg);
res.send(msg);
var timestamp = req.body.timestamp;
if (!timestamp) song = false;
var midi = { '_id' : timestamp, 'msg' : msg };
insert(song, midi);
});
app.post('/panic', function (req, res) {
var msg = req.body.msg;
Jazz.MidiOutLong(msg);
res.send(msg);
});
app.post('/OK', function (req, res) {
song = req.body.song;
var cursor = db.collection(song).find().sort( { _id: 1 } );
cursor.toArray(function(err, docs){
var timestamps = docs.map(function(obj){
return obj._id;
});
res.send(timestamps);
console.log("retrieved from: " + song);
console.log(docs);
});
});
app.post('/All', function (req, res) {
Song = req.body.song;
var cursor = db.collection(song).find().sort( { _id: 1 } );
cursor.toArray(function(err, docs){
res.send(docs);
});
});
/* Querying MongoDB*/
app.post('/remove', function (req, res) {
song = req.body.song;
if (typeof(req.body.timestamp) !== "undefined") {
var timestamp = req.body.timestamp;
db.collection(song).remove({_id: timestamp}, {safe: true}, function(err, result) {
if (err) {
console.log(err); throw err;
}
});
res.send("removed: " + timestamp);
}
});
app.post('/insert', function (req, res) {
var msg = req.body.msg;
var timestamp = req.body.timestamp;
res.send(msg);
var midi = { '_id' : timestamp, 'msg' : msg };
db.collection(Song).insert(midi, function(err, inserted) {
if(err) throw err;
console.dir("Inserted into: " + song + " " + JSON.stringify(inserted));
});
});
app.post('/update', function (req, res) {
var msg = req.body.msg;
Jazz.MidiOutLong(msg);
res.send(msg);
var timestamp = req.body._id;
var query = { '_id' : timestamp };
var operator = { '$set' : {'msg': msg} };
db.collection(Song).findAndModify( query,
[['_id','desc']],
operator, // replacement
function(err, object) {
if (err){
console.warn(err.message);
} else {
console.dir("old value: ");
console.dir(object);
}
});
});
var insert = function (song, midi) {
db.collection(song).insert(midi, function(err, inserted) {
if(err) throw err;
console.dir("Inserted into: " + song + " " + JSON.stringify(inserted));
});
}
- Open mongolab.com website
- Click Sign up button
- Fill in your user information then hit Create account
- From the dashboard, click on Create new button
- Select any cloud provider
- Under Plan click on Single-node (development) tab and select Sandbox (it's free)
- Leave MongoDB version as is
- Enter Database name for your app
- Then click on Create new MongoDB deployment button
- Click to the recently created database
- You should see the following message:
- A database user is required to connect to this database. Click here to create a new one.
- Click the link and fill in DB Username and DB Password fields
- Finally, in
jam.js
instead of'mongodb://localhost:27017/npm'
, use the following URI with your credentials: 'mongodb://USERNAME:PASSWORD@ds*****.mongolab.com:*****/DATABASE_NAME'
node ja
and point your browser to localhost:3003/ja.html
var jazz = require('jazz-midi')
, Jazz = new jazz.MIDI()
, express = require('express')
, http = require('http'), path = require('path');
var out = Jazz.MidiOutOpen(0);
var list = Jazz.MidiOutList();
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
app.use(express.favicon('public/images/favicon.ico'));
app.post('/post', function (req, res) {
var msg = req.body.msg;
console.log(msg);
Jazz.MidiOutLong(msg);
res.send(msg);
});
app.post('/list', function (req, res) {
res.send(list);
});
app.post('/out', function (req, res) {
var out = req.body.out;
Jazz.MidiOutOpen(out);
var msg = req.body.msg;
console.log(msg);
Jazz.MidiOutLong(msg);
});
var server = http.createServer(app).listen(3003, function () {
console.log("Express server listening on port 3003");
});
- natural major,ionian
- natural minor,aeolian,algerian
- harmonic minor
- harmonic major,ethiopian
- double harmonic major
- double harmonic minor
- neapolitan major
- neapolitan minor
- six tone symmetrical
- tritone
- 2 semitone tritone
- slendro,salendro
- pentatonic major
- pentatonic minor
- spanish,jewish,phrygian major
- spanish 8 tone
- flamenco
- chromatic
- nine tone
- enigmatic
- diminished
- inverted diminished,diminished blues,symmetrical
- half diminished
- whole tone
- leading whole tone
- augmented
- altered
- overtone,acoustic
- prometheus
- prometheus neapolitan
- dorian
- ukrainian dorian
- phrygian
- lydian minor
- lydian dominant
- lydian
- lydian augmented
- mixolydian,dominant 7th
- mixolydian augmented
- locrian
- locrian natural
- locrian major
- locrian ultra
- locrian super,whole tone diminished
- hungarian major
- hungarian minor,egyptian
- romanian
- gypsy
- persian
- oriental
- hindu,adonai malakh
- indian
- byzantine,chahargah,arabian
- marva
- mohammedan
- pD
- pE,balinese
- pC,pG,pF,chinese,mongolian
- pA,hirajoshi
- pB
- chinese 2
- javanese
- todi
- pelog
- iwato
- japanese,kumoi
- blues
- bluesy
- harmonics
- bebop major
- bebop minor
- bebop tonic minor
- bebop dominant
- bebop dominant flatnine
- 3 semitone
- 4 semitone