Skip to main content

audio_lab/plot/
mod.rs

1//! Plot waveforms, spectra and spectrograms in native windows.
2
3pub mod data;
4pub mod freq;
5mod legend;
6mod save;
7pub mod spectrogram;
8pub mod time;
9
10pub use data::show_real_data;
11pub use freq::show_freq;
12pub use spectrogram::{SpectrogramPlotOptions, show_spectrogram};
13pub use time::{TimePlotOptions, TimeValue, show_time};
14
15/// Error returned by all `show_*` functions.
16#[derive(Debug, thiserror::Error)]
17#[error(transparent)]
18pub struct Error(#[from] eframe::Error);
19
20pub(crate) fn native_options_any_thread() -> eframe::NativeOptions {
21    eframe::NativeOptions {
22        event_loop_builder: Some(Box::new(|builder| {
23            #[cfg(target_os = "linux")]
24            if std::env::var("WAYLAND_DISPLAY").is_ok() {
25                use winit::platform::wayland::EventLoopBuilderExtWayland;
26                builder.with_any_thread(true);
27            } else {
28                use winit::platform::x11::EventLoopBuilderExtX11;
29                builder.with_any_thread(true);
30            }
31            #[cfg(target_os = "windows")]
32            {
33                use winit::platform::windows::EventLoopBuilderExtWindows;
34                builder.with_any_thread(true);
35            }
36            // macOS only allows the event loop on the main thread, so there is nothing to set
37            #[cfg(not(any(target_os = "linux", target_os = "windows")))]
38            let _ = builder;
39        })),
40        ..Default::default()
41    }
42}