Skip to content

Commit 6e597de

Browse files
committed
impl Debug for handles, command types, and ResourceController
1 parent fac06ee commit 6e597de

File tree

30 files changed

+84
-2
lines changed

30 files changed

+84
-2
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fix sounds stopping after having already started if the clock they were originally
44
waiting on stops
55
- Implement `Default` for `Region`, `EndPosition`, `PlaybackPosition`, and `Value`
6+
- Implement `Debug` for handles, command types, and `ResourceController`
67

78
# v0.9.0 - May 11, 2024
89

crates/kira/src/clock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ use self::clock_info::ClockInfoProvider;
181181
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
182182
pub struct ClockId(pub(crate) Key);
183183

184+
#[derive(Debug)]
184185
pub(crate) struct ClockShared {
185186
ticking: AtomicBool,
186187
ticks: AtomicU64,

crates/kira/src/clock/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::{ClockId, ClockShared, ClockSpeed, ClockTime, CommandWriters};
88
///
99
/// When a [`ClockHandle`] is dropped, the corresponding clock
1010
/// will be removed.
11+
#[derive(Debug)]
1112
pub struct ClockHandle {
1213
pub(crate) id: ClockId,
1314
pub(crate) shared: Arc<ClockShared>,

crates/kira/src/command.rs

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use triple_buffer::{triple_buffer, Input, Output};
2424
use crate::tween::{Tween, Value};
2525

2626
/** Writes values that can be sent to a [`CommandReader`]. */
27+
#[derive(Debug)]
2728
pub struct CommandWriter<T: Send + Copy>(Input<Option<T>>);
2829

2930
impl<T: Send + Copy> CommandWriter<T> {
@@ -34,6 +35,7 @@ impl<T: Send + Copy> CommandWriter<T> {
3435
}
3536

3637
/** Reads values that were written to a [`CommandWriter`]. */
38+
#[derive(Debug)]
3739
pub struct CommandReader<T: Send + Copy>(Output<Option<T>>);
3840

3941
impl<T: Send + Copy> CommandReader<T> {
@@ -124,10 +126,12 @@ pub(crate) fn command_writers_and_readers() -> (CommandWriters, CommandReaders)
124126
#[macro_export]
125127
macro_rules! command_writers_and_readers {
126128
($($field_name:ident: $type:ty),*$(,)?) => {
129+
#[derive(Debug)]
127130
pub(crate) struct CommandWriters {
128131
$($field_name: $crate::command::CommandWriter<$type>),*
129132
}
130133

134+
#[derive(Debug)]
131135
pub(crate) struct CommandReaders {
132136
$($field_name: $crate::command::CommandReader<$type>),*
133137
}

crates/kira/src/effect/compressor/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::command::handle_param_setters;
55
use super::CommandWriters;
66

77
/// Controls a compressor.
8+
#[derive(Debug)]
89
pub struct CompressorHandle {
910
pub(super) command_writers: CommandWriters,
1011
}

crates/kira/src/effect/delay/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{command::handle_param_setters, Volume};
33
use super::CommandWriters;
44

55
/// Controls a delay effect.
6+
#[derive(Debug)]
67
pub struct DelayHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/effect/distortion/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{command::handle_param_setters, Volume};
33
use super::{CommandWriters, DistortionKind};
44

55
/// Controls a distortion effect.
6+
#[derive(Debug)]
67
pub struct DistortionHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/effect/eq_filter/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::command::handle_param_setters;
33
use super::{CommandWriters, EqFilterKind};
44

55
/// Controls an EQ filter.
6+
#[derive(Debug)]
67
pub struct EqFilterHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/effect/filter/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::command::handle_param_setters;
33
use super::{CommandWriters, FilterMode};
44

55
/// Controls a filter effect.
6+
#[derive(Debug)]
67
pub struct FilterHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/effect/panning_control/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::command::handle_param_setters;
33
use super::CommandWriters;
44

55
/// Controls a panning control effect.
6+
#[derive(Debug)]
67
pub struct PanningControlHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/effect/reverb/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::command::handle_param_setters;
33
use super::CommandWriters;
44

55
/// Controls a reverb effect.
6+
#[derive(Debug)]
67
pub struct ReverbHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/effect/volume_control/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{command::handle_param_setters, Volume};
33
use super::CommandWriters;
44

55
/// Controls a volume control effect.
6+
#[derive(Debug)]
67
pub struct VolumeControlHandle {
78
pub(super) command_writers: CommandWriters,
89
}

crates/kira/src/manager/backend/resources.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ pub(crate) mod spatial_scenes;
77
#[cfg(test)]
88
mod test;
99

10-
use std::sync::Mutex;
10+
use std::{
11+
fmt::{Debug, Formatter},
12+
sync::Mutex,
13+
};
1114

1215
use crate::{
1316
arena::{Arena, Controller, Key},
@@ -236,6 +239,32 @@ impl<T> ResourceController<T> {
236239
}
237240
}
238241

242+
impl<T> Debug for ResourceController<T> {
243+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
244+
f.debug_struct("ResourceController")
245+
.field("arena_controller", &self.arena_controller)
246+
.field("new_resource_producer", &HeapProducerDebug)
247+
.field("unused_resource_consumer", &HeapConsumerDebug)
248+
.finish()
249+
}
250+
}
251+
252+
struct HeapProducerDebug;
253+
254+
impl Debug for HeapProducerDebug {
255+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
256+
f.debug_struct("HeapProducer").finish()
257+
}
258+
}
259+
260+
struct HeapConsumerDebug;
261+
262+
impl Debug for HeapConsumerDebug {
263+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
264+
f.debug_struct("HeapConsumer").finish()
265+
}
266+
}
267+
239268
pub(crate) struct Resources {
240269
pub sounds: Sounds,
241270
pub mixer: Mixer,

crates/kira/src/modulator/lfo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl Waveform {
126126
}
127127
}
128128

129+
#[derive(Debug)]
129130
struct LfoShared {
130131
removed: AtomicBool,
131132
}

crates/kira/src/modulator/lfo/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{command::handle_param_setters, modulator::ModulatorId};
55
use super::{CommandWriters, LfoShared, Waveform};
66

77
/// Controls an LFO modulator.
8+
#[derive(Debug)]
89
pub struct LfoHandle {
910
pub(super) id: ModulatorId,
1011
pub(super) command_writers: CommandWriters,

crates/kira/src/modulator/tweener.rs

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ enum State {
122122
},
123123
}
124124

125+
#[derive(Debug)]
125126
struct TweenerShared {
126127
removed: AtomicBool,
127128
}

crates/kira/src/modulator/tweener/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{modulator::ModulatorId, tween::Tween};
55
use super::{CommandWriters, TweenerShared};
66

77
/// Controls a tweener.
8+
#[derive(Debug)]
89
pub struct TweenerHandle {
910
pub(super) id: ModulatorId,
1011
pub(super) command_writers: CommandWriters,

crates/kira/src/sound/static_sound/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
use super::{sound::Shared, CommandWriters};
1111

1212
/// Controls a static sound.
13+
#[derive(Debug)]
1314
pub struct StaticSoundHandle {
1415
pub(super) command_writers: CommandWriters,
1516
pub(super) shared: Arc<Shared>,

crates/kira/src/sound/static_sound/sound.rs

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ impl Sound for StaticSound {
296296
}
297297
}
298298

299+
#[derive(Debug)]
299300
pub(super) struct Shared {
300301
state: AtomicU8,
301302
position: AtomicU64,

crates/kira/src/sound/streaming.rs

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use crate::{
4444

4545
use super::{PlaybackRate, Region};
4646

47+
#[derive(Debug)]
4748
pub(crate) struct CommandWriters {
4849
set_volume: CommandWriter<ValueChangeCommand<Volume>>,
4950
set_playback_rate: CommandWriter<ValueChangeCommand<PlaybackRate>>,
@@ -65,6 +66,7 @@ pub(crate) struct CommandReaders {
6566
stop: CommandReader<Tween>,
6667
}
6768

69+
#[derive(Debug)]
6870
pub(crate) struct DecodeSchedulerCommandReaders {
6971
set_loop_region: CommandReader<Option<Region>>,
7072
seek_by: CommandReader<f64>,

crates/kira/src/sound/streaming/handle.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::sync::Arc;
1+
use std::{
2+
fmt::{Debug, Formatter},
3+
sync::Arc,
4+
};
25

36
use crate::{
47
command::handle_param_setters,
@@ -308,3 +311,21 @@ impl<Error> StreamingSoundHandle<Error> {
308311
self.error_consumer.pop()
309312
}
310313
}
314+
315+
impl<Error: Debug> Debug for StreamingSoundHandle<Error> {
316+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
317+
f.debug_struct("StreamingSoundHandle")
318+
.field("shared", &self.shared)
319+
.field("command_writers", &self.command_writers)
320+
.field("error_consumer", &HeapConsumerDebug)
321+
.finish()
322+
}
323+
}
324+
325+
struct HeapConsumerDebug;
326+
327+
impl Debug for HeapConsumerDebug {
328+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
329+
f.debug_struct("HeapConsumer").finish()
330+
}
331+
}

crates/kira/src/sound/streaming/sound.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use super::{CommandReaders, StreamingSoundSettings};
2626

2727
use self::decode_scheduler::DecodeScheduler;
2828

29+
#[derive(Debug)]
2930
pub(crate) struct Shared {
3031
state: AtomicU8,
3132
position: AtomicU64,

crates/kira/src/spatial/emitter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl EmitterId {
150150
}
151151
}
152152

153+
#[derive(Debug)]
153154
pub(crate) struct EmitterShared {
154155
removed: AtomicBool,
155156
}

crates/kira/src/spatial/emitter/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use super::{CommandWriters, EmitterId, EmitterShared};
1111
///
1212
/// When a [`EmitterHandle`] is dropped, the corresponding
1313
/// emitter will be removed.
14+
#[derive(Debug)]
1415
pub struct EmitterHandle {
1516
pub(crate) id: EmitterId,
1617
pub(crate) shared: Arc<EmitterShared>,

crates/kira/src/spatial/listener.rs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl Listener {
148148
}
149149
}
150150

151+
#[derive(Debug)]
151152
pub(crate) struct ListenerShared {
152153
removed: AtomicBool,
153154
}

crates/kira/src/spatial/listener/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use super::{CommandWriters, ListenerShared};
1111
///
1212
/// When a [`ListenerHandle`] is dropped, the corresponding
1313
/// listener will be removed.
14+
#[derive(Debug)]
1415
pub struct ListenerHandle {
1516
pub(crate) shared: Arc<ListenerShared>,
1617
pub(crate) command_writers: CommandWriters,

crates/kira/src/spatial/scene.rs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl SpatialScene {
102102
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
103103
pub struct SpatialSceneId(pub(crate) Key);
104104

105+
#[derive(Debug)]
105106
pub(crate) struct SpatialSceneShared {
106107
removed: AtomicBool,
107108
}

crates/kira/src/spatial/scene/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use super::{SpatialSceneId, SpatialSceneShared};
1919
///
2020
/// When a [`SpatialSceneHandle`] is dropped, the corresponding
2121
/// spatial scene will be removed.
22+
#[derive(Debug)]
2223
pub struct SpatialSceneHandle {
2324
pub(crate) id: SpatialSceneId,
2425
pub(crate) shared: Arc<SpatialSceneShared>,

crates/kira/src/track.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl From<&TrackHandle> for TrackId {
302302
}
303303
}
304304

305+
#[derive(Debug)]
305306
pub(crate) struct TrackShared {
306307
removed: AtomicBool,
307308
}

crates/kira/src/track/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl Error for NonexistentRoute {}
2525
///
2626
/// When a [`TrackHandle`] is dropped, the corresponding mixer
2727
/// track will be removed.
28+
#[derive(Debug)]
2829
pub struct TrackHandle {
2930
pub(crate) id: TrackId,
3031
pub(crate) shared: Option<Arc<TrackShared>>,

0 commit comments

Comments
 (0)