-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTextToMMLConverter.js
More file actions
60 lines (46 loc) · 1.24 KB
/
TextToMMLConverter.js
File metadata and controls
60 lines (46 loc) · 1.24 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function TextToMMLConverter(db) {
this.db = db;
}
TextToMMLConverter.prototype.getDuration = function () {
return Math.round(Math.random() * 9);
};
TextToMMLConverter.prototype.updateOctave = function () {
var rand = Math.round(Math.random() * 9);
if (rand == 1) {
return '<';
}
else if (rand == 2) {
return '>';
}
return '';
};
TextToMMLConverter.prototype.getRandom = function (max) {
return Math.floor(Math.random() * max) * 100;
};
TextToMMLConverter.prototype.convert = function (text) {
var notes = text.toLowerCase();
var convertedItem = '';
//notes = notes.replace(/[^cdefgab]/g, '');
notes = notes.replace(/[^cdega]/g, '');
console.log(notes.length);
for (var i = 0; i < notes.length; i++) {
convertedItem += this.updateOctave() + notes[i] + this.getDuration();
}
return {
//attack : this.getRandom(text.length),
release : this.getRandom(convertedItem.length),
lv : Math.random(),
length : text.length,
mml : convertedItem
};
};
TextToMMLConverter.prototype.getRandomSnippet = function (callback) {
var _this = this;
this.db.getRandomItem(function (err, item) {
if (err) {
return callback(err, null);
}
return callback(null, _this.convert(item));
});
};
module.exports = TextToMMLConverter;