Replace unwrap with expect, and make logging configuration work.

This commit is contained in:
Nolan Darilek 2022-08-15 10:53:59 -05:00
parent d500c9c445
commit e4b1df13ce

View File

@ -398,7 +398,7 @@ fn update_source_properties(
handle.gain().set(gain).expect("Failed to set gain"); handle.gain().set(gain).expect("Failed to set gain");
let mut clear_source = false; let mut clear_source = false;
if let Some(transform) = transform { if let Some(transform) = transform {
if let Some(source) = handle.cast_to::<syz::Source3D>().unwrap() { if let Some(source) = handle.cast_to::<syz::Source3D>().expect("Failed to cast") {
let translation = transform.translation(); let translation = transform.translation();
source source
.position() .position()
@ -461,7 +461,10 @@ fn update_source_properties(
clear_source = true; clear_source = true;
} }
} else if let Some(angular_pan) = angular_pan { } else if let Some(angular_pan) = angular_pan {
if let Some(source) = handle.cast_to::<syz::AngularPannedSource>().unwrap() { if let Some(source) = handle
.cast_to::<syz::AngularPannedSource>()
.expect("Failed to cast")
{
assert!(angular_pan.azimuth >= 0. && angular_pan.azimuth <= 360.); assert!(angular_pan.azimuth >= 0. && angular_pan.azimuth <= 360.);
source source
.azimuth() .azimuth()
@ -476,7 +479,10 @@ fn update_source_properties(
clear_source = true; clear_source = true;
} }
} else if let Some(scalar_pan) = scalar_pan { } else if let Some(scalar_pan) = scalar_pan {
if let Some(source) = handle.cast_to::<syz::ScalarPannedSource>().unwrap() { if let Some(source) = handle
.cast_to::<syz::ScalarPannedSource>()
.expect("Failed to cast")
{
assert!(**scalar_pan >= -1. && **scalar_pan <= 1.); assert!(**scalar_pan >= -1. && **scalar_pan <= 1.);
source source
.panning_scalar() .panning_scalar()
@ -630,8 +636,6 @@ fn sync_config(
.unwrap_or(defaults.closeness_boost_distance), .unwrap_or(defaults.closeness_boost_distance),
) )
.expect("Failed to set closeness_boost_distance"); .expect("Failed to set closeness_boost_distance");
// syz::log_set_level(config.log_level);
// syz::log_to_stderr(config.log_to_stderr);
} }
} }
@ -676,14 +680,15 @@ impl Plugin for SynthizerPlugin {
if !app.world.contains_resource::<SynthizerConfig>() { if !app.world.contains_resource::<SynthizerConfig>() {
app.insert_resource(SynthizerConfig::default()); app.insert_resource(SynthizerConfig::default());
} }
let config = app let config = app.world.get_resource::<SynthizerConfig>().unwrap().clone();
.world let mut syz_config = syz::LibraryConfig::new();
.get_resource::<SynthizerConfig>() syz_config.log_level(config.log_level);
.unwrap() if config.log_to_stderr {
.clone(); syz_config.log_to_stderr();
// syz::log_set_level(config.log_level); }
// syz::log_to_stderr(config.log_to_stderr); let guard = syz_config
let guard = syz::initialize().expect("Failed to initialize Synthizer"); .initialize()
.expect("Failed to initialize Synthizer");
let context = syz::Context::new().expect("Failed to create Synthizer context"); let context = syz::Context::new().expect("Failed to create Synthizer context");
let defaults = SynthizerDefaults { let defaults = SynthizerDefaults {
panner_strategy: context.default_panner_strategy().get().unwrap(), panner_strategy: context.default_panner_strategy().get().unwrap(),