music21/humdrum/comment.rs
1//! A `!!` line of a Humdrum file, music21's `GlobalComment`, and a `!`
2//! comment in one spine, its `SpineComment`.
3
4/// A comment on the whole table, kept in the score where it was written:
5/// music21's `GlobalComment`.
6///
7/// Its priority is the one music21 gives it, which puts it before the music
8/// standing at its offset.
9///
10/// ```
11/// use music21::humdrum::GlobalComment;
12///
13/// let comment = GlobalComment::new("transcribed by hand", -37);
14/// assert_eq!(comment.comment(), "transcribed by hand");
15/// assert_eq!(comment.priority(), -37);
16/// ```
17#[derive(Clone, Debug, Default, PartialEq, Eq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[must_use]
20pub struct GlobalComment {
21 comment: String,
22 priority: i32,
23}
24
25impl GlobalComment {
26 /// A comment with the priority music21 sorts it by.
27 pub fn new(comment: impl Into<String>, priority: i32) -> Self {
28 Self {
29 comment: comment.into(),
30 priority,
31 }
32 }
33
34 /// What it says: music21's `comment`.
35 pub fn comment(&self) -> &str {
36 &self.comment
37 }
38
39 /// music21's `priority`, which sorts it among what stands at its offset.
40 pub fn priority(&self) -> i32 {
41 self.priority
42 }
43}
44
45/// A `!` comment in one spine, kept where it was written: music21's
46/// `SpineComment`. Its priority, the line it was written on, is the
47/// event's.
48///
49/// ```
50/// use music21::humdrum::SpineComment;
51///
52/// assert_eq!(SpineComment::new("Cantus").comment(), "Cantus");
53/// ```
54#[derive(Clone, Debug, Default, PartialEq, Eq)]
55#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56#[must_use]
57pub struct SpineComment {
58 comment: String,
59}
60
61impl SpineComment {
62 /// A comment saying `comment`.
63 pub fn new(comment: impl Into<String>) -> Self {
64 Self {
65 comment: comment.into(),
66 }
67 }
68
69 /// What it says: music21's `comment`.
70 pub fn comment(&self) -> &str {
71 &self.comment
72 }
73}