Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Example usage
import notePlayer from "noteplayer.js";
const np = new notePlayer();

np.init();
np.setFrequency(440); // Sets frequency
np.play(); // Plays note
np.stop(); // Stops note
Expand All @@ -31,6 +32,8 @@ np.stop(); // Stops note
Functions

```js
init(): void;

setOscillatorDefaultSettings(): void;
setOscillatorType(type: OscillatorType): void;

Expand Down
6 changes: 5 additions & 1 deletion demo/src/components/PlayNote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ const np = new notePlayer()

const is_playing = ref(false)
const play_button_text = computed(() => (!is_playing.value ? 'Play note' : 'Playing note...'))

const np_initialized = ref(false)
function playNote() {
if (!np_initialized.value) {
np.init()
np_initialized.value = true
}
if (!is_playing.value) {
is_playing.value = true
np.play()
Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare class notePlayer {
private noteNames;
private noteNameRegex;
constructor();
init(): void;
setOscillatorDefaultSettings(): void;
setOscillatorType(type: OscillatorType): void;
setFrequency(frequency: number): void;
Expand Down
2 changes: 2 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var notePlayer = class {
this.oscillator = this.audioCtx.createOscillator();
this.oscillator.connect(this.gainNode);
this.setOscillatorDefaultSettings();
}
init() {
this.oscillator.start();
}
setOscillatorDefaultSettings() {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "noteplayer.js",
"version": "0.0.63",
"version": "0.0.64",
"description": "Play, tune, and transform notes and frequencies in a snap!",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default class notePlayer {
this.oscillator.connect(this.gainNode);

this.setOscillatorDefaultSettings();
}

init() {
this.oscillator.start();
}

Expand Down