Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"This isn't brain surgery; it's just television." -- David Letterman


devel / comp.lang.javascript / sidetrack

SubjectAuthor
* sidetrackluserdroog
+* Re: sidetrackMichael Haufe (TNO)
|`* Re: sidetrackluserdroog
| `* Re: sidetrackluserdroog
|  +* Re: sidetrackMichael Haufe (TNO)
|  |`* Re: sidetrackluserdroog
|  | +- Re: sidetrackluserdroog
|  | `- Re: sidetrackScott Sauyet
|  `* Re: sidetrackElhwen Dico
|   +- Re: sidetrackElhwen Dico
|   `* Re: sidetrackThomas 'PointedEars' Lahn
|    `- Re: sidetrackJulio Di Egidio
`- Re: sidetrackluserdroog

1
sidetrack

<06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a37:aad3:: with SMTP id t202mr3683360qke.458.1638931327724;
Tue, 07 Dec 2021 18:42:07 -0800 (PST)
X-Received: by 2002:a05:6830:22cf:: with SMTP id q15mr38369792otc.255.1638931327385;
Tue, 07 Dec 2021 18:42:07 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 7 Dec 2021 18:42:07 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
Subject: sidetrack
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Wed, 08 Dec 2021 02:42:07 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2809
 by: luserdroog - Wed, 8 Dec 2021 02:42 UTC

I'm making some progress at reconceiving my pianoroll app
to be a more coherent object based design. But also kinda
not making progress on it. I doodled up a sketch of the overall
structure of the MVC example but instead of working on that,
here's a "robust" function for decoding note names from letters
and producing a MIDI note number.

It uses two minor tetrachords to construct the intervals of an
aeolian scale then takes a running sum to get "fretstops" for
each of the scale degrees. Then you index the resulting array
with 0 for 'a', 1 for 'b' etc, a little more twiddling and poof kazow
presto! The desired number comes out the other end.

Is there a better way to do the running_sum()? I was trying to
do an APL "scan" and doing a reduce() while building the result
backwards was the best I could come up with.

const major_tetrachord = [ 2, 2, 1 ];
const mixolydian_mode = [ ...major_tetrachord,
...major_tetrachord,
2 ];
const minor_tetrachord = [ 2, 1, 2 ];
const aeolian_mode = [ ...minor_tetrachord,
...minor_tetrachord ];
const scale = [ ...mixolydian_mode,
...mixolydian_mode,
...major_tetrachord ];

function running_sum( a ){
return a.reduce( (pre,cur)=>[ cur+pre[0], ...pre ], [0] ).reverse();
} console.log(running_sum(aeolian_mode));
console.log(running_sum(scale));

function note( str, octave=0 ){
var num = str.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0);
var fromA = running_sum(aeolian_mode)[ num ] +
(str.length > 1 ? (str[1]=='#' ? 1 : -1)
: 0);
var fromC = fromA + 9;
return octave*12 + (fromC >= 12 ? fromC - 12 : fromC);
}

console.log(note("a",0));
console.log(note("c#",0));
console.log(note("eb",0));

Re: sidetrack

<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:59c9:: with SMTP id f9mr10986998qtf.581.1638997426070;
Wed, 08 Dec 2021 13:03:46 -0800 (PST)
X-Received: by 2002:a4a:8902:: with SMTP id f2mr898814ooi.59.1638997417587;
Wed, 08 Dec 2021 13:03:37 -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: Wed, 8 Dec 2021 13:03:37 -0800 (PST)
In-Reply-To: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:6000:8900:6915:9075:737:a4af:dd5b;
posting-account=hYRygAoAAABkmvJVmPilz9Q1TOjgPQAq
NNTP-Posting-Host: 2603:6000:8900:6915:9075:737:a4af:dd5b
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com>
Subject: Re: sidetrack
From: tno@thenewobjective.com (Michael Haufe (TNO))
Injection-Date: Wed, 08 Dec 2021 21:03:46 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 8
 by: Michael Haufe (TNO) - Wed, 8 Dec 2021 21:03 UTC

On Tuesday, December 7, 2021 at 8:42:11 PM UTC-6, luser...@gmail.com wrote:

