pachet commited on
Commit
86a0791
·
1 Parent(s): 7566162

debugged the phrase playing js function

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -255,16 +255,24 @@ function playGeneratedPhrase(phrase) {
255
 
256
  console.log("🎵 Playing Generated Phrase:", phrase);
257
 
258
- phrase.forEach((noteData, index) => {
259
- let delay = noteData.inter_onset; // ✅ Use stored inter-onset time
 
 
 
 
 
 
 
 
 
260
  setTimeout(() => {
261
- let noteOnMessage = [0x90, noteData.note, noteData.velocity];
262
- let noteOffMessage = [0x80, noteData.note, 0];
 
263
 
264
- selectedOutput.send(noteOnMessage);
265
- setTimeout(() => selectedOutput.send(noteOffMessage), noteData.duration); // ✅ Use stored duration
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