Skip to content

Commit

Permalink
Tweak default type-based actions
Browse files Browse the repository at this point in the history
Makes context corruption less likely.
  • Loading branch information
frostburn committed Apr 27, 2024
1 parent 984b320 commit 791e3f0
Showing 8 changed files with 366 additions and 337 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -77,28 +77,43 @@ Sub-scales are automatically unrolled onto the current scale.
Results in the scale `$ = [4\12, 7\12, 12\12]`.

### Coloring
If an expression evaluates to a color it is attached to the last interval in the scale.
If an expression evaluates to a color it is applied to all the intervals in the scale that don't have a color yet.
```javascript
5/4
3/2
green
2/1
red
```
Results in a scale equivalent to `$ = [3/2 #008000, 2/1 #FF0000]`.
Results in a scale equivalent to `$ = [5/4 #008000, 3/2 #008000, 2/1 #FF0000]`.

#### Inline colors
```javascript
5/4
3/2 green
2/1 red
```
Results in `$ = [5/4 green, 2/1 red]`.

It is up to a user interface to interprete colors. The original intent is to color notes in an on-screen keyboard.

### Labeling
If an expression evaluates to a string it is attached to the last interval in the scale.
### Scale title
If an expression evaluates to a string it is used as the scale title.
```javascript
"My fourth and octave"
4/3
"My P4"
2/1
'Unison / octave'
```
Results in the scale `$ = [(4/3 "My P4"), (2/1 "Unison / octave")]`.
Results in the scale `$ = [4/3, 2/1]`.

The title is included in the `.scl` export.

Labels are included in the `.scl` export.
#### Inline labels
```javascript
4/3 "My perfect fourth"
2/1 'octave'
```
Results in the scale `$ = [4/3 'My perfect fourth', 2/1 'octave']`.

It is up to a user interface to interprete labels. The original intent is to label notes in an on-screen keyboard.

37 changes: 27 additions & 10 deletions documentation/intermediate-dsl.md
Original file line number Diff line number Diff line change
@@ -26,26 +26,43 @@ Sub-scales are automatically unrolled onto the current scale.
Results in the scale `$ = [4\12, 7\12, 12\12]`.

### Coloring
If an expression evaluates to a color it is attached to the last interval in the scale.
```c
If an expression evaluates to a color it is applied to all the intervals in the scale that don't have a color yet.
```javascript
5/4
3/2
green
2/1
red
```
Results in a scale equivalent to `$ = [3/2 #008000, 2/1 #FF0000]`.
Results in a scale equivalent to `$ = [5/4 #008000, 3/2 #008000, 2/1 #FF0000]`.

It is up to a user interface to interprete colors. Scale Workshop uses colors in an on-screen keyboard.
#### Inline colors
```javascript
5/4
3/2 green
2/1 red
```
Results in `$ = [5/4 green, 2/1 red]`.

### Labeling
If an expression evaluates to a string it is attached to the last interval in the scale.
```c
It is up to a user interface to interprete colors. The original intent is to color notes in an on-screen keyboard.

### Scale title
If an expression evaluates to a string it is used as the scale title.
```javascript
"My fourth and octave"
4/3
"My P4"
2/1
'Unison / octave'
```
Results in the scale `$ = [(4/3 "My P4"), (2/1 "Unison / octave")]`.
Results in the scale `$ = [4/3, 2/1]`.

The title is included in the `.scl` export.

#### Inline labels
```javascript
4/3 "My perfect fourth"
2/1 'octave'
```
Results in the scale `$ = [4/3 'My perfect fourth', 2/1 'octave']`.

Labels are included in the `.scl` export of the [CLI](https://github.com/xenharmonic-devs/sonic-weave/blob/main/documentation/cli.md).

2 changes: 1 addition & 1 deletion src/parser/__tests__/expression.spec.ts
Original file line number Diff line number Diff line change
@@ -703,7 +703,7 @@ describe('SonicWeave expression evaluator', () => {
});

it("doesn't let you color pi (scale)", () => {
const purePi = evaluate('PI;chocolate;PI') as Interval;
const purePi = evaluate('PI;[chocolate];PI') as Interval;
expect(purePi.color?.value).toBe(undefined);
});

Loading

0 comments on commit 791e3f0

Please sign in to comment.