Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
fisher-alice committed Nov 6, 2023
2 parents b4a2bd1 + acd99f8 commit d6a9292
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/p5.dance.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ module.exports = class DanceParty {

this.songStartTime_ = 0;

// Whether to loop analysis events. Used in live preview.
this.loopAnalysisEvents = false;

new P5(p5Inst => {
this.p5_ = p5Inst;
this.resourceLoader_.initWithP5(p5Inst);
Expand Down Expand Up @@ -321,6 +324,7 @@ module.exports = class DanceParty {
this.world.keysPressed = new Set();
this.world.spriteGroupsCalledToChangeMove = [];
this.world.spriteStyles = [];
this.loopAnalysisEvents = false;
}

setEffectsInPreviewMode(inPreviewMode) {
Expand Down Expand Up @@ -366,6 +370,7 @@ module.exports = class DanceParty {
this.songMetadata_ = modifySongData(songData);
this.analysisPosition_ = 0;
this.songStartTime_ = new Date();
this.loopAnalysisEvents = true;
this.p5_.loop();
}

Expand Down Expand Up @@ -1396,6 +1401,13 @@ module.exports = class DanceParty {
this.analysisPosition_++;
}

// If we've reached the end of the analysis events and are looping, reset
// to the beginning. This is only used in live preview (where there is no song playback).
if (this.loopAnalysisEvents && this.analysisPosition_ >= length) {
this.analysisPosition_ = 0;
this.songStartTime_ = Date.now();
}

while (
this.world.cues.seconds.length > 0 &&
this.world.cues.seconds[0] < this.getCurrentTime()
Expand Down

0 comments on commit d6a9292

Please sign in to comment.