Skip to content

Commit 1f98cca

Browse files
committed
Add new sound docs + get examples working
1 parent f868d6b commit 1f98cca

File tree

289 files changed

+27278
-40541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+27278
-40541
lines changed

public/reference/data.json

Lines changed: 25779 additions & 31119 deletions
Large diffs are not rendered by default.

src/components/CodeEmbed/frame.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ canvas {
4242
}
4343
${code.css || ""}
4444
</style>
45-
${(code.scripts || []).map((src) => `<script type="text/javascript" src="${src}"></script>`).join('\n')}
45+
${(code.scripts ? [cdnLibraryUrl, ...code.scripts] : []).map((src) => `<script type="text/javascript" src="${src}"></script>`).join('\n')}
4646
<body>${code.htmlBody || ""}</body>
4747
<script id="code" type="text/javascript">${wrapSketch(code.js) || ""}</script>
48+
${(code.scripts?.length ?? 0) > 0 ? '' : `
4849
<script type="text/javascript">
4950
// Listen for p5.min.js text content and include in iframe's head as script
5051
window.addEventListener("message", event => {
@@ -59,6 +60,7 @@ ${(code.scripts || []).map((src) => `<script type="text/javascript" src="${src}"
5960
}
6061
})
6162
</script>
63+
`}
6264
`.replace(/\u00A0/g, " ");
6365

6466
export interface CodeFrameProps {

src/content/reference/en/p5.Amplitude/getLevel.mdx

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,14 @@
22
title: getLevel
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Returns a single Amplitude reading at the moment it is called.
8-
For continuous readings, run in the draw loop.</p>
9-
line: 3209
5+
file: src/Amplitude.js
6+
description: Get the current amplitude value of a sound.
7+
line: 62
108
isConstructor: false
119
itemtype: method
12-
example:
13-
- |-
14-
15-
<div><code>
16-
function preload(){
17-
sound = loadSound('/assets/beat.mp3');
18-
}
19-
20-
function setup() {
21-
let cnv = createCanvas(100, 100);
22-
cnv.mouseClicked(toggleSound);
23-
amplitude = new p5.Amplitude();
24-
}
25-
26-
function draw() {
27-
background(220, 150);
28-
textAlign(CENTER);
29-
text('tap to play', width/2, 20);
30-
31-
let level = amplitude.getLevel();
32-
let size = map(level, 0, 1, 0, 200);
33-
ellipse(width/2, height/2, size, size);
34-
}
35-
36-
function toggleSound(){
37-
if (sound.isPlaying()) {
38-
sound.stop();
39-
} else {
40-
sound.play();
41-
}
42-
}
43-
</code></div>
4410
class: p5.Amplitude
45-
params:
46-
- name: channel
47-
description: |
48-
<p>Optionally return only channel 0 (left) or 1 (right)</p>
49-
type: Number
50-
optional: true
5111
return:
52-
description: Amplitude as a number between 0.0 and 1.0
12+
description: Amplitude level (volume) of a sound.
5313
type: Number
5414
chainable: false
5515
---

src/content/reference/en/p5.Amplitude/setInput.mdx

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,16 @@
22
title: setInput
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Connects to the p5sound instance (main output) by default.
8-
Optionally, you can pass in a specific source (i.e. a soundfile).</p>
9-
line: 3117
5+
file: src/Amplitude.js
6+
description: Connect an audio source to the amplitude object.
7+
line: 52
108
isConstructor: false
119
itemtype: method
12-
example:
13-
- |-
14-
15-
<div><code>
16-
function preload(){
17-
sound1 = loadSound('/assets/beat.mp3');
18-
sound2 = loadSound('/assets/drum.mp3');
19-
}
20-
function setup(){
21-
cnv = createCanvas(100, 100);
22-
cnv.mouseClicked(toggleSound);
23-
24-
amplitude = new p5.Amplitude();
25-
amplitude.setInput(sound2);
26-
}
27-
28-
function draw() {
29-
background(220);
30-
text('tap to play', 20, 20);
31-
32-
let level = amplitude.getLevel();
33-
let size = map(level, 0, 1, 0, 200);
34-
ellipse(width/2, height/2, size, size);
35-
}
36-
37-
function toggleSound(){
38-
if (sound1.isPlaying() && sound2.isPlaying()) {
39-
sound1.stop();
40-
sound2.stop();
41-
} else {
42-
sound1.play();
43-
sound2.play();
44-
}
45-
}
46-
</code></div>
4710
class: p5.Amplitude
4811
params:
49-
- name: snd
50-
description: |
51-
<p>set the sound source
52-
(optional, defaults to
53-
main output)</p>
54-
type: SoundObject|undefined
55-
optional: true
56-
- name: smoothing
57-
description: |
58-
<p>a range between 0.0 and 1.0
59-
to smooth amplitude readings</p>
60-
type: Number|undefined
61-
optional: true
12+
- name: input
13+
description: '- An object that has audio output.'
14+
type: Object
6215
chainable: false
6316
---
6417

src/content/reference/en/p5.Amplitude/smooth.mdx

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/content/reference/en/p5.Amplitude/toggleNormalize.mdx

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/content/reference/en/p5.AudioIn/amp.mdx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22
title: amp
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Set amplitude (volume) of a mic input between 0 and 1.0. <br/></p>
8-
line: 6257
5+
file: src/AudioIn.js
6+
description: Set amplitude (volume) of a mic input between 0 and 1.0.
7+
line: 82
98
isConstructor: false
109
itemtype: method
1110
class: p5.AudioIn
1211
params:
13-
- name: vol
14-
description: |
15-
<p>between 0 and 1.0</p>
12+
- name: amplitudeAmount
13+
description: An amplitude value between 0 and 1.
1614
type: Number
17-
- name: time
18-
description: |
19-
<p>ramp time (optional)</p>
20-
type: Number
21-
optional: true
2215
chainable: false
2316
---
2417

src/content/reference/en/p5.AudioIn/amplitude.mdx

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/content/reference/en/p5.AudioIn/connect.mdx

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/content/reference/en/p5.AudioIn/currentSource.mdx

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)