mleml/lib.rs
1//! A library for working with music written in MML (music macro language) fashion.
2//!
3//! It strives to be flexible enough to:
4//! 1. allow creating sound output closely resembling that of a given platform
5//! 2. allow any type of usage, from a basic MML compiler to a DAW-like environment.
6//!
7//! # Overview
8//! Base trait for other traits is [`Resource`][crate::resource::Resource], which
9//! provides a name, a description, and a unique ID. It also provides configuration,
10//! which is a **flat** JSON array, and state, which is a byte-slice.
11//!
12//! Every resource has at least one function that, besides other inputs and outputs,
13//! takes config and state and returns new state. This allows making the functions pure.
14//!
15//! These resources are defined:
16//! - Mod: essentially is a function that takes some piece of data and produces a new
17//! piece of data.
18//! - Channel: takes a piece of data and is expected to pass it through multiple
19//! mods, respecting their configs and states.
20//! - Mixer: takes sounds (or pieces of sounds) and combines them into a new sound,
21//! which is returned along with unused pieces.
22//!
23//! Vec<Rc<dyn Mod>> is extended with Pipeline trait, adding functions to help with
24//! constructing a valid senquence of mods and examining how and when the data type changes.
25//!
26//! # Logic example
27//! Suppose that a program is receiving a stream of instructions of some sort,
28//! some of which may indicate that one or multiple channels need to be played,
29//! and the program simply needs to produce the resulting music.
30//!
31//! The program would create a necessary number of channels that produce sound from notes
32//! and a mixer. It would then apply state changes (for example, octave shifts)
33//! to channels' states, and, when an instructions asks to play a note,
34//! do that on the required channel, and then pass the newly created sound, along with
35//! previously left unused pieces of sound, to the mixer. Mixed sound is appended
36//! to the resulting music, and leftover pieces are reused in the next invocation.
37//! On all invocations of a channel or a mixer, their output state is reused,
38//! like mixer's leftover sounds.
39
40#![feature(ptr_from_ref)]
41#![cfg_attr(feature = "extra", feature(hash_set_entry))]
42#![warn(missing_docs)]
43// #![feature(rustdoc_missing_doc_code_examples)]
44// #![warn(rustdoc::missing_doc_code_examples)]
45
46pub mod resource;
47pub mod types;
48
49//Feature-gating is in extra/mod.rs
50pub mod extra;