Fix a lot of warnings

This commit is contained in:
Weird Constructor 2022-08-05 19:44:40 +02:00
parent a0478f64e9
commit db01caaac0
8 changed files with 58 additions and 52 deletions

View file

@ -24,7 +24,7 @@ synfx-dsp = "0.5.1"
[dev-dependencies] [dev-dependencies]
num-complex = "0.2" num-complex = "0.2"
jack = "0.6.6" jack = "0.10.0"
rustfft = "6.0.0" rustfft = "6.0.0"
cpal = "0.13.5" cpal = "0.13.5"
anyhow = "1.0.58" anyhow = "1.0.58"

View file

@ -147,11 +147,6 @@ impl jack::NotificationHandler for Notifications {
println!("JACK: freewheel mode is {}", if is_enabled { "on" } else { "off" }); println!("JACK: freewheel mode is {}", if is_enabled { "on" } else { "off" });
} }
fn buffer_size(&mut self, _: &jack::Client, sz: jack::Frames) -> jack::Control {
println!("JACK: buffer size changed to {}", sz);
jack::Control::Continue
}
fn sample_rate(&mut self, _: &jack::Client, srate: jack::Frames) -> jack::Control { fn sample_rate(&mut self, _: &jack::Client, srate: jack::Frames) -> jack::Control {
println!("JACK: sample rate changed to {}", srate); println!("JACK: sample rate changed to {}", srate);
let mut ne = self.node_exec.lock().unwrap(); let mut ne = self.node_exec.lock().unwrap();
@ -215,16 +210,6 @@ impl jack::NotificationHandler for Notifications {
println!("JACK: xrun occurred"); println!("JACK: xrun occurred");
jack::Control::Continue jack::Control::Continue
} }
fn latency(&mut self, _: &jack::Client, mode: jack::LatencyType) {
println!(
"JACK: {} latency has changed",
match mode {
jack::LatencyType::Capture => "capture",
jack::LatencyType::Playback => "playback",
}
);
}
} }
// This function starts the Jack backend and // This function starts the Jack backend and

View file

