Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37951
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2019-12-09 03:03 -0800 |
| References | <5753bf40-6ff1-4609-802c-5036f9a93d64@googlegroups.com> <67478597-1d96-4ff6-9da5-c99446684435@googlegroups.com> <cb509c2a-12ba-434b-a6cc-66782a7c3dd3@googlegroups.com> |
| Message-ID | <e9c28d17-7dfb-46ee-b236-d040cf2fe523@googlegroups.com> (permalink) |
| Subject | Re: My flaky math |
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
Den måndag 9 december 2019 kl. 09:59:51 UTC+1 skrev Jonas Thörnvall:
> Den måndag 9 december 2019 kl. 09:51:42 UTC+1 skrev Jonas Thörnvall:
> > Den lördag 7 december 2019 kl. 19:44:08 UTC+1 skrev Jonas Thörnvall:
> > > When i move selection to middle and then move the start point the selection start to drift within timeframe, should i calcMarking another way?
> > >
> > > There must be a logical error because as i see it left and right are percentages of the total time that is the length of the bar so i do not think i move it relative a static target just timespann. And the marking shrink and expand with the timetotal, but it drifts? "When you change startpoint relative the marking".
> > >
> > > https://midisequenser.000webhostapp.com/
> > >
> > > function calcMarking(){
> > > //Do calculation
> > > var LeftTime=parseInt(document.getElementById("recstart").value);
> > > var RightTime=parseInt(document.getElementById("recend").value);
> > > var TimeSPos=document.getElementById("EditStart").value;
> > > var TimeEPos=document.getElementById("EditEnd").value;
> > > var distanceTotal=Mwidth-50;
> > > var TimeTotal=TimeEPos-TimeSPos;
> > > console.log("TimeEPos="+TimeEPos+" TimeSPos="+TimeSPos+" Timetotal="+TimeTotal);
> > > var RightPercent=RightTime/TimeTotal;
> > > var LeftPercent=LeftTime/TimeTotal;
> > > zz=50+(RightPercent*distanceTotal);
> > > yy=50+(LeftPercent*distanceTotal);
> > > }
> > >
> > >
> > > // This below is just the drawout and i don't think it is anything there
> > > // I think there is flaky math or flaky logic above.
> > > // It has no real importance for the functionality, but should look nice i guess
> > >
> > > function drawMarked() {
> > > var LeftTime=parseInt(document.getElementById("recstart").value);
> > > var RightTime=parseInt(document.getElementById("recend").value);
> > > var TimeSPos=document.getElementById("EditStart").value;
> > > var TimeEPos=document.getElementById("EditEnd").value;
> > > if(LeftTime>=TimeSPos && RightTime<=TimeEPos && mode=="Listen") {
> > > calcMarking();
> > > drawOutMark();
> > > leftMarker();
> > > rightMarker();
> > > }
> > > }
> > >
> > >
> > >
> > > function drawOutMark(){
> > > ctm.fillStyle ="#661313";
> > > ctm.fillRect(yy, 25,zz-yy,Mheight);
> > > }
> > >
> > > function leftMarker(){
> > > ctm.fillStyle = "orange";
> > > ctm.beginPath();
> > > ctm.moveTo(yy-10, 15);
> > > ctm.lineTo(yy+10, 15);
> > > ctm.lineTo(yy, 25);
> > > ctm.fill();
> > > }
> > >
> > > function rightMarker(){
> > > ctm.fillStyle = "orange";
> > > ctm.beginPath();
> > > ctm.moveTo(zz-10, 15);
> > > ctm.lineTo(zz+10, 15);
> > > ctm.lineTo(zz, 25);
> > > ctm.lineWidth = 2;
> > > ctm.fill();
> > > }
> >
> > I think the correct math involve transforming right and left "selected markers" into fractions relative the length of FRACTION=(righttime-lefttime)/totaltime
> > And then newleftime=leftime*FRACTION and newrighttime=rightime*fraction.
> >
> > And then take the fraction of Rightperc=newrighttime/totaltime
> > And then Rightperc*totaltime
> >
> > But i am not in the mood to fiddle with it.
> > There is other things to fix like the trackeditor.
> >
> > I would say it work now, for the use intended "yeah i can see it drift a little" when the startbar run high.
>
> At bar 450 or so it have drifted a full bar...
Well now i think you will find the accuracy good enough for some hundred million of bars, but what is the math really?
function calcMarking(){
var STARTBAR=document.getElementById("SB").value;
var LeftTime=parseInt(document.getElementById("recstart").value);
var RightTime=parseInt(document.getElementById("recend").value);
var TimeSPos=document.getElementById("EditStart").value;
var TimeEPos=document.getElementById("EditEnd").value;
//Do calculation
distanceTotal=Mwidth-50;
TimeTotal=TimeEPos-TimeSPos;
RightPerc=RightTime/TimeTotal;
LeftPerc=LeftTime/TimeTotal;
zz=50+(RightPerc*distanceTotal)-(barlength*STARTBAR)*0.99771462;
yy=50+(LeftPerc*distanceTotal)-(barlength*STARTBAR)*0.99771462;
}
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-07 10:44 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-07 11:24 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-07 11:43 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 00:26 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 00:33 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 00:35 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 00:51 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 00:59 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 03:03 -0800
Re: My flaky math Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-12-09 04:12 -0800
csiph-web