Skip to main content

deduplicate

Function deduplicate 

Source
pub fn deduplicate(stream: &mut Stream)
Expand description

Folds together the instruments a part says more than once: music21’s instrument.deduplicate.

Each part of a score is done on its own, or the stream itself where it holds no parts, and the instruments standing at one offset of it, in a measure or the part itself, are settled together. Where they agree on the part’s name and on their own, or say nothing, all of them take those names; then of instruments all of one kind only the first is kept, and of instruments of several kinds the bare Instruments go.

use music21_rs::{instrument::deduplicate, Instrument, Stream, StreamElement};

let mut named = Instrument::new();
named.set_name(Some("Semi-Hollow Body".to_string()));
let mut guitar = Instrument::new();
guitar.set_part_name(Some("Electric Guitar".to_string()));
let mut stream = Stream::new();
stream.insert(4.0, named);
stream.insert(4.0, guitar);
deduplicate(&mut stream);
let [event] = stream.events() else { panic!("one instrument is left") };
let StreamElement::Instrument(left) = event.element() else { panic!() };
assert_eq!(left.part_name(), Some("Electric Guitar"));
assert_eq!(left.name(), Some("Semi-Hollow Body"));