Skip to main content

from_musedata

Function from_musedata 

Source
pub fn from_musedata(files: &[&str]) -> Result<Stream>
Expand description

Reads the files of a MuseData work, in order, into a score, as music21’s converter.parse reads a work’s directory or a single file.

Each part is a part of the score, named as its header names it, in measures as its measure records divide it, each measure opening with the barline its record draws and the first with the clef, key, meter and any tempo word the part’s attribute record gives. Notes, chords and rests take their lengths from the divisions of a quarter note; a stage-2 file also gives each note its beams, the accidental it shows, its articulations, fermatas, ornaments and dynamics, and its lyrics, and a back record starts another voice. A part written for a transposing instrument (X:) is turned to the pitch it sounds, and its accidentals are worked out again; a stage-1 part is given its best clef, its beams and its accidentals. The work’s title, number and movement are kept.

music21’s own habits are kept: every measure starts with a barline, the first measure is numbered one, a measure’s number is every digit of its record (so mheavy2 12 is measure 212), and a pitch of double sharps reads as a single sharp, of double flats as a single flat. Cue and grace notes are passed over, as is an attribute record after the first.

use music21_rs::musedata::from_musedata;

let part = "\n\n\n01/01/01 x\nWK#:1 MV#:1\nsource\nWork\nMovement\nFlute\n\
1 0\nGroup memberships: score\nscore: part 1 of 1\n\
$  K:0   Q:2   T:2/4   C:4\nC5     2        q     u\nD5     2        q     u\n\
measure 2\nE5     4        h     u\n/END\n";
let score = from_musedata(&[part])?;
assert_eq!(score.parts()[0].measures().len(), 2);

§Errors

A file with no part in it, an attribute record music21 cannot read, a clef or barline it does not know, a record whose length is not a number, or a transposition it has no interval for.