Skip to content
Snippets Groups Projects
Commit 05d96d0e authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Fix filter

parent 1e4c3a09
Branches master
No related tags found
No related merge requests found
......@@ -351,9 +351,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.75"
version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7"
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
dependencies = [
"proc-macro2",
"quote",
......
......@@ -13,4 +13,4 @@ libc = "0.2"
rosc = "~0.5"
rayon ="1.5"
arr_macro = "0.1.3"
clap = { version = "3.0.0-beta.2", features = ["color", "suggestions"] }
clap = { version = "3.0.0-beta.4", features = ["color", "suggestions"] }
......@@ -94,6 +94,68 @@ fn port_has_connections<T>(port: &Port<T>) -> bool {
}
}
pub struct Connection {
inputs: Vec<String>,
outputs: Vec<String>
}
impl Connection {
pub fn from_vec(v: Vec<&str>) -> Self {
let connections: Vec<Connector> = v.iter()
.map(|c| {
c.split(",")
.collect::<Vec<&str>>()
.iter()
.map(|x| x.trim())
.map(|x| Connector::new(x))
.collect::<Vec<Connector>>()
})
.flatten()
.collect::<Vec<Connector>>();
if connections.first().unwrap().is_own() {
// Outgoing Connections
} else {
// Incoming Connections
}
Self {
inputs: Vec::new(),
outputs: Vec::new()
}
}
}
pub struct Connector {
name: String
}
impl Connector {
pub fn new<S: AsRef<str>>(stringlike: S) -> Self {
Self {
name: stringlike.as_ref().to_string()
}
}
pub fn is_own(&self) -> bool {
!self.name.contains(":") || self.name == "all"
}
pub fn is_other(&self) -> bool {
!self.is_own()
}
pub fn is_own_input(&self) -> bool {
self.is_own() && self.name.starts_with("in_")
}
pub fn is_own_output(&self) -> bool {
self.is_own() && self.name.starts_with("out_")
}
}
fn main() {
let matches = App::new(option_env!("CARGO_PKG_NAME").unwrap())
......@@ -101,12 +163,14 @@ fn main() {
.about(option_env!("CARGO_PKG_DESCRIPTION").unwrap())
.help_template("{bin} ({version})\n{about}\n\nUsage:\n {usage}\n\nTo send a certain amount of one input to a output send a OSC message that looks like this: /ch/1/send/16 <volume>\nThis would set the send volume of input 1 to output 16 to the value of <volume>. A value of 0.0 would be off, a value of 1.0 would result in a unattenuated signal. Values above 1.0 result in amplification.\n\nOSC-Addresses:\n /ch/<in>/send/<out> <volume> Set the send volume (in → out)\n\nOptions:\n{options}")
.arg(Arg::new("--host")
.short('a')
.long("--host")
.value_name("HOST")
.required(true)
.about(format!("Set IP-address of {}", option_env!("CARGO_PKG_NAME").unwrap()).as_str())
.takes_value(true))
.arg(Arg::new("--receiving-port")
.short('p')
.long("--receiving-port")
.value_name("INPORT")
.required(true)
......@@ -118,14 +182,24 @@ fn main() {
.about("Set sending port (OSC)")
.takes_value(true))
.arg(Arg::new("--name")
.short('n')
.long("--name")
.value_name("NAME")
.about("Set the name of the jack node")
.takes_value(true))
.arg(Arg::new("--connect")
.short('c')
.long("--connect")
.alias("--connection")
.value_name("CONNECTION")
.about("Connect to annother jack node.")
. long_about("Foo")
.multiple_occurrences(true)
.multiple_values(true)
.min_values(2)
.takes_value(true))
.get_matches();
let ip = matches.value_of("--host").unwrap();
let inport = matches.value_of("--receiving-port").unwrap();
......@@ -136,6 +210,12 @@ fn main() {
let nodename = matches.value_of("--name").unwrap_or("Hexmatrix");
let connections: Vec<_> = matches.grouped_values_of("--connect").unwrap().filter_map(|c| {
println!("Got connection {:#?}", c);
let connection = Connection::from_vec(c);
Some(connection)
}).collect();
// Create new jack client (visible e.g. in Catia)
let (client, _status) =
jack::Client::new(nodename, jack::ClientOptions::NO_START_SERVER).expect("Couldn't connect to jack server. Not running?");
......@@ -178,19 +258,17 @@ fn main() {
output_buffers.par_iter_mut()
.enumerate()
.filter(|(output_index, _buffer)| port_has_connections(&outputs[*output_index]))
.for_each(|(output_index, b)| {
.map(|(output_index, buffer)| {
let volume = get_volume_for_input_output_pair(input_index, output_index);
(output_index, buffer, volume)
})
.filter(|(_, _, volume)| *volume != 0.0)
.for_each(|(_output_index, b, volume)| {
b.par_iter_mut()
.take(buffersize)
.enumerate()
.for_each(|(sample_index, sample)| {
let volume = get_volume_for_input_output_pair(input_index, output_index);
if volume != 0.0 {
// Multiply each input sample at position `sample_index` with the
// volume and sum it with the corresponding (existing) output sample
// at the same position
*sample = input_samples[sample_index].mul_add(volume, *sample);
}
});
});
});
......@@ -252,14 +330,14 @@ fn handle_packet(packet: OscPacket) {
/// Decides what to do with incoming OSC messages (e.g. set the atomic variables)
///
/// Implemented addresses:
/// - `/ch/{input}/send/{output} volume`: Set the volume at which a input is sent to an output (default is 0.0, no attenuation is 1.0, 7.0 equals +18 dB)
/// - `/chn/{input}/send/{output} volume`: Set the volume at which a input is sent to an output (default is 0.0, no attenuation is 1.0, 7.0 equals +18 dB)
fn process_message(msg: &OscMessage) {
// Split address at "/" and skip initial empty split
let addr = msg.addr.trim().split("/").skip(1).collect::<Vec<&str>>();
// Match the addresses
match addr[..] {
["ch", _, "send", _] => {
["chn", _, "send", _] => {
// Set the send volume for a given input/output pair
// Match the input channel
......@@ -281,7 +359,7 @@ fn process_message(msg: &OscMessage) {
match (maybe_input, maybe_output, maybe_volume) {
(Some(input), Some(output), Some(volume)) => {
// println!("ᐅ OSC: Set Volume of Input {} at Output {} to {:.8} ({:.8} dB)", input, output, volume.max(0.0), (20.0* volume.max(0.0).log(10.0)));
println!("ᐅ OSC: Set Volume of Input {} at Output {} to {:.8} ({:.8} dB)", input, output, volume.max(0.0), (20.0* volume.max(0.0).log(10.0)));
match input {
1 => VOLS1[output-1].store((volume * usize::MAX as f32) as usize, Ordering::Relaxed),
2 => VOLS2[output-1].store((volume * usize::MAX as f32) as usize, Ordering::Relaxed),
......@@ -302,11 +380,11 @@ fn process_message(msg: &OscMessage) {
_ => ()
}
},
_ => println!(" OSC: Ignored message with non-existing channels: {}, {:?} {:?}", msg.addr, maybe_input, maybe_output)
_ => println!(" OSC: Ignored message with non-existing channels: {}, {:?} {:?}", msg.addr, maybe_input, maybe_output)
}
},
_ => {
println!(" OSC: Ignored message with unknown address: {}", msg.addr);
println!(" OSC: Ignored message with unknown address: {}", msg.addr);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment