summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-22 22:42:05 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-22 22:42:05 +0100
commit47e1f28f1fe9fecf969d63f059b8ec8c0184605e (patch)
tree47ac2c6a2256b75601fa7077c994cdbfbeadc62a /src
parent70cc80a11a44c73c3cf548c7cedf2a520a025fb6 (diff)
Added Engine->Messageing system. Implemented LoadStatus Message. Added ProgressBar widget. Made FileBrowser chdir to old value (needs further fixing). More printf->hugin ports.
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;