m8_file_parser/lib.rs
1//! This library lets you parse Dirtywave M8 data
2//!
3//! See, in particular, the `read` method available on:
4//! - [`Song::read`]
5//! - [`Instrument::read`]
6//! - [`Scale::read`]
7//! - [`Theme::read`]
8//!
9//! E.g.:
10//! ```
11//! use m8_file_parser::*;
12//!
13//! let mut f = std::fs::File::open("./examples/songs/TEST-FILE.m8s").unwrap();
14//! let song = Song::read(&mut f).unwrap();
15//! dbg!(song);
16//! ```
17//!
18//! For song writing and file manipulation, you will need to load
19//! the whole file in memory, in order to be able to overwrite it
20//!
21//! ```
22//! use m8_file_parser::*;
23//! use m8_file_parser::remapper::Remapper;
24//! let mut song_data = std::fs::read("./examples/songs/V4EMPTY.m8s").unwrap();
25//! let mut song_reader = reader::Reader::new(song_data.clone());
26//! let mut song = Song::read_from_reader(&mut song_reader).unwrap();
27//!
28//! // let's renumber an instrument
29//! let mut remapper = Remapper::default_ver(song.version);
30//! let instrument : usize = 4;
31//! let to_instrument = 10;
32//! remapper.instrument_mapping.mapping[instrument] = to_instrument;
33//! remapper.instrument_mapping.to_move.push(instrument as u8);
34//! remapper.renumber(&mut song);
35//!
36//! dbg!(&song);
37//!
38//! let mut output_writer = writer::Writer::new(song_data);
39//!
40//! song.write(&mut output_writer);
41//! // ready to be written elsewhere
42//! let output_song_data = output_writer.finish();
43//! ```
44//!
45//! You also can perform more complex copies of chain, that
46//! will copy intrument/eq/table definitions required to copy
47//! a chain from a song to another
48//!
49//! ```
50//! use m8_file_parser::*;
51//! use m8_file_parser::remapper::Remapper;
52//!
53//! let mut from_file = std::fs::File::open("./examples/songs/TEST-FILE.m8s").unwrap();
54//! let from_song = Song::read(&mut from_file).unwrap();
55//! let mut empty_file = std::fs::File::open("./examples/songs/V6_2EMPTY.m8s").unwrap();
56//! let mut to_song = Song::read(&mut empty_file).unwrap();
57//! let chain : u8 = 12;
58//! let mapping =
59//! Remapper::create(&from_song, &to_song, vec![chain].iter()).unwrap();
60//! // you can inspec the mapping here if needed.
61//! // and apply the remapping
62//! mapping.apply(&from_song, &mut to_song);
63//! // you now have the chain 12 in to_song, and you can edit a song
64//! // cell to write it
65//! let final_chain = mapping.out_chain(chain);
66//! to_song.song.steps[2] = final_chain;
67//! ```
68mod eq;
69mod fx;
70mod instruments;
71pub mod reader;
72pub mod remapper;
73mod scale;
74mod settings;
75mod songs;
76mod theme;
77mod version;
78pub mod param_gatherer;
79pub mod writer;
80
81pub use eq::*;
82pub use fx::*;
83pub use instruments::*;
84pub use scale::*;
85pub use settings::*;
86pub use songs::*;
87pub use theme::*;
88pub use version::*;