A simple Rust library for working with .nbs files from Open Note Block Studio.
This library references pynbs and implements its basic functionality, aiming to serve as a fundamental NBS file processing library. Currently supports version 6 of the NBS standard.
However, due to language differences, some adaptations have been made, so behavior may not always be consistent. Since this project is quite niche, it hasn't been thoroughly tested. If you encounter any issues or have feature requests, please submit an issue.
This crate is in early development with a frequently changing API. Please pin your dependency to a specific version.
use rsnbs::note::{Instrument, Key, Note, Tone};
use rsnbs::song::Song;
use rsnbs::types::{Position, Tick, TimeAnchor};
// example 1: iterating over a song's notes
let song: Song = Song::open_nbs("fixtures/source.nbs").unwrap();
for (pos, note) in &song.notes {
let tick: Tick = pos.into_tick();
let key: Key = note.tone.key;
println!("tick: {tick}, key: {key}");
}
// example 2: generating a new song programmatically
let mut song: Song = Song::new();
song.header.is_loop = true;
for i in 0..25 {
let pos: Position = Position::new(i, 0);
let key: Key = Key::from_minecraft_note(i).unwrap();
let tone: Tone = Tone::new(Instrument::Harp, key);
song.notes.insert(pos, Note::new(tone));
}
song.save_nbs("fixtures/generated_example.nbs").unwrap();