-
Notifications
You must be signed in to change notification settings - Fork 0
/
musis.js
91 lines (76 loc) · 2.25 KB
/
musis.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
80
81
82
83
84
85
86
87
88
89
90
91
(function () {
// This is the glue code
musis = {}
var metronome;
var triggers;
var music;
var game;
musis.begin = function () {
draw = new musis.draw();
musis.ui.draw = draw;
play = new musis.play();
metronome = new musis.metronome();
music = new musis.music();
this.changeGame(musis.freeplay);
};
musis.changeGame = function (next) {
musis.ui.menu.clear();
musis.ui.title('');
musis.ui.hint('');
game = next;
game.begin();
triggers = createSolfegeTriggers();
};
var s = null;
musis.touchstart = function (x, y) {
s = { x: draw.xFromCanvas(x), y: draw.yFromCanvas(y) };
triggers.touch(s, s);
};
musis.touchmove = function (x, y) {
var e = { x: draw.xFromCanvas(x), y: draw.yFromCanvas(y) };
if (s === null) { s = e; }
triggers.touch(s, e);
s = { x: draw.xFromCanvas(x), y: draw.yFromCanvas(y) };
};
musis.touchend = function () {
s = null;
var nextHarmony = triggers.nextHarmony();
if (!nextHarmony) { return; }
if (nextHarmony.length > 0) {
toNextHarmony(nextHarmony);
}
};
musis.frame = function (t, dt, gl, cw, ch) {
if (s) {
triggers.touch(s, s);
}
if (dt > 0.1) { console.log("Long frame: "+dt); }
metronome.update(play.timeNow(), function (beat) {
music.beat(beat, function (events, notes) {
musis.perform.beat(play, events);
});
});
triggers.update(dt);
draw.frameStart(t, gl, cw, ch);
triggers.render(draw);
};
var createSolfegeTriggers = function () {
if (!game.solfegeTriggers) { return new musis.triggers([]); }
var enabled = game.solfegeTriggers();
var info = [ { value: 'do', acc: 'nat' },
{ value: 'me', acc: 'flat' }, { value: 'mi', acc: 'nat' },
{ value: 'sol', acc: 'nat' },
{ value: 'te', acc: 'flat' }, { value: 'ti', acc: 'nat' },
{ value: 're', acc: 'nat' },
{ value: 'fa', acc: 'nat' }, { value: 'fi', acc: 'sharp' },
{ value: 'le', acc: 'flat' }, { value: 'la', acc: 'nat' }
].filter(function (t) {
return enabled.indexOf(t.value) >= 0;
});
return new musis.triggers(info, "solfege");
};
var toNextHarmony = function (nextHarmony) {
var analysis = music.nextHarmony(nextHarmony);
triggers = createSolfegeTriggers();
};
})();