@ -193,7 +193,6 @@ pub enum BlkJITCompileError {
} }
pub struct Block2JITCompiler { pub struct Block2JITCompiler {
id_node_map: HashMap<usize, BlkASTRef>,
idout_var_map: HashMap<String, String>, idout_var_map: HashMap<String, String>,
lang: Rc<RefCell<BlockLanguage>>, lang: Rc<RefCell<BlockLanguage>>,
tmpvar_counter: usize, tmpvar_counter: usize,
@ -210,7 +209,7 @@ enum ASTNode {
impl Block2JITCompiler { impl Block2JITCompiler {
pub fn new(lang: Rc<RefCell<BlockLanguage>>) -> Self { pub fn new(lang: Rc<RefCell<BlockLanguage>>) -> Self {
Self { id_node_map: HashMap::new(), idout_var_map: HashMap::new(), lang, tmpvar_counter: 0 } Self { idout_var_map: HashMap::new(), lang, tmpvar_counter: 0 }
} }
pub fn next_tmpvar_name(&mut self, extra: &str) -> String { pub fn next_tmpvar_name(&mut self, extra: &str) -> String {
@ -226,7 +225,7 @@ impl Block2JITCompiler {
self.idout_var_map.get(&format!("{}/{}", id, out)).map(|s| &s[..]) self.idout_var_map.get(&format!("{}/{}", id, out)).map(|s| &s[..])
} }
pub fn trans2bjit( fn trans2bjit(
&mut self, &mut self,
node: &ASTNodeRef, node: &ASTNodeRef,
my_out: Option<String>, my_out: Option<String>,
@ -392,7 +391,7 @@ impl Block2JITCompiler {
} }
#[cfg(feature = "synfx-dsp-jit")] #[cfg(feature = "synfx-dsp-jit")]
pub fn bjit2jit(&mut self, ast: &BlkASTRef) -> Result<Box<ASTNode>, BlkJITCompileError> { fn bjit2jit(&mut self, ast: &BlkASTRef) -> Result<Box<ASTNode>, BlkJITCompileError> {
use synfx_dsp_jit::build::*; use synfx_dsp_jit::build::*;
match &**ast { match &**ast {
@ -407,11 +406,11 @@ impl Block2JITCompiler {
let e = self.bjit2jit(&expr)?; let e = self.bjit2jit(&expr)?;
Ok(assign(var, e)) Ok(assign(var, e))
} }
BlkASTNode::Get { id, var: varname } => Ok(var(varname)), BlkASTNode::Get { var: varname, .. } => Ok(var(varname)),
BlkASTNode::Node { id, out, typ, lbl, childs } => match &typ[..] { BlkASTNode::Node { id, typ, childs, .. } => match &typ[..] {
"if" => Err(BlkJITCompileError::UnknownError), "if" => Err(BlkJITCompileError::UnknownError),
"zero" => Ok(literal(0.0)), "zero" => Ok(literal(0.0)),
node => { _ => {
if *id == 0 { if *id == 0 {
return Err(BlkJITCompileError::NodeWithoutID(typ.to_string())); return Err(BlkJITCompileError::NodeWithoutID(typ.to_string()));
} }
@ -426,7 +425,6 @@ impl Block2JITCompiler {
} }
if inputs.len() > 0 && inputs[0] == Some("".to_string()) { if inputs.len() > 0 && inputs[0] == Some("".to_string()) {
// We assume all inputs are unnamed:
if inputs.len() != childs.len() { if inputs.len() != childs.len() {
return Err(BlkJITCompileError::WrongNumberOfChilds( return Err(BlkJITCompileError::WrongNumberOfChilds(
typ.to_string(), typ.to_string(),
@ -435,7 +433,8 @@ impl Block2JITCompiler {
)); ));
} }
for (inp, c) in childs.iter() { // We assume all inputs are unnamed:
for (_inp, c) in childs.iter() {
args.push(self.bjit2jit(&c)?); args.push(self.bjit2jit(&c)?);
} }
} else { } else {

View file

@ -197,11 +197,10 @@ impl Block {
let c0 = if let Some(c) = self.contains.0 { c.into() } else { Value::Null }; let c0 = if let Some(c) = self.contains.0 { c.into() } else { Value::Null };
let c1 = if let Some(c) = self.contains.1 { c.into() } else { Value::Null }; let c1 = if let Some(c) = self.contains.1 { c.into() } else { Value::Null };
let mut contains = json!([c0, c1]);
json!({ json!({
"id": self.id as i64, "id": self.id as i64,
"rows": self.rows as i64, "rows": self.rows as i64,
"contains": contains, "contains": json!([c0, c1]),
"expanded": self.expanded, "expanded": self.expanded,
"typ": self.typ, "typ": self.typ,
"lbl": self.lbl, "lbl": self.lbl,
@ -343,12 +342,15 @@ impl BlockView for Block {
#[derive(Debug)] #[derive(Debug)]
pub struct BlockChain { pub struct BlockChain {
/// The area ID this BlockChain was created from. /// The area ID this BlockChain was created from.
#[allow(dead_code)]
area_id: usize, area_id: usize,
/// Stores the positions of the blocks of the chain inside the [BlockArea]. /// Stores the positions of the blocks of the chain inside the [BlockArea].
blocks: HashSet<(i64, i64)>, blocks: HashSet<(i64, i64)>,
/// Stores the positions of blocks that only have output ports. /// Stores the positions of blocks that only have output ports.
#[allow(dead_code)]
sources: HashSet<(i64, i64)>, sources: HashSet<(i64, i64)>,
/// Stores the positions of blocks that only have input ports. /// Stores the positions of blocks that only have input ports.
#[allow(dead_code)]
sinks: HashSet<(i64, i64)>, sinks: HashSet<(i64, i64)>,
/// This field stores _loaded_ blocks from the [BlockArea] /// This field stores _loaded_ blocks from the [BlockArea]
/// into this [BlockChain] for inserting or analyzing them. /// into this [BlockChain] for inserting or analyzing them.

View file

@ -7,7 +7,7 @@ use crate::nodes::{NodeAudioContext, NodeExecContext};
#[cfg(feature = "synfx-dsp-jit")] #[cfg(feature = "synfx-dsp-jit")]
use crate::wblockdsp::CodeEngineBackend; use crate::wblockdsp::CodeEngineBackend;
use crate::dsp::MAX_BLOCK_SIZE; //use crate::dsp::MAX_BLOCK_SIZE;
/// A WBlockDSP code execution node for JIT'ed DSP code /// A WBlockDSP code execution node for JIT'ed DSP code
pub struct Code { pub struct Code {
@ -87,17 +87,20 @@ impl DspNode for Code {
ctx: &mut T, ctx: &mut T,
_ectx: &mut NodeExecContext, _ectx: &mut NodeExecContext,
_nctx: &NodeContext, _nctx: &NodeContext,
atoms: &[SAtom], _atoms: &[SAtom],
inputs: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], outputs: &mut [ProcBuf],
ctx_vals: LedPhaseVals, ctx_vals: LedPhaseVals,
) { ) {
use crate::dsp::{at, denorm, inp, out, out_idx}; use crate::dsp::{inp, out_idx};
// let clock = inp::TSeq::clock(inputs); let in1 = inp::Code::in1(inputs);
// let trig = inp::TSeq::trig(inputs); let in2 = inp::Code::in2(inputs);
// let cmode = at::TSeq::cmode(atoms); let a = inp::Code::alpha(inputs);
let out = out::Code::sig(outputs); let b = inp::Code::beta(inputs);
let d = inp::Code::delta(inputs);
let g = inp::Code::gamma(inputs);
let out_i = out_idx::Code::sig1(); let out_i = out_idx::Code::sig1();
let (sig, sig1) = outputs.split_at_mut(out_i); let (sig, sig1) = outputs.split_at_mut(out_i);
let (sig1, sig2) = sig1.split_at_mut(1); let (sig1, sig2) = sig1.split_at_mut(1);
let sig = &mut sig[0]; let sig = &mut sig[0];
@ -114,15 +117,26 @@ impl DspNode for Code {
backend.process_updates(); backend.process_updates();
let mut ret = 0.0;
let mut s1 = 0.0;
#[allow(unused_assignments)]
let mut s2 = 0.0;
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
let (s1, s2, ret) = backend.process(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); (s1, s2, ret) = backend.process(
in1.read(frame),
in2.read(frame),
a.read(frame),
b.read(frame),
d.read(frame),
g.read(frame),
);
sig.write(frame, ret); sig.write(frame, ret);
sig1.write(frame, s1); sig1.write(frame, s1);
sig2.write(frame, s2); sig2.write(frame, s2);
} }
ctx_vals[0].set(0.0); ctx_vals[0].set(ret);
ctx_vals[1].set(0.0); ctx_vals[1].set(s1);
} }
} }
} }

View file

@ -713,9 +713,7 @@ impl NodeConfigurator {
let mut compiler = Block2JITCompiler::new(block_fun.block_language()); let mut compiler = Block2JITCompiler::new(block_fun.block_language());
let ast = compiler.compile(&block_fun)?; let ast = compiler.compile(&block_fun)?;
// let ast = block_compiler::compile(block_fun);
if let Some(cod) = self.code_engines.get_mut(id) { if let Some(cod) = self.code_engines.get_mut(id) {
use synfx_dsp_jit::build::*;
match cod.upload(ast) { match cod.upload(ast) {
Err(e) => return Err(BlkJITCompileError::JITCompileError(e)), Err(e) => return Err(BlkJITCompileError::JITCompileError(e)),
Ok(()) => (), Ok(()) => (),

View file

@ -6,11 +6,9 @@ use synfx_dsp_jit::*;
use ringbuf::{Consumer, Producer, RingBuffer}; use ringbuf::{Consumer, Producer, RingBuffer};
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
const MAX_RINGBUF_SIZE: usize = 128; const MAX_RINGBUF_SIZE: usize = 128;
const MAX_CONTEXTS: usize = 32;
enum CodeUpdateMsg { enum CodeUpdateMsg {
UpdateFun(Box<DSPFunction>), UpdateFun(Box<DSPFunction>),
@ -52,7 +50,7 @@ impl CodeEngine {
pub fn upload(&mut self, ast: Box<ASTNode>) -> Result<(), JITCompileError> { pub fn upload(&mut self, ast: Box<ASTNode>) -> Result<(), JITCompileError> {
let jit = JIT::new(self.lib.clone(), self.dsp_ctx.clone()); let jit = JIT::new(self.lib.clone(), self.dsp_ctx.clone());
let fun = jit.compile(ASTFun::new(ast))?; let fun = jit.compile(ASTFun::new(ast))?;
self.update_prod.push(CodeUpdateMsg::UpdateFun(fun)); let _ = self.update_prod.push(CodeUpdateMsg::UpdateFun(fun));
Ok(()) Ok(())
} }
@ -146,7 +144,7 @@ impl CodeEngineBackend {
CodeUpdateMsg::UpdateFun(mut fun) => { CodeUpdateMsg::UpdateFun(mut fun) => {
std::mem::swap(&mut self.function, &mut fun); std::mem::swap(&mut self.function, &mut fun);
self.function.init(self.sample_rate as f64, Some(&fun)); self.function.init(self.sample_rate as f64, Some(&fun));
self.return_prod.push(CodeReturnMsg::DestroyFun(fun)); let _ = self.return_prod.push(CodeReturnMsg::DestroyFun(fun));
} }
} }
} }

View file

@ -5,6 +5,8 @@
mod common; mod common;
use common::*; use common::*;
use hexodsp::blocklang::BlockFun;
fn setup() -> (Matrix, NodeExecutor) { fn setup() -> (Matrix, NodeExecutor) {
let (node_conf, node_exec) = new_node_engine(); let (node_conf, node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3); let mut matrix = Matrix::new(node_conf, 3, 3);
@ -22,6 +24,14 @@ fn setup() -> (Matrix, NodeExecutor) {
(matrix, node_exec) (matrix, node_exec)
} }
fn put_n(bf: &mut BlockFun, a: usize, x: i64, y: i64, s: &str) {
bf.instanciate_at(a, x, y, s, None).expect("no put error");
}
fn put_v(bf: &mut BlockFun, a: usize, x: i64, y: i64, s: &str, v: &str) {
bf.instanciate_at(a, x, y, s, Some(v.to_string())).expect("no put error");
}
#[test] #[test]
fn check_node_code_1() { fn check_node_code_1() {
let (mut matrix, mut node_exec) = setup(); let (mut matrix, mut node_exec) = setup();
@ -29,8 +39,8 @@ fn check_node_code_1() {
let block_fun = matrix.get_block_function(0).expect("block fun exists"); let block_fun = matrix.get_block_function(0).expect("block fun exists");
{ {
let mut block_fun = block_fun.lock().expect("matrix lock"); let mut block_fun = block_fun.lock().expect("matrix lock");
block_fun.instanciate_at(0, 0, 1, "value", Some("0.3".to_string())); put_v(&mut block_fun, 0, 0, 1, "value", "0.3");
block_fun.instanciate_at(0, 1, 1, "set", Some("&sig1".to_string())); put_v(&mut block_fun, 0, 1, 1, "set", "&sig1");
} }
matrix.check_block_function(0).expect("no compile error"); matrix.check_block_function(0).expect("no compile error");
@ -46,13 +56,13 @@ fn check_node_code_state() {
let block_fun = matrix.get_block_function(0).expect("block fun exists"); let block_fun = matrix.get_block_function(0).expect("block fun exists");
{ {
let mut block_fun = block_fun.lock().expect("matrix lock"); let mut block_fun = block_fun.lock().expect("matrix lock");
block_fun.instanciate_at(0, 0, 2, "value", Some("220.0".to_string())); put_v(&mut block_fun, 0, 0, 2, "value", "220.0");
block_fun.instanciate_at(0, 1, 2, "phase", None); put_n(&mut block_fun, 0, 1, 2, "phase");
block_fun.instanciate_at(0, 1, 3, "value", Some("2.0".to_string())); put_v(&mut block_fun, 0, 1, 3, "value", "2.0");
block_fun.instanciate_at(0, 2, 2, "*", None); put_n(&mut block_fun, 0, 2, 2, "*");
block_fun.instanciate_at(0, 3, 1, "-", None); put_n(&mut block_fun, 0, 3, 1, "-");
block_fun.instanciate_at(0, 2, 1, "value", Some("1.0".to_string())); put_v(&mut block_fun, 0, 2, 1, "value", "1.0");
block_fun.instanciate_at(0, 4, 1, "set", Some("&sig1".to_string())); put_v(&mut block_fun, 0, 4, 1, "set", "&sig1");
} }
matrix.check_block_function(0).expect("no compile error"); matrix.check_block_function(0).expect("no compile error");