Skip to main content

to_tsv

Function to_tsv 

Source
pub fn to_tsv(stream: &Stream, version: Version) -> Result<String>
Expand description

A score written as one of the lab’s tables: music21’s M21toTSV, which writes a row for every numeral of the score, in the order a walk of it meets them.

Every column the standard names is written, in the standard’s own order, and what the standard has no answer for is written empty, as music21 writes it: where a phrase ends, the note held under a chord, the tones a chord changes. The columns music21 fills from a numeral’s editorial – the cells its reader did not read and kept beside the row – are empty here too; to_tsv_with_extra is how a caller hands them back.

use music21_rs::romantext::tsv::{Version, from_tsv, to_tsv};

let table = "chord\tmeasure\tbeat\ttimesig\tglobal_key\tlocal_key\tnumeral\n\
             I\t1\t1.0\t4/4\tC\tC\tI\n";
let written = to_tsv(&from_tsv(table, Version::One)?, Version::One)?;
let mut lines = written.lines();
assert!(lines.next().is_some_and(|header| header.starts_with("chord\t")));
assert!(lines.next().is_some_and(|row| row.starts_with("I\t\t1\t1.0")));

§Errors

A version 1 table with no row at all – music21 reads the global key off the first numeral and asks its walk for one – or a numeral standing where no meter is in force, which has no beat.