[英]Javascript: How to Export a MIDI File?
I am new to working with MIDI in my javascript code, and I would like to create an application that simply generates a MIDI file based on the user's input. 我是新手在我的javascript代码中使用MIDI,我想创建一个简单地根据用户输入生成MIDI文件的应用程序。 I have looked at using MIDI.js , but I'm not sure if I need any of the library.
我看过使用MIDI.js ,但我不确定我是否需要任何库。 Ideally, I would like to be able to work with note values rather than hexadecimal MIDI codes... would I need to use the converter within
plugin.js
? 理想情况下,我希望能够使用音符值而不是十六进制MIDI代码......我是否需要在
plugin.js
使用转换器?
My current research has indicated that generated soundfonts are the suggested way to go; 我目前的研究表明,生成的声音字体是建议的方式; however, I would like to export/generate a MIDI file for use in a professional DAW.
但是,我想导出/生成一个MIDI文件,用于专业的DAW。
Thanks for any help. 谢谢你的帮助。
You can use a library I found called MidiWriterJS . 您可以使用我发现的名为MidiWriterJS的库。
It is very easy to use: 这是非常容易使用:
The easiest way to insall is to use npm . 最简单的方法是使用npm 。
$ npm install midi-writer-js
Then 然后
var MidiWriter = require('midi-writer-js');
var tracks = [];
for(t of <your existing track array>){
var notes = [];
for(n of <your existing note array for the track>){
notes.push(new MidiWriter.NoteEvent({pitch: <array of all notes in the chord>, duration: <how long the chord should last>});
}
var newTrack = new MidiWriter.Track();
newTrack.addEvent(notes, function(event, index){ return {sequential: true}; });
tracks.push(newTrack);
}
var writer = new MidiWriter.Writer(tracks);
writer.saveMIDI(<filename>);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.