Library for rendering and playing Minecraft Note Block songs, built on NoteBlockLib and AudioMixer.
To use NoteBlockRenderer in your application, check out the Usage section.
- Loads all formats supported by NoteBlockLib (.nbs, .mid, .txt, .mcsp and .mcsp2)
- Exports to all formats supported by AudioMixer (.wav, .flac, .mp3, .opus)
- Very accurate, high quality and fast song renderer
- Supports Custom Instruments
- Supports Tempo Changers
- Supports Sound Stoppers
- Optional timing jitter for a more natural sound
- Optional multithreaded rendering
- Plays songs in real time using the Java Sound API (SourceDataLine)
To use NoteBlockRenderer with Gradle/Maven you can get it from Maven Central, Lenni0451's Maven or Jitpack. You can also find instructions how to implement it into your build script there.
If you just want the latest jar file you can download it from GitHub Actions.
A SoundProvider supplies the sound samples used for instruments. The following implementations are included:
NoteBlockStudioSoundProviderloads sounds from the default Minecraft Note Block Studio sound directory for the current operating system. UseDirectorySoundProviderfor a custom directory.DirectorySoundProviderloads sounds from a local directory, passed as aString,FileorPath.ResourceSoundProviderloads sounds from classpath resources, such as files bundled in your application's JAR. It defaults to the classpath root.MapSoundProviderloads sounds from aMap<String, byte[]>supplied to its constructor.UrlSoundProviderdownloads Minecraft instrument sounds from a Minecraft assets repository by default. You can pass a different base URL to its constructor.NoOpSoundProvidersupplies no sounds and throws anIOExceptionfor every request. Can be used as the last provider in a chain to get a clear error message if a sound is missing.
DirectorySoundProvider, ResourceSoundProvider and MapSoundProvider look up Minecraft sounds at minecraft/<mcSoundPath>.ogg relative to their base path.
You can chain providers using first.then(second). The second provider is used if the first provider throws an IOException while loading the requested sound sample. For example, try Note Block Studio sounds first, then bundled resources, and finally download missing Minecraft sounds:
SoundProvider soundProvider = new NoteBlockStudioSoundProvider()
.then(new ResourceSoundProvider("sounds/"))
.then(new UrlSoundProvider());Create a NoteBlockRenderer with a song, an AudioFormat and a sound provider.
Call renderFully(<progressConsumer>) to render the entire song. The progress consumer receives percentages from 0 to 100.
Create a NoteBlockPlayer with a SourceDataLine, a song and a sound provider. The player is paused by default. Call setPaused(false) to begin playback.
You can pause and resume using setPaused, seek using setTick, setProgress or setMillisecondPosition, and read the current position using getTick, getProgress or getMillisecondPosition.
Call close() when you are done with the player to stop its audio writer and close the audio line.
Both renderers accept an AudioMixerNoteBlockRenderer.Options instance in their constructor. Use its with... methods to change the options you want.
Complete examples with imports can be found in the src/example directory:
- FileExample renders a song and saves it as MP3.
- RealtimeExample plays a song with volume, position and pause controls.
Here is a list of reference implementations that use NoteBlockRenderer:
- nbs-cli: CLI tool for working with NBS files.
- NoteBlockTool-Web: Web App for rendering Minecraft Note Block Studio songs to audio files.
If you encounter any issues, please report them on the
issue tracker.
If you just want to talk or need help implementing NoteBlockRenderer feel free to join my
Discord.