MCPcopy Create free account
hub / github.com/cjcliffe/CubicSDR / getOutputFileName

Method getOutputFileName

src/audio/AudioFileWAV.cpp:185–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185std::string AudioFileWAV::getOutputFileName() {
186
187 std::string recPath = wxGetApp().getConfig()->getRecordingPath();
188
189 // Strip any invalid characters from the name
190 std::string stripChars("<>:\"/\\|?*");
191 std::string filenameBaseSafe = filenameBase;
192
193 for (size_t i = 0, iMax = filenameBaseSafe.length(); i < iMax; i++) {
194 if (stripChars.find(filenameBaseSafe[i]) != std::string::npos) {
195 filenameBaseSafe.replace(i, 1, "_");
196 }
197 }
198
199 // Create output file name
200 std::stringstream outputFileName;
201 outputFileName << recPath << filePathSeparator << filenameBaseSafe;
202
203 //customized part: append a sequence number.
204 if (currentSequenceNumber > 0) {
205 outputFileName << "_" << std::setfill('0') << std::setw(3) << currentSequenceNumber;
206 }
207
208 int idx = 0;
209
210 // If the file exists; then find the next non-existing file in sequence.
211 std::string fileNameCandidate = outputFileName.str();
212
213 while (FILE *file = fopen((fileNameCandidate + "." + getExtension()).c_str(), "r")) {
214 fclose(file);
215 fileNameCandidate = outputFileName.str() + "-" + std::to_string(++idx);
216 }
217
218 return fileNameCandidate + "." + getExtension();
219}

Callers

nothing calls this directly

Calls 5

getRecordingPathMethod · 0.80
getConfigMethod · 0.80
findMethod · 0.80
c_strMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected