Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation of amplitude.disconnect() method #682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,44 @@ class Amplitude {
// }
}

/**
* Disconnects the output of this p5.Amplitude object.
*
* @method disconnect
* @for p5.Amplitude
* @example
* <div><code>
* let sound, amplitude;
* function preload(){
* sound = loadSound('assets/beat.mp3');
* }
*
* function setup() {
* let cnv = createCanvas(200, 200);
* cnv.mouseClicked(togglePlay);
* amplitude = new p5.Amplitude();
* sound.loop();
* }
*
* function draw() {
* background(220);
* text('Disconnect:', 20, 20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make the text "Click to disconnect" so it's clearer you can click anywhere?

Copy link
Contributor Author

@Nitesh639 Nitesh639 Nov 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I do it.

* let level = amplitude.getLevel();
* let size = map(level, 0, 1, 0, 400);
* ellipse(width/2, height/2, size, size);
* }
*
* function togglePlay() {
* if (sound.isPlaying()){
* sound.pause();
* amplitude.disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think calling disconnect here might not be the best illustration of what's going on since disconnect only disconnects the amplitude's outputs. If we don't call sound.pause() on the line above, nothing appears to happen. Is there an example we can make where we connect the amplitude's output to something else, so that we can disconnect the amplitude's output from that rather than pausing its input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a separate button for the disconnect method?

* }
* else{
* sound.play();
* }
* }
* </code></div>
*/
disconnect() {
if (this.output) {
this.output.disconnect();
Expand Down