我一直在尝试使用node.js脚本将一些数据转换为音乐。该脚本出于某种原因仅返回一个音符:
github上的原始脚本:https://github.com/wbkd/from-data-to-sound具有res.concat(scribble.scale('c',但引发了一个错误的无效标度名称。
const scribble = require('scribbletune');
// example data
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
const min = Math.min(...data);
const octaves = [...Array(5)].map((d, i) => i + 1); // [1, 2, 3, 4, 5]
// creates array of notes like 'c1', 'd1', 'e1', 'gb1', 'ab1', 'bb1', 'c2', ...
const notes = octaves.reduce((res, octave) =>
res.concat(scribble.scale('c1 major', 'whole tone', octave, false))
, []);
const midiData = scribble.clip({
notes: data.map(value => notes[value - min]),
pattern: 'x',
noteLength: '1/16',
});
// write the MIDI file
scribble.midi(midiData, 'data-sonification.mid');
答案 0 :(得分:1)
来自scribbletune文档:
每个x表示事件注释
由于在scribble.clip
中仅传递1个'x'作为模式,因此它仅演奏1个音符。为了演奏所有音符,您可以尝试如下操作:
const midiData = scribble.clip({
notes: data.map(value => notes[value - min]),
- pattern: 'x', // only play 1 note
+ pattern: 'x'.repeat(data.length), // repeat this pattern for each note in data
noteLength: '1/16',
});