diff options
Diffstat (limited to 'src/drumkitloader.cc')
-rw-r--r-- | src/drumkitloader.cc | 86 |
1 files changed, 40 insertions, 46 deletions
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index d785bc4..3a0e096 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -26,6 +26,8 @@ */ #include "drumkitloader.h" +#include <iostream> + #include <hugin.hpp> #include "drumkitparser.h" @@ -34,6 +36,7 @@ DrumKitLoader::DrumKitLoader(Settings& settings) : framesize(0) , settings(settings) + , getter(settings) { run(); run_semaphore.wait(); // Wait for the thread to actually start. @@ -55,7 +58,7 @@ DrumKitLoader::~DrumKitLoader() void DrumKitLoader::stop() { { - MutexAutolock l(mutex); + std::lock_guard<std::mutex> guard(mutex); load_queue.clear(); } @@ -66,68 +69,48 @@ void DrumKitLoader::stop() void DrumKitLoader::skip() { - MutexAutolock l(mutex); + std::lock_guard<std::mutex> guard(mutex); load_queue.clear(); } void DrumKitLoader::setFrameSize(size_t framesize) { - DEBUG(loader, "%s pre\n", __PRETTY_FUNCTION__); - - { - MutexAutolock l(mutex); - this->framesize = framesize; - framesize_semaphore.post(); // Signal that the framesize has been set. - } - - DEBUG(loader, "%s post\n", __PRETTY_FUNCTION__); + std::lock_guard<std::mutex> guard(mutex); + this->framesize = framesize; + framesize_semaphore.post(); // Signal that the framesize has been set. } bool DrumKitLoader::isDone() { - MutexAutolock l(mutex); + std::lock_guard<std::mutex> guard(mutex); return load_queue.size() == 0; } void DrumKitLoader::loadKit(DrumKit *kit) { - MutexAutolock l(mutex); + std::lock_guard<std::mutex> guard(mutex); DEBUG(loader, "Create AudioFile queue from DrumKit\n"); - total_num_audiofiles = 0;// For UI Progress Messages - - { // Count total number of files that need loading: - Instruments::iterator i = kit->instruments.begin(); - while(i != kit->instruments.end()) - { - Instrument *instr = *i; - total_num_audiofiles += instr->audiofiles.size(); - ++i; - } - } + std::size_t total_num_audiofiles = 0;// For UI Progress Messages - fraction = total_num_audiofiles / 200; - if(fraction == 0) + // Count total number of files that need loading: + for(auto instr : kit->instruments) { - fraction = 1; + total_num_audiofiles += instr->audiofiles.size(); } - { // Now actually queue them for loading: - Instruments::iterator i = kit->instruments.begin(); - while(i != kit->instruments.end()) - { - Instrument *instr = *i; + settings.number_of_files.store(total_num_audiofiles); - std::vector<AudioFile*>::iterator af = instr->audiofiles.begin(); - while(af != instr->audiofiles.end()) - { - AudioFile *audiofile = *af; - load_queue.push_back(audiofile); - af++; - } - - ++i; + // Now actually queue them for loading: + for(auto instr : kit->instruments) + { + std::vector<AudioFile*>::iterator af = instr->audiofiles.begin(); + while(af != instr->audiofiles.end()) + { + AudioFile *audiofile = *af; + load_queue.push_back(audiofile); + af++; } } @@ -151,23 +134,35 @@ void DrumKitLoader::thread_main() { size_t size; { - MutexAutolock l(mutex); + std::lock_guard<std::mutex> guard(mutex); size = load_queue.size(); } // Only sleep if queue is empty. if(size == 0) { - semaphore.wait(); + semaphore.wait(std::chrono::milliseconds(1000)); + } + + if(getter.drumkit_file.hasChanged()) + { + //std::cout << "RELOAD DRUMKIT!" << std::endl; + } + + if(getter.midimap_file.hasChanged()) + { + //std::cout << "RELOAD MIDIMAP!" << std::endl; } std::string filename; { - MutexAutolock l(mutex); + std::lock_guard<std::mutex> guard(mutex); + if(load_queue.size() == 0) { continue; } + AudioFile *audiofile = load_queue.front(); load_queue.pop_front(); filename = audiofile->filename; @@ -185,10 +180,9 @@ void DrumKitLoader::thread_main() ++loaded; - settings.number_of_files.store(total_num_audiofiles); settings.number_of_files_loaded.store(loaded); - if(total_num_audiofiles == loaded) + if(settings.number_of_files.load() == loaded) { settings.drumkit_load_status.store(LoadStatus::Done); } |