Skip to content

Commit 3af813c

Browse files
authored
Merge pull request #374 from b-ma/refactor/remove-audio-buffer-source-inner-state
Refactor: removed `InnerState` struct in `AudioBufferSourceNode`
2 parents e897a89 + a9754a6 commit 3af813c

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/node/audio_buffer_source.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ pub struct AudioBufferSourceNode {
109109
playback_rate: AudioParam, // has constraints, no a-rate
110110
buffer_time: Arc<AtomicF64>,
111111
buffer: Option<AudioBuffer>,
112-
inner_state: InnerState,
113-
}
114-
115-
#[derive(Debug, Clone)]
116-
struct InnerState {
117112
loop_state: LoopState,
118113
source_started: bool,
119114
}
@@ -153,7 +148,7 @@ impl AudioScheduledSourceNode for AudioBufferSourceNode {
153148

154149
fn stop_at(&mut self, when: f64) {
155150
assert!(
156-
self.inner_state.source_started,
151+
self.source_started,
157152
"InvalidStateError cannot stop before start"
158153
);
159154

@@ -217,18 +212,15 @@ impl AudioBufferSourceNode {
217212
ended_triggered: false,
218213
};
219214

220-
let inner_state = InnerState {
221-
loop_state,
222-
source_started: false,
223-
};
224215
let mut node = Self {
225216
registration,
226217
channel_config: ChannelConfig::default(),
227218
detune: d_param,
228219
playback_rate: pr_param,
229220
buffer_time: Arc::clone(&renderer.render_state.buffer_time),
230221
buffer: None,
231-
inner_state,
222+
loop_state,
223+
source_started: false,
232224
};
233225

234226
if let Some(buf) = buffer {
@@ -255,10 +247,10 @@ impl AudioBufferSourceNode {
255247
/// Panics if the source was already started
256248
pub fn start_at_with_offset_and_duration(&mut self, start: f64, offset: f64, duration: f64) {
257249
assert!(
258-
!self.inner_state.source_started,
250+
!self.source_started,
259251
"InvalidStateError: Cannot call `start` twice"
260252
);
261-
self.inner_state.source_started = true;
253+
self.source_started = true;
262254

263255
let control = ControlMessage::StartWithOffsetAndDuration(start, offset, duration);
264256
self.registration.post_message(control);
@@ -317,32 +309,32 @@ impl AudioBufferSourceNode {
317309
/// Defines if the playback the [`AudioBuffer`] should be looped
318310
#[allow(clippy::missing_panics_doc)]
319311
pub fn loop_(&self) -> bool {
320-
self.inner_state.loop_state.is_looping
312+
self.loop_state.is_looping
321313
}
322314

323315
pub fn set_loop(&mut self, value: bool) {
324-
self.inner_state.loop_state.is_looping = value;
316+
self.loop_state.is_looping = value;
325317
self.registration.post_message(ControlMessage::Loop(value));
326318
}
327319

328320
/// Defines the loop start point, in the time reference of the [`AudioBuffer`]
329321
pub fn loop_start(&self) -> f64 {
330-
self.inner_state.loop_state.start
322+
self.loop_state.start
331323
}
332324

333325
pub fn set_loop_start(&mut self, value: f64) {
334-
self.inner_state.loop_state.start = value;
326+
self.loop_state.start = value;
335327
self.registration
336328
.post_message(ControlMessage::LoopStart(value));
337329
}
338330

339331
/// Defines the loop end point, in the time reference of the [`AudioBuffer`]
340332
pub fn loop_end(&self) -> f64 {
341-
self.inner_state.loop_state.end
333+
self.loop_state.end
342334
}
343335

344336
pub fn set_loop_end(&mut self, value: f64) {
345-
self.inner_state.loop_state.end = value;
337+
self.loop_state.end = value;
346338
self.registration
347339
.post_message(ControlMessage::LoopEnd(value));
348340
}

0 commit comments

Comments
 (0)