-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (69 loc) · 1.79 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const fs = require("fs-extra");
const parseMidi = require("midi-file").parseMidi;
const AfterEffectScriptLauncher = require("aftereffect-script-launcher")();
const input = fs.readFileSync("midi/Twilight.mid");
const parsed = parseMidi(input);
console.log(parsed);
var time = 0;
var speed = 0.8;
var outfadeTime = 0;
var defaultDuration = 1;
var row = 1;
var col = 1;
var list = [];
var chanelList = [];
for (var i = 0; i < row * col; i++) chanelList[i] = false;
var maxMultiplayCount = 0;
var multiplayCount = 0;
for (i in parsed.tracks[1]) {
const data = parsed.tracks[1][i];
time += (data.deltaTime / 480) * speed;
switch (data.type) {
case "noteOn":
var noteNumber = data.noteNumber;
list.push([noteNumber, time, time + defaultDuration]);
multiplayCount += 1;
if (multiplayCount > maxMultiplayCount)
maxMultiplayCount = multiplayCount;
break;
case "noteOff":
for (var j = list.length - 1; j >= 0; j--) {
var prev = list[j];
if (prev[0] == data.noteNumber) {
prev[2] = time + outfadeTime;
break;
}
}
multiplayCount -= 1;
break;
}
}
const data = `
var data = ${JSON.stringify(list)}
var maxMultiplayCount = ${maxMultiplayCount}
var rowNum = ${row}
var colNum = ${col}
var compWidth = 1920
var compHeight = 1080
`;
AfterEffectScriptLauncher.generate(
data,
`${__dirname}/AEScript.jsx`,
`${__dirname}/AEScriptWithData.jsx`
)
.then(path => {
console.log("jsx generate success");
AfterEffectScriptLauncher.run(path)
.then(code => {
console.log("jsx run success");
})
.catch(err => {
console.log("jsx run fail");
console.log(err);
});
})
.catch(err => {
console.log("jsx generate fail");
console.log(err);
});
//40~76 총 37개