Skip to content

Commit e2c7768

Browse files
refactor: minor simplifications
Signed-off-by: Maika Namuo <httpworldview@gmail.com>
1 parent 58a013f commit e2c7768

11 files changed

Lines changed: 38 additions & 61 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Debian/RPM release number.
167167
src/domain.rs shared capture policy and visual identifiers
168168
src/dsp.rs AudioBlock and small DSP types
169169
src/meter.rs capture timeline, silence handling, and DSP batching
170-
src/util/ low-level audio math, color, musical, and telemetry helpers
170+
src/util/ low-level audio math, color, and musical helpers
171171
src/infra/pipewire/ owned PipeWire graph, tap policy, stream, and audio transport
172172
src/persistence/ settings schema, lossy loading, store, themes, visual config
173173
src/visuals.rs visual module declarations, option enums, widget macros

‎src/dsp.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> AudioBlock<'a> {
257257
}
258258

259259
pub fn is_empty(&self) -> bool {
260-
self.frame_count() == 0
260+
self.samples.len() < self.channels.max(1)
261261
}
262262
}
263263

‎src/infra/pipewire/transport.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ impl CaptureWriter {
219219
) -> AudioFormat {
220220
self.flush_pending();
221221
let format = self.publish_format(channels, rate, positions);
222-
self.configure_pool(format);
223-
self.format = Some(format);
222+
if self.format.replace(format) != Some(format) {
223+
self.configure_pool(format);
224+
}
224225
self.disconnected = false;
225226
format
226227
}

‎src/main.rs‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ mod visuals;
1515

1616
use infra::pipewire::AudioBackend;
1717
use persistence::settings::SettingsHandle;
18-
use std::cell::RefCell;
19-
use std::process::ExitCode;
20-
use std::rc::Rc;
21-
use ui::UiConfig;
22-
use util::telemetry;
23-
18+
use std::{cell::RefCell, process::ExitCode, rc::Rc};
2419
use tracing::{error, info};
20+
use tracing_subscriber::{EnvFilter, fmt};
21+
use ui::UiConfig;
2522

2623
fn main() -> ExitCode {
27-
telemetry::init();
24+
let env_filter = match EnvFilter::try_from_default_env() {
25+
Ok(filter) => filter,
26+
Err(_) => EnvFilter::new("openmeters=info"),
27+
};
28+
if let Err(err) = fmt()
29+
.with_env_filter(env_filter)
30+
.with_target(false)
31+
.compact()
32+
.try_init()
33+
{
34+
eprintln!("[telemetry] failed to initialise tracing subscriber: {err}");
35+
}
2836
info!("OpenMeters starting up");
2937

3038
let settings_handle = SettingsHandle::load_or_default();

‎src/util.rs‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,3 @@ pub(crate) fn unpoison<T>(lock: std::sync::LockResult<T>) -> T {
1818
pub fn lerp(a: f32, b: f32, t: f32) -> f32 {
1919
a + (b - a) * t
2020
}
21-
22-
pub mod telemetry {
23-
use std::sync::OnceLock;
24-
use tracing::Level;
25-
use tracing_subscriber::{EnvFilter, fmt};
26-
27-
static TELEMETRY_INIT: OnceLock<()> = OnceLock::new();
28-
29-
pub fn init() {
30-
TELEMETRY_INIT.get_or_init(|| {
31-
let env_filter = EnvFilter::try_from_default_env()
32-
.or_else(|_| EnvFilter::try_new("openmeters=info"))
33-
.unwrap_or_else(|_| EnvFilter::default().add_directive(Level::INFO.into()));
34-
35-
if let Err(err) = fmt()
36-
.with_env_filter(env_filter)
37-
.with_target(false)
38-
.compact()
39-
.try_init()
40-
{
41-
eprintln!("[telemetry] failed to initialise tracing subscriber: {err}");
42-
}
43-
});
44-
}
45-
}

‎src/visuals/loudness/render.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ impl LoudnessParams {
6161

6262
Some((meter_x, bar_width, stride))
6363
}
64-
}
6564

66-
impl LoudnessParams {
6765
fn build_vertices(&self, scratch: &mut GeometryScratch) {
6866
let clip = ClipTransform::from_bounds(self.bounds);
6967
let Some((meter_x, bar_width, stride)) = self.meter_bounds() else {
@@ -162,7 +160,6 @@ impl LoudnessParams {
162160
clip,
163161
));
164162
}
165-
166163
}
167164
}
168165

