LCOV - code coverage report
Current view: top level - src/audio/recorder - recorder.cpp (source / functions) Coverage Total Hit
Test: merged.info Lines: 97.6 % 41 40
Test Date: 2026-06-03 09:13:19 Functions: 100.0 % 5 5

            Line data    Source code
       1              : #include "audio/recorder/recorder.h"
       2              : #include "audio/recorder/recorder_impl.h"
       3              : #include <iostream>
       4              : #include <ctime>
       5              : #include <cstring>
       6              : #include <cstdio>
       7              : 
       8              : #ifdef _WIN32
       9              : #include <direct.h>
      10              : #define MKDIR(path) _mkdir(path)
      11              : #else
      12              : #include <sys/stat.h>
      13              : #define MKDIR(path) mkdir(path, 0755)
      14              : #endif
      15              : 
      16              : namespace Amplitron {
      17              : 
      18           81 : void mkdirs(const std::string& path) {
      19           81 :     std::string current;
      20         1271 :     for (char c : path) {
      21         1190 :         current += c;
      22         1190 :         if (c == '/' || c == '\\') {
      23           57 :             MKDIR(current.c_str());
      24           26 :         }
      25              :     }
      26           81 :     MKDIR(path.c_str());
      27           81 : }
      28              : 
      29         1254 : Recorder::Recorder() {
      30       480681 :     for (auto& v : waveform_buf_) v.store(0.0f);
      31          937 : }
      32              : 
      33         1254 : Recorder::~Recorder() {
      34          937 :     if (recording_) stop();
      35         1254 : }
      36              : 
      37            9 : std::string Recorder::get_recordings_dir() {
      38              : #if defined(__APPLE__)
      39            3 :     const char* home = std::getenv("HOME");
      40            3 :     if (home) {
      41            3 :         std::string dir = std::string(home) + "/Documents/Amplitron/recordings";
      42            3 :         mkdirs(dir);
      43            3 :         return dir;
      44            3 :     }
      45              : #elif !defined(_WIN32)
      46            3 :     const char* home = std::getenv("HOME");
      47            3 :     if (home) {
      48            3 :         std::string dir = std::string(home) + "/.local/share/amplitron/recordings";
      49            3 :         mkdirs(dir);
      50            3 :         return dir;
      51            3 :     }
      52              : #endif
      53            3 :     std::string dir = "recordings";
      54            3 :     MKDIR(dir.c_str());
      55            3 :     return dir;
      56            3 : }
      57              : 
      58            6 : std::string Recorder::generate_filename() {
      59            6 :     std::time_t now = std::time(nullptr);
      60            2 :     char buf[64];
      61            2 :     std::tm time_info;
      62              : #ifdef _WIN32
      63            2 :     localtime_s(&time_info, &now);
      64              : #else
      65            4 :     localtime_r(&now, &time_info);
      66              : #endif
      67            6 :     std::strftime(buf, sizeof(buf), "%Y%m%d_%H%M%S", &time_info);
      68           12 :     return get_recordings_dir() + "/" + std::string(buf) + ".wav";
      69            0 : }
      70              : 
      71              : } // namespace Amplitron
        

Generated by: LCOV version 2.0-1