SpectMorph
sminstenccache.hh
1 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html
2 
3 #ifndef SPECTMORPH_INSTENCCACHE_HH
4 #define SPECTMORPH_INSTENCCACHE_HH
5 
6 #include "smwavdata.hh"
7 #include "smencoder.hh"
8 #include "sminstrument.hh"
9 
10 #include <mutex>
11 #include <regex>
12 
13 namespace SpectMorph
14 {
15 
17 {
18  struct CacheData
19  {
20  std::string version;
21  std::vector<unsigned char> data;
22  uint64 read_stamp = 0;
23 
24  CacheData();
25  ~CacheData();
26  };
27 
28  std::map<std::string, CacheData> cache;
29  std::mutex cache_mutex;
30  const std::regex cache_file_re;
31  uint64 cache_read_stamp = 0;
32 
33  void cache_save_L (const std::string& key);
34  void cache_try_load_L (const std::string& key, const std::string& need_version);
35  Audio *cache_lookup (const std::string& cache_key, const std::string& version);
36  void cache_add (const std::string& cache_key, const std::string& version, const Audio *audio);
37 
38  void delete_old_files();
39  void delete_old_memory_L();
40 
41 public:
42  class Group
43  {
44  public:
45  std::string id;
46  };
47 
48  Audio *encode (Group *group, const WavData& wav_data, const std::string& wav_data_hash,
49  int midi_note, int iclipstart, int iclipend, Instrument::EncoderConfig& cfg,
50  const std::function<bool()>& kill_function);
51  void clear();
52  Group *create_group();
53 
54  InstEncCache();
55 
56  static InstEncCache *the(); // Singleton
57 };
58 
59 }
60 
61 #endif
Audio sample containing many blocks.
Definition: smaudio.hh:80
Definition: sminstenccache.hh:43
Definition: sminstenccache.hh:17
Definition: smwavdata.hh:17
Definition: sminstrument.hh:106