‎src/visuals/render/common.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,23 @@ pub(in crate::visuals) use sdf_primitive;
704704
#[cfg(test)]
705705
mod tests {
706706
use super::*;
707+
use wgpu::naga::front::wgsl::parse_str;
708+
709+
#[test]
710+
fn shaders_are_valid() {
711+
for source in [
712+
include_str!("shaders/sdf.wgsl"),
713+
include_str!("shaders/spectrogram.wgsl"),
714+
] {
715+
let module = parse_str(source).expect("shader should parse");
716+
wgpu::naga::valid::Validator::new(
717+
wgpu::naga::valid::ValidationFlags::all(),
718+
wgpu::naga::valid::Capabilities::all(),
719+
)
720+
.validate(&module)
721+
.expect("shader should validate");
722+
}
723+
}
707724

708725
#[test]
709726
fn decimate_line_advances_when_bucket_edge_rounds_below_point() {

‎src/visuals/spectrogram/render.rs‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -653,20 +653,6 @@ fn make_bind_group(
653653
mod tests {
654654
use super::*;
655655

656-
#[test]
657-
fn shader_is_valid() {
658-
let module = wgpu::naga::front::wgsl::parse_str(include_str!(
659-
"../render/shaders/spectrogram.wgsl"
660-
))
661-
.expect("spectrogram shader should parse");
662-
wgpu::naga::valid::Validator::new(
663-
wgpu::naga::valid::ValidationFlags::all(),
664-
wgpu::naga::valid::Capabilities::all(),
665-
)
666-
.validate(&module)
667-
.expect("spectrogram shader should validate");
668-
}
669-
670656
#[test]
671657
fn equal_byte_capacity_does_not_reuse_a_different_ring_layout() {
672658
let current = RingLayout {

‎src/visuals/spectrogram/state.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,10 @@ impl SpectrogramState {
323323
return None;
324324
}
325325
let age = match self.rotation_index() {
326-
0 => bounds.x + bounds.width - cursor.x,
327326
1 => bounds.y + bounds.height - cursor.y,
328327
2 => cursor.x - bounds.x,
329328
3 => cursor.y - bounds.y,
330-
_ => return None,
329+
_ => bounds.x + bounds.width - cursor.x,
331330
};
332331
if age < 0.0 || age >= self.history.col_count as f32 { return None; }
333332
let secs = age * (self.hop_size as f32 / self.sample_rate);

‎src/visuals/spectrum/processor.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ impl SpectrumProcessor {
213213
}
214214

215215
fn process_trace_window(&mut self, trace: usize, dt_seconds: f32, floor: f32) -> bool {
216-
let bins = self.config.fft_size / 2 + 1;
217216
copy_dc_removed_windowed_from_deque(
218217
&mut self.real_buffer,
219218
&self.pcm_buffers[trace],
@@ -239,7 +238,6 @@ impl SpectrumProcessor {
239238
.spectrum_buffer
240239
.iter()
241240
.zip(&self.bin_normalization)
242-
.take(bins)
243241
.enumerate()
244242
{
245243
level.scratch_power[idx] = complex.norm_sqr() * *norm;
@@ -422,8 +420,6 @@ fn a_weight(freq_hz: f32) -> f32 {
422420
let numerator = C4 * f2 * f2;
423421
let denom = (f2 + C1) * ((f2 + C2) * (f2 + C3)).sqrt() * (f2 + C4);
424422

425-
if denom <= 0.0 || numerator <= 0.0 { return f32::NEG_INFINITY; }
426-
427423
let ra = numerator / denom;
428424
(20.0 * ra.log10() + 2.0) as f32
429425
}

0 commit comments

Comments
 (0)