euphony_store/
lib.rs

1use euphony_compiler::{Hash, Writer};
2use euphony_mix::Mixer;
3use std::{io, path::PathBuf};
4
5mod codec;
6mod dc;
7mod ext;
8mod mix;
9pub mod storage;
10pub mod timeline;
11
12pub type DefaultStorage = storage::fs::Directory;
13pub type DefaultTimeline = timeline::Timeline;
14
15#[derive(Clone, Debug, Default)]
16pub struct Store<S: Writer = DefaultStorage, T: Writer = DefaultTimeline> {
17    pub storage: S,
18    pub timeline: T,
19}
20
21impl Store {
22    #[inline]
23    pub fn new(path: PathBuf) -> Self {
24        Self {
25            storage: DefaultStorage::new(path),
26            timeline: Default::default(),
27        }
28    }
29}
30
31impl<S: storage::Storage + Writer, T: Writer> Store<S, T> {
32    #[inline]
33    pub fn mix_group<M: Mixer<Error = E>, E: Into<io::Error>>(
34        &self,
35        group: &Hash,
36        mixer: &mut M,
37    ) -> io::Result<()> {
38        mix::mix(&self.storage, group, mixer)
39    }
40}
41
42impl<S: Writer, T: Writer> Writer for Store<S, T> {
43    #[inline]
44    fn is_cached(&self, hash: &Hash) -> bool {
45        self.storage.is_cached(hash)
46    }
47
48    #[inline]
49    fn sink(&mut self, hash: &Hash) -> euphony_node::BoxProcessor {
50        self.storage.sink(hash)
51    }
52
53    #[inline]
54    fn group<I: Iterator<Item = euphony_compiler::Entry>>(
55        &mut self,
56        name: &str,
57        hash: &Hash,
58        entries: I,
59    ) {
60        self.storage.group(name, hash, entries);
61        self.timeline.group(name, hash, None.into_iter());
62    }
63
64    fn buffer<
65        F: FnOnce(
66            Box<dyn euphony_compiler::BufferReader>,
67        ) -> euphony_compiler::Result<Vec<euphony_compiler::ConvertedBuffer>, E>,
68        E,
69    >(
70        &self,
71        path: &str,
72        sample_rate: u64,
73        init: F,
74    ) -> euphony_compiler::Result<Vec<euphony_compiler::CachedBuffer>, E> {
75        self.storage.buffer(path, sample_rate, init)
76    }
77}