Spaces:
Sleeping
Sleeping
debugged the phrase playing js function
Browse files
app.py
CHANGED
|
@@ -255,16 +255,24 @@ function playGeneratedPhrase(phrase) {
|
|
| 255 |
|
| 256 |
console.log("🎵 Playing Generated Phrase:", phrase);
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
setTimeout(() => {
|
| 261 |
-
|
| 262 |
-
|
|
|
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
}, delay);
|
| 267 |
-
});
|
| 268 |
}
|
| 269 |
|
| 270 |
|
|
|
|
| 255 |
|
| 256 |
console.log("🎵 Playing Generated Phrase:", phrase);
|
| 257 |
|
| 258 |
+
let accumulatedDelay = 0; // ✅ Track total delay from phrase start
|
| 259 |
+
phrase.forEach((noteData, index) => {
|
| 260 |
+
accumulatedDelay += noteData.inter_onset; // ✅ Accumulate inter-onset time
|
| 261 |
+
|
| 262 |
+
setTimeout(() => {
|
| 263 |
+
let noteOnMessage = [0x90, noteData.note, noteData.velocity];
|
| 264 |
+
let noteOffMessage = [0x80, noteData.note, 0];
|
| 265 |
+
|
| 266 |
+
selectedOutput.send(noteOnMessage);
|
| 267 |
+
console.log(`🎶 Note ON: ${noteData.note}, Velocity: ${noteData.velocity}, Start Delay: ${accumulatedDelay}ms`);
|
| 268 |
+
|
| 269 |
setTimeout(() => {
|
| 270 |
+
selectedOutput.send(noteOffMessage);
|
| 271 |
+
console.log(`🔇 Note OFF: ${noteData.note}`);
|
| 272 |
+
}, noteData.duration); // ✅ Use stored duration
|
| 273 |
|
| 274 |
+
}, accumulatedDelay); // ✅ Use accumulated delay for precise timing
|
| 275 |
+
});
|
|
|
|
|
|
|
| 276 |
}
|
| 277 |
|
| 278 |
|