This crate provides functionality for decoding & encoding (Open)NoteBlockStudio buffers.
It supports the original NBS format, aswell as version 1-4 of the unofficial new format introduced in OpenNoteBlockStudio.
Documentation on the NBS format can be found at NoteBlockStudio and OpenNoteBlockStudio.
use nbs::{
noteblocks::{instrument, note::Note},
Nbs,
};
use std::fs::File;
fn main() {
let mut file = File::open("tests/1.nbs").unwrap();
let mut nbs = Nbs::decode(&mut file).unwrap();
nbs.noteblocks.layers[2].name = String::from("Cows");
nbs.noteblocks.layers[2].volume = 25;
nbs.noteblocks.layers[2].notes.insert(
0,
Note::new(instrument::COW_BELL, 33, Some(100), Some(100), Some(0)),
);
nbs.encode(&mut File::create("out1.nbs").unwrap()).unwrap();
}
use nbs::{
header::Header,
noteblocks::{instrument, instrument::CustomInstruments, layer::Layer, note::Note, NoteBlocks},
Nbs, NbsFormat,
};
use std::fs::File;
fn main() {
let mut file = File::create("out2.nbs").unwrap();
let mut header = Header::new(NbsFormat::OpenNoteBlockStudio(4));
header.song_name = String::from("test");
let mut noteblocks = NoteBlocks::new();
noteblocks
.layers
.push(Layer::from_format(NbsFormat::OpenNoteBlockStudio(4)));
for i in 0..20 {
noteblocks.layers[0].notes.insert(
i,
Note::new(
instrument::PIANO,
(33 + i) as i8,
Some(100),
Some(100),
Some(0),
),
);
}
let custom_instruments = CustomInstruments::new();
let mut nbs = Nbs::from_componets(header, noteblocks, custom_instruments);
nbs.update();
nbs.encode(&mut file);
}