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
use crate::arnalisamplic::{LoadableDevice, Mapping}; use crate::{file_load_json as load_json, LoadPathPattern, Result}; use indexmap::IndexSet; use std::path::PathBuf; #[derive(Clone, Debug)] pub struct Device { inner: crate::filesystem::Device, } impl Device { pub fn new(inner: crate::filesystem::Device) -> Self { Device { inner } } pub fn sampling_dir(&self, sampling_id: &str) -> PathBuf { self.inner.sampling_dir(sampling_id).join("arnalisamplic") } pub fn sampling_mapping_file( &self, sampling_id: &str, mapping_id: &str, ) -> PathBuf { self.sampling_dir(sampling_id) .join(format!("{}.json", mapping_id)) } } impl LoadableDevice for Device { fn load_sampling_mapping_index( &self, sampling_id: &str, ) -> Result<IndexSet<String>> { IndexSet::load_path_pattern_from_dir( self.sampling_dir(sampling_id), "*.json", ) } fn load_sampling_mapping( &self, sampling_id: &str, mapping_id: &str, ) -> Result<Mapping> { load_json(self.sampling_mapping_file(sampling_id, mapping_id)) } }