Skip to content

Commit

Permalink
Improve stdlib naming convention
Browse files Browse the repository at this point in the history
Remove near-duplicate methods of obscure operations.

ref #350
  • Loading branch information
frostburn committed Jun 18, 2024
1 parent 8e3b2b0 commit e2b4c39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
24 changes: 9 additions & 15 deletions documentation/BUILTIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,6 @@ Calculate the inverse hyperbolic cosine of x.
### add(*...terms*)
Calculate the (linear) sum of the arguments.

### antiperiodiff(*constantOfIntegration*, *array*)
Calculate the cumulative geometric sums of a periodic difference pattern. Undoes what periodiff does.

### asinh(*x*)
Calculate the inverse hyperbolic sine of x.

Expand Down Expand Up @@ -509,9 +506,6 @@ Calculate e raised to the power of x.
### fail(*message*)
Throw the given message as an error.

### flatRepeat(*times = 2*, *scale = ££*)
Repeat the popped/given intervals as-is without accumulating equaves.

### ftom(*freq*)
Convert absolute frequency to MIDI note number / MTS value (fractional semitones with A440 = 69).

Expand Down Expand Up @@ -587,12 +581,6 @@ Obtain a copy of the popped/given scale reduced by its last interval, sorted and
### parallelotope(*basis*, *ups = niente*, *downs = niente*, *equave = 2*, *basisSizeHints = niente*, *equaveSizeHint = niente*)
Span a parallelotope by extending a basis combinatorically. `ups` defaults to all ones while `downs` defaults to all zeros. The size hints are used to get the correct period reduction when generating a preimage.

### periodiff(*array*)
Calculate the geometric differences of the periodic interval pattern.

### periostack(*guideGenerator*, *array = ££*)
Stack the popped/given inflections along with the guide generator into a periodic sequence of steps.

### pow(*x*, *y*)
Calculate x to the power of y.

Expand Down Expand Up @@ -626,6 +614,9 @@ Convert interval to relative logarithmic representation.
### repeat(*times = 2*, *scale = ££*)
Stack the popped/given scale on top of itself.

### repeatFlat(*times = 2*, *scale = ££*)
Repeat the popped/given intervals as-is without accumulating equaves.

### repeatLinear(*times = 2*, *scale = ££*)
Repeat the popped/given scale shifted linearly each time.

Expand Down Expand Up @@ -662,6 +653,9 @@ Cumulatively stack the popped/given intervals on top of each other.
### stackLinear(*array = ££*)
Cumulatively sum the numbers of the popped/given array.

### stackPeriodic(*guideGenerator*, *array = ££*)
Stack the popped/given inflections along with the guide generator into a periodic sequence of steps.

### stretch(*amount*, *scale = ££*)
Obtain a copy of the popped/given scale streched by the given amount. A value of `1` corresponds to no change.

Expand Down Expand Up @@ -698,12 +692,12 @@ Find a combination of three vals that is closer to just intonation.
### u(*scale = ££*)
Obtain a undertonal reflection of the popped/given overtonal scale.

### unperiostack(*array = ££*)
Convert the popped/given periodic sequence of steps into inflections of the last interval as the guide generator.

### unstack(*array = ££*)
Unstack the popped/given scale into steps.

### unstackPeriodic(*array = ££*)
Convert the popped/given periodic sequence of steps into inflections of the last interval as the guide generator.

### values(*record*)
Obtain an array of values of the record.

Expand Down
10 changes: 5 additions & 5 deletions src/parser/__tests__/stdlib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ describe('SonicWeave standard library', () => {

it('can reduce Raga Bhairavi to a comma recipe (inline)', () => {
const scale = expand(
'periodiff(geodiff([16/15, 9/8, 6/5, 27/20, 3/2, 8/5, 9/5, 2/1]))'
'unstackPeriodic(unstack([16/15, 9/8, 6/5, 27/20, 3/2, 8/5, 9/5, 2/1]))'
);
expect(scale).toEqual([
'24/25',
Expand All @@ -530,7 +530,7 @@ describe('SonicWeave standard library', () => {

it('can reduce Raga Bhairavi to a comma recipe (verbs)', () => {
const scale = expand(
'16/15;9/8;6/5;27/20;3/2;8/5;9/5;2/1;unstack();unperiostack()'
'16/15;9/8;6/5;27/20;3/2;8/5;9/5;2/1;unstack();unstackPeriodic()'
);
expect(scale).toEqual([
'24/25',
Expand All @@ -547,7 +547,7 @@ describe('SonicWeave standard library', () => {
it('can recover Raga Bhairavi from its comma recipe (inline)', () => {
const scale = expand(`
cumprod(
antiperiodiff(
stackPeriodic(
10/9,
[
24/25,
Expand Down Expand Up @@ -585,7 +585,7 @@ describe('SonicWeave standard library', () => {
24/25
135/128
80/81
periostack(10/9)
stackPeriodic(10/9)
stack()
simplify
`);
Expand Down Expand Up @@ -948,7 +948,7 @@ describe('SonicWeave standard library', () => {
});

it('can repeat unstacked steps', () => {
const zarlino7 = expand('5;3/5;flatRepeat(3);stack();2;reduce();sort()');
const zarlino7 = expand('5;3/5;repeatFlat(3);stack();2;reduce();sort()');
expect(zarlino7).toEqual([
'9/8',
'5/4',
Expand Down
16 changes: 3 additions & 13 deletions src/stdlib/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ riff geodiff(array) {
return unstack(array);
}
riff unperiostack(array = ££) {
riff unstackPeriodic(array = ££) {
"Convert the popped/given periodic sequence of steps into inflections of the last interval as the guide generator.";
array;
const first = $[0] ~% $[-1];
Expand All @@ -316,12 +316,7 @@ riff unperiostack(array = ££) {
$[0] = first;
}
riff periodiff(array) {
"Calculate the geometric differences of the periodic interval pattern.";
return unperiostack(array);
}
riff periostack(guideGenerator, array = ££) {
riff stackPeriodic(guideGenerator, array = ££) {
"Stack the popped/given inflections along with the guide generator into a periodic sequence of steps.";
if (not isInterval(guideGenerator))
throw "Guide generator must be an interval.";
Expand All @@ -333,11 +328,6 @@ riff periostack(guideGenerator, array = ££) {
$[i] ~*= $[i-1r];
}
riff antiperiodiff(constantOfIntegration, array) {
"Calculate the cumulative geometric sums of a periodic difference pattern. Undoes what periodiff does.";
return periostack(constantOfIntegration, array);
}
riff enumerate(array = $$) {
"Produce an array of [index, element] pairs from the given current/given array.";
return [[i, array[i]] for i in array];
Expand Down Expand Up @@ -775,7 +765,7 @@ riff repeatLinear(times = 2, scale = ££) {
(scale ~- 1) ~+ level ~+ 1;
}
riff flatRepeat(times = 2, scale = ££) {
riff repeatFlat(times = 2, scale = ££) {
"Repeat the popped/given intervals as-is without accumulating equaves.";
return arrayRepeat(times, scale);
}
Expand Down

0 comments on commit e2b4c39

Please sign in to comment.