-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwindowed.js
More file actions
51 lines (45 loc) · 1.33 KB
/
windowed.js
File metadata and controls
51 lines (45 loc) · 1.33 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
function get_windowed(window_duration, step_duration) {
let active = Object.entries(T.active)
.filter(x => x[1])
.map(x => x[0]);
if (active.length !== 1) {
alert("Please expand exactly one recording.");
return;
}
const recording_id = active[0];
const doc = T.docs[recording_id];
// Estimate duration from pitch results
const pitch = D.urls["/media/" + doc.pitch];
if (!pitch) {
alert(
"Pitch has not yet loaded. Please wait until you can see the pitch trace, and then try running this function again."
);
return;
}
const duration = pitch.length / 100; // seconds
const output = {}; // start_time -> result object
let n_reqs = 0;
for (let t = 0; t < duration; t += step_duration) {
n_reqs += 1;
(start_time => {
fetch(
`/_measure?id=${recording_id}&start_time=${start_time}&end_time=${Math.min(
duration,
start_time + window_duration
)}`
)
.then(x => x.json())
.then(res => {
n_reqs -= 1;
output[start_time] = res;
if (n_reqs === 0) {
console.log("output=", output);
window.output = output;
} else {
const n_out = Object.keys(output).length;
console.log(`Got result ${n_out} of ${n_out + n_reqs}`);
}
});
})(t);
}
}