From 80d7df910987db5201402fe987124f29f09344f3 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 25 Jul 2023 17:42:36 +1000 Subject: fuck off --- src/audio/audio_fsm.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/audio/audio_fsm.cpp') diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp index 5f4f8783..c3313820 100644 --- a/src/audio/audio_fsm.cpp +++ b/src/audio/audio_fsm.cpp @@ -14,6 +14,8 @@ #include "esp_log.h" #include "event_queue.hpp" #include "fatfs_audio_input.hpp" +#include "freertos/portmacro.h" +#include "future_fetcher.hpp" #include "i2s_audio_output.hpp" #include "i2s_dac.hpp" #include "pipeline.hpp" @@ -29,14 +31,16 @@ drivers::IGpios* AudioState::sIGpios; std::shared_ptr AudioState::sDac; std::weak_ptr AudioState::sDatabase; +std::unique_ptr AudioState::sTask; std::unique_ptr AudioState::sFileSource; std::unique_ptr AudioState::sI2SOutput; -std::vector> AudioState::sPipeline; TrackQueue* AudioState::sTrackQueue; +std::optional AudioState::sCurrentTrack; auto AudioState::Init(drivers::IGpios* gpio_expander, std::weak_ptr database, + std::shared_ptr tag_parser, TrackQueue* queue) -> bool { sIGpios = gpio_expander; sTrackQueue = queue; @@ -48,19 +52,10 @@ auto AudioState::Init(drivers::IGpios* gpio_expander, sDac.reset(dac.value()); sDatabase = database; - sFileSource.reset(new FatfsAudioInput()); + sFileSource.reset(new FatfsAudioInput(tag_parser)); sI2SOutput.reset(new I2SAudioOutput(sIGpios, sDac)); - // Perform initial pipeline configuration. - // TODO(jacqueline): Factor this out once we have any kind of dynamic - // reconfiguration. - AudioDecoder* codec = new AudioDecoder(); - sPipeline.emplace_back(codec); - - Pipeline* pipeline = new Pipeline(sPipeline.front().get()); - pipeline->AddInput(sFileSource.get()); - - task::StartPipeline(pipeline, sI2SOutput.get()); + AudioTask::Start(sFileSource.get(), sI2SOutput.get()); return true; } @@ -85,9 +80,9 @@ void AudioState::react(const system_fsm::KeyDownChanged& ev) { void AudioState::react(const system_fsm::HasPhonesChanged& ev) { if (ev.falling) { - ESP_LOGI(kTag, "headphones in!"); + // ESP_LOGI(kTag, "headphones in!"); } else { - ESP_LOGI(kTag, "headphones out!"); + // ESP_LOGI(kTag, "headphones out!"); } } @@ -107,13 +102,15 @@ void Standby::react(const QueueUpdate& ev) { return; } + sCurrentTrack = current_track; + auto db = sDatabase.lock(); if (!db) { ESP_LOGW(kTag, "database not open; ignoring play request"); return; } - sFileSource->OpenFile(db->GetTrackPath(*current_track)); + sFileSource->SetPath(db->GetTrackPath(*current_track)); } void Playback::entry() { @@ -127,20 +124,25 @@ void Playback::exit() { } void Playback::react(const QueueUpdate& ev) { + if (!ev.current_changed) { + return; + } auto current_track = sTrackQueue->GetCurrent(); if (!current_track) { - // TODO: return to standby? + sFileSource->SetPath(); + sCurrentTrack.reset(); + transit(); return; } + sCurrentTrack = current_track; + auto db = sDatabase.lock(); if (!db) { return; } - // TODO: what if we just finished this, and are preemptively loading the next - // one? - sFileSource->OpenFile(db->GetTrackPath(*current_track)); + sFileSource->SetPath(db->GetTrackPath(*current_track)); } void Playback::react(const PlaybackUpdate& ev) { @@ -161,7 +163,7 @@ void Playback::react(const internal::InputFileClosed& ev) { return; } ESP_LOGI(kTag, "preemptively opening next file"); - sFileSource->OpenFile(db->GetTrackPath(upcoming.front())); + sFileSource->SetPath(db->GetTrackPath(upcoming.front())); } void Playback::react(const internal::InputFileFinished& ev) { -- cgit v1.2.3