javascript - Sonnification javascript 只返回一个音符

标签 javascript node.js midi

我一直在尝试使用 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

scribbletune docs/core/clip

由于您在 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/

相关文章:

javascript - libphonenumber-js : 'Uncaught TypeError: A text for parsing must be a string'

javascript - AngularJs - 将 2 个关键相似的数组合并为 1 个 ng-repeat

javascript - 处理 Promise 对象中的错误结果的正确方法是什么?

java - MidiSystem.getMidiDevice(...) 返回意外的类

java - 解码未知的 MIDI 事件

Javascript - 按当前月份的时间顺序对月份数组进行排序

Javascript:防止元素中存在内部元素 "scrolling"

node.js - Firebase 实时数据库规则拒绝权限

javascript - Neo4j连接nodejs报错

java - 如何从 MIDI 序列获取音符开/关消息?