summaryrefslogtreecommitdiff
path: root/src/drumkitloader.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-04-16 13:23:11 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-04-16 13:23:11 +0200
commit35e804b984c28131fe13d229c5a0867762c6e8cf (patch)
tree200a8c3029e38fbf0f33318faec05c4f9f8e71c3 /src/drumkitloader.cc
parentc7577fa4ecf6f9858483c5d8b4a46e7caa2b376d (diff)
Some DrumKitLoader refactoring.
Diffstat (limited to 'src/drumkitloader.cc')
-rw-r--r--src/drumkitloader.cc86
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);
}