Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 17df418

Browse files
committed
Update Documentation
1 parent 2ccb95a commit 17df418

File tree

4 files changed

+125
-8
lines changed

4 files changed

+125
-8
lines changed

packages/core/controls.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,8 @@ export const { midimap } = registerControl('midimap');
16291629
*
16301630
* @name midiport
16311631
* @param {number | Pattern} port MIDI port
1632+
* @example
1633+
* note("c a f e").midiport("<0 1 2 3>").midi()
16321634
*/
16331635
export const { midiport } = registerControl('midiport');
16341636

packages/midi/README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Additional controls can be mapped using the mapping object passed to `.midi()`:
4141

4242
## Examples
4343

44-
### midi(outputName?)
44+
### midi(outputName?, options?)
4545

4646
Either connect a midi device or use the IAC Driver (Mac) or Midi Through Port (Linux) for internal midi messages.
4747
If no outputName is given, it uses the first midi output it finds.
@@ -52,6 +52,42 @@ $: chord("<C^7 A7 Dm7 G7>").voicing().midi('IAC Driver')
5252

5353
In the console, you will see a log of the available MIDI devices as soon as you run the code, e.g. `Midi connected! Using "Midi Through Port-0".`
5454

55+
### Options
56+
57+
The `.midi()` function accepts an options object with the following properties:
58+
59+
```javascript
60+
$: note("c a f e").midi('IAC Driver', { isController: true, midimap: 'default'})
61+
```
62+
63+
<details>
64+
<summary>Available Options</summary>
65+
66+
| Option | Type | Default | Description |
67+
|--------|------|---------|-------------|
68+
| isController | boolean | false | When true, disables sending note messages. Useful for MIDI controllers |
69+
| latencyMs | number | 34 | Latency in milliseconds to align MIDI with audio engine |
70+
| noteOffsetMs | number | 10 | Offset in milliseconds for note-off messages to prevent glitching |
71+
| midichannel | number | 1 | Default MIDI channel (1-16) |
72+
| velocity | number | 0.9 | Default note velocity (0-1) |
73+
| gain | number | 1 | Default gain multiplier for velocity (0-1) |
74+
| midimap | string | 'default' | Name of MIDI mapping to use for control changes |
75+
| midiport | string/number | - | MIDI device name or index |
76+
77+
</details>
78+
79+
80+
81+
82+
### midiport(outputName)
83+
84+
Selects the MIDI output device to use, pattern can be used to switch between devices.
85+
86+
```javascript
87+
$: midiport('IAC Driver')
88+
$: note("c a f e").midiport("<0 1 2 3>").midi()
89+
```
90+
5591
### midichan(number)
5692

5793
Selects the MIDI channel to use. If not used, `.midi` will use channel 1 by default.

test/__snapshots__/examples.test.mjs.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,6 +5215,15 @@ exports[`runs examples > example "midi" example index 0 1`] = `
52155215
]
52165216
`;
52175217

