File size: 1,060 Bytes
af6912c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
var SynthSequence = function() {
	var self = this;
	self.tracks = [];
	self.totalDuration = 0;
	self.currentInstrument = [];
	self.starts = [];

	self.addTrack = function() {
		self.tracks.push([]);
		self.currentInstrument.push(0);
		self.starts.push(0);
		return self.tracks.length - 1;
	};

	self.setInstrument = function(trackNumber, instrumentNumber) {
		self.tracks[trackNumber].push({
			channel: 0,
			cmd: "program",
			instrument: instrumentNumber
		});
		self.currentInstrument[trackNumber] = instrumentNumber;
	};

	self.appendNote = function(trackNumber, pitch, durationInMeasures, volume, cents) {
		var note = {
			cmd: "note",
			duration: durationInMeasures,
			gap: 0,
			instrument: self.currentInstrument[trackNumber],
			pitch: pitch,
			start: self.starts[trackNumber],
			volume: volume
		};
		if (cents)
			note.cents = cents;
		self.tracks[trackNumber].push(note);
		self.starts[trackNumber] += durationInMeasures;

		self.totalDuration = Math.max(self.totalDuration, self.starts[trackNumber]);
	};
};

module.exports = SynthSequence;