Add simple record UI to audio app.

This commit is contained in:
Jared Boone 2016-04-22 12:30:02 -07:00
parent a6538bc48b
commit adf573be20
2 changed files with 53 additions and 6 deletions

View File

@ -84,6 +84,8 @@ AnalogAudioView::AnalogAudioView(
&field_vga,
&options_modulation,
&field_volume,
&button_record,
&text_record_filename,
&waterfall,
} });
@ -136,6 +138,10 @@ AnalogAudioView::AnalogAudioView(
this->on_headphone_volume_changed(v);
};
button_record.on_select = [this](ImageButton&) {
this->on_record();
};
audio::output::start();
update_modulation(static_cast<ReceiverModel::Mode>(modulation));
@ -281,7 +287,7 @@ void AnalogAudioView::on_headphone_volume_changed(int32_t v) {
void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) {
audio::output::mute();
capture_thread.reset();
record_stop();
const auto is_wideband_spectrum_mode = (modulation == ReceiverModel::Mode::SpectrumAnalysis);
receiver_model.set_baseband_configuration({
@ -293,12 +299,36 @@ void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) {
receiver_model.enable();
if( !is_wideband_spectrum_mode ) {
const auto filename = next_filename_matching_pattern("AUD_????.S16");
if( !filename.empty() ) {
capture_thread = std::make_unique<CaptureThread>(filename);
}
audio::output::unmute();
}
}
bool AnalogAudioView::is_recording() const {
return (bool)capture_thread;
}
void AnalogAudioView::on_record() {
if( is_recording() ) {
record_stop();
} else {
record_start();
}
}
void AnalogAudioView::record_start() {
const auto filename = next_filename_matching_pattern("AUD_????.S16");
text_record_filename.set(filename);
if( filename.empty() ) {
return;
}
capture_thread = std::make_unique<CaptureThread>(filename);
button_record.set_bitmap(&bitmap_stop);
}
void AnalogAudioView::record_stop() {
capture_thread.reset();
button_record.set_bitmap(&bitmap_record);
}
} /* namespace ui */

View File

@ -93,7 +93,7 @@ public:
void focus() override;
private:
static constexpr ui::Dim header_height = 2 * 16;
static constexpr ui::Dim header_height = 3 * 16;
const Rect options_view_rect { 0 * 8, 1 * 16, 30 * 8, 1 * 16 };
@ -142,6 +142,18 @@ private:
std::unique_ptr<Widget> options_widget;
ImageButton button_record {
{ 0 * 8, 2 * 16, 2 * 8, 1 * 16 },
&bitmap_record,
Color::red(),
Color::black()
};
Text text_record_filename {
{ 3 * 8, 2 * 16, 12 * 8, 16 },
"",
};
spectrum::WaterfallWidget waterfall;
std::unique_ptr<CaptureThread> capture_thread;
@ -164,6 +176,11 @@ private:
void set_options_widget(std::unique_ptr<Widget> new_widget);
void update_modulation(const ReceiverModel::Mode modulation);
void on_record();
bool is_recording() const;
void record_start();
void record_stop();
};
} /* namespace ui */