forked from elainewlin/MusicBuddy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.js
174 lines (142 loc) · 4.07 KB
/
setup.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
var speechOn = (window.localStorage.getItem("speechOn") === "true");
var motionOn = (window.localStorage.getItem("motionOn") === "true");
var gazeOn = (window.localStorage.getItem("gazeOn") === "true");
var debugOn = (window.localStorage.getItem("debugOn") === "true");
// Modes
var speech;
var motion;
var gaze;
var songView;
var finalY;
var scrollInterval;
$(document).ready(function() {
// start button
$(document).on('click', '#start', function() {
// begin standard scrolling
scrollInterval = setInterval(function(){
fusedScroll();
},SCROLL_INTERVAL);
// start gaze
if (gaze) {
gaze.setReady(true);
}
// start motion
if (motion) {
setTimeout(function() {
motion.setReady(true);
}, 3000); // time between pressing and putting hand back on uke
}
// start speech
if (speech) {
speech.start();
}
var stopButton = $('<button id="stop" class="btn btn-danger">Stop</button>');
$('.start-btn-container').append(stopButton);
$('#start').remove();
});
// stop button
$(document).on('click', '#stop', function(e) {
//end standard scrolling
clearInterval(scrollInterval);
// stop gaze
if (gaze) {
gaze.setReady(false);
}
// stop motion
if (motion) {
motion.setReady(false);
}
// stop speech
if (speech) {
speech.stopRecognition();
}
var startButton = $('<button id="start" class="btn btn-success">Start</button>');
$('.start-btn-container').append(startButton);
$('#stop').remove();
});
/*** Song View Set-Up ****/
var songViewParams = {
numLyricLines: $('.lyrics').length,
numChordLines: $('.chords').length,
debug: false
};
songView = new SongView(songViewParams);
/**** Speech Recognition Set-Up ****/
if (!debugOn) {
$('#results').remove();
}
if (speechOn) {
var speechParams = {
song: songView,
matchCutoff: 3,
finalId: 'final_span',
interimId: 'interim_span',
endTimeout: 1000
};
speech = new SpeechRec(speechParams);
if (debugOn)
songView.getLineElement(speech.getCurrentLine()).addClass('current');
// listens for when the speech recognition updates the line
$(speech).on('speechUpdate', function(e, info) {
if (debugOn) {
songView.getLineElement(info.previousLine).removeClass('current');
songView.getLineElement(info.nextLine).addClass('current');
}
if (!info.fusing)
fuse();
});
$(".line").click(function(e) {
var id = e.currentTarget.id;
speech.setCurrentLine(parseInt(id));
});
}
/**** Motion Detection Set-Up ****/
if (motionOn) {
var motionParams = {
song: songView,
pixelDiffThreshold: PIXEL_DIFF,
scoreThreshold: SCORE_THRESH,
x: MOTION_X,
y: MOTION_Y
};
motion = new MotionDetect(motionParams);
if (debugOn)
songView.getChordElement(motion.getCurrentLine()).addClass('current');
var engine = motion.start();
// Calibration video removal
$('#calibrate').click(function() {
$("#rendercanvas, #motionCanvas").each(function(){
$(this).toggle();
});
});
// listens for when the motion detection updates the line
$(motion).on('motionUpdate', function(e, info) {
if (debugOn) {
songView.getChordElement(info.previousLine).removeClass('current');
songView.getChordElement(info.nextLine).addClass('current');
}
if (!info.fusing)
fuse();
});
$(".line").click(function(e) {
var id = e.currentTarget.id;
motion.setCurrentLine(parseInt(id));
motion.setActualTransitions(0);
});
} else {
$('#calibrate').remove();
}
/*** Gaze Tracking Set-Up ***/
if (gazeOn) {
var gazeParams = {
fusionDebug: true,
debug: debugOn // turns on the red dot
};
gaze = new GazeTracker(gazeParams);
gaze.start();
// listens for when the gaze tracking updates the y-coord
$(gaze).on('gazeUpdate', function(e, info) {
fuse();
});
}
});