lofty/musepack/
mod.rs

1//! Musepack specific items
2pub mod constants;
3mod read;
4pub mod sv4to6;
5pub mod sv7;
6pub mod sv8;
7
8use crate::ape::tag::ApeTag;
9use crate::id3::v1::tag::Id3v1Tag;
10use crate::id3::v2::tag::Id3v2Tag;
11use crate::properties::FileProperties;
12
13use lofty_attr::LoftyFile;
14
15/// Audio properties of an MPC file
16///
17/// The information available differs between stream versions
18#[derive(Debug, Clone, PartialEq)]
19pub enum MpcProperties {
20	/// MPC stream version 8 properties
21	Sv8(sv8::MpcSv8Properties),
22	/// MPC stream version 7 properties
23	Sv7(sv7::MpcSv7Properties),
24	/// MPC stream version 4-6 properties
25	Sv4to6(sv4to6::MpcSv4to6Properties),
26}
27
28impl Default for MpcProperties {
29	fn default() -> Self {
30		Self::Sv8(sv8::MpcSv8Properties::default())
31	}
32}
33
34impl From<MpcProperties> for FileProperties {
35	fn from(input: MpcProperties) -> Self {
36		match input {
37			MpcProperties::Sv8(sv8prop) => sv8prop.into(),
38			MpcProperties::Sv7(sv7prop) => sv7prop.into(),
39			MpcProperties::Sv4to6(sv4to6prop) => sv4to6prop.into(),
40		}
41	}
42}
43
44/// The version of the MPC stream
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
46pub enum MpcStreamVersion {
47	/// Stream version 8
48	#[default]
49	Sv8,
50	/// Stream version 7
51	Sv7,
52	/// Stream version 4 to 6
53	Sv4to6,
54}
55
56/// An MPC file
57#[derive(LoftyFile, Default)]
58#[lofty(read_fn = "read::read_from")]
59#[lofty(internal_write_module_do_not_use_anywhere_else)]
60pub struct MpcFile {
61	/// The stream version
62	pub(crate) stream_version: MpcStreamVersion,
63	/// An ID3v2 tag (Not officially supported)
64	#[lofty(tag_type = "Id3v2")]
65	pub(crate) id3v2_tag: Option<Id3v2Tag>,
66	/// An ID3v1 tag
67	#[lofty(tag_type = "Id3v1")]
68	pub(crate) id3v1_tag: Option<Id3v1Tag>,
69	/// An APEv1/v2 tag
70	#[lofty(tag_type = "Ape")]
71	pub(crate) ape_tag: Option<ApeTag>,
72	/// The file's audio properties
73	pub(crate) properties: MpcProperties,
74}
75
76impl MpcFile {
77	/// The version of the MPC stream
78	pub fn stream_version(&self) -> MpcStreamVersion {
79		self.stream_version
80	}
81}