compoze
Version:
music writer
70 lines (56 loc) • 1.63 kB
JavaScript
// Generated by CoffeeScript 1.8.0
(function() {
var Duration, fileName, fs, json, measures, s, song, xml, xml2json;
xml2json = require('xml2json');
fs = require('fs');
fileName = '新世纪福音战士';
xml = fs.readFileSync('../demo/musicxml/' + fileName + '.xml');
json = xml2json.toJson(xml, {
object: true
});
song = json['score-partwise'];
measures = [];
Duration = {
'16th': '16',
'32th': '32',
'eighth': '8',
'quarter': 'q',
'half': 'h'
};
song.part.measure.forEach(function(measure, i) {
var chord, duration;
if (!measures[i]) {
measures[i] = 'notes ';
}
chord = [];
duration = null;
return measure.note.forEach(function(note) {
var temp;
temp = '';
if (chord.length > 0 && !note.chord) {
if (chord.length === 1) {
temp += chord[0] + ' ';
} else {
temp += '(' + chord.join('+') + ') ';
}
if (duration !== note.type) {
temp = (Duration[duration] ? ' :' + Duration[duration] : '') + ' ' + temp;
}
measures[i] += temp;
duration = note.type;
chord = [];
}
duration = note.type;
if (note.rest) {
return chord.push('##');
} else {
return chord.push(note.notations.technical.fret + '/' + note.notations.technical.string);
}
});
});
s = 'options player=true tempo=76 width=980\n';
measures.forEach(function(m) {
return s += 'tabstave notation=true tablature=true\n' + m + '\n';
});
fs.writeFileSync('../demo/musicxml/' + fileName + '.md', s);
}).call(this);