1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use either::{Either, Either::Left, Either::Right};
use std::time::Duration;
use crate::backend::display::duration_estimate_to_str;
use crate::backend::units::frames_to_duration;
pub trait Signal {
fn frame_rate_hz(&self) -> u32;
fn num_channels(&self) -> u16;
fn num_frames_estimate(&self) -> Option<usize>;
fn duration_estimate(&self) -> Option<Duration> {
self.num_frames_estimate()
.map(|n| frames_to_duration(n, self.frame_rate_hz()))
}
fn duration_estimate_to_str(&self) -> String {
duration_estimate_to_str(self.duration_estimate())
}
}
impl<L, R> Signal for Either<L, R>
where
L: Signal,
R: Signal,
{
#[inline]
fn frame_rate_hz(&self) -> u32 {
match self {
Left(left) => left.frame_rate_hz(),
Right(right) => right.frame_rate_hz(),
}
}
#[inline]
fn num_channels(&self) -> u16 {
match self {
Left(left) => left.num_channels(),
Right(right) => right.num_channels(),
}
}
#[inline]
fn num_frames_estimate(&self) -> Option<usize> {
match self {
Left(left) => left.num_frames_estimate(),
Right(right) => right.num_frames_estimate(),
}
}
#[inline]
fn duration_estimate(&self) -> Option<Duration> {
match self {
Left(left) => left.duration_estimate(),
Right(right) => right.duration_estimate(),
}
}
#[inline]
fn duration_estimate_to_str(&self) -> String {
match self {
Left(left) => left.duration_estimate_to_str(),
Right(right) => right.duration_estimate_to_str(),
}
}
}