summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audiofile.cc2
-rw-r--r--src/drumgizmo.cc23
-rw-r--r--src/drumgizmo.h13
-rw-r--r--src/drumkitloader.cc46
-rw-r--r--src/drumkitloader.h5
-rw-r--r--src/instrument.cc6
6 files changed, 70 insertions, 25 deletions
diff --git a/src/audiofile.cc b/src/audiofile.cc
index 1927034..3f0bd82 100644
--- a/src/audiofile.cc
+++ b/src/audiofile.cc
@@ -82,7 +82,7 @@ void AudioFile::load()
is_loaded = true;
mutex.unlock();
- DEBUG(audiofile, "Loading of %s completed.\n", filename.c_str());
+ //DEBUG(audiofile, "Loading of %s completed.\n", filename.c_str());
}
bool AudioFile::isLoaded()
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 93426de..e8ced6a 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -39,7 +39,7 @@
#include "drumkitparser.h"
DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i)
- : oe(o), ie(i)
+ : loader(this), oe(o), ie(i)
{
loader.run(); // Start drumkit loader thread.
}
@@ -57,13 +57,12 @@ DrumGizmo::~DrumGizmo()
}
/*
- * Send a message to the engine. The engine takes over the memory.
+ * Add a message to the GUI message queue.
*/
void DrumGizmo::sendMessage(Message *msg)
{
- message_mutex.lock();
+ MutexAutolock l(message_mutex);
message_queue.push_back(msg);
- message_mutex.unlock();
}
/*
@@ -71,13 +70,25 @@ void DrumGizmo::sendMessage(Message *msg)
*/
Message *DrumGizmo::receiveMessage()
{
+ MutexAutolock l(message_mutex);
Message *msg = NULL;
- message_mutex.lock();
if(message_queue.size()) {
msg = message_queue.front();
message_queue.pop_front();
}
- message_mutex.unlock();
+ return msg;
+}
+
+/*
+ * Receive message from the engine without removing it from the queue.
+ */
+Message *DrumGizmo::peekMessage()
+{
+ MutexAutolock l(message_mutex);
+ Message *msg = NULL;
+ if(message_queue.size()) {
+ msg = message_queue.front();
+ }
return msg;
}
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 92faa3c..b7df7b9 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -71,14 +71,19 @@ public:
std::string kitfile;
/*
- * Send a message to the engine. The engine takes over the memory.
+ * Receive message from the engine. The caller takes over the memory.
*/
- void sendMessage(Message *msg);
+ Message *receiveMessage();
/*
- * Receive message from the engine. The caller takes over the memory.
+ * Receive message from the engine without removing it from the queue.
*/
- Message *receiveMessage();
+ Message *peekMessage();
+
+ /*
+ * Add a message to the GUI message queue.
+ */
+ void sendMessage(Message *msg);
private:
Mutex message_mutex;
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index 9f514d0..53af7db 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -29,9 +29,11 @@
#include <hugin.hpp>
#include "drumkitparser.h"
+#include "drumgizmo.h"
-DrumKitLoader::DrumKitLoader()
+DrumKitLoader::DrumKitLoader(DrumGizmo *dg)
{
+ drumgizmo = dg;
is_done = false;
quitit = false;
}
@@ -75,19 +77,41 @@ void DrumKitLoader::thread_main()
if(quitit) return;
- Instruments::iterator i = kit->instruments.begin();
- while(i != kit->instruments.end()) {
- Instrument *instr = *i;
+ unsigned int count = 0;
+ { // Count total number of files that need loading:
+ Instruments::iterator i = kit->instruments.begin();
+ while(i != kit->instruments.end()) {
+ Instrument *instr = *i;
- std::vector<AudioFile*>::iterator a = instr->audiofiles.begin();
- while(a != instr->audiofiles.end()) {
- // usleep(10000);
- AudioFile *af = *a;
- af->load();
- a++;
+ count += instr->audiofiles.size();
+ i++;
}
+ }
- i++;
+ { // Now actually load them:
+ unsigned int loaded = 0;
+ Instruments::iterator i = kit->instruments.begin();
+ while(i != kit->instruments.end()) {
+ Instrument *instr = *i;
+
+ std::vector<AudioFile*>::iterator a = instr->audiofiles.begin();
+ while(a != instr->audiofiles.end()) {
+ //usleep(5000);
+ AudioFile *af = *a;
+ af->load();
+ loaded++;
+
+ LoadStatus *ls = new LoadStatus();
+ ls->number_of_files = count;
+ ls->numer_of_files_loaded = loaded;
+ ls->current_file = af->filename;
+ drumgizmo->sendMessage(ls);
+
+ a++;
+ }
+
+ i++;
+ }
}
mutex.lock();
diff --git a/src/drumkitloader.h b/src/drumkitloader.h
index c308761..b9bc102 100644
--- a/src/drumkitloader.h
+++ b/src/drumkitloader.h
@@ -35,9 +35,11 @@
#include "drumkit.h"
+class DrumGizmo;
+
class DrumKitLoader : public Thread {
public:
- DrumKitLoader();
+ DrumKitLoader(DrumGizmo *drumgizmo);
~DrumKitLoader();
void loadKit(DrumKit *kit);
@@ -47,6 +49,7 @@ public:
bool isDone();
private:
+ DrumGizmo *drumgizmo;
Semaphore semaphore;
DrumKit *kit;
bool is_done;
diff --git a/src/instrument.cc b/src/instrument.cc
index b10d990..297e6c6 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -29,19 +29,21 @@
#include <stdlib.h>
#include <stdio.h>
+#include <hugin.hpp>
+
#include "sample.h"
#include "configuration.h"
Instrument::Instrument()
{
- printf("new Instrument %p\n", this);
+ DEBUG(instrument, "new %p\n", this);
mod = 1.0;
lastpos = 0;
}
Instrument::~Instrument()
{
- printf("delete Instrument %p\n", this);
+ DEBUG(instrument, "delete %p\n", this);
std::vector<AudioFile*>::iterator i = audiofiles.begin();
while(i != audiofiles.end()) {
delete *i;