grimmdude / MidiWriterJS

♬ A JavaScript library which provides an API for programmatically generating and creating expressive multi-track MIDI files and JSON.
MIT License
547 stars 58 forks source link

How to write out drum tracks #91

Closed wrcstewart closed 2 years ago

wrcstewart commented 2 years ago

I'm not sure how midi files record the fact that the track is intended for channel 10. Is there a way to make the track write to ch10 in MidiWriterJS. In other words how does one write out drum parts - an example bit of code would be great.

grimmdude commented 2 years ago

Hey @wrcstewart,

You can define the channel per note. Admittedly I haven't worked much with drum parts, but this should work:

// Add a single note on channel 10
const note = new MidiWriter.NoteEvent({pitch: ['C4'], duration: '4', channel: 10});
track.addEvent(note);

// Add multiple notes on channel 10
track.addEvent([
    new MidiWriter.NoteEvent({pitch: ['C4'], duration: '4'}),
    new MidiWriter.NoteEvent({pitch: ['D4'], duration: '4'}),
    new MidiWriter.NoteEvent({pitch: ['E4'], duration: '4'}),
], function(event) {
    return {channel: 10};
});
wrcstewart commented 2 years ago

Fantastic thanks

Sent from my iPhone

On 12 Feb 2022, at 19:23, Garrett Grimm @.***> wrote:

 Hey @wrcstewart,

You can define the channel per note. Admittedly I haven't worked much with drum parts, but this should work:

// Add a single note on channel 10 const note = new MidiWriter.NoteEvent({pitch: ['C4'], duration: '4', channel: 10}); track.addEvent(note);

// Add multiple notes on channel 10 track.addEvent([ new MidiWriter.NoteEvent({pitch: ['C4'], duration: '4'}), new MidiWriter.NoteEvent({pitch: ['D4'], duration: '4'}), new MidiWriter.NoteEvent({pitch: ['E4'], duration: '4'}), ], function(event) { return {channel: 10}; }); — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.