mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-12-12 19:42:07 +00:00
Add audio playback ability to WAV Viewer app (#1829)
This commit is contained in:
@@ -24,12 +24,15 @@
|
||||
#include "ui_navigation.hpp"
|
||||
#include "io_wave.hpp"
|
||||
#include "spectrum_color_lut.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "replay_thread.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class ViewWavView : public View {
|
||||
public:
|
||||
ViewWavView(NavigationView& nav);
|
||||
~ViewWavView();
|
||||
|
||||
void focus() override;
|
||||
void paint(Painter&) override;
|
||||
@@ -37,6 +40,9 @@ class ViewWavView : public View {
|
||||
std::string title() const override { return "WAV viewer"; };
|
||||
|
||||
private:
|
||||
app_settings::SettingsManager settings_{
|
||||
"wav_viewer", app_settings::Mode::NO_RF};
|
||||
|
||||
NavigationView& nav_;
|
||||
static constexpr uint32_t subsampling_factor = 8;
|
||||
|
||||
@@ -46,6 +52,20 @@ class ViewWavView : public View {
|
||||
void on_pos_changed();
|
||||
void load_wav(std::filesystem::path file_path);
|
||||
void reset_controls();
|
||||
bool is_active();
|
||||
void stop();
|
||||
void handle_replay_thread_done(const uint32_t return_code);
|
||||
void set_ready();
|
||||
void file_error();
|
||||
void start_playback();
|
||||
void on_playback_progress(const uint32_t progress);
|
||||
|
||||
std::filesystem::path wav_file_path{};
|
||||
std::unique_ptr<ReplayThread> replay_thread{};
|
||||
bool ready_signal{false};
|
||||
const size_t read_size{2048};
|
||||
const size_t buffer_count{3};
|
||||
const uint32_t progress_interval_samples{1536000 / 20};
|
||||
|
||||
std::unique_ptr<WAVFileReader> wav_reader{};
|
||||
|
||||
@@ -60,10 +80,11 @@ class ViewWavView : public View {
|
||||
{{0 * 8, 1 * 16}, "Samplerate:", Color::light_grey()},
|
||||
{{0 * 8, 2 * 16}, "Title:", Color::light_grey()},
|
||||
{{0 * 8, 3 * 16}, "Duration:", Color::light_grey()},
|
||||
{{0 * 8, 11 * 16}, "Position: s Scale:", Color::light_grey()},
|
||||
{{0 * 8, 12 * 16}, "Cursor A:", Color::dark_cyan()},
|
||||
{{0 * 8, 13 * 16}, "Cursor B:", Color::dark_magenta()},
|
||||
{{0 * 8, 14 * 16}, "Delta:", Color::light_grey()}};
|
||||
{{0 * 8, 12 * 16}, "Position: s Scale:", Color::light_grey()},
|
||||
{{0 * 8, 13 * 16}, "Cursor A:", Color::dark_cyan()},
|
||||
{{0 * 8, 14 * 16}, "Cursor B:", Color::dark_magenta()},
|
||||
{{0 * 8, 15 * 16}, "Delta:", Color::light_grey()},
|
||||
{{24 * 8, 18 * 16}, "Vol:", Color::light_grey()}};
|
||||
|
||||
Text text_filename{
|
||||
{5 * 8, 0 * 16, 12 * 8, 16},
|
||||
@@ -80,6 +101,13 @@ class ViewWavView : public View {
|
||||
Button button_open{
|
||||
{24 * 8, 8, 6 * 8, 2 * 16},
|
||||
"Open"};
|
||||
ImageButton button_play{
|
||||
{24 * 8, 17 * 16, 2 * 8, 1 * 16},
|
||||
&bitmap_play,
|
||||
Color::green(),
|
||||
Color::black()};
|
||||
AudioVolumeField field_volume{
|
||||
{28 * 8, 18 * 16}};
|
||||
|
||||
Waveform waveform{
|
||||
{0, 5 * 16, 240, 64},
|
||||
@@ -89,34 +117,29 @@ class ViewWavView : public View {
|
||||
false,
|
||||
Color::white()};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{0 * 8, 11 * 16, 30 * 8, 8}};
|
||||
|
||||
NumberField field_pos_seconds{
|
||||
{9 * 8, 11 * 16},
|
||||
{9 * 8, 12 * 16},
|
||||
3,
|
||||
{0, 999},
|
||||
1,
|
||||
' '};
|
||||
NumberField field_pos_samples{
|
||||
{14 * 8, 11 * 16},
|
||||
{14 * 8, 12 * 16},
|
||||
6,
|
||||
{0, 999999},
|
||||
1,
|
||||
'0'};
|
||||
NumberField field_scale{
|
||||
{28 * 8, 11 * 16},
|
||||
{28 * 8, 12 * 16},
|
||||
2,
|
||||
{1, 40},
|
||||
1,
|
||||
' '};
|
||||
|
||||
NumberField field_cursor_a{
|
||||
{9 * 8, 12 * 16},
|
||||
3,
|
||||
{0, 239},
|
||||
1,
|
||||
' ',
|
||||
true};
|
||||
|
||||
NumberField field_cursor_b{
|
||||
{9 * 8, 13 * 16},
|
||||
3,
|
||||
{0, 239},
|
||||
@@ -124,9 +147,40 @@ class ViewWavView : public View {
|
||||
' ',
|
||||
true};
|
||||
|
||||
NumberField field_cursor_b{
|
||||
{9 * 8, 14 * 16},
|
||||
3,
|
||||
{0, 239},
|
||||
1,
|
||||
' ',
|
||||
true};
|
||||
|
||||
Text text_delta{
|
||||
{6 * 8, 14 * 16, 30 * 8, 16},
|
||||
{7 * 8, 15 * 16, 30 * 8, 16},
|
||||
"-"};
|
||||
|
||||
MessageHandlerRegistration message_handler_replay_thread_error{
|
||||
Message::ID::ReplayThreadDone,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const ReplayThreadDoneMessage*>(p);
|
||||
this->handle_replay_thread_done(message.return_code);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_fifo_signal{
|
||||
Message::ID::RequestSignal,
|
||||
[this](const Message* const p) {
|
||||
const auto message = static_cast<const RequestSignalMessage*>(p);
|
||||
if (message->signal == RequestSignalMessage::Signal::FillRequest) {
|
||||
this->set_ready();
|
||||
}
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_playback_progress(message.progress);
|
||||
}};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
Reference in New Issue
Block a user