Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ exports.extensions['.bms'] = function (source) {
})
}

exports.extensions['.dtx'] = function (source) {
return readBMS(source).then(function(str) {
var chart = bms.Compiler.compile(str, { format: 'dtx' }).chart
var info = bms.SongInfo.fromBMSChart(chart)
var notes = bms.Notes.fromBMSChart(chart)
var timing = bms.Timing.fromBMSChart(chart)
return {
info: info,
notes: notes,
timing: timing,
scratch: false,
keys: getKeys(chart, { format: 'dtx' } ),
}
})
}

exports.extensions['.bmson'] = function (source) {
return (
Promise.try(function () {
Expand Down
35 changes: 34 additions & 1 deletion keys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@

function getKeys(chart) {
function getKeys(chart, options) {
options = options || { }
if (options.format === 'dtx') {
return getKeysDtx(chart)
} else {
return getKeysBms(chart)
}
}

function getKeysDtx(chart) {
var objects = chart.objects.all()
var stat = { }
for (var i = 0; i < objects.length; i++) {
var object = objects[i]
var channel = object.channel
if (channel[0] !== '1') {
continue
}

stat[channel] = (stat[channel] || 0) + 1
}

if (Object.keys(stat).length === 0) return 'empty'

if (stat['16'] || stat['18'] || stat['17'] || stat['1A']) {
// Use 12 drum pads if there are cymbals, open hihat or floor tom
return '12D'
}
else {
return '8D'
}
}

function getKeysBms(chart) {
var objects = chart.objects.all()
var stat = {}
for (var i = 0; i < objects.length; i++) {
var object = objects[i]
var channel = +object.channel
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"homepage": "https://github.com/bemusic/indexer",
"dependencies": {
"bluebird": "^2.9.25",
"bms": "^2.0.0",
"bms": "^2.1.0-beta.1",
"bmson": "^3.1.0",
"invariant": "^2.1.0",
"lodash": "^3.8.0",
Expand Down
128 changes: 128 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,134 @@ describe('getFileInfo (bms)', function() {

})

describe('getFileInfo (dtx)', function() {

function info(source) {
return indexer.getFileInfo(new Buffer(source), { name: 'meow.dtx' })
}

describe('.md5', function() {
it('should return hash', function() {
return expect(info('').get('md5'))
.to.eventually.equal('d41d8cd98f00b204e9800998ecf8427e')
})
})

describe('.info', function() {
it('should return song info', function() {
var source = '#TITLE: meow'
return expect(info(source).get('info').get('title'))
.to.eventually.equal('meow')
})
})

describe('.noteCount', function() {
it('should not count BGM', function() {
var source = '#00101: 01'
return expect(info(source).get('noteCount')).to.eventually.equal(0)
})
it('should count playable notes', function() {
var source = '#00111: 01'
return expect(info(source).get('noteCount')).to.eventually.equal(1)
})
})

describe('.scratch', function() {
it('is false when no scratch track', function() {
var source = '#00101: 01'
return expect(info(source).get('scratch')).to.eventually.be.false
})
it('is false with scratch track too', function() {
var source = '#00116: 01'
return expect(info(source).get('scratch')).to.eventually.be.false
})
})

describe('.keys', function() {
it('should be empty when no notes', function() {
var source = '#00101: 01'
return expect(info(source).get('keys')).to.eventually.equal('empty')
})
it('should be 12D when left cymbal presented', function() {
var source = [
'#0011A: 01'
].join('\n')
return expect(info(source).get('keys')).to.eventually.equal('12D')
})
it('should be 12D when right cymbal presented', function() {
var source = [
'#00116: 01'
].join('\n')
return expect(info(source).get('keys')).to.eventually.equal('12D')
})
it('should be 12D when floor tom presented', function() {
var source = [
'#00117: 01'
].join('\n')
return expect(info(source).get('keys')).to.eventually.equal('12D')
})
it('should be 12D when open hihat presented', function() {
var source = [
'#00118: 01'
].join('\n')
return expect(info(source).get('keys')).to.eventually.equal('12D')
})
it('should be 8D when no cymbals, open hihat or floor tom presented', function() {
var source = [
'#00111: 01',
'#00114: 01',
].join('\n')
return expect(info(source).get('keys')).to.eventually.equal('8D')
})
})

describe('.duration', function() {

it('should be correct', function() {
var source = [
'#BPM: 120',
'#00111: 0101',
].join('\n')
return expect(info(source).get('duration')).to.eventually.equal(3)
})

})

describe('.bpm', function() {

var source = [
'#BPM: 120',
'#BPM01: 240',
'#00111: 01',
'#00108: 01',
'#00203: 3C78',
'#00211: 01',
'#00311: 01',
].join('\n')

var bpm

beforeEach(function() {
return info(source).get('bpm').tap(function(x) { bpm = x })
})

it('init should be the BPM at first beat', function() {
expect(bpm.init).to.equal(120)
})
it('median should be the median BPM', function() {
expect(bpm.median).to.equal(120)
})
it('min should be the minimum BPM', function() {
expect(bpm.min).to.equal(60)
})
it('max should be the maximum BPM', function() {
expect(bpm.max).to.equal(240)
})

})

})


describe('getFileInfo (bmson)', function() {

Expand Down