【问题标题】:Sonnification javascript only returning a single noteSonnification javascript只返回一个音符
【发布时间】:2018-12-12 11:33:13
【问题描述】:

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

【问题讨论】:

    标签: javascript node.js midi


    【解决方案1】:

    来自 scribbletune 文档:

    每个 x 表示事件的注释

    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',
      });
    

    【讨论】:

    • 你绝对的英雄。谢谢一百万
    猜你喜欢
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    相关资源
    最近更新 更多