-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkov-midi.js
37 lines (32 loc) · 1.18 KB
/
markov-midi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const MidiPlayer = require('midi-player-js');
const MidiWriter = require('midi-writer-js');
const request = require('request').defaults({
encoding: null
});
var Player = new MidiPlayer.Player(function(event) {
console.log(event);
});
module.exports = (message, content, herokupg) => {
if (message.attachments.array().length > 0 && message.attachments.array()[0].url.includes('.mid')){
request.get(message.attachments.array()[0].url, function (err, res, body) {
Player.loadArrayBuffer(body);
console.log(JSON.stringify(Player.getEvents()).length);
console.log(JSON.stringify(Player.getEvents()));
});
}
if (content.startsWith('b!makemidi')){
var track = new MidiWriter.Track();
// Define an instrument (optional):
//track.addEvent(new MidiWriter.ProgramChangeEvent({instrument : 1}));
// Add some notes:
var note = new MidiWriter.NoteEvent({pitch:['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
track.addEvent(note);
// Generate a data URI
var write = new MidiWriter.Writer([track]);
console.log(Buffer.from(write.buildFile()));
message.channel.send({
files: [{attachment: Buffer.from(write.buildFile()),name: 'test.mid'}]
});
}
}