Skip to content

Commit 1bc2156

Browse files
committed
Derive Debug for AudioBufferSourceNode and its components
1 parent 2544ef1 commit 1bc2156

File tree

7 files changed

+68
-8
lines changed

7 files changed

+68
-8
lines changed

src/buffer.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,19 @@ impl AudioBuffer {
364364
/// Single channel audio samples, basically wraps a `Arc<Vec<f32>>`
365365
///
366366
/// ChannelData has copy-on-write semantics, so it is cheap to clone.
367-
#[derive(Clone, Debug, PartialEq)]
367+
#[derive(Clone, PartialEq)]
368368
pub(crate) struct ChannelData {
369369
data: Arc<Vec<f32>>,
370370
}
371371

372+
impl std::fmt::Debug for ChannelData {
373+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
374+
f.debug_struct("ChannelData")
375+
.field("len", &self.len())
376+
.finish_non_exhaustive()
377+
}
378+
}
379+
372380
impl ChannelData {
373381
pub fn new(length: usize) -> Self {
374382
let buffer = vec![0.; length];

src/context/concrete_base.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ impl AudioNodeIdProvider {
5252
/// [`OfflineAudioContext`](crate::context::OfflineAudioContext), and the `context()` method on
5353
/// `AudioNode`s.
5454
///
55-
/// The `ConcreteBaseAudioContext` allows for cheap cloning (using an `Arc` internally).
55+
/// The `ConcreteBaseAudioContext` allows for shallow cloning (using an `Arc` internally).
5656
#[allow(clippy::module_name_repetitions)]
5757
#[derive(Clone)]
5858
#[doc(hidden)]
5959
pub struct ConcreteBaseAudioContext {
60-
/// inner makes `ConcreteBaseAudioContext` cheap to clone
6160
inner: Arc<ConcreteBaseAudioContextInner>,
6261
}
6362

@@ -257,6 +256,10 @@ impl ConcreteBaseAudioContext {
257256
base
258257
}
259258

259+
pub(crate) fn address(&self) -> usize {
260+
Arc::as_ptr(&self.inner) as usize
261+
}
262+
260263
/// Send a control message to the render thread
261264
///
262265
/// When the render thread is closed or crashed, the message is discarded and a log warning is

src/context/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ pub struct AudioContextRegistration {
9494
id: AudioNodeId,
9595
}
9696

97+
impl std::fmt::Debug for AudioContextRegistration {
98+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99+
f.debug_struct("AudioContextRegistration")
100+
.field("id", &self.id)
101+
.field(
102+
"context",
103+
&format!("BaseAudioContext@{}", self.context.address()),
104+
)
105+
.finish()
106+
}
107+
}
108+
97109
impl AudioContextRegistration {
98110
/// Get the audio node id of the registration
99111
#[must_use]

src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,17 @@ pub use media_element::MediaElement;
5656
mod resampling;
5757
pub mod worklet;
5858

59-
#[derive(Debug)]
6059
#[repr(transparent)]
6160
pub(crate) struct AtomicF32 {
6261
bits: AtomicU32,
6362
}
6463

64+
impl std::fmt::Debug for AtomicF32 {
65+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66+
f.write_fmt(format_args!("{}", self.load(Ordering::Relaxed)))
67+
}
68+
}
69+
6570
impl AtomicF32 {
6671
#[must_use]
6772
pub fn new(value: f32) -> Self {
@@ -81,12 +86,17 @@ impl AtomicF32 {
8186
}
8287

8388
/// Atomic float 64, only `load` and `store` are supported, no arithmetic
84-
#[derive(Debug)]
8589
#[repr(transparent)]
8690
pub(crate) struct AtomicF64 {
8791
bits: AtomicU64,
8892
}
8993

94+
impl std::fmt::Debug for AtomicF64 {
95+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96+
f.write_fmt(format_args!("{}", self.load(Ordering::Relaxed)))
97+
}
98+
}
99+
90100
impl AtomicF64 {
91101
#[must_use]
92102
pub fn new(value: f64) -> Self {

src/node/audio_buffer_source.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ enum ControlMessage {
102102
/// - `cargo run --release --example trigger_soundfile`
103103
/// - `cargo run --release --example granular`
104104
///
105+
#[derive(Debug)]
105106
pub struct AudioBufferSourceNode {
106107
registration: AudioContextRegistration,
107108
channel_config: ChannelConfig,

src/node/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Default for ChannelConfigOptions {
151151
/// interpretation: ChannelInterpretation::Discrete,
152152
/// };
153153
/// let _: ChannelConfig = opts.into();
154-
#[derive(Clone, Debug)]
154+
#[derive(Clone)]
155155
pub struct ChannelConfig {
156156
inner: Arc<Mutex<ChannelConfigInner>>,
157157
}
@@ -169,6 +169,16 @@ impl Default for ChannelConfig {
169169
}
170170
}
171171

172+
impl std::fmt::Debug for ChannelConfig {
173+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
174+
f.debug_struct("ChannelConfig")
175+
.field("count", &self.count())
176+
.field("count_mode", &self.count_mode())
177+
.field("interpretation", &self.interpretation())
178+
.finish()
179+
}
180+
}
181+
172182
// All methods on this struct are marked `pub(crate)` because we don't want outside users to be
173183
// able to change the values directly. These methods are only accessible via the AudioNode
174184
// interface, so AudioNode's that have channel count/mode constraints should be able to assert

src/param.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,30 @@ impl AudioParamEventTimeline {
261261
}
262262

263263
/// AudioParam controls an individual aspect of an AudioNode's functionality, such as volume.
264-
#[derive(Clone)] // for the node bindings, see #378
264+
#[derive(Clone)] // `Clone` for the node bindings, see #378
265265
pub struct AudioParam {
266266
registration: Arc<AudioContextRegistration>,
267267
raw_parts: AudioParamInner,
268268
}
269269

270+
impl std::fmt::Debug for AudioParam {
271+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
272+
f.debug_struct("AudioParam")
273+
.field("registration", &self.registration())
274+
.field("automation_rate", &self.automation_rate())
275+
.field(
276+
"automation_rate_constrained",
277+
&self.raw_parts.automation_rate_constrained,
278+
)
279+
.field("default_value", &self.default_value())
280+
.field("min_value", &self.min_value())
281+
.field("max_value", &self.max_value())
282+
.finish()
283+
}
284+
}
285+
270286
// helper struct to attach / detach to context (for borrow reasons)
271-
#[derive(Clone)]
287+
#[derive(Debug, Clone)]
272288
pub(crate) struct AudioParamInner {
273289
default_value: f32, // immutable
274290
min_value: f32, // immutable

0 commit comments

Comments
 (0)