mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
iterators can be played now
This commit is contained in:
@@ -359,7 +359,7 @@ pub async fn execute_inner(
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
BEETHOVEN.play().await.unwrap_or_default(); // ignore error in playing the song
|
(&BEETHOVEN).play().await.unwrap_or_default(); // ignore error in playing the song
|
||||||
tracing::error!("Error recovering drive!: {}", e);
|
tracing::error!("Error recovering drive!: {}", e);
|
||||||
tracing::debug!("{:?}", e);
|
tracing::debug!("{:?}", e);
|
||||||
*ctx.recovery_status.write().await = Some(Err(e.into()));
|
*ctx.recovery_status.write().await = Some(Err(e.into()));
|
||||||
|
|||||||
@@ -112,19 +112,23 @@ pub struct Song<Notes> {
|
|||||||
tempo_qpm: u16,
|
tempo_qpm: u16,
|
||||||
note_sequence: Notes,
|
note_sequence: Notes,
|
||||||
}
|
}
|
||||||
impl<'a, T: 'a> Song<T>
|
impl<'a, T> Song<T>
|
||||||
where
|
where
|
||||||
&'a T: IntoIterator<Item = &'a (Option<Note>, TimeSlice)>,
|
T: IntoIterator<Item = (Option<Note>, TimeSlice)> + Clone,
|
||||||
{
|
{
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
pub async fn play(&'a self) -> Result<(), Error> {
|
pub async fn play(&self) -> Result<(), Error> {
|
||||||
#[cfg(feature = "sound")]
|
#[cfg(feature = "sound")]
|
||||||
{
|
{
|
||||||
let mut sound = SoundInterface::lease().await?;
|
let mut sound = SoundInterface::lease().await?;
|
||||||
for (note, slice) in &self.note_sequence {
|
for (note, slice) in self.note_sequence.clone() {
|
||||||
match note {
|
match note {
|
||||||
None => tokio::time::sleep(slice.to_duration(self.tempo_qpm)).await,
|
None => tokio::time::sleep(slice.to_duration(self.tempo_qpm)).await,
|
||||||
Some(n) => sound.play_for_time_slice(self.tempo_qpm, n, slice).await?,
|
Some(n) => {
|
||||||
|
sound
|
||||||
|
.play_for_time_slice(self.tempo_qpm, &n, &slice)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
sound.close().await?;
|
sound.close().await?;
|
||||||
@@ -285,6 +289,7 @@ pub fn circle_of_fourths(note: &Note) -> impl Iterator<Item = Note> {
|
|||||||
iterate(|n| interval(&FOURTH, n), note)
|
iterate(|n| interval(&FOURTH, n), note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct CircleOf<'a> {
|
pub struct CircleOf<'a> {
|
||||||
current: Note,
|
current: Note,
|
||||||
duration: TimeSlice,
|
duration: TimeSlice,
|
||||||
@@ -404,7 +409,7 @@ pub const BEETHOVEN: Song<[(Option<Note>, TimeSlice); 9]> = song!(216, [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub static ref CIRCLE_OF_5THS_SHORT: Song<Vec<(Option<Note>, TimeSlice)>> = Song {
|
pub static ref CIRCLE_OF_5THS_SHORT: Song<std::iter::Take<CircleOf<'static>>> = Song {
|
||||||
tempo_qpm: 300,
|
tempo_qpm: 300,
|
||||||
note_sequence: CircleOf::new(
|
note_sequence: CircleOf::new(
|
||||||
&FIFTH,
|
&FIFTH,
|
||||||
@@ -414,7 +419,7 @@ lazy_static::lazy_static! {
|
|||||||
},
|
},
|
||||||
TimeSlice::Triplet(&TimeSlice::Eighth),
|
TimeSlice::Triplet(&TimeSlice::Eighth),
|
||||||
)
|
)
|
||||||
.take(6).collect(),
|
.take(6),
|
||||||
};
|
};
|
||||||
pub static ref CIRCLE_OF_4THS_SHORT: Song<std::iter::Take<CircleOf<'static>>> = Song {
|
pub static ref CIRCLE_OF_4THS_SHORT: Song<std::iter::Take<CircleOf<'static>>> = Song {
|
||||||
tempo_qpm: 300,
|
tempo_qpm: 300,
|
||||||
|
|||||||
Reference in New Issue
Block a user