Skip to content

Commit 6395e2d

Browse files
committed
update docs with new JS Pitch and Map functions
1 parent d9f8630 commit 6395e2d

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

src/content/docs/js/map.mdx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ constructor(
173173
fifth: number,
174174
referencePitch?: string,
175175
referenceFreq?: number
176+
midiMap?: Map1D;
176177
);
177178
```
178179

@@ -241,11 +242,29 @@ T.toCents(m); // 400
241242
toRatio(m: Interval): number;
242243
```
243244

244-
returns the ratio of the passed `Interval` as a decimal number.
245+
Returns the ratio of the passed `Interval` as a decimal number.
245246

246247
```ts
247248
const T = TuningMap.fromEDO(31);
248249

249250
let m = Interval.fromName("A6");
250251
T.toRatio(m); // 1.7489046221194973
251252
```
253+
254+
### `toMIDI`
255+
256+
```ts
257+
toMIDI(p: Pitch): number;
258+
```
259+
260+
Returns an ordered pitch numbering for the passed `Pitch` as an integer. Available in any EDO `TuningMap` created via `TuningMap.fromEDO`. For 12TET, this will be the ordinary MIDI value for a given `Pitch`, but for other EDO tunings it provides an ordered MIDI-equvalent mapping.
261+
262+
```ts
263+
const T1 = TuningMap.fromEDO(12);
264+
const T2 = TuningMap.fromEDO(31);
265+
266+
let p = SPN.toPitch("C4");
267+
268+
T1.toMIDI(p); // 60
269+
T2.toMIDI(p); // 155
270+
```

src/content/docs/js/pitch.mdx

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ let p = SPN.toPitch("F4");
172172
p.octave; // 4
173173
```
174174

175+
### `intervalTo`
176+
177+
```ts
178+
intervalTo(p: Pitch): Interval;
179+
```
180+
181+
Returns the [`Interval`](/js/interval) from the current Pitch to another passed-in vector. Often a more convenient way to access [`Interval.between`](/js/interval/#intervalbetween)
182+
183+
```ts
184+
let p = SPN.toPitch("C4");
185+
let q = SPN.toPitch("E4");
186+
187+
let m = p.intervalTo(q); // m now holds a major third Interval
188+
let n = Interval.between(p, q); // equivalent
189+
```
190+
175191
### `stepsTo`
176192

177193
```ts
@@ -278,26 +294,53 @@ p = SPN.toPitch("Bbb4")
278294
p.alterationIn(context); // -2, Bbb is too flat for this context
279295
```
280296

281-
## Transformations
297+
### `highest`
282298

283-
The following methods produce a new vector from the current `Pitch`. None of them mutate the original object.
299+
```ts
300+
highest(arr: Pitch[], T?: TuningMap): Pitch;
301+
```
284302

285-
### `intervalTo`
303+
Returns the highest `Pitch` in a passed-in array. Uses an optional `TuningMap` to determine which `Pitch` is higher than the others; if no `TuningMap` is passed in, defaults to 12TET.
286304

287305
```ts
288-
intervalTo(p: Pitch): Interval;
306+
const pitchArray = ["C4", "F#4", "D4", "Bb4", "A#4", "G4"].map(p => SPN.toPitch(p));
307+
308+
const highest = Pitch.highest(pitchArray); // highest holds Bb4
289309
```
290310

291-
Returns the [`Interval`](/js/interval) from the current Pitch to another passed-in vector. Often a more convenient way to access [`Interval.between`](/js/interval/#intervalbetween)
311+
### `lowest`
292312

293313
```ts
294-
let p = SPN.toPitch("C4");
295-
let q = SPN.toPitch("E4");
314+
lowest(arr: Pitch[], T?: TuningMap): Pitch;
315+
```
296316

297-
let m = p.intervalTo(q); // m now holds a major third Interval
298-
let n = Interval.between(p, q); // equivalent
317+
Returns the lowest `Pitch` in a passed-in array. Uses an optional `TuningMap` to determine which `Pitch` is lower than the others; if no `TuningMap` is passed in, defaults to 12TET.
318+
319+
```ts
320+
const pitchArray = ["C4", "F#4", "D4", "Bb4", "A#4", "G4"].map(p => SPN.toPitch(p));
321+
322+
const lowest = Pitch.lowest(pitchArray); // lowest holds C4
299323
```
300324

325+
### `nearest`
326+
327+
```ts
328+
nearest(arr: Pitch[], T?: TuningMap): Pitch;
329+
```
330+
331+
Returns the nearest `Pitch` in a passed-in array to the calling `Pitch` instance. Uses an optional `TuningMap` to determine which `Pitch` is lower than the others; if no `TuningMap` is passed in, defaults to 12TET.
332+
333+
```ts
334+
const pitchArray = ["C4", "F#4", "D4", "Bb4", "A#4", "G4"].map(p => SPN.toPitch(p));
335+
let p = SPN.toPitch("Eb4");
336+
337+
const nearest = p.nearest(pitchArray); // nearest holds D4
338+
```
339+
340+
## Transformations
341+
342+
The following methods produce a new `Pitch` from the current `Pitch`. None of them mutate the original object.
343+
301344
### `transposeReal`
302345

303346
```ts

0 commit comments

Comments
 (0)