Skip to content

Commit

Permalink
Merge branch 'master' of ssh://gitlab.com/agrahn/ABLoopPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Grahn committed Oct 27, 2023
2 parents 42b63cf + ee30482 commit 7f0d6bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ABLoopPlayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h1 style="font-size:150%;margin-top:0;margin-bottom:0.5em;">AB Loop Player</h1>
onmousedown="onJumpToA()" onmouseup="myPlay()"></button><!--
--><label for="myTimeA">A:</label> <input id="myTimeA" onchange="onInputTime(this,0)" size="8"/>
<label for="myTimeB">B:</label> <input id="myTimeB" onchange="onInputTime(this,1)" size="8"/>
<button id="bmkAddButton" style="width:1.5em;height:1.5em;vertical-align:bottom;background-size:80%;background-image:url('svg/star.svg');"></button>&ensp;
<button id="bmkAddButton" style="width:1.5em;height:1.5em;vertical-align:bottom;background-size:80%;background-image:url('svg/star.svg');"></button>
<input type="checkbox" onchange="toggleQuant(this, help)" disabled id="quant"/><label for="quant">quantise</label>&emsp;&emsp;
<button id="loopBackwardsButton" style="width:1.5em;height:1.5em;font-size:110%;" onmouseup="onLoopBackwards()">&laquo;</button><!--
--><button id="loopHalveButton" style="width:2.4em;height:1.5em;font-size:110%;" onmouseup="onLoopHalve()">&times;&frac12;</button><!--
Expand Down
19 changes: 12 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ $(document).ready(function(){
$("#scrub").slider({
min: 0, step: 0.001, range: "min",
slide: function(e,ui){
loopMeas.splice(0);
mySetCurrentTime(ui.value);
},
})
Expand Down Expand Up @@ -396,6 +397,7 @@ var onSliderSlide=function(e,ui){
timeA=ui.values[0];
timeB=ui.values[1];
}
loopMeas.splice(0);
updateLoopUI();
}

Expand All @@ -406,21 +408,22 @@ var onLoopTimerUpdate=function(){
let tMedia=myGetCurrentTime();
if(tMedia<timeA) loopMeas.splice(0);
if(tMedia<timeA && !intro.checked || tMedia>=timeB){
//quantise loop based on tapped tempo
let curDate=Date.now()/1000; //[s]
if(
quant.checked && tMedia>=timeB
&& (!loopMeas.length || curDate-loopMeas.at(-1)>=(timeB-timeA)/rate)
tMedia>=timeB && (!loopMeas.length || curDate-loopMeas.at(-1)>=(timeB-timeA)/rate)
){
loopMeas.push(curDate);
if(loopMeas.length>1){
loopMeas.splice(0,loopMeas.length-2);
//long-term averaged latency of media rewind (minimum weight of current value: 1/16)
tLavg=(tLavg*tLcount + (loopMeas[1]-loopMeas[0])*rate+timeA-timeB)/++tLcount;
if(tLcount>15) tLcount=15;
let tBOld=timeB;
timeB=toNearest5ms(timeA+Math.round((timeB-timeA)/beatNormal)*beatNormal-tLavg);
if(timeB-tBOld!=0) updateLoopUI();
//quantise loop based on tapped tempo and average latency
if(quant.checked) {
let tBOld=timeB;
timeB=toNearest5ms(timeA+Math.round((timeB-timeA)/beatNormal)*beatNormal-tLavg);
if(timeB-tBOld!=0) updateLoopUI();
}
}
}
mySetCurrentTime(timeA);
Expand Down Expand Up @@ -1108,8 +1111,10 @@ var onPlayerStateChange=function(e, id, ta, tb, s){ //event object, video id loo
$("#scrub").slider("option", "value", myGetCurrentTimeYT());
}, 5
));
if (isTimeASet && isTimeBSet && !loopTimer.length)
if (isTimeASet && isTimeBSet && !loopTimer.length){
loopMeas.splice(0);
loopTimer.push(setInterval(onLoopTimerUpdate, 5));
}
}
else if(e.data==YT.PlayerState.PAUSED){
while(loopTimer.length) clearInterval(loopTimer.pop());
Expand Down
Binary file modified zip/ABLoopPlayer.zip
Binary file not shown.

0 comments on commit 7f0d6bc

Please sign in to comment.