Change next-file naming functions to work on filename stems.

This paves the way for writing metadata files with similar prefixes, and avoids confusing numbering of capture files with different extensions (e.g. BAD_0000.S16 and BBD_0000.S8).
This commit is contained in:
Jared Boone 2016-04-29 11:27:12 -07:00
parent dc8c34487f
commit 12b8a1b2a9
7 changed files with 29 additions and 34 deletions

View File

@ -316,13 +316,13 @@ void AnalogAudioView::on_record() {
}
void AnalogAudioView::record_start() {
const auto filename = next_filename_matching_pattern("AUD_????.S16");
text_record_filename.set(filename);
if( filename.empty() ) {
const auto filename_stem = next_filename_stem_matching_pattern("AUD_????");
text_record_filename.set(filename_stem);
if( filename_stem.empty() ) {
return;
}
capture_thread = std::make_unique<CaptureThread>(filename, 12, 2);
capture_thread = std::make_unique<CaptureThread>(filename_stem + ".S16", 12, 2);
button_record.set_bitmap(&bitmap_stop);
}

View File

@ -150,7 +150,7 @@ private:
};
Text text_record_filename {
{ 3 * 8, 2 * 16, 12 * 8, 16 },
{ 3 * 8, 2 * 16, 8 * 8, 16 },
"",
};

View File

@ -115,14 +115,14 @@ void CaptureAppView::on_record() {
capture_thread.reset();
button_record.set_bitmap(&bitmap_record);
} else {
const auto filename = next_filename_matching_pattern("BBD_????.C16");
text_record_filename.set(filename);
const auto filename_stem = next_filename_stem_matching_pattern("BBD_????");
text_record_filename.set(filename_stem);
text_record_dropped.set("");
if( filename.empty() ) {
if( filename_stem.empty() ) {
return;
}
capture_thread = std::make_unique<CaptureThread>(filename, 14, 1);
capture_thread = std::make_unique<CaptureThread>(filename_stem + ".C16", 14, 1);
button_record.set_bitmap(&bitmap_stop);
}
}

View File

@ -75,7 +75,7 @@ private:
};
Text text_record_filename {
{ 3 * 8, 2 * 16, 12 * 8, 16 },
{ 3 * 8, 2 * 16, 8 * 8, 16 },
"",
};

View File

@ -94,22 +94,16 @@ static std::string find_last_file_matching_pattern(const std::string& pattern) {
return last_match;
}
static std::string increment_filename_ordinal(const std::string& filename) {
std::string result { filename };
static std::string remove_filename_extension(const std::string& filename) {
const auto extension_index = filename.find_last_of('.');
return filename.substr(0, extension_index);
}
static std::string increment_filename_stem_ordinal(const std::string& filename_stem) {
std::string result { filename_stem };
auto it = result.rbegin();
// Back up past extension.
for(; it != result.rend(); ++it) {
if( *it == '.' ) {
++it;
break;
}
}
if( it == result.rend() ) {
return { };
}
// Increment decimal number before the extension.
for(; it != result.rend(); ++it) {
const auto c = *it;
@ -128,15 +122,16 @@ static std::string increment_filename_ordinal(const std::string& filename) {
return result;
}
std::string next_filename_matching_pattern(const std::string& filename_pattern) {
auto filename = find_last_file_matching_pattern(filename_pattern);
if( filename.empty() ) {
filename = filename_pattern;
std::replace(std::begin(filename), std::end(filename), '?', '0');
std::string next_filename_stem_matching_pattern(const std::string& filename_stem_pattern) {
const auto filename = find_last_file_matching_pattern(filename_stem_pattern + ".*");
auto filename_stem = remove_filename_extension(filename);
if( filename_stem.empty() ) {
filename_stem = filename_stem_pattern;
std::replace(std::begin(filename_stem), std::end(filename_stem), '?', '0');
} else {
filename = increment_filename_ordinal(filename);
filename_stem = increment_filename_stem_ordinal(filename_stem);
}
return filename;
return filename_stem;
}
namespace std {

View File

@ -57,7 +57,7 @@ private:
FIL f;
};
std::string next_filename_matching_pattern(const std::string& filename_pattern);
std::string next_filename_stem_matching_pattern(const std::string& filename_stem_pattern);
namespace std {
namespace filesystem {

View File

@ -81,12 +81,12 @@ void SystemStatusView::set_title(const std::string new_value) {
}
void SystemStatusView::on_camera() {
const auto filename = next_filename_matching_pattern("SCR_????.PNG");
if( filename.empty() ) {
const auto filename_stem = next_filename_stem_matching_pattern("SCR_????");
if( filename_stem.empty() ) {
return;
}
PNGWriter png { filename };
PNGWriter png { filename_stem + ".PNG" };
for(int i=0; i<320; i++) {
std::array<ColorRGB888, 240> row;