/[svn]/linuxsampler/trunk/src/engines/sfz/sfz.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sfz/sfz.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4015 by schoenebeck, Mon Jan 3 15:10:25 2022 UTC revision 4016 by schoenebeck, Mon Jan 3 15:36:02 2022 UTC
# Line 28  Line 28 
28  #include <cctype>  #include <cctype>
29  #include <cstdio>  #include <cstdio>
30  #include <cstring>  #include <cstring>
31    #include <sys/stat.h>
32    
33  #include "../../common/File.h"  #include "../../common/File.h"
34  #include "../../common/Path.h"  #include "../../common/Path.h"
# Line 1103  namespace sfz Line 1104  namespace sfz
1104          std::string line;          std::string line;
1105          currentLine = 0;          currentLine = 0;
1106    
1107            // remember latest modification time of file
1108            checkFileModified(file);
1109    
1110          while (std::getline(fs, line))          while (std::getline(fs, line))
1111          {          {
1112              currentLine++;              currentLine++;
# Line 1292  namespace sfz Line 1296  namespace sfz
1296          }          }
1297      }      }
1298    
1299        optional<File::Time> File::getModTimeOfFile(std::string filename) {
1300            struct stat st;
1301    
1302            if (stat(filename.c_str(), &st))
1303                return optional<File::Time>::nothing;
1304    
1305            return (Time) {
1306                #if defined(WIN32)
1307                .sec = (intmax_t) st.st_mtime,
1308                .nsec = (uint32_t) 0
1309                #elif defined(__APPLE__)
1310                .sec = (intmax_t) st.st_mtimespec.tv_sec,
1311                .nsec = (uint32_t) st.st_mtimespec.tv_nsec
1312                #else
1313                .sec = (intmax_t) st.st_mtim.tv_sec,
1314                .nsec = (uint32_t) st.st_mtim.tv_nsec
1315                #endif
1316            };
1317        }
1318    
1319        bool File::checkFileModified(std::string filename) {
1320            if (filename.empty()) {
1321                bool res = false;
1322                for (const auto& mod_time : mod_times) {
1323                    res |= checkFileModified(mod_time.first);
1324                }
1325                return res;
1326            }
1327            optional<Time> mod_time = getModTimeOfFile(filename);
1328            if (!mod_time) return false;
1329            Time& prevTime = mod_times[filename];
1330            const bool res = *mod_time != prevTime;
1331            prevTime = *mod_time; // remember changed mtime
1332            return res;
1333        }
1334    
1335      File::~File()      File::~File()
1336      {      {
1337          for (int i = 0; i < _current_containers.size(); i++)          for (int i = 0; i < _current_containers.size(); i++)

Legend:
Removed from v.4015  
changed lines
  Added in v.4016

  ViewVC Help
Powered by ViewVC