pub struct Melody {
pub items: Vec<MelodyItem>,
}Expand description
A single monophonic line of notes and rests in sequence.
Fields§
§items: Vec<MelodyItem>The ordered notes and rests of the line.
Implementations§
Source§impl Melody
impl Melody
Sourcepub fn new(items: Vec<MelodyItem>) -> Result<Self, MusicError>
pub fn new(items: Vec<MelodyItem>) -> Result<Self, MusicError>
Builds a melody, validating that every item duration is non-negative.
Sourcepub fn total_duration(&self) -> Time
pub fn total_duration(&self) -> Time
Returns the summed duration of all items in the line.
§Examples
use sim_lib_music_core::{Melody, MelodyItem, Rest, Time};
let melody = Melody::new(vec![
MelodyItem::Rest(Rest::new(Time::from_integer(1)).unwrap()),
MelodyItem::Rest(Rest::new(Time::from_integer(2)).unwrap()),
])
.unwrap();
assert_eq!(melody.total_duration(), Time::from_integer(3));Trait Implementations§
impl Eq for Melody
Source§impl MusicObject for Melody
impl MusicObject for Melody
impl StructuralPartialEq for Melody
Auto Trait Implementations§
impl Freeze for Melody
impl RefUnwindSafe for Melody
impl Send for Melody
impl Sync for Melody
impl Unpin for Melody
impl UnsafeUnpin for Melody
impl UnwindSafe for Melody
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more