ABCScoreWithPlayer
The <ABCScoreWithPlayer> React component renders ABC notation on screen with playback support.
Installation
pnpm add @music-ui/core @music-ui/reactUsage
The following code renders a score with the passed notes and the playback buttons:
Wrap your app in a <PlayerProvider> if you want to use playback features.
import { playerFactory } from "@music-ui/core";
import { ABCScoreWithPlayer, PlayerProvider } from "@music-ui/react";
import "@music-ui/abc/styles.css";
const player = playerFactory();
function App() {
return (
<PlayerProvider player={player}>
<main>
<h1>My App</h1>
{/* rest of your app */}
<ABCScoreWithPlayer>CDEF GABc|</ABCScoreWithPlayer>
</main>
</PlayerProvider>
);
}Output:
With free tempo:
import { playerFactory } from "@music-ui/core";
import { ABCScoreWithPlayer, PlayerProvider } from "@music-ui/react";
import "@music-ui/abc/styles.css";
const player = playerFactory();
function App() {
return (
<PlayerProvider player={player}>
<main>
<h1>My App</h1>
{/* rest of your app */}
<ABCScoreWithPlayer>
M: 1/1 L: 1/1 Q: 200 C D E F G A B c || c d e f g a b c' |
</ABCScoreWithPlayer>
</main>
</PlayerProvider>
);
}Component props
In addition to the ABCScore component props, the component accepts the following props:
| Name | Type | Default Value | Description |
|---|---|---|---|
showPiano | boolean | false | Displays or hides the piano view |
pianoOptions | object | DEFAULT_PIANO_OPTIONS | Props expected by the Piano renderer |
showTempoControls | boolean | true | Displays or hides the tempo controls |
highlightBars | boolean | false | Highlights the current played bar |
playButtonLabel | string | Play | The play button aria label |
stopButtonLabel | string | Pause | The stop button aria label |
pauseButtonLabel | string | Stop | The pause button aria label |
resetTempoButtonLabel | string | Reset Tempo | The reset tempo button aria label |
playButtonContent | ReactNode | Play | The play button content |
stopButtonContent | ReactNode | Pause | The stop button content |
pauseButtonContent | ReactNode | Stop | The pause button content |
resetTempoButtonContent | ReactNode | Reset | The reset tempo button content |
Props showcase
A showcase of the component props:
import { playerFactory } from "@music-ui/core";
import { ABCScoreWithPlayer, PlayerProvider } from "@music-ui/react";
import "@music-ui/abc/styles.css";
import "@music-ui/piano/styles.css";
const player = playerFactory();
function App() {
return (
<PlayerProvider player={player}>
<ABCScoreWithPlayer highlightBars>CDEF GABc|cBAGFEDC|</ABCScoreWithPlayer>
<ABCScoreWithPlayer showTempoControls={false}>
CDEF GABc|
</ABCScoreWithPlayer>
<ABCScoreWithPlayer
showPiano
pianoOptions={{ showOctaves: true, octaves: 3 }}
>
CDEF GABc|
</ABCScoreWithPlayer>
</PlayerProvider>
);
}highlightBars
showTempoControls
showPiano
Customize buttons
The buttons contain plain text labels by default. You can pass custom JSX as in the documentation examples:
import { playerFactory } from "@music-ui/core";
import { PianoWithPlayer, PlayerProvider } from "@music-ui/react";
import "@music-ui/piano/styles.css";
// you can use any icon source
import { IoPlay, IoMusicalNotes } from "react-icons/io5";
const player = playerFactory();
function App() {
return (
<PlayerProvider player={player}>
<ABCScoreWithPlayer
playButtonContent={
<>
<IoPlay /> Play
</>
}
>
CDEF GABc|cBAGFEDC|
</ABCScoreWithPlayer>
</PlayerProvider>
);
}Last updated on