diff --git a/lua/playing.lua b/lua/playing.lua index c6a3f47e..22b3390f 100644 --- a/lua/playing.lua +++ b/lua/playing.lua @@ -147,7 +147,8 @@ return function(opts) local play_pause_btn = controls:Button {} play_pause_btn:onClicked(function() - playback.playing:set(not playback.playing:get()) + --playback.playing:set(not playback.playing:get()) + playback.position:set(playback.position:get() + 5) end) play_pause_btn:focus() local play_pause_img = play_pause_btn:Image { src = img.pause } diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index eaa9ff9c..68a8a86b 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -148,16 +148,15 @@ auto Decoder::BeginDecoding(std::shared_ptr stream) -> bool { ESP_LOGI(kTag, "stream started ok"); events::Audio().Dispatch(internal::InputFileOpened{}); - // TODO: How does this need to change? auto tags = std::make_shared(Track{ .tags = stream->tags(), .db_info = {}, .bitrate_kbps = open_res->sample_rate_hz, .encoding = stream->type(), + .filepath = stream->Filepath(), }); timer_.reset(new Timer(tags, open_res.value(), stream->Offset())); - // TODO: How does *this?* need to change? PlaybackUpdate ev{.seconds_elapsed = stream->Offset(), .track = tags}; events::Audio().Dispatch(ev); events::Ui().Dispatch(ev); diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp index 75e3c24a..0e213b6e 100644 --- a/src/audio/audio_fsm.cpp +++ b/src/audio/audio_fsm.cpp @@ -246,14 +246,16 @@ void Uninitialised::react(const system_fsm::BootComplete& ev) { void Standby::react(const PlayFile& ev) { sCurrentTrack = 0; sIsPlaybackAllowed = true; - sFileSource->SetPath(ev.filename, 10); + sFileSource->SetPath(ev.filename); } void Playback::react(const PlayFile& ev) { - sFileSource->SetPath(ev.filename, 10); + sFileSource->SetPath(ev.filename); } void Standby::react(const SeekFile& ev) { + sCurrentTrack = 0; + sIsPlaybackAllowed = true; sFileSource->SetPath(ev.filename, ev.offset); } diff --git a/src/audio/audio_source.cpp b/src/audio/audio_source.cpp index 2543db44..d9e8e04a 100644 --- a/src/audio/audio_source.cpp +++ b/src/audio/audio_source.cpp @@ -12,8 +12,9 @@ namespace audio { TaggedStream::TaggedStream(std::shared_ptr t, std::unique_ptr w, + std::string filepath, uint32_t offset) - : codecs::IStream(w->type()), tags_(t), wrapped_(std::move(w)), offset_(offset) {} + : codecs::IStream(w->type()), tags_(t), wrapped_(std::move(w)), filepath_(filepath), offset_(offset) {} auto TaggedStream::tags() -> std::shared_ptr { return tags_; @@ -43,6 +44,10 @@ auto TaggedStream::Offset() -> uint32_t { return offset_; } +auto TaggedStream::Filepath() -> std::string { + return filepath_; +} + auto TaggedStream::SetPreambleFinished() -> void { wrapped_->SetPreambleFinished(); } diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index 665e8c1d..74c1154b 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -136,7 +136,7 @@ auto FatfsAudioInput::OpenFile(const std::string& path,uint32_t offset) -> bool auto source = std::make_unique(stream_type.value(), std::move(file)); - new_stream_.reset(new TaggedStream(tags, std::move(source), offset)); + new_stream_.reset(new TaggedStream(tags, std::move(source), path, offset)); return true; } diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp index 8459333f..96e77987 100644 --- a/src/audio/include/audio_events.hpp +++ b/src/audio/include/audio_events.hpp @@ -26,6 +26,7 @@ struct Track { uint32_t duration; uint32_t bitrate_kbps; codecs::StreamType encoding; + std::string filepath; }; struct PlaybackStarted : tinyfsm::Event {}; @@ -46,8 +47,8 @@ struct PlayFile : tinyfsm::Event { }; struct SeekFile : tinyfsm::Event { + uint32_t offset; std::string filename; - uint32_t offset; }; struct StepUpVolume : tinyfsm::Event {}; diff --git a/src/audio/include/audio_source.hpp b/src/audio/include/audio_source.hpp index b2fd173d..b38acd7a 100644 --- a/src/audio/include/audio_source.hpp +++ b/src/audio/include/audio_source.hpp @@ -17,7 +17,9 @@ class TaggedStream : public codecs::IStream { public: TaggedStream(std::shared_ptr, std::unique_ptr wrapped, - uint32_t offset = 0); + std::string path, + uint32_t offset = 0 + ); auto tags() -> std::shared_ptr; @@ -33,11 +35,14 @@ class TaggedStream : public codecs::IStream { auto Offset() -> uint32_t; + auto Filepath() -> std::string; + auto SetPreambleFinished() -> void override; private: std::shared_ptr tags_; std::unique_ptr wrapped_; + std::string filepath_; int32_t offset_; }; diff --git a/src/codecs/wav.cpp b/src/codecs/wav.cpp index 22cbd49c..5dd6f031 100644 --- a/src/codecs/wav.cpp +++ b/src/codecs/wav.cpp @@ -218,7 +218,6 @@ auto WavDecoder::DecodeTo(cpp::span output) buffer_.ConsumeBytes([&](cpp::span buf) -> size_t { size_t bytes_read = buf.size_bytes(); - ESP_LOGI(kTag, "Bytes read: %d", bytes_read); size_t frames_read = bytes_read / bytes_per_sample_ / output_format_.num_channels; @@ -244,10 +243,6 @@ auto WavDecoder::DecodeTo(cpp::span output) return samples_written * bytes_per_sample_; }); - ESP_LOGI(kTag, "Samples written %d", samples_written); - if (is_eof) { - ESP_LOGI(kTag, "EOF"); - } return OutputInfo{.samples_written = samples_written, .is_stream_finished = samples_written == 0 && is_eof}; diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 24145ead..3e85c36e 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -123,7 +123,21 @@ lua::Property UiState::sPlaybackPlaying{ }}; lua::Property UiState::sPlaybackTrack{}; -lua::Property UiState::sPlaybackPosition{0}; +lua::Property UiState::sPlaybackPosition{0, [](const lua::LuaValue& val) { + int current_val = std::get(sPlaybackPosition.Get()); + if (!std::holds_alternative(val)) { + return false; + } + int new_val = std::get(val); + if (current_val != new_val) { + auto track = sPlaybackTrack.Get(); + if (!std::holds_alternative(track)) { + return false; + } + events::Audio().Dispatch(audio::SeekFile{.offset = (uint32_t)new_val, .filename = std::get(track).filepath}); + } + return true; +}}; lua::Property UiState::sQueuePosition{0}; lua::Property UiState::sQueueSize{0};