mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-26 06:26:17 -05:00
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:
parent
dc8c34487f
commit
12b8a1b2a9
@ -316,13 +316,13 @@ void AnalogAudioView::on_record() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AnalogAudioView::record_start() {
|
void AnalogAudioView::record_start() {
|
||||||
const auto filename = next_filename_matching_pattern("AUD_????.S16");
|
const auto filename_stem = next_filename_stem_matching_pattern("AUD_????");
|
||||||
text_record_filename.set(filename);
|
text_record_filename.set(filename_stem);
|
||||||
if( filename.empty() ) {
|
if( filename_stem.empty() ) {
|
||||||
return;
|
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);
|
button_record.set_bitmap(&bitmap_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Text text_record_filename {
|
Text text_record_filename {
|
||||||
{ 3 * 8, 2 * 16, 12 * 8, 16 },
|
{ 3 * 8, 2 * 16, 8 * 8, 16 },
|
||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,14 +115,14 @@ void CaptureAppView::on_record() {
|
|||||||
capture_thread.reset();
|
capture_thread.reset();
|
||||||
button_record.set_bitmap(&bitmap_record);
|
button_record.set_bitmap(&bitmap_record);
|
||||||
} else {
|
} else {
|
||||||
const auto filename = next_filename_matching_pattern("BBD_????.C16");
|
const auto filename_stem = next_filename_stem_matching_pattern("BBD_????");
|
||||||
text_record_filename.set(filename);
|
text_record_filename.set(filename_stem);
|
||||||
text_record_dropped.set("");
|
text_record_dropped.set("");
|
||||||
if( filename.empty() ) {
|
if( filename_stem.empty() ) {
|
||||||
return;
|
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);
|
button_record.set_bitmap(&bitmap_stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Text text_record_filename {
|
Text text_record_filename {
|
||||||
{ 3 * 8, 2 * 16, 12 * 8, 16 },
|
{ 3 * 8, 2 * 16, 8 * 8, 16 },
|
||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,22 +94,16 @@ static std::string find_last_file_matching_pattern(const std::string& pattern) {
|
|||||||
return last_match;
|
return last_match;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string increment_filename_ordinal(const std::string& filename) {
|
static std::string remove_filename_extension(const std::string& filename) {
|
||||||
std::string result { 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();
|
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.
|
// Increment decimal number before the extension.
|
||||||
for(; it != result.rend(); ++it) {
|
for(; it != result.rend(); ++it) {
|
||||||
const auto c = *it;
|
const auto c = *it;
|
||||||
@ -128,15 +122,16 @@ static std::string increment_filename_ordinal(const std::string& filename) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string next_filename_matching_pattern(const std::string& filename_pattern) {
|
std::string next_filename_stem_matching_pattern(const std::string& filename_stem_pattern) {
|
||||||
auto filename = find_last_file_matching_pattern(filename_pattern);
|
const auto filename = find_last_file_matching_pattern(filename_stem_pattern + ".*");
|
||||||
if( filename.empty() ) {
|
auto filename_stem = remove_filename_extension(filename);
|
||||||
filename = filename_pattern;
|
if( filename_stem.empty() ) {
|
||||||
std::replace(std::begin(filename), std::end(filename), '?', '0');
|
filename_stem = filename_stem_pattern;
|
||||||
|
std::replace(std::begin(filename_stem), std::end(filename_stem), '?', '0');
|
||||||
} else {
|
} else {
|
||||||
filename = increment_filename_ordinal(filename);
|
filename_stem = increment_filename_stem_ordinal(filename_stem);
|
||||||
}
|
}
|
||||||
return filename;
|
return filename_stem;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
@ -57,7 +57,7 @@ private:
|
|||||||
FIL f;
|
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 std {
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
@ -81,12 +81,12 @@ void SystemStatusView::set_title(const std::string new_value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SystemStatusView::on_camera() {
|
void SystemStatusView::on_camera() {
|
||||||
const auto filename = next_filename_matching_pattern("SCR_????.PNG");
|
const auto filename_stem = next_filename_stem_matching_pattern("SCR_????");
|
||||||
if( filename.empty() ) {
|
if( filename_stem.empty() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PNGWriter png { filename };
|
PNGWriter png { filename_stem + ".PNG" };
|
||||||
|
|
||||||
for(int i=0; i<320; i++) {
|
for(int i=0; i<320; i++) {
|
||||||
std::array<ColorRGB888, 240> row;
|
std::array<ColorRGB888, 240> row;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user