> Is there a better way to do the running_sum()? I was trying to
> do an APL "scan" and doing a reduce() while building the result
> backwards was the best I could come up with.

A `reduceRight` method exists on arrays:

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight>

Re: sidetrack

<f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ae9:e507:: with SMTP id w7mr10077400qkf.328.1639009021827;
Wed, 08 Dec 2021 16:17:01 -0800 (PST)
X-Received: by 2002:aca:2103:: with SMTP id 3mr2908708oiz.48.1639009021442;
Wed, 08 Dec 2021 16:17:01 -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: Wed, 8 Dec 2021 16:17:01 -0800 (PST)
In-Reply-To: <93cb03fa-9811-4e19-8469-6e0a0b9cae19n@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: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com> <93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
Subject: Re: sidetrack
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Thu, 09 Dec 2021 00:17:01 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 25
 by: luserdroog - Thu, 9 Dec 2021 00:17 UTC

On Wednesday, December 8, 2021 at 3:03:49 PM UTC-6, Michael Haufe (TNO) wrote:
> On Tuesday, December 7, 2021 at 8:42:11 PM UTC-6, luser...@gmail.com wrote:
>
> > Is there a better way to do the running_sum()? I was trying to
> > do an APL "scan" and doing a reduce() while building the result
> > backwards was the best I could come up with.
> A `reduceRight` method exists on arrays:
>
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight>

Hmm. The parameter names make that seem like the right choice. At least it gives
you an `accumulator`. But on closer inspection, reverse()'s `previousValue` behaves
exactly the same, and might have been (better IMO) called *accumulator*, too.

I could do it without reversing by just pushing each intermediate result (that's all
an APL scan is: an array of the intermediate results from a reduce operation, probably
ought to have defined it more precisely in OP).

function running_sum( a ){
var t = [];
a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur} );
return t;
}

It's not a "one liner", but this is probably a bit more efficient AFAICT.
In APL, it's just `+\`.

Re: sidetrack

<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6214:20a8:: with SMTP id 8mr12414203qvd.85.1639009385035;
Wed, 08 Dec 2021 16:23:05 -0800 (PST)
X-Received: by 2002:a05:6808:1396:: with SMTP id c22mr2927634oiw.59.1639009384771;
Wed, 08 Dec 2021 16:23: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: Wed, 8 Dec 2021 16:23:04 -0800 (PST)
In-Reply-To: <f38be122-740c-448e-b9d4-3691bcad8964n@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: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com> <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
Subject: Re: sidetrack
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Thu, 09 Dec 2021 00:23:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 16
 by: luserdroog - Thu, 9 Dec 2021 00:23 UTC

On Wednesday, December 8, 2021 at 6:17:07 PM UTC-6, luserdroog wrote:

> function running_sum( a ){
> var t = [];
> a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur}

, 0

> );
> return t;
> }
>
> It's not a "one liner", but this is probably a bit more efficient AFAICT.
> In APL, it's just `+\`.

Need to use initial value zero (or prepend the original first element).
I really think that's right, now.

Re: sidetrack

<b94ff525-ca41-4574-a77d-da1f7c37fbd2n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:454:: with SMTP id o20mr14410616qtx.633.1639028307036;
Wed, 08 Dec 2021 21:38:27 -0800 (PST)
X-Received: by 2002:aca:2205:: with SMTP id b5mr3756418oic.177.1639028306663;
Wed, 08 Dec 2021 21:38:26 -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: Wed, 8 Dec 2021 21:38:26 -0800 (PST)
In-Reply-To: <692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:6000:8900:6915:2891:539c:67d4:af19;
posting-account=hYRygAoAAABkmvJVmPilz9Q1TOjgPQAq
NNTP-Posting-Host: 2603:6000:8900:6915:2891:539c:67d4:af19
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com> <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b94ff525-ca41-4574-a77d-da1f7c37fbd2n@googlegroups.com>
Subject: Re: sidetrack
From: tno@thenewobjective.com (Michael Haufe (TNO))
Injection-Date: Thu, 09 Dec 2021 05:38:27 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 22
 by: Michael Haufe (TNO) - Thu, 9 Dec 2021 05:38 UTC

On Wednesday, December 8, 2021 at 6:23:12 PM UTC-6, luser...@gmail.com wrote:
> On Wednesday, December 8, 2021 at 6:17:07 PM UTC-6, luserdroog wrote:
>
> > function running_sum( a ){
> > var t = [];
> > a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur}
> , 0
> > );
> > return t;
> > }
> >
> > It's not a "one liner", but this is probably a bit more efficient AFAICT.
> > In APL, it's just `+\`.
> Need to use initial value zero (or prepend the original first element).
> I really think that's right, now.

functionally:

const add = (left, right) => left + right

const sum = (xs) => xs.reduce(add,0)

sum([1,2,3,4,5]) // 15

Re: sidetrack

<a01b7437-266b-47a5-90b3-6818a59ee7c1n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6214:29e9:: with SMTP id jv9mr21715121qvb.67.1639100358039;
Thu, 09 Dec 2021 17:39:18 -0800 (PST)
X-Received: by 2002:a9d:4f0b:: with SMTP id d11mr8897806otl.227.1639100357618;
Thu, 09 Dec 2021 17:39:17 -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, 9 Dec 2021 17:39:17 -0800 (PST)
In-Reply-To: <b94ff525-ca41-4574-a77d-da1f7c37fbd2n@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: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com> <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com> <b94ff525-ca41-4574-a77d-da1f7c37fbd2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a01b7437-266b-47a5-90b3-6818a59ee7c1n@googlegroups.com>
Subject: Re: sidetrack
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Fri, 10 Dec 2021 01:39:18 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 54
 by: luserdroog - Fri, 10 Dec 2021 01:39 UTC

On Wednesday, December 8, 2021 at 11:38:30 PM UTC-6, Michael Haufe (TNO) wrote:
> On Wednesday, December 8, 2021 at 6:23:12 PM UTC-6, luser...@gmail.com wrote:
> > On Wednesday, December 8, 2021 at 6:17:07 PM UTC-6, luserdroog wrote:
> >
> > > function running_sum( a ){
> > > var t = [];
> > > a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur}
> > , 0
> > > );
> > > return t;
> > > }
> > >
> > > It's not a "one liner", but this is probably a bit more efficient AFAICT.
> > > In APL, it's just `+\`.
> > Need to use initial value zero (or prepend the original first element).
> > I really think that's right, now.
> functionally:
>
> const add = (left, right) => left + right
>
> const sum = (xs) => xs.reduce(add,0)
>
> sum([1,2,3,4,5]) // 15

That does an APL reduce (coincidentally named) which looks like:

+/

But I'm after the subtly different function does a "scan" or piece-wise
reduce. In APL, it's almost imperceptibly different:

+\

(There's a joke that APL\360 was named with the backslash character
in there so the product name means "APL extends 360" if treated as
an APL program. \ means "extend" if the left and right are values, but
in the snippets under consideration \ means "scan" because the left
(+) is a function and not a value. I will endeavor to stop talking about
APL after this message.)
To be more functional, I think it would look like this:

Array.prototype.scan = function( f ){
return this.map( (e,i,a)=>a.slice(0,i+1).reduce(f,0) );
} const add = (left,right) => left + right

function running_sum( a ){
return [ 0, ...a.scan( add )];
}

(I forgot I also needed the result of running_sum() to start with a zero,
in addition to the zero that gets fed to reduce() to ensure the first
element of the input array shows up in the output array.)

Re: sidetrack

<54d48386-efba-4696-b99d-eaf8f7d152cdn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ad4:5aeb:: with SMTP id c11mr22402899qvh.69.1639100675418;
Thu, 09 Dec 2021 17:44:35 -0800 (PST)
X-Received: by 2002:aca:2103:: with SMTP id 3mr9949120oiz.48.1639100675053;
Thu, 09 Dec 2021 17:44:35 -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, 9 Dec 2021 17:44:34 -0800 (PST)
In-Reply-To: <a01b7437-266b-47a5-90b3-6818a59ee7c1n@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: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com> <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com> <b94ff525-ca41-4574-a77d-da1f7c37fbd2n@googlegroups.com>
<a01b7437-266b-47a5-90b3-6818a59ee7c1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <54d48386-efba-4696-b99d-eaf8f7d152cdn@googlegroups.com>
Subject: Re: sidetrack
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Fri, 10 Dec 2021 01:44:35 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 59
 by: luserdroog - Fri, 10 Dec 2021 01:44 UTC

