Skip to main content

music21/stream/
enums.rs

1//! The members of music21's `stream.enums`, by music21's names and values.
2//!
3//! The enums themselves are Python classes; what is here is their members,
4//! so that anything building them builds music21's. `StaffType` is the
5//! crate's [`StaffType`](crate::layout::StaffType) by its MusicXML names.
6
7use crate::common::enums::Member;
8use crate::common::enums::MemberValue::Text;
9
10/// `StaffType`: what a staff is for, each member's value the name
11/// MusicXML's `<staff-type>` gives it.
12pub const STAFF_TYPE: &[Member] = &[
13    ("REGULAR", Text("regular")),
14    ("OSSIA", Text("ossia")),
15    ("CUE", Text("cue")),
16    ("EDITORIAL", Text("editorial")),
17    ("ALTERNATE", Text("alternate")),
18    ("OTHER", Text("other")),
19];
20
21/// `GivenElementsBehavior`: how a stream built with elements places them.
22pub const GIVEN_ELEMENTS_BEHAVIOR: &[Member] = &[
23    ("APPEND", Text("append")),
24    ("OFFSETS", Text("offsets")),
25    ("INSERT", Text("insert")),
26];
27
28/// `RecursionType`: the order a context search looks through a stream in.
29pub const RECURSION_TYPE: &[Member] = &[
30    ("ELEMENTS_FIRST", Text("elementsFirst")),
31    ("FLATTEN", Text("flatten")),
32    ("ELEMENTS_ONLY", Text("elementsOnly")),
33];
34
35/// `ShowNumber`: whether a measure's number is shown.
36pub const SHOW_NUMBER: &[Member] = &[
37    ("DEFAULT", Text("default")),
38    ("ALWAYS", Text("always")),
39    ("NEVER", Text("never")),
40];
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45    use crate::layout::StaffType;
46
47    /// Each `StaffType` member's value names the crate's staff type of the
48    /// same name, and back.
49    #[test]
50    fn staff_type_members_are_the_crates_staff_types() {
51        for (name, value) in STAFF_TYPE {
52            let Text(value) = value else {
53                panic!("{name} holds no text");
54            };
55            let found = StaffType::from_name(value).expect("a staff type");
56            assert_eq!(found.as_str(), *value);
57            assert_eq!(value.to_uppercase(), *name);
58        }
59    }
60}