From 2f3554e354ea0cbfe788387785c4ef227fa4ecef Mon Sep 17 00:00:00 2001 From: mii443 Date: Wed, 14 Feb 2024 18:52:15 +0900 Subject: [PATCH] wip --- local_test.yaml | 18 +++++++++ src/commands/run.rs | 75 +++++++++++++++++++++++++++++++++++- src/config.rs | 8 ++++ src/device/virtual_device.rs | 8 +--- 4 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 local_test.yaml diff --git a/local_test.yaml b/local_test.yaml new file mode 100644 index 0000000..a33b03b --- /dev/null +++ b/local_test.yaml @@ -0,0 +1,18 @@ +virtual_devices: + - name: "mic" + channels: 2 + sample_rate: 96000 +routes: + input: + - name: "Mic" + virtual_device: "mic" + device: + local: + name: "VoiceMeeter Output (VB-Audio VoiceMeeter VAIO)" + output: + - name: "Speaker" + input: + virtual_device: "mic" + device: + local: + name: "VoiceMeeter Input (VB-Audio VoiceMeeter VAIO)" \ No newline at end of file diff --git a/src/commands/run.rs b/src/commands/run.rs index 8b50a2a..943f6c5 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,5 +1,7 @@ use std::io::Read; +use cpal::{traits::{DeviceTrait, HostTrait}, Device}; + use crate::args::Run; pub fn run(run: Run) { @@ -22,5 +24,76 @@ pub fn run(run: Run) { let config: crate::config::Config = serde_yaml::from_str(&buf).unwrap(); - println!("{:?}", config); + let host = cpal::default_host(); + let input_devices: Vec = host.input_devices().unwrap().collect(); + let output_devices: Vec = host.output_devices().unwrap().collect(); + + // create virtual devices + let mut virtual_devices = Vec::new(); + for virtual_device in config.virtual_devices { + let device = crate::device::virtual_device::VirtualDevice::new(virtual_device.name, virtual_device.channels, virtual_device.sample_rate); + virtual_devices.push(device); + } + + for input_route in config.routes.input { + println!("Input: {}", input_route.name); + println!(" Virtual device: {}", input_route.virtual_device); + if virtual_devices.iter().any(|device| device.name == input_route.virtual_device) { + println!(" Found"); + } else { + println!(" Not found"); + } + + match input_route.device { + crate::config::Device::Local { local } => { + println!(" Local device: {}", local.name); + if input_devices + .iter() + .any(|device| device.name().unwrap() == local.name) + { + println!(" Found"); + } else { + println!(" Not found"); + } + } + crate::config::Device::Remote { remote } => { + println!(" Remote device: {}", remote.address); + println!(" Port: {}", remote.port); + println!(" Protocol: {}", remote.protocol); + println!(" Buffer: {}", remote.buffer); + println!(" Channels: {}", remote.channels); + } + } + } + + for output_route in config.routes.output { + println!("Output: {}", output_route.name); + println!(" Virtual device: {}", output_route.input.virtual_device); + if virtual_devices.iter().any(|device| device.name == output_route.input.virtual_device) { + println!(" Found"); + } else { + println!(" Not found"); + } + + match output_route.device { + crate::config::Device::Local { local } => { + println!(" Local device: {}", local.name); + if output_devices + .iter() + .any(|device| device.name().unwrap() == local.name) + { + println!(" Found"); + } else { + println!(" Not found"); + } + } + crate::config::Device::Remote { remote } => { + println!(" Remote device: {}", remote.address); + println!(" Port: {}", remote.port); + println!(" Protocol: {}", remote.protocol); + println!(" Buffer: {}", remote.buffer); + println!(" Channels: {}", remote.channels); + } + } + } } diff --git a/src/config.rs b/src/config.rs index fb3eec5..3cceb44 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,9 +2,17 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct Config { + pub virtual_devices: Vec, pub routes: Routes, } +#[derive(Debug, Serialize, Deserialize)] +pub struct VirtualDevice { + pub name: String, + pub channels: u8, + pub sample_rate: u32, +} + #[derive(Debug, Serialize, Deserialize)] pub struct Routes { pub input: Vec, diff --git a/src/device/virtual_device.rs b/src/device/virtual_device.rs index 07bfd91..550befe 100644 --- a/src/device/virtual_device.rs +++ b/src/device/virtual_device.rs @@ -1,8 +1,5 @@ pub struct VirtualDevice { pub name: String, - pub id: String, - pub is_input: bool, - pub is_output: bool, pub channels: u8, pub sample_rate: u32, output_index: Vec, @@ -10,12 +7,9 @@ pub struct VirtualDevice { } impl VirtualDevice { - pub fn new(name: String, id: String, is_input: bool, is_output: bool, channels: u8, sample_rate: u32) -> Self { + pub fn new(name: String, channels: u8, sample_rate: u32) -> Self { VirtualDevice { name, - id, - is_input, - is_output, channels, sample_rate, output_index: Vec::new(),