5218+
exports[`runs examples > example "midi" example index 1 1`] = `
5219+
[
5220+
"[ 0/1 → 1/1 | note:c4 midichan:1 ]",
5221+
"[ 1/1 → 2/1 | note:c4 midichan:1 ]",
5222+
"[ 2/1 → 3/1 | note:c4 midichan:1 ]",
5223+
"[ 3/1 → 4/1 | note:c4 midichan:1 ]",
5224+
]
5225+
`;
5226+
52185227
exports[`runs examples > example "midibend" example index 0 1`] = `
52195228
[
52205229
"[ 0/1 → 1/1 | note:c4 midibend:0 ]",
@@ -5453,6 +5462,27 @@ exports[`runs examples > example "midin" example index 0 1`] = `
54535462
]
54545463
`;
54555464

5465+
exports[`runs examples > example "midiport" example index 0 1`] = `
5466+
[
5467+
"[ 0/1 → 1/4 | note:c midiport:0 ]",
5468+
"[ 1/4 → 1/2 | note:a midiport:0 ]",
5469+
"[ 1/2 → 3/4 | note:f midiport:0 ]",
5470+
"[ 3/4 → 1/1 | note:e midiport:0 ]",
5471+
"[ 1/1 → 5/4 | note:c midiport:1 ]",
5472+
"[ 5/4 → 3/2 | note:a midiport:1 ]",
5473+
"[ 3/2 → 7/4 | note:f midiport:1 ]",
5474+
"[ 7/4 → 2/1 | note:e midiport:1 ]",
5475+
"[ 2/1 → 9/4 | note:c midiport:2 ]",
5476+
"[ 9/4 → 5/2 | note:a midiport:2 ]",
5477+
"[ 5/2 → 11/4 | note:f midiport:2 ]",
5478+
"[ 11/4 → 3/1 | note:e midiport:2 ]",
5479+
"[ 3/1 → 13/4 | note:c midiport:3 ]",
5480+
"[ 13/4 → 7/2 | note:a midiport:3 ]",
5481+
"[ 7/2 → 15/4 | note:f midiport:3 ]",
5482+
"[ 15/4 → 4/1 | note:e midiport:3 ]",
5483+
]
5484+
`;
5485+
54565486
exports[`runs examples > example "miditouch" example index 0 1`] = `
54575487
[
54585488
"[ 0/1 → 1/1 | note:c4 miditouch:0.5 ]",

website/src/pages/learn/input-output.mdx

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,63 @@ It is also possible to pattern other things with Strudel, such as software and h
1616

1717
Strudel supports MIDI without any additional software (thanks to [webmidi](https://npmjs.com/package/webmidi)), just by adding methods to your pattern:
1818

19-
## midi(outputName?)
19+
## midiin(inputName?)
20+
21+
<JsDoc client:idle name="midin" h={0} />
22+
23+
## midi(outputName?,options?)
2024

2125
Either connect a midi device or use the IAC Driver (Mac) or Midi Through Port (Linux) for internal midi messages.
2226
If no outputName is given, it uses the first midi output it finds.
2327

24-
<MiniRepl client:idle tune={`chord("<C^7 A7 Dm7 G7>").voicing().midi()`} />
28+
<MiniRepl
29+
client:idle
30+
tune={`
31+
$: chord("<C^7 A7 Dm7 G7>").voicing().midi('IAC Driver')
32+
`}
33+
/>
34+
35+
In the console, you will see a log of the available MIDI devices as soon as you run the code,
36+
e.g.
37+
38+
```
39+
`Midi connected! Using "Midi Through Port-0".`
40+
```
41+
42+
The `.midi()` function accepts an options object with the following properties:
43+
44+
<MiniRepl
45+
client:idle
46+
tune={`$: note("d e c a f").midi('IAC Driver', { isController: true, midimap: 'default'})
47+
`}
48+
/>
49+
50+
<details>
51+
<summary>Available Options</summary>
52+
53+
| Option | Type | Default | Description |
54+
| ------------ | ------------- | --------- | ---------------------------------------------------------------------- |
55+
| isController | boolean | false | When true, disables sending note messages. Useful for MIDI controllers |
56+
| latencyMs | number | 34 | Latency in milliseconds to align MIDI with audio engine |
57+
| noteOffsetMs | number | 10 | Offset in milliseconds for note-off messages to prevent glitching |
58+
| midichannel | number | 1 | Default MIDI channel (1-16) |
59+
| velocity | number | 0.9 | Default note velocity (0-1) |
60+
| gain | number | 1 | Default gain multiplier for velocity (0-1) |
61+
| midimap | string | 'default' | Name of MIDI mapping to use for control changes |
62+
| midiport | string/number | - | MIDI device name or index |
63+
64+
</details>
65+
66+
### midiport(outputName)
67+
68+
Selects the MIDI output device to use, pattern can be used to switch between devices.
69+
70+
```javascript
71+
$: midiport('IAC Driver');
72+
$: note('c a f e').midiport('<0 1 2 3>').midi();
73+
```
2574

26-
In the console, you will see a log of the available MIDI devices as soon as you run the code, e.g. `Midi connected! Using "Midi Through Port-0".`
75+
<JsDoc client:idle name="midiport" h={0} />
2776

2877
## midichan(number)
2978

@@ -106,8 +155,8 @@ The value should be an array of numbers between 0-255 representing the SysEx dat
106155
let id = 0x43; //Yamaha
107156
//let id = "0x00:0x20:0x32"; //Behringer ID can be an array of numbers
108157
let data = "0x79:0x09:0x11:0x0A:0x00:0x00"; // Set NSX-39 voice to say "Aa"
109-
$: note("c d e f e d c").sysex(id, data).midi();
110-
$: note("c d e f e d c").sysexid(id).sysexdata(data).midi();`}
158+
$: note("c a f e").sysex(id, data).midi();
159+
$: note("c a f e").sysexid(id).sysexdata(data).midi();`}
111160
/>
112161

113162
The exact format of SysEx messages depends on your MIDI device's specification.
@@ -118,9 +167,9 @@ Consult your device's MIDI implementation guide for details on supported SysEx m
118167
`midibend` sets MIDI pitch bend (-1 - 1)
119168
`miditouch` sets MIDI key after touch (0-1)
120169

121-
<MiniRepl client:idle tune={`note("c d e f e d c").midibend(sine.slow(4).range(-0.4,0.4)).midi()`} />
170+
<MiniRepl client:idle tune={`note("c a f e").midibend(sine.slow(4).range(-0.4,0.4)).midi()`} />
122171

123-
<MiniRepl client:idle tune={`note("c d e f e d c").miditouch(sine.slow(4).range(0,1)).midi()`} />
172+
<MiniRepl client:idle tune={`note("c a f e").miditouch(sine.slow(4).range(0,1)).midi()`} />
124173

125174
# OSC/SuperDirt/StrudelDirt
126175

0 commit comments

Comments
 (0)