bppt/structure.rs
1use derive_new::new;
2use std::fmt::Debug;
3use std::num::{NonZeroU16, NonZeroU8, NonZeroUsize};
4
5mod de;
6mod default;
7mod iter;
8
9/// N container. Stores mask atoms from the score and the length of the set used to calculate the notes frequencies.
10/// To iterate through flattened mask atoms (without container atoms), use [`flat_iter`](fn@Notes::flat_iter).
11#[derive(new, PartialEq, Debug, Clone)]
12pub struct Notes {
13 /// Length of the note set used to calculate note frequencies.
14 pub set: u8,
15 pub(crate) score: Vec<Atom>,
16}
17
18/// Mask atoms are musical bricks from the score that either indicate :
19/// - a sound (or silence)
20/// - a command (to change parametters)
21/// - a wrapper (an element applying rules on the atoms it contains)
22/// To iterate through flattened mask atoms (without container atoms), use [`Notes::flat_iter(&self)`].
23#[derive(PartialEq, Debug, Clone)]
24pub enum Atom {
25 /// Set octave
26 O(NonZeroU8),
27 /// Set length
28 L(NonZeroU8),
29 /// Set volume
30 V(u8),
31 /// Play a note from the set using the set index and the tuple level (a number to divide the length by if the note is in a tuple, 1 by default)
32 N(u8, NonZeroUsize),
33 /// Play a rest
34 Rest(NonZeroUsize),
35 /// Increase the octave
36 OIncr,
37 /// Decrease the octave
38 ODecr,
39 /// Increase the length
40 LIncr,
41 /// Decrease the length
42 LDecr,
43 /// Increase the volume
44 VIncr,
45 /// Decrease the volume
46 VDecr,
47 /// Extend the previous note (implementation may vary)
48 More,
49 /// Loop the contained atom sequence n times
50 Loop(NonZeroU16, Vec<Atom>),
51 /// Tuplet : alter the contained atoms so that the total of their length equals the length of a single note
52 Tuplet(Vec<Atom>),
53}