summaryrefslogtreecommitdiff
path: root/src
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
parentc7577fa4ecf6f9858483c5d8b4a46e7caa2b376d (diff)
Some DrumKitLoader refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/drumkitloader.cc86
-rw-r--r--src/drumkitloader.h12
-rw-r--r--src/settings.h12
3 files changed, 52 insertions, 58 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);
}
diff --git a/src/drumkitloader.h b/src/drumkitloader.h
index 2410074..3fd7ec1 100644
--- a/src/drumkitloader.h
+++ b/src/drumkitloader.h
@@ -28,10 +28,11 @@
#include <string>
#include <list>
+#include <mutex>
+#include "mutex.h"
#include "thread.h"
#include "semaphore.h"
-#include "mutex.h"
#include "drumkit.h"
#include "settings.h"
@@ -76,12 +77,11 @@ protected:
Semaphore run_semaphore;
Semaphore semaphore;
Semaphore framesize_semaphore;
- Mutex mutex;
+ std::mutex mutex;
volatile bool running{false};
std::list<AudioFile*> load_queue;
- size_t total_num_audiofiles{0};
- size_t fraction{1};
- size_t loaded{0};
- size_t framesize{0};
+ std::size_t loaded{0};
+ std::size_t framesize{0};
Settings& settings;
+ SettingsGetter getter;
};
diff --git a/src/settings.h b/src/settings.h
index c79e4e5..6b4e882 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -61,8 +61,8 @@ struct Settings
Atomic<bool> enable_resampling{true};
- Atomic<int> number_of_files;
- Atomic<int> number_of_files_loaded;
+ Atomic<std::size_t> number_of_files;
+ Atomic<std::size_t> number_of_files_loaded;
Atomic<std::string> current_file;
};
@@ -86,8 +86,8 @@ struct SettingsGetter
SettingRef<bool> enable_resampling;
- SettingRef<int> number_of_files;
- SettingRef<int> number_of_files_loaded;
+ SettingRef<std::size_t> number_of_files;
+ SettingRef<std::size_t> number_of_files_loaded;
SettingRef<std::string> current_file;
SettingsGetter(Settings& settings)
@@ -130,8 +130,8 @@ public:
Notifier<bool> enable_resampling;
- Notifier<int> number_of_files;
- Notifier<int> number_of_files_loaded;
+ Notifier<std::size_t> number_of_files;
+ Notifier<std::size_t> number_of_files_loaded;
Notifier<std::string> current_file;
void evaluate()