pub(crate) mod raw;
pub mod cn3;
pub mod midi;
pub mod nc2;
pub mod nc2d;
pub mod nd2;
pub mod nd3;
pub mod ne3;
pub mod ne4;
pub mod ne5;
pub mod ne6;
pub mod ne7;
pub mod ng2;
pub mod nl4;
pub mod nla1;
pub mod no3;
pub mod np;
pub mod np2;
pub mod np3;
pub mod np4;
pub mod np5;
pub mod npip;
pub mod npno;
pub mod ns2;
pub mod ns3;
pub mod ns4;
pub mod nsclassic;
pub mod nsmp;
pub mod nsmpproj;
pub mod nw;
pub mod nw2;
pub mod sysex;
use crate::error::{Error, ParseError};
pub(crate) fn known_version(
format: &'static str,
version: u32,
supported: &'static [u32],
) -> Result<(), Error> {
if supported.contains(&version) {
Ok(())
} else {
Err(ParseError::UnsupportedVersion {
format,
version,
supported,
}
.into())
}
}
#[cfg(feature = "bundle")]
pub(crate) fn zip_members(
reader: &mut (impl std::io::Read + std::io::Seek),
format: &'static str,
) -> Result<Vec<(String, crate::cbin::Cbin<crate::cbin::RawBody>)>, Error> {
use std::io::Read;
let mut zip = zip::ZipArchive::new(reader)?;
let mut members = Vec::new();
for i in 0..zip.len() {
let mut file = zip.by_index(i)?;
if file.is_dir() {
continue;
}
let name = file.name().to_string();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let member = crate::cbin::read(&mut std::io::Cursor::new(buffer), format)?;
members.push((name, member));
}
Ok(members)
}
#[cfg(feature = "bundle")]
pub(crate) fn zip_raw_members(
reader: &mut (impl std::io::Read + std::io::Seek),
) -> Result<Vec<(String, crate::cbin::Cbin<crate::cbin::RawBody>)>, Error> {
use std::io::Read;
let mut zip = zip::ZipArchive::new(reader)?;
let mut members = Vec::new();
for i in 0..zip.len() {
let mut file = zip.by_index(i)?;
if file.is_dir() || file.name().ends_with("meta.xml") {
continue;
}
let name = file.name().to_string();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let member = crate::cbin::read_raw(&mut std::io::Cursor::new(buffer))?;
members.push((name, member));
}
Ok(members)
}