Skip to content

Commit 0e38c71

Browse files
authored
fix: Sampler documentation (#62)
1 parent 8abc8d3 commit 0e38c71

File tree

6 files changed

+63
-23
lines changed

6 files changed

+63
-23
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,21 @@ const piano = new SplendidGrandPiano(context, { storage });
296296

297297
### Sampler
298298

299-
An audio buffer sampler.
299+
An audio buffer sampler. Pass a `buffers` object with the files to be load:
300300

301301
```js
302302
import { Sampler } from "smplr";
303303

304-
const samples = {
304+
const buffers = {
305305
kick: "https://danigb.github.io/samples/drum-machines/808-mini/kick.m4a",
306306
snare: "https://danigb.github.io/samples/drum-machines/808-mini/snare-1.m4a",
307307
};
308-
const sampler = new Sampler(new AudioContext(), { samples });
308+
const sampler = new Sampler(new AudioContext(), { buffers });
309+
```
310+
311+
And then use the name of the buffer as note name:
312+
313+
```js
309314
sampler.start({ note: "kick" });
310315
```
311316

site/package-lock.json

+5-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"webmidi": "^3.1.5"
1818
},
1919
"devDependencies": {
20-
"@next/font": "^13.4.2",
2120
"@types/node": "^20.1.7",
2221
"@types/react": "^18.2.6",
2322
"@types/react-dom": "^18.2.4",

site/pages/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Inter } from "@next/font/google";
1+
import { Inter } from "next/font/google";
22
import Head from "next/head";
33
import { DrumMachineExample } from "src/DrumMachineExample";
44
import { ElectricPianoExample } from "src/ElectricPianoExample";

site/pages/tests.tsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Inter } from "next/font/google";
2+
import Head from "next/head";
3+
import { useEffect, useRef } from "react";
4+
import { Sampler } from "smplr";
5+
import { getAudioContext } from "src/audio-context";
6+
7+
const inter = Inter({ subsets: ["latin"] });
8+
9+
export default function Tests() {
10+
const samplerRef = useRef<Sampler | null>(null);
11+
12+
useEffect(() => {
13+
const audioContext = getAudioContext();
14+
const sampler = new Sampler(audioContext, {
15+
buffers: { test: "test.mp3" },
16+
});
17+
samplerRef.current = sampler;
18+
}, []);
19+
20+
return (
21+
<>
22+
<Head>
23+
<title>smplr</title>
24+
<meta name="description" content="Plug and play web instruments" />
25+
<meta name="viewport" content="width=device-width, initial-scale=1" />
26+
</Head>
27+
<main className={"max-w-4xl mx-auto my-20 p-4" + inter.className}>
28+
<div className="flex items-end mb-16">
29+
<h1 className="text-6xl font-bold">smplr</h1>
30+
</div>
31+
32+
<div>
33+
<button
34+
onClick={() => {
35+
samplerRef.current?.start({
36+
note: "test",
37+
loop: true,
38+
loopStart: 1.0,
39+
loopEnd: 9.0,
40+
});
41+
}}
42+
>
43+
Play
44+
</button>
45+
</div>
46+
</main>
47+
</>
48+
);
49+
}

site/public/test.mp3

25.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)