return readBMS(source).then(function(str) { var chart = bms.Compiler.compile(str).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: hasScratch(chart), keys: getKeys(chart), } })
co(function * () { log('Loading file list') let list = yield loader.fileList let bmsFile = list.filter(f => f.match(/\.(?:bms|bme|bml|pms)$/i))[0] log('Loading ' + bmsFile) let arraybuffer = yield (yield loader.file(bmsFile)).read() let buffer = Buffer.from(new Uint8Array(arraybuffer)) let text = yield Promise.promisify(Reader.readAsync)(buffer) let chart = Compiler.compile(text).chart var timing = Timing.fromBMSChart(chart) var notes = Notes.fromBMSChart(chart) var info = SongInfo.fromBMSChart(chart) $('<pre wrap></pre>') .text(JSON.stringify(info, null, 2)) .appendTo($sampler) log('Loading samples') var samples = yield loadSamples(notes, chart) log('Click the button to play!') yield waitForPlay() void (function () { master.unmute() for (let note of notes.all()) { setTimeout(() => { let sample = samples[note.keysound] if (!sample) { console.log('warn: unknown sample ' + note.keysound) return } let span = $('<span></span>') .text('[' + note.keysound + '] ') .appendTo($sampler) let instance = sample.play() $sampler[0].scrollTop = $sampler[0].scrollHeight instance.onstop = function () { span.addClass('is-off') } }, timing.beatToSeconds(note.beat) * 1000) } return false })() }).done()
export function fromBMSChart (bms, playerOptions) { let notes = BMS.Notes.fromBMSChart(bms).all() let timing = BMS.Timing.fromBMSChart(bms) let keysounds = BMS.Keysounds.fromBMSChart(bms) let songInfo = BMS.SongInfo.fromBMSChart(bms) let positioning = BMS.Positioning.fromBMSChart(bms) let spacing = BMS.Spacing.fromBMSChart(bms) let data = { notes, timing, keysounds, songInfo, positioning, spacing, barLines: generateBarLinesFromBMS(notes, bms), expertJudgmentWindow: getJudgmentWindowFromBMS(bms) } return new Notechart(data, playerOptions) }