Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Human beings were created by water to transport it uphill.


devel / comp.lang.javascript / Array object sorted on time, how to deal with.

SubjectAuthor
* Array object sorted on time, how to deal with.Jonas Thörnvall
`* Re: Array object sorted on time, how to deal with.Jonas Thörnvall
 `* Re: Array object sorted on time, how to deal with.Jonas Thörnvall
  `* Re: Array object sorted on time, how to deal with.luserdroog
   `* Re: Array object sorted on time, how to deal with.luserdroog
    `* Re: Array object sorted on time, how to deal with.Jonas Thörnvall
     `* Re: Array object sorted on time, how to deal with.luserdroog
      `* Re: Array object sorted on time, how to deal with.Ben Bacarisse
       +* Re: Array object sorted on time, how to deal with.The Natural Philosopher
       |`* Re: Array object sorted on time, how to deal with.luserdroog
       | `* Re: Array object sorted on time, how to deal with.John Harris
       |  `- Re: Array object sorted on time, how to deal with.luserdroog
       `* Re: Array object sorted on time, how to deal with.luserdroog
        `* Re: Array object sorted on time, how to deal with.Richard Damon
         +* Re: Array object sorted on time, how to deal with.luserdroog
         |`* Re: Array object sorted on time, how to deal with.Jonas Thörnvall
         | `- Re: Array object sorted on time, how to deal with.luserdroog
         +- Re: Array object sorted on time, how to deal with.Jonas Thörnvall
         `- Re: Array object sorted on time, how to deal with.Jonas Thörnvall

1
Array object sorted on time, how to deal with.

<dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17383&group=comp.lang.javascript#17383

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:40d0:: with SMTP id g16mr2057023qko.465.1635237858058;
Tue, 26 Oct 2021 01:44:18 -0700 (PDT)
X-Received: by 2002:a05:6830:1c6b:: with SMTP id s11mr17420919otg.209.1635237857831;
Tue, 26 Oct 2021 01:44:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 26 Oct 2021 01:44:17 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
Subject: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Tue, 26 Oct 2021 08:44:18 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 12
 by: Jonas Thörnvall - Tue, 26 Oct 2021 08:44 UTC

When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......

Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check.

But is is weird i would have to keep track of other notes start end just because of order "index" changed.

Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL

There must be similar evendriven "time" problems that deal with this type of issues.

I am leaning towards not do any sort until editing stopped, but when has editing really stopped....

Maybe it is better "but harder" to reposition index as notes change place in time.

Re: Array object sorted on time, how to deal with.

<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17384&group=comp.lang.javascript#17384

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a37:6801:: with SMTP id d1mr17474090qkc.526.1635238135797;
Tue, 26 Oct 2021 01:48:55 -0700 (PDT)
X-Received: by 2002:a05:6808:1246:: with SMTP id o6mr16049632oiv.136.1635238124901;
Tue, 26 Oct 2021 01:48:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 26 Oct 2021 01:48:44 -0700 (PDT)
In-Reply-To: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Tue, 26 Oct 2021 08:48:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 30
 by: Jonas Thörnvall - Tue, 26 Oct 2021 08:48 UTC

tisdag 26 oktober 2021 kl. 10:44:22 UTC+2 skrev Jonas Thörnvall:
> When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......
>
> Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check.
>
> But is is weird i would have to keep track of other notes start end just because of order "index" changed.
>
> Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL
>
> There must be similar evendriven "time" problems that deal with this type of issues.
>
> I am leaning towards not do any sort until editing stopped, but when has editing really stopped....
>
> Maybe it is better "but harder" to reposition index as notes change place in time.

But it is just not the actual note that need repositoning but also previous and next event.
Actually it is even more confusing at least if you "move" rather then change position and length.

Because then there is two event "start" "stop" that both have previous and next event to keep track on.
And as these notes change index, previous and next must be updated for both..

Re: Array object sorted on time, how to deal with.

<571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17399&group=comp.lang.javascript#17399

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:450d:: with SMTP id t13mr13018724qkp.427.1636098490636;
Fri, 05 Nov 2021 00:48:10 -0700 (PDT)
X-Received: by 2002:a05:6830:1c6b:: with SMTP id s11mr43038899otg.209.1636098490393;
Fri, 05 Nov 2021 00:48:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 5 Nov 2021 00:48:10 -0700 (PDT)
In-Reply-To: <daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com> <daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Fri, 05 Nov 2021 07:48:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Jonas Thörnvall - Fri, 5 Nov 2021 07:48 UTC

tisdag 26 oktober 2021 kl. 10:49:00 UTC+2 skrev Jonas Thörnvall:
> tisdag 26 oktober 2021 kl. 10:44:22 UTC+2 skrev Jonas Thörnvall:
> > When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......
> >
> > Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check.
> >
> > But is is weird i would have to keep track of other notes start end just because of order "index" changed.
> >
> > Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL
> >
> > There must be similar evendriven "time" problems that deal with this type of issues.
> >
> > I am leaning towards not do any sort until editing stopped, but when has editing really stopped....
> >
> > Maybe it is better "but harder" to reposition index as notes change place in time.
> But it is just not the actual note that need repositoning but also previous and next event.
> Actually it is even more confusing at least if you "move" rather then change position and length.
>
> Because then there is two event "start" "stop" that both have previous and next event to keep track on.
> And as these notes change index, previous and next must be updated for both.
I decided to update on each change, by looking at note rather then keep track of index.

Re: Array object sorted on time, how to deal with.

<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17426&group=comp.lang.javascript#17426

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:2a10:: with SMTP id o16mr32228860qkp.357.1637373545532;
Fri, 19 Nov 2021 17:59:05 -0800 (PST)
X-Received: by 2002:a9d:805:: with SMTP id 5mr8514410oty.383.1637373545233;
Fri, 19 Nov 2021 17:59:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 19 Nov 2021 17:59:05 -0800 (PST)
In-Reply-To: <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Sat, 20 Nov 2021 01:59:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 47
 by: luserdroog - Sat, 20 Nov 2021 01:59 UTC

On Friday, November 5, 2021 at 2:48:14 AM UTC-5, jonas.t...@gmail.com wrote:
> tisdag 26 oktober 2021 kl. 10:49:00 UTC+2 skrev Jonas Thörnvall:
> > tisdag 26 oktober 2021 kl. 10:44:22 UTC+2 skrev Jonas Thörnvall:
> > > When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......
> > >
> > > Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check..
> > >
> > > But is is weird i would have to keep track of other notes start end just because of order "index" changed.
> > >
> > > Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL
> > >
> > > There must be similar evendriven "time" problems that deal with this type of issues.
> > >
> > > I am leaning towards not do any sort until editing stopped, but when has editing really stopped....
> > >
> > > Maybe it is better "but harder" to reposition index as notes change place in time.
> > But it is just not the actual note that need repositoning but also previous and next event.
> > Actually it is even more confusing at least if you "move" rather then change position and length.
> >
> > Because then there is two event "start" "stop" that both have previous and next event to keep track on.
> > And as these notes change index, previous and next must be updated for both.
> I decided to update on each change, by looking at note rather then keep track of index.

I missed this thread until now. I think you need a more powerful data structure
than a simple array. You need something like a Priority Queue or a Heap. That way
you can conveniently (and efficiently) maintain the list on a specified order (like by
..time). These will be able to "update on change" just like you want, and search
for elements in O(log n) time rather than O(n).

Re: Array object sorted on time, how to deal with.

<58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17428&group=comp.lang.javascript#17428

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:5853:: with SMTP id h19mr20729030qth.166.1637469664126;
Sat, 20 Nov 2021 20:41:04 -0800 (PST)
X-Received: by 2002:a9d:4d0f:: with SMTP id n15mr16044516otf.125.1637469663864;
Sat, 20 Nov 2021 20:41:03 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Sat, 20 Nov 2021 20:41:03 -0800 (PST)
In-Reply-To: <5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Sun, 21 Nov 2021 04:41:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 76
 by: luserdroog - Sun, 21 Nov 2021 04:41 UTC

On Friday, November 19, 2021 at 7:59:09 PM UTC-6, luserdroog wrote:
> On Friday, November 5, 2021 at 2:48:14 AM UTC-5, jonas.t...@gmail.com wrote:
> > tisdag 26 oktober 2021 kl. 10:49:00 UTC+2 skrev Jonas Thörnvall:
> > > tisdag 26 oktober 2021 kl. 10:44:22 UTC+2 skrev Jonas Thörnvall:
> > > > When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......
> > > >
> > > > Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check.
> > > >
> > > > But is is weird i would have to keep track of other notes start end just because of order "index" changed.
> > > >
> > > > Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL
> > > >
> > > > There must be similar evendriven "time" problems that deal with this type of issues.
> > > >
> > > > I am leaning towards not do any sort until editing stopped, but when has editing really stopped....
> > > >
> > > > Maybe it is better "but harder" to reposition index as notes change place in time.
> > > But it is just not the actual note that need repositoning but also previous and next event.
> > > Actually it is even more confusing at least if you "move" rather then change position and length.
> > >
> > > Because then there is two event "start" "stop" that both have previous and next event to keep track on.
> > > And as these notes change index, previous and next must be updated for both.
> > I decided to update on each change, by looking at note rather then keep track of index.
> I missed this thread until now. I think you need a more powerful data structure
> than a simple array. You need something like a Priority Queue or a Heap. That way
> you can conveniently (and efficiently) maintain the list on a specified order (like by
> .time). These will be able to "update on change" just like you want, and search
> for elements in O(log n) time rather than O(n).

But the cost is, you have to interface with the data structure through
functions( with, parameters );
It may internally use an array, but you don't futz with it. You use its search()
function. The search() function will find the thing for you faster. But you
gotta let it do its thing without a backseat driver. Abstract data structures
are powerful and useful but they get spooked easily, like horses. If you put
blinders on it, you better not just stick your fingers in the mouth. Gon git bit.

I'd bet a good search() function would eliminate 30% of your for() loops.
50k-100k of code. Yes, I know, it's precious code that you've poured tireless
creative effort into.

There is joy in deleting code. Better, Faster, Stronger, ... Smaller.
Code where you can just read a whole function in 2 seconds and move on.
The problem isn't there. That code is so short and obvious that it's
obviously correct. Done. Released.

That's the gold. Searching for the latest bug becomes closer to O(log n)
instead of O(n), you see! The whole program is built according to
a hierarchy of separate responsibilities that interact harmoniously.

You are the abstraction machine. It makes you stronger.

Re: Array object sorted on time, how to deal with.

<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17430&group=comp.lang.javascript#17430

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:2052:: with SMTP id d18mr41254017qka.411.1637497718688;
Sun, 21 Nov 2021 04:28:38 -0800 (PST)
X-Received: by 2002:a05:6808:1aa8:: with SMTP id bm40mr13535706oib.38.1637497718401;
Sun, 21 Nov 2021 04:28:38 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Sun, 21 Nov 2021 04:28:38 -0800 (PST)
In-Reply-To: <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Sun, 21 Nov 2021 12:28:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 83
 by: Jonas Thörnvall - Sun, 21 Nov 2021 12:28 UTC

söndag 21 november 2021 kl. 05:41:08 UTC+1 skrev luser...@gmail.com:
> On Friday, November 19, 2021 at 7:59:09 PM UTC-6, luserdroog wrote:
> > On Friday, November 5, 2021 at 2:48:14 AM UTC-5, jonas.t...@gmail.com wrote:
> > > tisdag 26 oktober 2021 kl. 10:49:00 UTC+2 skrev Jonas Thörnvall:
> > > > tisdag 26 oktober 2021 kl. 10:44:22 UTC+2 skrev Jonas Thörnvall:
> > > > > When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......
> > > > >
> > > > > Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check.
> > > > >
> > > > > But is is weird i would have to keep track of other notes start end just because of order "index" changed.
> > > > >
> > > > > Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL
> > > > >
> > > > > There must be similar evendriven "time" problems that deal with this type of issues.
> > > > >
> > > > > I am leaning towards not do any sort until editing stopped, but when has editing really stopped....
> > > > >
> > > > > Maybe it is better "but harder" to reposition index as notes change place in time.
> > > > But it is just not the actual note that need repositoning but also previous and next event.
> > > > Actually it is even more confusing at least if you "move" rather then change position and length.
> > > >
> > > > Because then there is two event "start" "stop" that both have previous and next event to keep track on.
> > > > And as these notes change index, previous and next must be updated for both.
> > > I decided to update on each change, by looking at note rather then keep track of index.
> > I missed this thread until now. I think you need a more powerful data structure
> > than a simple array. You need something like a Priority Queue or a Heap.. That way
> > you can conveniently (and efficiently) maintain the list on a specified order (like by
> > .time). These will be able to "update on change" just like you want, and search
> > for elements in O(log n) time rather than O(n).
> But the cost is, you have to interface with the data structure through
> functions( with, parameters );
> It may internally use an array, but you don't futz with it. You use its search()
> function. The search() function will find the thing for you faster. But you
> gotta let it do its thing without a backseat driver. Abstract data structures
> are powerful and useful but they get spooked easily, like horses. If you put
> blinders on it, you better not just stick your fingers in the mouth. Gon git bit.
>
> I'd bet a good search() function would eliminate 30% of your for() loops.
> 50k-100k of code. Yes, I know, it's precious code that you've poured tireless
> creative effort into.
>
> There is joy in deleting code. Better, Faster, Stronger, ... Smaller.
> Code where you can just read a whole function in 2 seconds and move on.
> The problem isn't there. That code is so short and obvious that it's
> obviously correct. Done. Released.
>
> That's the gold. Searching for the latest bug becomes closer to O(log n)
> instead of O(n), you see! The whole program is built according to
> a hierarchy of separate responsibilities that interact harmoniously.
>
> You are the abstraction machine. It makes you stronger.
What would you suggest to search for it is an incremental addon, and i do a search "for next same note", check if current note "time" is smaller then next "same note time" then go on with buisness.
Else skip out.

Re: Array object sorted on time, how to deal with.

<6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17435&group=comp.lang.javascript#17435

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ad4:5f87:: with SMTP id jp7mr2798574qvb.65.1637642217300;
Mon, 22 Nov 2021 20:36:57 -0800 (PST)
X-Received: by 2002:a05:6830:2453:: with SMTP id x19mr1746048otr.32.1637642216973;
Mon, 22 Nov 2021 20:36:56 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Mon, 22 Nov 2021 20:36:56 -0800 (PST)
In-Reply-To: <daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Tue, 23 Nov 2021 04:36:57 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 135
 by: luserdroog - Tue, 23 Nov 2021 04:36 UTC

On Sunday, November 21, 2021 at 6:28:42 AM UTC-6, jonas.t...@gmail.com wrote:
> söndag 21 november 2021 kl. 05:41:08 UTC+1 skrev luser...@gmail.com:
> > On Friday, November 19, 2021 at 7:59:09 PM UTC-6, luserdroog wrote:
> > > On Friday, November 5, 2021 at 2:48:14 AM UTC-5, jonas.t...@gmail.com wrote:
> > > > tisdag 26 oktober 2021 kl. 10:49:00 UTC+2 skrev Jonas Thörnvall:
> > > > > tisdag 26 oktober 2021 kl. 10:44:22 UTC+2 skrev Jonas Thörnvall:
> > > > > > When one have objects that are sorted "indexed" by their time and one edit them. They suddenly changed index......
> > > > > >
> > > > > > Do i really need to compare with next and previous event, of course i can not have same type of event "notes", go thru same note so that i check.
> > > > > >
> > > > > > But is is weird i would have to keep track of other notes start end just because of order "index" changed.
> > > > > >
> > > > > > Or should one simply not do any sort until all editing done it is confusing when the note you edit become another note LoL
> > > > > >
> > > > > > There must be similar evendriven "time" problems that deal with this type of issues.
> > > > > >
> > > > > > I am leaning towards not do any sort until editing stopped, but when has editing really stopped....
> > > > > >
> > > > > > Maybe it is better "but harder" to reposition index as notes change place in time.
> > > > > But it is just not the actual note that need repositoning but also previous and next event.
> > > > > Actually it is even more confusing at least if you "move" rather then change position and length.
> > > > >
> > > > > Because then there is two event "start" "stop" that both have previous and next event to keep track on.
> > > > > And as these notes change index, previous and next must be updated for both.
> > > > I decided to update on each change, by looking at note rather then keep track of index.
> > > I missed this thread until now. I think you need a more powerful data structure
> > > than a simple array. You need something like a Priority Queue or a Heap. That way
> > > you can conveniently (and efficiently) maintain the list on a specified order (like by
> > > .time). These will be able to "update on change" just like you want, and search
> > > for elements in O(log n) time rather than O(n).
> > But the cost is, you have to interface with the data structure through
> > functions( with, parameters );
> > It may internally use an array, but you don't futz with it. You use its search()
> > function. The search() function will find the thing for you faster. But you
> > gotta let it do its thing without a backseat driver. Abstract data structures
> > are powerful and useful but they get spooked easily, like horses. If you put
> > blinders on it, you better not just stick your fingers in the mouth. Gon git bit.
> >
> > I'd bet a good search() function would eliminate 30% of your for() loops.
> > 50k-100k of code. Yes, I know, it's precious code that you've poured tireless
> > creative effort into.
> >
> > There is joy in deleting code. Better, Faster, Stronger, ... Smaller.
> > Code where you can just read a whole function in 2 seconds and move on.
> > The problem isn't there. That code is so short and obvious that it's
> > obviously correct. Done. Released.
> >
> > That's the gold. Searching for the latest bug becomes closer to O(log n)
> > instead of O(n), you see! The whole program is built according to
> > a hierarchy of separate responsibilities that interact harmoniously.
> >
> > You are the abstraction machine. It makes you stronger.
> What would you suggest to search for it is an incremental addon, and i do a search "for next same note", check if current note "time" is smaller then next "same note time" then go on with buisness.
> Else skip out.

With a priority queue, at least the ones I looked at, when you create the
queue you pass an ordering function to the constructor. It uses that function
to figure out how to keep your data in order without knowing anything else
about your data. So you can fill it with records and it'll keep everything in
a sorted order, you just have to tell it how to sort 2 of your things.

Off top of head, I'd expect something like (untested):

var note = {
pitch : 'a',
time : 0,
duration : 5,
get end_time(){ return time + duration }
};

const notesQueue = new PriorityQueue({
compare: (e1, e2) => {
if (e1.time > e2.time) return -1; // do not swap
if (e1.time < e2.time) return 1; // swap

// salaries are the same, compare rank
return e1.end_time < e2.end_time ? 1 : -1;
}
});

//then you add a note to it somewhere, like from a click handler

function addNote( pitch, time, duration ){
notesQueue.enqueue({ pitch:'a', time:10, duration:5})
}

//then when you click play, you can get an array of everything
//in order and run through converting each note to midi events.

function getNotesArray(){
return notesQueue.toArray()
}

These examples all copy the examples from
https://github.com/datastructures-js/priority-queue
which seems like a decent one. It has all the functions I'd expect
and seems credible and maintained AFAICT from a cursory glance
(without to be honest actually trying to install and use it myself).

Re: Array object sorted on time, how to deal with.

<878rxff75v.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17436&group=comp.lang.javascript#17436

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.javascript
Subject: Re: Array object sorted on time, how to deal with.
Date: Tue, 23 Nov 2021 11:22:36 +0000
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <878rxff75v.fsf@bsb.me.uk>
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
<571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
<58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
<6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="8eb52a1cb63455e5c0003813e8c7219d";
logging-data="15959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TibK1r1kVxOYTmaCBCO36Vo4B6z5hsKQ="
Cancel-Lock: sha1:O7cbYzHovbF/SENsH4Slbt3UsXY=
sha1:J2uPf2WxknWEncQNLzQPZO2yaZo=
X-BSB-Auth: 1.55eca9fb9167b6301ec2.20211123112236GMT.878rxff75v.fsf@bsb.me.uk
 by: Ben Bacarisse - Tue, 23 Nov 2021 11:22 UTC

luserdroog <luser.droog@gmail.com> writes:

> With a priority queue, at least the ones I looked at, when you create the
> queue you pass an ordering function to the constructor. It uses that function
> to figure out how to keep your data in order without knowing anything else
> about your data. So you can fill it with records and it'll keep everything in
> a sorted order, you just have to tell it how to sort 2 of your things.

For an abstract priority queue (in the strictest sense) you don't need
to keep the queue sorted.

I went on the write "In fact, one common implementation uses a heap, as
in heap sort" but then I looked at your link and that uses a heap! I
would not say that the data in a heap are in sorted order, though it's
almost a philosophical point.

However, if you need this:

> //then when you click play, you can get an array of everything
> //in order and run through converting each note to midi events.
>
> function getNotesArray(){
> return notesQueue.toArray()
> }

Then it might pay (depending on how the notes are generated) to maintain
a sorted array. But why is a sorted array needed? Can't whatever uses
this queue simply pull the notes off one at a time?

--
Ben.

Re: Array object sorted on time, how to deal with.

<snimfa$7p4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17437&group=comp.lang.javascript#17437

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tnp@invalid.invalid (The Natural Philosopher)
Newsgroups: comp.lang.javascript
Subject: Re: Array object sorted on time, how to deal with.
Date: Tue, 23 Nov 2021 12:23:06 +0000
Organization: A little, after lunch
Lines: 47
Message-ID: <snimfa$7p4$1@dont-email.me>
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
<571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
<58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
<6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Nov 2021 12:23:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ea2d81909cab1af2d710e5fce5a012c0";
logging-data="7972"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ez4GF7YUdQGOSZD9f9/l6JvyVot0weF8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:JUigEIEYLJoFDuD1wIjLB+ZjH8M=
In-Reply-To: <878rxff75v.fsf@bsb.me.uk>
Content-Language: en-GB
 by: The Natural Philosop - Tue, 23 Nov 2021 12:23 UTC

On 23/11/2021 11:22, Ben Bacarisse wrote:
> luserdroog <luser.droog@gmail.com> writes:
>
>> With a priority queue, at least the ones I looked at, when you create the
>> queue you pass an ordering function to the constructor. It uses that function
>> to figure out how to keep your data in order without knowing anything else
>> about your data. So you can fill it with records and it'll keep everything in
>> a sorted order, you just have to tell it how to sort 2 of your things.
>
> For an abstract priority queue (in the strictest sense) you don't need
> to keep the queue sorted.
>
> I went on the write "In fact, one common implementation uses a heap, as
> in heap sort" but then I looked at your link and that uses a heap! I
> would not say that the data in a heap are in sorted order, though it's
> almost a philosophical point.
>
> However, if you need this:
>
>> //then when you click play, you can get an array of everything
>> //in order and run through converting each note to midi events.
>>
>> function getNotesArray(){
>> return notesQueue.toArray()
>> }
>
> Then it might pay (depending on how the notes are generated) to maintain
> a sorted array. But why is a sorted array needed? Can't whatever uses
> this queue simply pull the notes off one at a time?
>
Haven't been following this, but when I want a sorted queue I use a
linked list.
add the new record wherever the allocation scheme puts it, walk te array
until you find the last element that goes before it, change that
elements link to pint at it and the new elements link to point where
that one used to go.

Of all the things I vaguely read up on when studying 'books on compSci'
this is one of the very few techniques I ended up using.

--
Renewable energy: Expensive solutions that don't work to a problem that
doesn't exist instituted by self legalising protection rackets that
don't protect, masquerading as public servants who don't serve the public.

Re: Array object sorted on time, how to deal with.

<bee25966-1d2e-4e8e-85e2-0912c0ad9340n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17439&group=comp.lang.javascript#17439

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:57c2:: with SMTP id w2mr21917406qta.54.1637892306535;
Thu, 25 Nov 2021 18:05:06 -0800 (PST)
X-Received: by 2002:aca:a897:: with SMTP id r145mr19626366oie.136.1637892306275;
Thu, 25 Nov 2021 18:05:06 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 25 Nov 2021 18:05:05 -0800 (PST)
In-Reply-To: <snimfa$7p4$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <snimfa$7p4$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bee25966-1d2e-4e8e-85e2-0912c0ad9340n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Fri, 26 Nov 2021 02:05:06 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 60
 by: luserdroog - Fri, 26 Nov 2021 02:05 UTC

On Tuesday, November 23, 2021 at 6:23:14 AM UTC-6, The Natural Philosopher wrote:
> On 23/11/2021 11:22, Ben Bacarisse wrote:
> > luserdroog <luser...@gmail.com> writes:
> >
> >> With a priority queue, at least the ones I looked at, when you create the
> >> queue you pass an ordering function to the constructor. It uses that function
> >> to figure out how to keep your data in order without knowing anything else
> >> about your data. So you can fill it with records and it'll keep everything in
> >> a sorted order, you just have to tell it how to sort 2 of your things.
> >
> > For an abstract priority queue (in the strictest sense) you don't need
> > to keep the queue sorted.
> >
> > I went on the write "In fact, one common implementation uses a heap, as
> > in heap sort" but then I looked at your link and that uses a heap! I
> > would not say that the data in a heap are in sorted order, though it's
> > almost a philosophical point.
> >
> > However, if you need this:
> >
> >> //then when you click play, you can get an array of everything
> >> //in order and run through converting each note to midi events.
> >>
> >> function getNotesArray(){
> >> return notesQueue.toArray()
> >> }
> >
> > Then it might pay (depending on how the notes are generated) to maintain
> > a sorted array. But why is a sorted array needed? Can't whatever uses
> > this queue simply pull the notes off one at a time?
> >
> Haven't been following this, but when I want a sorted queue I use a
> linked list.
> add the new record wherever the allocation scheme puts it, walk te array
> until you find the last element that goes before it, change that
> elements link to pint at it and the new elements link to point where
> that one used to go.
>
> Of all the things I vaguely read up on when studying 'books on compSci'
> this is one of the very few techniques I ended up using.
>
>

Agreed that there might be other data structures that are even better suited
to the task. But I hope I can safely say we all agree that it is a good idea
to abstract this stuff off and make the data structure reasonably self-contained
and isolated from the business logic of the application. Ie. you'd still
interface with the linked list through *functions*, right?

My only qualm about recommending a linked list is that it's simple enough
to present a strong temptation to inline all the functionality and then that
would undermine my whole crusade here.

So, as long as I can spin it to mean that you agree with me on this more
fundamental point, hell yes! vary it up and pick an even better data structure!
But functions.

Everybody must use functions.

You will obey the call of the functions. Do not plug your ears, do not tie
yourself to the mast. Their call must be heeded.

Re: Array object sorted on time, how to deal with.

<66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17440&group=comp.lang.javascript#17440

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:5ccf:: with SMTP id s15mr21723791qta.220.1637893062269;
Thu, 25 Nov 2021 18:17:42 -0800 (PST)
X-Received: by 2002:a05:6830:22cf:: with SMTP id q15mr25296380otc.255.1637893061961;
Thu, 25 Nov 2021 18:17:41 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 25 Nov 2021 18:17:41 -0800 (PST)
In-Reply-To: <878rxff75v.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Fri, 26 Nov 2021 02:17:42 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 48
 by: luserdroog - Fri, 26 Nov 2021 02:17 UTC

On Tuesday, November 23, 2021 at 5:22:44 AM UTC-6, Ben Bacarisse wrote:
> luserdroog <luser...@gmail.com> writes:
>
> > With a priority queue, at least the ones I looked at, when you create the
> > queue you pass an ordering function to the constructor. It uses that function
> > to figure out how to keep your data in order without knowing anything else
> > about your data. So you can fill it with records and it'll keep everything in
> > a sorted order, you just have to tell it how to sort 2 of your things.
> For an abstract priority queue (in the strictest sense) you don't need
> to keep the queue sorted.
>
> I went on the write "In fact, one common implementation uses a heap, as
> in heap sort" but then I looked at your link and that uses a heap! I
> would not say that the data in a heap are in sorted order, though it's
> almost a philosophical point.
>
> However, if you need this:
> > //then when you click play, you can get an array of everything
> > //in order and run through converting each note to midi events.
> >
> > function getNotesArray(){
> > return notesQueue.toArray()
> > }
> Then it might pay (depending on how the notes are generated) to maintain
> a sorted array. But why is a sorted array needed? Can't whatever uses
> this queue simply pull the notes off one at a time?
>

The way I understand the application (but I could be wrong) is that there's
a display of a "piano-roll" grid showing midi notes and when the user
clicks in the grid, we need to locate an existing note by its x coordinate
on screen or create a new note if there isn't one there already. (Dealing
with the x-coordinate here has me thinking there needs to be a scolling
sub-View control that can adjust the x-coordinate to be "global" for the list
rather than just trying to work with the on-screen coordinate.)

Then when the user clicks the 'play' button, a sorted stream of midi on/off
events needs to be sent to the midi player. So we need to maintain a sorted
list or a search tree to locate and manipulate the Model data. (I'm trying to
nudge towards an MVC design "from the other side", if possible). And then
we'll need to iterate through the data structure to create midi events.

But I think there also needs to be another sorting step later on if the midi on/off events
are generated by just running through the list because some notes can be held longer
so in general the on/off events will not automatically come out in time order.

But IMO this part should be isolated to the View code. Unless/until performance
analysis shows it to be a problem, just generate midi on request and throw it away
afterward.

Re: Array object sorted on time, how to deal with.

<luYnJ.71498$Ql5.55123@fx39.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17441&group=comp.lang.javascript#17441

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx39.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Subject: Re: Array object sorted on time, how to deal with.
Content-Language: en-US
Newsgroups: comp.lang.javascript
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
<571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
<58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
<6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk>
<66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
From: Richard@Damon-Family.org (Richard Damon)
In-Reply-To: <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 62
Message-ID: <luYnJ.71498$Ql5.55123@fx39.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 25 Nov 2021 22:27:15 -0500
X-Received-Bytes: 4611
 by: Richard Damon - Fri, 26 Nov 2021 03:27 UTC

On 11/25/21 9:17 PM, luserdroog wrote:
> On Tuesday, November 23, 2021 at 5:22:44 AM UTC-6, Ben Bacarisse wrote:
>> luserdroog <luser...@gmail.com> writes:
>>
>>> With a priority queue, at least the ones I looked at, when you create the
>>> queue you pass an ordering function to the constructor. It uses that function
>>> to figure out how to keep your data in order without knowing anything else
>>> about your data. So you can fill it with records and it'll keep everything in
>>> a sorted order, you just have to tell it how to sort 2 of your things.
>> For an abstract priority queue (in the strictest sense) you don't need
>> to keep the queue sorted.
>>
>> I went on the write "In fact, one common implementation uses a heap, as
>> in heap sort" but then I looked at your link and that uses a heap! I
>> would not say that the data in a heap are in sorted order, though it's
>> almost a philosophical point.
>>
>> However, if you need this:
>>> //then when you click play, you can get an array of everything
>>> //in order and run through converting each note to midi events.
>>>
>>> function getNotesArray(){
>>> return notesQueue.toArray()
>>> }
>> Then it might pay (depending on how the notes are generated) to maintain
>> a sorted array. But why is a sorted array needed? Can't whatever uses
>> this queue simply pull the notes off one at a time?
>>
>
> The way I understand the application (but I could be wrong) is that there's
> a display of a "piano-roll" grid showing midi notes and when the user
> clicks in the grid, we need to locate an existing note by its x coordinate
> on screen or create a new note if there isn't one there already. (Dealing
> with the x-coordinate here has me thinking there needs to be a scolling
> sub-View control that can adjust the x-coordinate to be "global" for the list
> rather than just trying to work with the on-screen coordinate.)
>
> Then when the user clicks the 'play' button, a sorted stream of midi on/off
> events needs to be sent to the midi player. So we need to maintain a sorted
> list or a search tree to locate and manipulate the Model data. (I'm trying to
> nudge towards an MVC design "from the other side", if possible). And then
> we'll need to iterate through the data structure to create midi events.
>
> But I think there also needs to be another sorting step later on if the midi on/off events
> are generated by just running through the list because some notes can be held longer
> so in general the on/off events will not automatically come out in time order.
>
> But IMO this part should be isolated to the View code. Unless/until performance
> analysis shows it to be a problem, just generate midi on request and throw it away
> afterward.
>

I think the key here is that a Note is actual TWO events, a start and a
stop, so you actually want to put TWO (related) items into your search
tree.

This also will have impact into the UI, as a note is not a 'dot' but a
bar, with duration.

Now, it might make sense to have two different representations, one for
the UI and a second for playing, if they need the data enough
differently for the two uses.

Re: Array object sorted on time, how to deal with.

<a05c3058-44fd-4405-965d-1fd6fba5342cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17442&group=comp.lang.javascript#17442

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ad4:5aa4:: with SMTP id u4mr22769489qvg.7.1637900098365;
Thu, 25 Nov 2021 20:14:58 -0800 (PST)
X-Received: by 2002:a9d:2647:: with SMTP id a65mr25496892otb.185.1637900098049;
Thu, 25 Nov 2021 20:14:58 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 25 Nov 2021 20:14:57 -0800 (PST)
In-Reply-To: <luYnJ.71498$Ql5.55123@fx39.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
<luYnJ.71498$Ql5.55123@fx39.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a05c3058-44fd-4405-965d-1fd6fba5342cn@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Fri, 26 Nov 2021 04:14:58 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 92
 by: luserdroog - Fri, 26 Nov 2021 04:14 UTC

On Thursday, November 25, 2021 at 9:27:22 PM UTC-6, Richard Damon wrote:
> On 11/25/21 9:17 PM, luserdroog wrote:
> > On Tuesday, November 23, 2021 at 5:22:44 AM UTC-6, Ben Bacarisse wrote:
> >> luserdroog <luser...@gmail.com> writes:
> >>
> >>> With a priority queue, at least the ones I looked at, when you create the
> >>> queue you pass an ordering function to the constructor. It uses that function
> >>> to figure out how to keep your data in order without knowing anything else
> >>> about your data. So you can fill it with records and it'll keep everything in
> >>> a sorted order, you just have to tell it how to sort 2 of your things.
> >> For an abstract priority queue (in the strictest sense) you don't need
> >> to keep the queue sorted.
> >>
> >> I went on the write "In fact, one common implementation uses a heap, as
> >> in heap sort" but then I looked at your link and that uses a heap! I
> >> would not say that the data in a heap are in sorted order, though it's
> >> almost a philosophical point.
> >>
> >> However, if you need this:
> >>> //then when you click play, you can get an array of everything
> >>> //in order and run through converting each note to midi events.
> >>>
> >>> function getNotesArray(){
> >>> return notesQueue.toArray()
> >>> }
> >> Then it might pay (depending on how the notes are generated) to maintain
> >> a sorted array. But why is a sorted array needed? Can't whatever uses
> >> this queue simply pull the notes off one at a time?
> >>
> >
> > The way I understand the application (but I could be wrong) is that there's
> > a display of a "piano-roll" grid showing midi notes and when the user
> > clicks in the grid, we need to locate an existing note by its x coordinate
> > on screen or create a new note if there isn't one there already. (Dealing
> > with the x-coordinate here has me thinking there needs to be a scolling
> > sub-View control that can adjust the x-coordinate to be "global" for the list
> > rather than just trying to work with the on-screen coordinate.)
> >
> > Then when the user clicks the 'play' button, a sorted stream of midi on/off
> > events needs to be sent to the midi player. So we need to maintain a sorted
> > list or a search tree to locate and manipulate the Model data. (I'm trying to
> > nudge towards an MVC design "from the other side", if possible). And then
> > we'll need to iterate through the data structure to create midi events.
> >
> > But I think there also needs to be another sorting step later on if the midi on/off events
> > are generated by just running through the list because some notes can be held longer
> > so in general the on/off events will not automatically come out in time order.
> >
> > But IMO this part should be isolated to the View code. Unless/until performance
> > analysis shows it to be a problem, just generate midi on request and throw it away
> > afterward.
> >
> I think the key here is that a Note is actual TWO events, a start and a
> stop, so you actually want to put TWO (related) items into your search
> tree.
>
> This also will have impact into the UI, as a note is not a 'dot' but a
> bar, with duration.
>
> Now, it might make sense to have two different representations, one for
> the UI and a second for playing, if they need the data enough
> differently for the two uses.

Yes, I think the separation into two representation would offer benefits
later on. In particular, there could be an "articulation" control to add gaps
between successive notes, ranging from "tenuto" with just enough
separation so repeating the same note sounds distinct up through
"staccato" to "marcato" or some fun extreme term.

Having a conversion step makes a natural place to add effects like
this or even more mundane stuff like globally transposing all the notes.

It also helps (I hope) encapsulate the "master data structure" and
abstract away other data that can be easily generated as needed.
Because OP already has code, a mostly working program AIUI.
To be enticing to him, it should ... hmm. Maybe I shouldn't pretend
to know the answer to that.

But yes, the midi stream is organized as a stream of events that can
be "Note On", "Note Off", or "Control Change ..." (for stuff like the
position of the bender if it's moving, or selecting a GM sound on a
channel). All of these are prefixed with a relative time-offset IIRC
in a variable-length integer format where the 7th bit On indicates
the last byte. I'm note sure how much of this is needed by the midi
player. It probably can process the integer for you.

I wrote a program years ago that created midi files using a
line oriented input format (it even required an "END" line at the
end or it wouldn't work). It read in data for several channels
separately and then had sort the list of events because even
though each channel was sequential, the several channels
together were supposed to be interleaved.

Re: Array object sorted on time, how to deal with.

<ea2145bd-16de-4194-abd9-b1f0452f9271n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17443&group=comp.lang.javascript#17443

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:4495:: with SMTP id x21mr11517445qkp.633.1637901712117;
Thu, 25 Nov 2021 20:41:52 -0800 (PST)
X-Received: by 2002:a05:6830:3499:: with SMTP id c25mr26865469otu.206.1637901711864;
Thu, 25 Nov 2021 20:41:51 -0800 (PST)
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 25 Nov 2021 20:41:51 -0800 (PST)
In-Reply-To: <luYnJ.71498$Ql5.55123@fx39.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
<luYnJ.71498$Ql5.55123@fx39.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ea2145bd-16de-4194-abd9-b1f0452f9271n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Fri, 26 Nov 2021 04:41:52 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 65
 by: Jonas Thörnvall - Fri, 26 Nov 2021 04:41 UTC

fredag 26 november 2021 kl. 04:27:22 UTC+1 skrev Richard Damon:
> On 11/25/21 9:17 PM, luserdroog wrote:
> > On Tuesday, November 23, 2021 at 5:22:44 AM UTC-6, Ben Bacarisse wrote:
> >> luserdroog <luser...@gmail.com> writes:
> >>
> >>> With a priority queue, at least the ones I looked at, when you create the
> >>> queue you pass an ordering function to the constructor. It uses that function
> >>> to figure out how to keep your data in order without knowing anything else
> >>> about your data. So you can fill it with records and it'll keep everything in
> >>> a sorted order, you just have to tell it how to sort 2 of your things.
> >> For an abstract priority queue (in the strictest sense) you don't need
> >> to keep the queue sorted.
> >>
> >> I went on the write "In fact, one common implementation uses a heap, as
> >> in heap sort" but then I looked at your link and that uses a heap! I
> >> would not say that the data in a heap are in sorted order, though it's
> >> almost a philosophical point.
> >>
> >> However, if you need this:
> >>> //then when you click play, you can get an array of everything
> >>> //in order and run through converting each note to midi events.
> >>>
> >>> function getNotesArray(){
> >>> return notesQueue.toArray()
> >>> }
> >> Then it might pay (depending on how the notes are generated) to maintain
> >> a sorted array. But why is a sorted array needed? Can't whatever uses
> >> this queue simply pull the notes off one at a time?
> >>
> >
> > The way I understand the application (but I could be wrong) is that there's
> > a display of a "piano-roll" grid showing midi notes and when the user
> > clicks in the grid, we need to locate an existing note by its x coordinate
> > on screen or create a new note if there isn't one there already. (Dealing
> > with the x-coordinate here has me thinking there needs to be a scolling
> > sub-View control that can adjust the x-coordinate to be "global" for the list
> > rather than just trying to work with the on-screen coordinate.)
> >
> > Then when the user clicks the 'play' button, a sorted stream of midi on/off
> > events needs to be sent to the midi player. So we need to maintain a sorted
> > list or a search tree to locate and manipulate the Model data. (I'm trying to
> > nudge towards an MVC design "from the other side", if possible). And then
> > we'll need to iterate through the data structure to create midi events.
> >
> > But I think there also needs to be another sorting step later on if the midi on/off events
> > are generated by just running through the list because some notes can be held longer
> > so in general the on/off events will not automatically come out in time order.
> >
> > But IMO this part should be isolated to the View code. Unless/until performance
> > analysis shows it to be a problem, just generate midi on request and throw it away
> > afterward.
> >
> I think the key here is that a Note is actual TWO events, a start and a
> stop, so you actually want to put TWO (related) items into your search
> tree.
>
> This also will have impact into the UI, as a note is not a 'dot' but a
> bar, with duration.
>
> Now, it might make sense to have two different representations, one for
> the UI and a second for playing, if they need the data enough
> differently for the two uses.

Depending on "note duration ***time***", "BPM" and "number of BARS" the presented note have a dimension. So basicly UI note is just a length calculated using those three factors.
But one can not forget that it is one more factor to consider It all take place within a range, that range have the length of "number of bars visible" but the start and end must be used to know where to draw note.

Re: Array object sorted on time, how to deal with.

<4978d88f-73bc-461d-9d10-b5d0cf1b96d3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17444&group=comp.lang.javascript#17444

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6214:d84:: with SMTP id e4mr10656240qve.128.1637902966994;
Thu, 25 Nov 2021 21:02:46 -0800 (PST)
X-Received: by 2002:a05:6830:22cf:: with SMTP id q15mr25891653otc.255.1637902966758;
Thu, 25 Nov 2021 21:02:46 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 25 Nov 2021 21:02:46 -0800 (PST)
In-Reply-To: <a05c3058-44fd-4405-965d-1fd6fba5342cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
<luYnJ.71498$Ql5.55123@fx39.iad> <a05c3058-44fd-4405-965d-1fd6fba5342cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4978d88f-73bc-461d-9d10-b5d0cf1b96d3n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Fri, 26 Nov 2021 05:02:46 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 101
 by: Jonas Thörnvall - Fri, 26 Nov 2021 05:02 UTC

fredag 26 november 2021 kl. 05:15:03 UTC+1 skrev luser...@gmail.com:
> On Thursday, November 25, 2021 at 9:27:22 PM UTC-6, Richard Damon wrote:
> > On 11/25/21 9:17 PM, luserdroog wrote:
> > > On Tuesday, November 23, 2021 at 5:22:44 AM UTC-6, Ben Bacarisse wrote:
> > >> luserdroog <luser...@gmail.com> writes:
> > >>
> > >>> With a priority queue, at least the ones I looked at, when you create the
> > >>> queue you pass an ordering function to the constructor. It uses that function
> > >>> to figure out how to keep your data in order without knowing anything else
> > >>> about your data. So you can fill it with records and it'll keep everything in
> > >>> a sorted order, you just have to tell it how to sort 2 of your things.
> > >> For an abstract priority queue (in the strictest sense) you don't need
> > >> to keep the queue sorted.
> > >>
> > >> I went on the write "In fact, one common implementation uses a heap, as
> > >> in heap sort" but then I looked at your link and that uses a heap! I
> > >> would not say that the data in a heap are in sorted order, though it's
> > >> almost a philosophical point.
> > >>
> > >> However, if you need this:
> > >>> //then when you click play, you can get an array of everything
> > >>> //in order and run through converting each note to midi events.
> > >>>
> > >>> function getNotesArray(){
> > >>> return notesQueue.toArray()
> > >>> }
> > >> Then it might pay (depending on how the notes are generated) to maintain
> > >> a sorted array. But why is a sorted array needed? Can't whatever uses
> > >> this queue simply pull the notes off one at a time?
> > >>
> > >
> > > The way I understand the application (but I could be wrong) is that there's
> > > a display of a "piano-roll" grid showing midi notes and when the user
> > > clicks in the grid, we need to locate an existing note by its x coordinate
> > > on screen or create a new note if there isn't one there already. (Dealing
> > > with the x-coordinate here has me thinking there needs to be a scolling
> > > sub-View control that can adjust the x-coordinate to be "global" for the list
> > > rather than just trying to work with the on-screen coordinate.)
> > >
> > > Then when the user clicks the 'play' button, a sorted stream of midi on/off
> > > events needs to be sent to the midi player. So we need to maintain a sorted
> > > list or a search tree to locate and manipulate the Model data. (I'm trying to
> > > nudge towards an MVC design "from the other side", if possible). And then
> > > we'll need to iterate through the data structure to create midi events.
> > >
> > > But I think there also needs to be another sorting step later on if the midi on/off events
> > > are generated by just running through the list because some notes can be held longer
> > > so in general the on/off events will not automatically come out in time order.
> > >
> > > But IMO this part should be isolated to the View code. Unless/until performance
> > > analysis shows it to be a problem, just generate midi on request and throw it away
> > > afterward.
> > >
> > I think the key here is that a Note is actual TWO events, a start and a
> > stop, so you actually want to put TWO (related) items into your search
> > tree.
> >
> > This also will have impact into the UI, as a note is not a 'dot' but a
> > bar, with duration.
> >
> > Now, it might make sense to have two different representations, one for
> > the UI and a second for playing, if they need the data enough
> > differently for the two uses.
> Yes, I think the separation into two representation would offer benefits
> later on. In particular, there could be an "articulation" control to add gaps
> between successive notes, ranging from "tenuto" with just enough
> separation so repeating the same note sounds distinct up through
> "staccato" to "marcato" or some fun extreme term.
>
> Having a conversion step makes a natural place to add effects like
> this or even more mundane stuff like globally transposing all the notes.
>
> It also helps (I hope) encapsulate the "master data structure" and
> abstract away other data that can be easily generated as needed.
> Because OP already has code, a mostly working program AIUI.
> To be enticing to him, it should ... hmm. Maybe I shouldn't pretend
> to know the answer to that.
>
> But yes, the midi stream is organized as a stream of events that can
> be "Note On", "Note Off", or "Control Change ..." (for stuff like the
> position of the bender if it's moving, or selecting a GM sound on a
> channel). All of these are prefixed with a relative time-offset IIRC
> in a variable-length integer format where the 7th bit On indicates
> the last byte. I'm note sure how much of this is needed by the midi
> player. It probably can process the integer for you.
>
> I wrote a program years ago that created midi files using a
> line oriented input format (it even required an "END" line at the
> end or it wouldn't work). It read in data for several channels
> separately and then had sort the list of events because even
> though each channel was sequential, the several channels
> together were supposed to be interleaved.

I am not sure what you mean with interleaved, the tracks are separate entities holding a full song if you so want "using all/any channels".
Midi is a bit confusing because channel is just a 7 bit "within a 4 bit range" that also signify note on and off depending which 4 bit range 0-127 you use.
So having an interleaved? structure for playup is not meaningful, you downmix "all events" to a track i use ZERO and then just que them.
The separation is just value interpretation by the module.

It is a varialble length format that is decided on the first "byte" 7-bit value. So i think hardware wise is rather complex to implement, i really hate the format LoL
So i use tone.js that make some json objects that is easier to read out "partse" import from, but the sequenser use my own format to store sequensing data.

The bitfiddling making original midi implementation would be endless... will not do that again.

Re: Array object sorted on time, how to deal with.

<044df0de-229f-4768-b1c9-697df73f377cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17445&group=comp.lang.javascript#17445

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a37:8d86:: with SMTP id p128mr12036671qkd.706.1637903200700;
Thu, 25 Nov 2021 21:06:40 -0800 (PST)
X-Received: by 2002:a9d:2486:: with SMTP id z6mr26635419ota.210.1637903200478;
Thu, 25 Nov 2021 21:06:40 -0800 (PST)
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 25 Nov 2021 21:06:40 -0800 (PST)
In-Reply-To: <luYnJ.71498$Ql5.55123@fx39.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.164.86; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.164.86
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
<luYnJ.71498$Ql5.55123@fx39.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <044df0de-229f-4768-b1c9-697df73f377cn@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Fri, 26 Nov 2021 05:06:40 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 63
 by: Jonas Thörnvall - Fri, 26 Nov 2021 05:06 UTC

fredag 26 november 2021 kl. 04:27:22 UTC+1 skrev Richard Damon:
> On 11/25/21 9:17 PM, luserdroog wrote:
> > On Tuesday, November 23, 2021 at 5:22:44 AM UTC-6, Ben Bacarisse wrote:
> >> luserdroog <luser...@gmail.com> writes:
> >>
> >>> With a priority queue, at least the ones I looked at, when you create the
> >>> queue you pass an ordering function to the constructor. It uses that function
> >>> to figure out how to keep your data in order without knowing anything else
> >>> about your data. So you can fill it with records and it'll keep everything in
> >>> a sorted order, you just have to tell it how to sort 2 of your things.
> >> For an abstract priority queue (in the strictest sense) you don't need
> >> to keep the queue sorted.
> >>
> >> I went on the write "In fact, one common implementation uses a heap, as
> >> in heap sort" but then I looked at your link and that uses a heap! I
> >> would not say that the data in a heap are in sorted order, though it's
> >> almost a philosophical point.
> >>
> >> However, if you need this:
> >>> //then when you click play, you can get an array of everything
> >>> //in order and run through converting each note to midi events.
> >>>
> >>> function getNotesArray(){
> >>> return notesQueue.toArray()
> >>> }
> >> Then it might pay (depending on how the notes are generated) to maintain
> >> a sorted array. But why is a sorted array needed? Can't whatever uses
> >> this queue simply pull the notes off one at a time?
> >>
> >
> > The way I understand the application (but I could be wrong) is that there's
> > a display of a "piano-roll" grid showing midi notes and when the user
> > clicks in the grid, we need to locate an existing note by its x coordinate
> > on screen or create a new note if there isn't one there already. (Dealing
> > with the x-coordinate here has me thinking there needs to be a scolling
> > sub-View control that can adjust the x-coordinate to be "global" for the list
> > rather than just trying to work with the on-screen coordinate.)
> >
> > Then when the user clicks the 'play' button, a sorted stream of midi on/off
> > events needs to be sent to the midi player. So we need to maintain a sorted
> > list or a search tree to locate and manipulate the Model data. (I'm trying to
> > nudge towards an MVC design "from the other side", if possible). And then
> > we'll need to iterate through the data structure to create midi events.
> >
> > But I think there also needs to be another sorting step later on if the midi on/off events
> > are generated by just running through the list because some notes can be held longer
> > so in general the on/off events will not automatically come out in time order.
> >
> > But IMO this part should be isolated to the View code. Unless/until performance
> > analysis shows it to be a problem, just generate midi on request and throw it away
> > afterward.
> >
> I think the key here is that a Note is actual TWO events, a start and a
> stop, so you actually want to put TWO (related) items into your search
> tree.
>
> This also will have impact into the UI, as a note is not a 'dot' but a
> bar, with duration.
>
> Now, it might make sense to have two different representations, one for
> the UI and a second for playing, if they need the data enough
> differently for the two uses.
Well i generate UI data during playback, so there is no UI structure to store it either in "view/edit, play or record" it is generated as needed from the recorded file data.
You could say it is a data view with a range.

Re: Array object sorted on time, how to deal with.

<snr8d4$vmj$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17446&group=comp.lang.javascript#17446

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: niam@jghnorth.org.uk.invalid (John Harris)
Newsgroups: comp.lang.javascript
Subject: Re: Array object sorted on time, how to deal with.
Date: Fri, 26 Nov 2021 18:18:11 +0000
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <snr8d4$vmj$1@dont-email.me>
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com>
<571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com>
<58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com>
<6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <snimfa$7p4$1@dont-email.me>
<bee25966-1d2e-4e8e-85e2-0912c0ad9340n@googlegroups.com>
Reply-To: jgharris@ic4life.net
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 26 Nov 2021 18:18:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="957f49f44fe5dc3206654cc9c199b637";
logging-data="32467"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PeWmV/GViqdDEhrQ+/X21MYRuBwv269w="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:QnsWe8wU2hw5pQRGFG6mPaMgM78=
In-Reply-To: <bee25966-1d2e-4e8e-85e2-0912c0ad9340n@googlegroups.com>
Content-Language: en-US
 by: John Harris - Fri, 26 Nov 2021 18:18 UTC

On 26/11/2021 02:05, luserdroog wrote:

<snip>> Agreed that there might be other data structures that are
even better suited
> to the task. But I hope I can safely say we all agree that it is a good idea
> to abstract this stuff off and make the data structure reasonably self-contained
> and isolated from the business logic of the application. Ie. you'd still
> interface with the linked list through *functions*, right?
<snip>

It's an object, so when you say *functions* you really mean *method
function*, right?

John

Re: Array object sorted on time, how to deal with.

<542db347-0e59-4297-bc56-9bc77ebd7214n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17447&group=comp.lang.javascript#17447

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:a50:: with SMTP id j16mr17391306qka.766.1637971342470;
Fri, 26 Nov 2021 16:02:22 -0800 (PST)
X-Received: by 2002:a9d:8e9:: with SMTP id 96mr32406894otf.192.1637971342128;
Fri, 26 Nov 2021 16:02:22 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 26 Nov 2021 16:02:21 -0800 (PST)
In-Reply-To: <snr8d4$vmj$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <snimfa$7p4$1@dont-email.me> <bee25966-1d2e-4e8e-85e2-0912c0ad9340n@googlegroups.com>
<snr8d4$vmj$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <542db347-0e59-4297-bc56-9bc77ebd7214n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Sat, 27 Nov 2021 00:02:22 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 36
 by: luserdroog - Sat, 27 Nov 2021 00:02 UTC

On Friday, November 26, 2021 at 12:18:20 PM UTC-6, John Harris wrote:
> On 26/11/2021 02:05, luserdroog wrote:
>
> <snip>> Agreed that there might be other data structures that are
> even better suited
> > to the task. But I hope I can safely say we all agree that it is a good idea
> > to abstract this stuff off and make the data structure reasonably self-contained
> > and isolated from the business logic of the application. Ie. you'd still
> > interface with the linked list through *functions*, right?
> <snip>
>
> It's an object, so when you say *functions* you really mean *method
> function*, right?
>
> John

They could certainly be method functions. And if we're borrowing the
implementation from somewhere on the web then it's almost certain
to be built with method functions. But I don't consider it a hard line.
If Jonas finds it easier to do with normal (global) functions, then that
still fits with my programme.

Either using methods or just plain functions, both should have the
benefit of eliminating code duplication and reducing the size of
existing functions.

I think this all falls under the DRY (Don't Repeat Yourself) principle.

If you have the same (or similar) code in more than one place,
then sooner or later you're going to forget to change one spot
when it needs to change.

But if the code is in one place, one function, and everything calls
that function instead of using inline code, then you have just
one place to change. Doing this consistently can eliminate a
whole class of bugs that just waste your time (and rob the world
of the results of your creativity).

Re: Array object sorted on time, how to deal with.

<aa48d471-d3f9-4434-ae43-d8c57a797942n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17448&group=comp.lang.javascript#17448

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:4495:: with SMTP id x21mr16957647qkp.633.1637972284760;
Fri, 26 Nov 2021 16:18:04 -0800 (PST)
X-Received: by 2002:aca:2103:: with SMTP id 3mr3988320oiz.48.1637972284489;
Fri, 26 Nov 2021 16:18:04 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 26 Nov 2021 16:18:04 -0800 (PST)
In-Reply-To: <4978d88f-73bc-461d-9d10-b5d0cf1b96d3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <dcf606f5-10c9-432c-aee1-152d5fd997ban@googlegroups.com>
<daf9ffa9-4e7a-43ba-aac6-69c655253e59n@googlegroups.com> <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com>
<5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com>
<daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com>
<878rxff75v.fsf@bsb.me.uk> <66ff0bde-6587-4284-9f8d-ee93a585b7d5n@googlegroups.com>
<luYnJ.71498$Ql5.55123@fx39.iad> <a05c3058-44fd-4405-965d-1fd6fba5342cn@googlegroups.com>
<4978d88f-73bc-461d-9d10-b5d0cf1b96d3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <aa48d471-d3f9-4434-ae43-d8c57a797942n@googlegroups.com>
Subject: Re: Array object sorted on time, how to deal with.
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Sat, 27 Nov 2021 00:18:04 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 96
 by: luserdroog - Sat, 27 Nov 2021 00:18 UTC

On Thursday, November 25, 2021 at 11:02:52 PM UTC-6, jonas.t...@gmail.com wrote:
> fredag 26 november 2021 kl. 05:15:03 UTC+1 skrev luser...@gmail.com:
> > On Thursday, November 25, 2021 at 9:27:22 PM UTC-6, Richard Damon wrote:
> > > On 11/25/21 9:17 PM, luserdroog wrote:
> > > > The way I understand the application (but I could be wrong) is that there's
> > > > a display of a "piano-roll" grid showing midi notes and when the user
> > > > clicks in the grid, we need to locate an existing note by its x coordinate
> > > > on screen or create a new note if there isn't one there already. (Dealing
> > > > with the x-coordinate here has me thinking there needs to be a scolling
> > > > sub-View control that can adjust the x-coordinate to be "global" for the list
> > > > rather than just trying to work with the on-screen coordinate.)
> > > >
> > > > Then when the user clicks the 'play' button, a sorted stream of midi on/off
> > > > events needs to be sent to the midi player. So we need to maintain a sorted
> > > > list or a search tree to locate and manipulate the Model data. (I'm trying to
> > > > nudge towards an MVC design "from the other side", if possible). And then
> > > > we'll need to iterate through the data structure to create midi events.
> > > >
> > > > But I think there also needs to be another sorting step later on if the midi on/off events
> > > > are generated by just running through the list because some notes can be held longer
> > > > so in general the on/off events will not automatically come out in time order.
> > > >
> > > > But IMO this part should be isolated to the View code. Unless/until performance
> > > > analysis shows it to be a problem, just generate midi on request and throw it away
> > > > afterward.
> > > >
> > > I think the key here is that a Note is actual TWO events, a start and a
> > > stop, so you actually want to put TWO (related) items into your search
> > > tree.
> > >
> > > This also will have impact into the UI, as a note is not a 'dot' but a
> > > bar, with duration.
> > >
> > > Now, it might make sense to have two different representations, one for
> > > the UI and a second for playing, if they need the data enough
> > > differently for the two uses.
> > Yes, I think the separation into two representation would offer benefits
> > later on. In particular, there could be an "articulation" control to add gaps
> > between successive notes, ranging from "tenuto" with just enough
> > separation so repeating the same note sounds distinct up through
> > "staccato" to "marcato" or some fun extreme term.
> >
> > Having a conversion step makes a natural place to add effects like
> > this or even more mundane stuff like globally transposing all the notes.
> >
> > It also helps (I hope) encapsulate the "master data structure" and
> > abstract away other data that can be easily generated as needed.
> > Because OP already has code, a mostly working program AIUI.
> > To be enticing to him, it should ... hmm. Maybe I shouldn't pretend
> > to know the answer to that.
> >
> > But yes, the midi stream is organized as a stream of events that can
> > be "Note On", "Note Off", or "Control Change ..." (for stuff like the
> > position of the bender if it's moving, or selecting a GM sound on a
> > channel). All of these are prefixed with a relative time-offset IIRC
> > in a variable-length integer format where the 7th bit On indicates
> > the last byte. I'm note sure how much of this is needed by the midi
> > player. It probably can process the integer for you.
> >
> > I wrote a program years ago that created midi files using a
> > line oriented input format (it even required an "END" line at the
> > end or it wouldn't work). It read in data for several channels
> > separately and then had sort the list of events because even
> > though each channel was sequential, the several channels
> > together were supposed to be interleaved.
> I am not sure what you mean with interleaved, the tracks are separate entities holding a full song if you so want "using all/any channels".
> Midi is a bit confusing because channel is just a 7 bit "within a 4 bit range" that also signify note on and off depending which 4 bit range 0-127 you use.
> So having an interleaved? structure for playup is not meaningful, you downmix "all events" to a track i use ZERO and then just que them.
> The separation is just value interpretation by the module.

Yeah. My program wasn't great. It was the first "big" program
I tried to write on my own over the summer after my first college
programming course. I think I had recently discover wotsit.org

https://web.archive.org/web/20080220223430/http://www.wotsit.org/

So getting into some binary data formatting, and saving myself the
$200 price tag for a drum machine were my motivations. It was more
like a midi Assembler with mnemonics for adjusting stuff (ppp, pp, p, f, ff, fff, ffff).
So to actually make "loops" or patterns, I made a separate macro expander
program that could repeat phrases multiple times.
And that's what led to the multiple sequences getting interleaved.
If I made a macro for an 8 beat bassline riff, then expanding that
would put me at some non-zero offset from the start of the song.
If I wanted a 2-bar melody riff to go over the top of the bassline, then
I would use a mnemonic that reset the time for subsequent notes.
So, they're more like multiple "voices" and not channels. I could
select which channel the notes would be assigned to but they
were usually just 1, 2 (,maybe 3), and 10 (the General Midi drum channel).

> It is a varialble length format that is decided on the first "byte" 7-bit value. So i think hardware wise is rather complex to implement, i really hate the format LoL
> So i use tone.js that make some json objects that is easier to read out "partse" import from, but the sequenser use my own format to store sequensing data.
>
> The bitfiddling making original midi implementation would be endless... will not do that again.

Good deal. So you've already got a tool that handles the integer business.
I was hoping that was the case.


devel / comp.lang.javascript / Array object sorted on time, how to deal with.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor