use std::ops::Range;
#[derive(Copy, Clone, Debug)]
pub struct SampleLocation {
pub channel: usize,
pub frame: usize,
}
impl SampleLocation {
pub fn new(channel: usize, frame: usize) -> Self {
Self { channel, frame }
}
pub fn channel(channel: usize) -> Self {
Self { channel, frame: 0 }
}
pub fn frame(frame: usize) -> Self {
Self { channel: 0, frame }
}
pub fn offset_frames(self, frame_offset: usize) -> Self {
self.with_frame(self.frame + frame_offset)
}
pub fn offset_channels(self, channel_offset: usize) -> Self {
self.with_channel(self.channel + channel_offset)
}
pub fn with_channel(&self, channel: usize) -> Self {
Self {
channel,
frame: self.frame,
}
}
pub fn with_frame(&self, frame: usize) -> Self {
Self {
channel: self.channel,
frame,
}
}
pub fn origin() -> Self {
Self {
channel: 0,
frame: 0,
}
}
}
pub struct SampleRange {
pub channel: usize,
pub frame: usize,
pub channel_count: usize,
pub frame_count: usize,
}
impl SampleRange {
pub fn new(channel: usize, frame: usize, channel_count: usize, frame_count: usize) -> Self {
Self {
channel,
frame,
channel_count,
frame_count,
}
}
pub fn channel_and_frame_count(channel_count: usize, frame_count: usize) -> Self {
Self {
channel: 0,
frame: 0,
channel_count,
frame_count,
}
}
pub fn channel_range(&self) -> Range<usize> {
self.channel..self.channel + self.channel_count
}
pub fn frame_range(&self) -> Range<usize> {
self.frame..self.frame + self.frame_count
}
}