On Thursday, December 9, 2021 at 7:39:22 PM UTC-6, luserdroog wrote:
> On Wednesday, December 8, 2021 at 11:38:30 PM UTC-6, Michael Haufe (TNO) wrote:
> > On Wednesday, December 8, 2021 at 6:23:12 PM UTC-6, luser...@gmail.com wrote:
> > > On Wednesday, December 8, 2021 at 6:17:07 PM UTC-6, luserdroog wrote:
> > >
> > > > function running_sum( a ){
> > > > var t = [];
> > > > a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur}
> > > , 0
> > > > );
> > > > return t;
> > > > }
> > > >
> > > > It's not a "one liner", but this is probably a bit more efficient AFAICT.
> > > > In APL, it's just `+\`.
> > > Need to use initial value zero (or prepend the original first element).
> > > I really think that's right, now.
> > functionally:
> >
> > const add = (left, right) => left + right
> >
> > const sum = (xs) => xs.reduce(add,0)
> >
> > sum([1,2,3,4,5]) // 15
> That does an APL reduce (coincidentally named) which looks like:
>
> +/
>
> But I'm after the subtly different function does a "scan" or piece-wise
> reduce. In APL, it's almost imperceptibly different:
>
> +\
>
> (There's a joke that APL\360 was named with the backslash character
> in there so the product name means "APL extends 360" if treated as
> an APL program. \ means "extend" if the left and right are values, but
> in the snippets under consideration \ means "scan" because the left
> (+) is a function and not a value. I will endeavor to stop talking about
> APL after this message.)
>
> To be more functional, I think it would look like this:
>
> Array.prototype.scan = function( f ){
> return this.map( (e,i,a)=>a.slice(0,i+1).reduce(f,0) );

dangitall.

> }
> const add = (left,right) => left + right
>
> function running_sum( a ){
> return [ 0, ...a.scan( add )];
> }
>
> (I forgot I also needed the result of running_sum() to start with a zero,
> in addition to the zero that gets fed to reduce() to ensure the first
> element of the input array shows up in the output array.)

Erhm. We don't need that zero in reduce() anymore. The map() takes
care of that.

Re: sidetrack

<23dc480c-f9f4-4920-bdb9-e7477b809d75n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:3cb:: with SMTP id k11mr10981083qtx.381.1639106577309; Thu, 09 Dec 2021 19:22:57 -0800 (PST)
X-Received: by 2002:a05:6830:2453:: with SMTP id x19mr9201052otr.32.1639106576915; Thu, 09 Dec 2021 19:22:56 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.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, 9 Dec 2021 19:22:56 -0800 (PST)
In-Reply-To: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@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: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <23dc480c-f9f4-4920-bdb9-e7477b809d75n@googlegroups.com>
Subject: Re: sidetrack
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Fri, 10 Dec 2021 03:22:57 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 131
 by: luserdroog - Fri, 10 Dec 2021 03:22 UTC

On Tuesday, December 7, 2021 at 8:42:11 PM UTC-6, luserdroog wrote:
> I'm making some progress at reconceiving my pianoroll app
> to be a more coherent object based design. But also kinda
> not making progress on it. I doodled up a sketch of the overall
> structure of the MVC example but instead of working on that,
> here's a "robust" function for decoding note names from letters
> and producing a MIDI note number.
>
> It uses two minor tetrachords to construct the intervals of an
> aeolian scale then takes a running sum to get "fretstops" for
> each of the scale degrees. Then you index the resulting array
> with 0 for 'a', 1 for 'b' etc, a little more twiddling and poof kazow
> presto! The desired number comes out the other end.

Revised and expanded code from OP. It can now produce an array
of midi note numbers given a chord name (like "Bbm" or "F#7").
Some explanation of how I'm using the scale and the chord template
is in this post:

https://music.stackexchange.com/a/6181/1344

Adding Major 7th chords would require some reworking like starting
with a different mode. Another nice extension would be an option
for closed vs. open voicing or a spectrum or palette of voicings.

const major_tetrachord = [ 2, 2, 1 ];
const minor_tetrachord = [ 2, 1, 2 ];

//mode names according to Boethius
const ionian_mode = [ ...major_tetrachord, //defined by Nicomachus as two disjunct
2, //tetrachords separated by a tone
...major_tetrachord ];

const mixolydian_mode = [ ...major_tetrachord, //need this for 7th chords and stuff
...major_tetrachord, //like A/E and C/G chords
2 ];

const aeolian_mode = [ ...minor_tetrachord, //defined by Nicomachus as two conjoint
...minor_tetrachord ]; //tetrachords

const long_mix_scale = [ ...mixolydian_mode,
...mixolydian_mode,
...major_tetrachord ];

const long_scale = ( scale )=>[ ...scale, ...scale, ...scale ];

Array.prototype.scan = function( f ){
return this.map( (e,i,a)=>a.slice(0,i+1).reduce(f) );
} Array.prototype.scan_v2 = function( f ){
var r = [];
this.reduce( (left,right)=>{ var t = f(left,right); r.push(t); return t; }, 0 );
return r;
} const add = (left,right) => left + right
const running_sum = ( a ) => [ 0, ...a.scan( add ) ]

console.log(running_sum(aeolian_mode));
console.log(running_sum(long_mix_scale));
console.log(running_sum(long_scale(mixolydian_mode)));

function note( str, octave=0 ){
var num = str.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0);
var fromA = running_sum(aeolian_mode)[ num ] +
(str.length > 1 ? (str[1]=='#' ? 1 : -1)
: 0);
var fromC = fromA + 9;
return octave*12 + (fromC >= 12 ? fromC - 12 : fromC);
}

function chord( str, octave=0 ){
var off = 0;
var tweak = 0;
var is7th = 0;
var twiddle = -3; //+9 (midi number of 'A') -12 (lower octave)

var num = str.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0);
var base = running_sum(aeolian_mode)[ num ];
str = str.slice(1);

if( str.length > 0 ){
off = str[0]=='#' ? 1
: str[0]=='b' ? -1
: 0;
if( off ){ str = str.slice(1); }
}

if( str.length > 0 && str[0]=='m' ){
tweak = -1;
str = str.slice(1);
}

if( str.length > 0 && str[0]=='7' ){
is7th = 1;
}

var template = is7th ? [ 1,5,7,8,10,12,14,15 ] //figured bass for chord shape
: [ 1,5, 8,10,12, 15 ];
var mode = [ ...mixolydian_mode ];
mode[1] += tweak; //minor chord uses a flat 3rd
mode[2] -= tweak; //balance the adjacent interval
//console.log( mode );
//console.log( running_sum( mode ) );

var scale = running_sum( long_scale( mode ) );
//console.log( scale );

var chord = template.map( x=> scale[x-1] + base + off + twiddle );
chord = chord.map( x=> x+octave*12 );
chord = chord.filter( x=> x>=0 );
return chord;
}

console.log(note("a",0));
console.log(note("c#",0));
console.log(note("eb",0));
console.log(chord("a"));
console.log(chord("am"));
console.log(chord("a7"));
console.log(chord("ebm7",4));

Output:
9 1
3 Array(5) [ 4, 9, 13, 16, 21 ]
Array(5) [ 4, 9, 12, 16, 21 ]
Array(7) [ 4, 7, 9, 13, 16, 19, 21 ]
Array(8) [ 51, 58, 61, 63, 66, 70, 73, 75 ]

Re: sidetrack

<34bb7f81-ba88-4abf-abeb-ffd10bb84b5cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:a50:: with SMTP id j16mr20177843qka.766.1639150003582;
Fri, 10 Dec 2021 07:26:43 -0800 (PST)
X-Received: by 2002:a05:6808:3097:: with SMTP id bl23mr12829549oib.0.1639150003294;
Fri, 10 Dec 2021 07:26:43 -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, 10 Dec 2021 07:26:43 -0800 (PST)
In-Reply-To: <a01b7437-266b-47a5-90b3-6818a59ee7c1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.103; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.103
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com> <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com> <b94ff525-ca41-4574-a77d-da1f7c37fbd2n@googlegroups.com>
<a01b7437-266b-47a5-90b3-6818a59ee7c1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <34bb7f81-ba88-4abf-abeb-ffd10bb84b5cn@googlegroups.com>
Subject: Re: sidetrack
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Fri, 10 Dec 2021 15:26:43 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 39
 by: Scott Sauyet - Fri, 10 Dec 2021 15:26 UTC

