mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 22:52:32 +00:00
Move FileProperties to types
This commit is contained in:
parent
0b79cd6bcf
commit
30bea9c24b
3 changed files with 61 additions and 61 deletions
|
@ -1,62 +1,2 @@
|
||||||
pub(crate) mod logic;
|
pub(crate) mod logic;
|
||||||
pub(crate) mod tags;
|
pub(crate) mod tags;
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
/// Various *immutable* audio properties
|
|
||||||
///
|
|
||||||
/// NOTE: All fields are invalidated after any type of conversion
|
|
||||||
pub struct FileProperties {
|
|
||||||
duration: Duration,
|
|
||||||
bitrate: Option<u32>,
|
|
||||||
sample_rate: Option<u32>,
|
|
||||||
channels: Option<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FileProperties {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
duration: Duration::ZERO,
|
|
||||||
bitrate: None,
|
|
||||||
sample_rate: None,
|
|
||||||
channels: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FileProperties {
|
|
||||||
/// Create a new FileProperties
|
|
||||||
pub const fn new(
|
|
||||||
duration: Duration,
|
|
||||||
bitrate: Option<u32>,
|
|
||||||
sample_rate: Option<u32>,
|
|
||||||
channels: Option<u8>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
duration,
|
|
||||||
bitrate,
|
|
||||||
sample_rate,
|
|
||||||
channels,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Duration
|
|
||||||
pub fn duration(&self) -> Duration {
|
|
||||||
self.duration
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bitrate (kbps)
|
|
||||||
pub fn bitrate(&self) -> Option<u32> {
|
|
||||||
self.bitrate
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sample rate (Hz)
|
|
||||||
pub fn sample_rate(&self) -> Option<u32> {
|
|
||||||
self.sample_rate
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Channel count
|
|
||||||
pub fn channels(&self) -> Option<u8> {
|
|
||||||
self.channels
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +1,4 @@
|
||||||
pub(crate) mod album;
|
pub(crate) mod album;
|
||||||
pub(crate) mod anytag;
|
pub(crate) mod anytag;
|
||||||
pub(crate) mod picture;
|
pub(crate) mod picture;
|
||||||
|
pub(crate) mod properties;
|
||||||
|
|
59
src/types/properties.rs
Normal file
59
src/types/properties.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// Various *immutable* audio properties
|
||||||
|
///
|
||||||
|
/// NOTE: All fields are invalidated after any type of conversion
|
||||||
|
pub struct FileProperties {
|
||||||
|
duration: Duration,
|
||||||
|
bitrate: Option<u32>,
|
||||||
|
sample_rate: Option<u32>,
|
||||||
|
channels: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for FileProperties {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
duration: Duration::ZERO,
|
||||||
|
bitrate: None,
|
||||||
|
sample_rate: None,
|
||||||
|
channels: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileProperties {
|
||||||
|
/// Create a new FileProperties
|
||||||
|
pub const fn new(
|
||||||
|
duration: Duration,
|
||||||
|
bitrate: Option<u32>,
|
||||||
|
sample_rate: Option<u32>,
|
||||||
|
channels: Option<u8>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
duration,
|
||||||
|
bitrate,
|
||||||
|
sample_rate,
|
||||||
|
channels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Duration
|
||||||
|
pub fn duration(&self) -> Duration {
|
||||||
|
self.duration
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bitrate (kbps)
|
||||||
|
pub fn bitrate(&self) -> Option<u32> {
|
||||||
|
self.bitrate
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sample rate (Hz)
|
||||||
|
pub fn sample_rate(&self) -> Option<u32> {
|
||||||
|
self.sample_rate
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Channel count
|
||||||
|
pub fn channels(&self) -> Option<u8> {
|
||||||
|
self.channels
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue