return index of the audio channel instead of the channel itself

this is more useful because playing/stopping can be done on a specific
channel more easily by specifying a channel index. and the index can
obviously also be used to get the channel itself when/if needed, but
it's not super convenient to get the index of a channel when you only
have the channel itself
This commit is contained in:
Gered 2022-07-10 12:58:14 -04:00
parent 06d3d927fe
commit cbfd66d42e

View file

@ -205,13 +205,13 @@ impl AudioDevice {
&mut self,
buffer: &AudioBuffer,
loops: bool,
) -> Result<Option<&mut AudioChannel>, AudioDeviceError> {
) -> Result<Option<usize>, AudioDeviceError> {
if *buffer.spec() != self.spec {
Err(AudioDeviceError::AudioSpecMismatch)
} else {
if let Some(channel) = self.stopped_channels_iter_mut().next() {
if let Some((index, channel)) = self.stopped_channels_iter_mut().enumerate().next() {
channel.play_buffer(buffer, loops);
Ok(Some(channel))
Ok(Some(index))
} else {
Ok(None)
}
@ -238,10 +238,10 @@ impl AudioDevice {
&mut self,
generator: Box<dyn AudioGenerator>,
loops: bool,
) -> Result<Option<&mut AudioChannel>, AudioDeviceError> {
if let Some(channel) = self.stopped_channels_iter_mut().next() {
) -> Result<Option<usize>, AudioDeviceError> {
if let Some((index, channel)) = self.stopped_channels_iter_mut().enumerate().next() {
channel.play_generator(generator, loops);
Ok(Some(channel))
Ok(Some(index))
} else {
Ok(None)
}