bms_rs/lib.rs
1//! The BMS format parser.
2//!
3//! Be-Music Source, called BMS for short, is a file format devised by Urao Yane in 1998 for a simulator of the game Beatmania by KONAMI. This describes what and when notes are arranged and its music metadata. It is a plain text file with some "command" lines starting with `#` character.
4//!
5//! # Usage
6//!
7//! At first, you can get the tokens stream with [`lex::parse`]. Then pass it and the random generator to [`parse::Bms::from_token_stream`] to get the notes data. Because BMS format has some randomized syntax.
8//!
9//! ```
10//! use bms_rs::{
11//! lex::parse,
12//! parse::{prompt::AlwaysHalt, rng::RngMock, Bms},
13//! };
14//!
15//! let source = std::fs::read_to_string("tests/lilith_mx.bms").unwrap();
16//! let token_stream = parse(&source).expect("must be parsed");
17//! let rng = RngMock([1]);
18//! let bms = Bms::from_token_stream(&token_stream, rng, AlwaysHalt).expect("must be parsed");
19//! ```
20//!
21//! # About the format
22//!
23//! ## Command
24//!
25//! Each command starts with `#` character, and other lines will be ignored. Some commands require arguments separated by whitespace character such as spaces or tabs.
26//!
27//! ```text
28//! #PLAYER 1
29//! #GENRE FUGA
30//! #TITLE BAR(^^)
31//! #ARTIST MikuroXina
32//! #BPM 120
33//! #PLAYLEVEL 6
34//! #RANK 2
35//!
36//! #WAV01 hoge.WAV
37//! #WAV02 foo.WAV
38//! #WAV03 bar.WAV
39//!
40//! #00211:0303030303
41//! ```
42//!
43//! ### Header command
44//!
45//! Header commands are used to express the metadata of the music or the definition for note arrangement.
46//!
47//! ### Message command
48//!
49//! Message command starts with `#XXXYY:ZZ...`. `XXX` is the number of the measure, `YY` is the channel of the message, and `ZZ...` is the object id sequence.
50//!
51//! The measure must start from 1, but some player may allow the 0 measure (i.e. Lunatic Rave 2).
52//!
53//! The channel commonly expresses what the lane be arranged the note to.
54//!
55//! The object id is formed by 2-digit of 36-radix (`[0-9a-zA-Z]`) integer. So the sequence length must be an even number. The `00` object id is the special id, expresses the rest (no object lies). The object lies on the position divided equally by how many the object is in the measure. For example:
56//!
57//! ```text
58//! #00211:0303000303
59//! ```
60//!
61//! This will be placed as:
62//!
63//! ```text
64//! 003|--|--------------|
65//! | |03 |
66//! | |03 |
67//! | | |
68//! | |03 |
69//! 002|--|03------------|
70//! | | [] [] [] |
71//! |()|[] [] [] []|
72//! |-----------------|
73//! ```
74
75#![warn(missing_docs)]
76#![deny(rustdoc::broken_intra_doc_links)]
77#![cfg_attr(docsrs, feature(doc_cfg))]
78
79pub mod bms;
80#[cfg(feature = "bmson")]
81#[cfg_attr(docsrs, doc(cfg(feature = "bmson")))]
82pub mod bmson;
83
84pub use bms::{lex, parse, time};