-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (44 loc) · 1.36 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require('fs');
const util = require('util');
const melakarta = require('./melakarta.json');
const svara = require('./svara.json');
const template = require('./template');
const mkdir = util.promisify(fs.mkdir);
const writeFile = util.promisify(fs.writeFile);
const generate = async () => {
for (const [chakra, ragas] of Object.entries(melakarta)) {
try {
await mkdir(`./Melakarta/${chakra}`);
} catch (e) {}
for (const [raga, notes] of Object.entries(ragas)) {
const arr = notes.split(/\s/);
const map = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
arr.forEach((a) => {
if (typeof svara[a] === 'undefined') {
throw 'Cannot process ' + a;
}
map[svara[a]] = svara[a];
});
for (let i = 0; i < map.length; i++) {
if (
typeof map[i + 1] === 'undefined' &&
typeof map[i - 1] === 'undefined'
) {
throw `Cannot process ${raga} for ${map.toString()}`;
}
if (map[i + 1] === -1 && map[i + 1] > -1) {
map[i] = map[i + 1];
}
if (map[i] === -1 && map[i - 1] > -1) {
map[i] = map[i - 1];
}
}
await writeFile(
`./Melakarta/${chakra}/${raga}.adv`,
template.getTranspiledXml(map)
);
console.log(`Created ${chakra}/${raga}.adv!`);
}
}
};
generate();