luser wrote:

> But I'm after the subtly different function does a "scan" or piece-wise
> reduce. In APL, it's almost imperceptibly different:
> [ ...]
> To be more functional, I think it would look like this:
>
> Array.prototype.scan = function( f ){
> return this.map( (e,i,a)=>a.slice(0,i+1).reduce(f,0) );
> }
> const add = (left,right) => left + right
>
> function running_sum( a ){
> return [ 0, ...a.scan( add )];
> }

I find this much cleaner:

const scan = (fn) => (init) => (xs) =>
xs .reduce ((ys, x) => ((ys .push (fn (ys .at (-1), x))), ys), [init])

const running_sum = scan ((a, b) => a + b) (0)

running_sum ([1, 2, 3, 4, 5]) //=> [0, 1, 3, 6, 10, 15]

While this is more elegant:

const scan = (fn) => (init) => (xs) =>
xs .reduce ((ys, x) => [...ys, fn (ys .at (-1), x)], [init])

It will almost certainly be less efficient as it has to build a new
array on each iteration.

If `Array.prototype.at` is not available in your environment, it's
trivial enough to write your own `last` function and replace
`ys .at (-1)` with `last (ys)`.

-- Scott

Re: sidetrack

<61b3727a$0$3675$426a74cc@news.free.fr>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!abe005.abavia.com!abe002.abavia.com!proxad.net!feeder1-1.proxad.net!cleanfeed1-b.proxad.net!nnrp1-1.free.fr!not-for-mail
Date: Fri, 10 Dec 2021 16:30:01 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Subject: Re: sidetrack
Content-Language: fr
Newsgroups: comp.lang.javascript
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com>
<f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
From: elhwen.dicote@gmail.com (Elhwen Dico)
In-Reply-To: <692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 29
Message-ID: <61b3727a$0$3675$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 10 Dec 2021 16:30:02 CET
NNTP-Posting-Host: 91.169.85.6
X-Trace: 1639150202 news-3.free.fr 3675 91.169.85.6:63376
X-Complaints-To: abuse@proxad.net
X-Received-Bytes: 1877
 by: Elhwen Dico - Fri, 10 Dec 2021 15:30 UTC

function running_sum(a: number[]) {
return a.reduce(
(acc: number, current: number) => acc + current,
0);
}

console.log(running_sum([1, 2, 3]));
console.log(running_sum([]));

Le 09/12/2021 à 01:23, luserdroog a écrit :
> On Wednesday, December 8, 2021 at 6:17:07 PM UTC-6, luserdroog wrote:
>
>> function running_sum( a ){
>> var t = [];
>> a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur}
>
> , 0
>
>> );
>> return t;
>> }
>>
>> It's not a "one liner", but this is probably a bit more efficient AFAICT.
>> In APL, it's just `+\`.
>
> Need to use initial value zero (or prepend the original first element).
> I really think that's right, now.

Re: sidetrack

<61b3741e$0$8893$426a74cc@news.free.fr>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!abe006.abavia.com!abe001.abavia.com!proxad.net!feeder1-1.proxad.net!cleanfeed1-a.proxad.net!nnrp1-1.free.fr!not-for-mail
Date: Fri, 10 Dec 2021 16:37:02 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Subject: Re: sidetrack
Content-Language: fr
Newsgroups: comp.lang.javascript
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com>
<f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
<61b3727a$0$3675$426a74cc@news.free.fr>
From: elhwen.dicote@gmail.com (Elhwen Dico)
In-Reply-To: <61b3727a$0$3675$426a74cc@news.free.fr>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 39
Message-ID: <61b3741e$0$8893$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 10 Dec 2021 16:37:02 CET
NNTP-Posting-Host: 91.169.85.6
X-Trace: 1639150622 news-3.free.fr 8893 91.169.85.6:63403
X-Complaints-To: abuse@proxad.net
X-Received-Bytes: 2179
 by: Elhwen Dico - Fri, 10 Dec 2021 15:37 UTC

