Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow retrieving the queue signal in a sink when using crossbeam-channel feature #600

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/conversions/sample.rs
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified because it did not pass CI with clippy error: doc list item missing indentation

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
/// - For `u16`, silence corresponds to the value `u16::max_value() / 2`. The minimum and maximum
/// amplitudes are represented by `0` and `u16::max_value()` respectively.
/// - For `f32`, silence corresponds to the value `0.0`. The minimum and maximum amplitudes are
/// represented by `-1.0` and `1.0` respectively.
/// represented by `-1.0` and `1.0` respectively.
///
/// You can implement this trait on your own type as well if you wish so.
///
Expand Down
27 changes: 26 additions & 1 deletion src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ impl Sink {
/// Appends a sound to the queue of sounds to play.
#[inline]
pub fn append<S>(&self, source: S)
where
S: Source + Send + 'static,
f32: FromSample<S::Item>,
S::Item: Sample + Send,
{
self.append_with_signal(source);
}

/// Appends a sound to the queue of sounds to play
///
/// When using the feature flag `crossbeam-channel` in rodio the `crossbeam_channel::Receiver` will be returned when the sound has finished playing.
#[inline]
pub fn append_with_signal<S>(&self, source: S) -> Option<Receiver<()>>
where
S: Source + Send + 'static,
f32: FromSample<S::Item>,
Expand Down Expand Up @@ -159,7 +172,19 @@ impl Sink {
.convert_samples();
self.sound_count.fetch_add(1, Ordering::Relaxed);
let source = Done::new(source, self.sound_count.clone());
*self.sleep_until_end.lock().unwrap() = Some(self.queue_tx.append_with_signal(source));
let rx = self.queue_tx.append_with_signal(source);

#[cfg(not(feature = "crossbeam-channel"))]
{
*self.sleep_until_end.lock().unwrap() = Some(rx);
None
}

#[cfg(feature = "crossbeam-channel")]
{
*self.sleep_until_end.lock().unwrap() = Some(rx.clone());
Some(rx)
}
}

/// Gets the volume of the sound.
Expand Down