我一直在尝试使用 node.js 脚本将一些数据转换为音乐。由于某种原因,该脚本仅返回一条注释:
github上的原始脚本:https://github.com/wbkd/from-data-to-sound有 res.concat(scribble.scale('c', 但抛出错误 Invalid Scale name.
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');
最佳答案
来自 scribbletune 文档:
each x implies a note on event
由于您在 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',
});
关于javascript - Sonnification javascript 只返回一个音符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53742137/