const running_sum = (a) => a.reduce((acc, curr) => acc + curr, 0);

console.log(running_sum([1, 2, 3]));
console.log(running_sum([]));

Le 10/12/2021 à 16:30, Elhwen Dico a écrit :
>
> function running_sum(a: number[]) {
>     return a.reduce(
>         (acc: number, current: number) => acc + current,
>         0);
> }
>
> console.log(running_sum([1, 2, 3]));
> console.log(running_sum([]));
>
> Le 09/12/2021 à 01:23, luserdroog a écrit :
>> On Wednesday, December 8, 2021 at 6:17:07 PM UTC-6, luserdroog wrote:
>>
>>> function running_sum( a ){
>>> var t = [];
>>> a.reduce( (pre,cur)=>{t.push(pre+cur),pre+cur}
>>
>>    , 0
>>
>>> );
>>> return t;
>>> }
>>>
>>> It's not a "one liner", but this is probably a bit more efficient
>>> AFAICT.
>>> In APL, it's just `+\`.
>>
>> Need to use initial value zero (or prepend the original first element).
>> I really think that's right, now.
>

Re: sidetrack

<1778291.atdPhlSkOF@PointedEars.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.178.197.213.95!not-for-mail
From: PointedEars@web.de (Thomas 'PointedEars' Lahn)
Newsgroups: comp.lang.javascript
Subject: Re: sidetrack
Date: Sat, 11 Dec 2021 01:56:11 +0100
Organization: PointedEars Software (PES)
Lines: 10
Message-ID: <1778291.atdPhlSkOF@PointedEars.de>
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com> <93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com> <f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com> <692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com> <61b3727a$0$3675$426a74cc@news.free.fr>
Reply-To: Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7Bit
Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.213.95";
logging-data="472857"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: KNode/4.14.10
Cancel-Lock: sha1:Og+CcW651s8HkgPyCHlKgk/3v44=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
X-User-ID: U2FsdGVkX1+3PtudfrDBT+ylQmidMMG/OlWu6fWAnS5qZ38806riOA==
 by: Thomas 'Pointed - Sat, 11 Dec 2021 00:56 UTC

Elhwen Dico wrote:

> [top post]

Bats are supposed to post next door.

--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Re: sidetrack

<sp1q1p$o39$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: julio@diegidio.name (Julio Di Egidio)
Newsgroups: comp.lang.javascript
Subject: Re: sidetrack
Date: Sat, 11 Dec 2021 10:12:25 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <sp1q1p$o39$1@dont-email.me>
References: <06038aa0-e554-4cc7-b3cc-77fa0d3c143fn@googlegroups.com>
<93cb03fa-9811-4e19-8469-6e0a0b9cae19n@googlegroups.com>
<f38be122-740c-448e-b9d4-3691bcad8964n@googlegroups.com>
<692463e5-c0df-4a6f-b6ad-e1cb1c96c92cn@googlegroups.com>
<61b3727a$0$3675$426a74cc@news.free.fr> <1778291.atdPhlSkOF@PointedEars.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 11 Dec 2021 09:12:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a742ab04f9cafcd550c9ca6d5f7a30c1";
logging-data="24681"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ByK7lHDURax+UkcH1eeggPxiEGv1kG6U="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:uetZ0XSSfOdAFHeKT2QpvOayzuI=
In-Reply-To: <1778291.atdPhlSkOF@PointedEars.de>
Content-Language: en-GB
 by: Julio Di Egidio - Sat, 11 Dec 2021 09:12 UTC

On 11/12/2021 01:56, Thomas 'PointedEars' Lahn wrote:
> Elhwen Dico wrote:
>
>> [top post]
>
> Bats are supposed to post next door.

Since of course he has posted the best code so far in this thread...

And that's all you do, you incompetent spamming retarded piece of shit.

*Troll Alert*

Julio


devel / comp.lang.javascript / sidetrack

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor