summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-04-04 21:19:58 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2013-04-04 21:19:58 +0200
commit77b3943b751bed43d230de6db322a750bfd1fc8e (patch)
treecd7d98bc8c06c660558a52f2b6b6ed73982efdf2 /src
parent0e436ebcd7faacb557ab94952765cb6bcfd7d259 (diff)
New message system. New common midi input class. Some compiler warning fixes. New ListBoxBasic class used by both LustBox and ComboBox. New embossed font.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/Makefile.am.drumgizmo1
-rw-r--r--src/audioinputengine.h2
-rw-r--r--src/audioinputenginemidi.cc14
-rw-r--r--src/audioinputenginemidi.h12
-rw-r--r--src/drumgizmo.cc116
-rw-r--r--src/drumgizmo.h30
-rw-r--r--src/drumkitloader.cc5
-rw-r--r--src/message.h22
-rw-r--r--src/midimapper.cc6
-rw-r--r--src/midimapper.h2
11 files changed, 182 insertions, 29 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 258c68d..386d373 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,7 @@ EXTRA_DIST = \
audiofile.cc \
audioinputengine.cc \
audiooutputengine.cc \
+ audioinputenginemidi.cc \
beatmapper.cc \
channel.cc \
channelmixer.cc \
diff --git a/src/Makefile.am.drumgizmo b/src/Makefile.am.drumgizmo
index 54de5e3..428d2a7 100644
--- a/src/Makefile.am.drumgizmo
+++ b/src/Makefile.am.drumgizmo
@@ -1,4 +1,5 @@
DRUMGIZMO_SOURCES = \
+ $(top_srcdir)/src/audioinputenginemidi.cc \
$(top_srcdir)/src/audiofile.cc \
$(top_srcdir)/src/channel.cc \
$(top_srcdir)/src/channelmixer.cc \
diff --git a/src/audioinputengine.h b/src/audioinputengine.h
index c2d2e24..f2b49c0 100644
--- a/src/audioinputengine.h
+++ b/src/audioinputengine.h
@@ -37,6 +37,8 @@ class AudioInputEngine {
public:
virtual ~AudioInputEngine() {}
+ virtual bool isMidiEngine() { return false; }
+
virtual bool init(Instruments &instruments) = 0;
virtual void setParm(std::string parm, std::string value) = 0;
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc
index 5986471..6aa9d45 100644
--- a/src/audioinputenginemidi.cc
+++ b/src/audioinputenginemidi.cc
@@ -26,15 +26,23 @@
*/
#include "audioinputenginemidi.h"
-void InputLV2::loadMidiMap(std::string f)
+#include "midimapparser.h"
+
+#include <hugin.hpp>
+
+void AudioInputEngineMidi::loadMidiMap(std::string f, Instruments &instruments)
{
+ DEBUG(mmap, "loadMidiMap(%s, i.size() == %d)\n", f.c_str(),
+ instruments.size());
if(f == "") return;
MidiMapParser p(f);
if(p.parse()) {/*return false;*/}
+
+ mmap.clear();
mmap.midimap = p.midimap;
- for(size_t i = 0; i < instruments->size(); i++) {
- mmap.instrmap[(*instruments)[i]->name()] = i;
+ for(size_t i = 0; i < instruments.size(); i++) {
+ mmap.instrmap[instruments[i]->name()] = i;
}
}
diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h
index e52a54f..4cae78b 100644
--- a/src/audioinputenginemidi.h
+++ b/src/audioinputenginemidi.h
@@ -29,10 +29,17 @@
#include "audioinputengine.h"
-class AudioInputEngineMidi {
+#include <string>
+
+#include "midimapper.h"
+#include "instrument.h"
+
+class AudioInputEngineMidi : public AudioInputEngine {
public:
virtual ~AudioInputEngineMidi() {}
+ bool isMidiEngine() { return true; }
+
virtual bool init(Instruments &instruments) = 0;
virtual void setParm(std::string parm, std::string value) = 0;
@@ -44,10 +51,9 @@ public:
virtual event_t *run(size_t pos, size_t len, size_t *nevents) = 0;
virtual void post() = 0;
- void loadMidiMap(std::string file);
+ void loadMidiMap(std::string file, Instruments &i);
protected:
-
MidiMapper mmap;
};
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 71346d4..219ec7b 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -37,6 +37,7 @@
#include <hugin.hpp>
#include "drumkitparser.h"
+#include "audioinputenginemidi.h"
DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i)
: loader(this), oe(o), ie(i)
@@ -59,22 +60,22 @@ DrumGizmo::~DrumGizmo()
/*
* Add a message to the GUI message queue.
*/
-void DrumGizmo::sendMessage(Message *msg)
+void DrumGizmo::sendGUIMessage(Message *msg)
{
- MutexAutolock l(message_mutex);
- message_queue.push_back(msg);
+ MutexAutolock l(gui_message_mutex);
+ gui_message_queue.push_back(msg);
}
/*
* Receive message from the engine. The caller takes over the memory.
*/
-Message *DrumGizmo::receiveMessage()
+Message *DrumGizmo::receiveGUIMessage()
{
- MutexAutolock l(message_mutex);
+ MutexAutolock l(gui_message_mutex);
Message *msg = NULL;
- if(message_queue.size()) {
- msg = message_queue.front();
- message_queue.pop_front();
+ if(gui_message_queue.size()) {
+ msg = gui_message_queue.front();
+ gui_message_queue.pop_front();
}
return msg;
}
@@ -82,12 +83,48 @@ Message *DrumGizmo::receiveMessage()
/*
* Receive message from the engine without removing it from the queue.
*/
-Message *DrumGizmo::peekMessage()
+Message *DrumGizmo::peekGUIMessage()
{
- MutexAutolock l(message_mutex);
+ MutexAutolock l(gui_message_mutex);
Message *msg = NULL;
- if(message_queue.size()) {
- msg = message_queue.front();
+ if(gui_message_queue.size()) {
+ msg = gui_message_queue.front();
+ }
+ return msg;
+}
+
+/*
+ * Add a message to the GUI message queue.
+ */
+void DrumGizmo::sendEngineMessage(Message *msg)
+{
+ MutexAutolock l(engine_message_mutex);
+ engine_message_queue.push_back(msg);
+}
+
+/*
+ * Receive message from the engine. The caller takes over the memory.
+ */
+Message *DrumGizmo::receiveEngineMessage()
+{
+ MutexAutolock l(engine_message_mutex);
+ Message *msg = NULL;
+ if(engine_message_queue.size()) {
+ msg = engine_message_queue.front();
+ engine_message_queue.pop_front();
+ }
+ return msg;
+}
+
+/*
+ * Receive message from the engine without removing it from the queue.
+ */
+Message *DrumGizmo::peekEngineMessage()
+{
+ MutexAutolock l(engine_message_mutex);
+ Message *msg = NULL;
+ if(engine_message_queue.size()) {
+ msg = engine_message_queue.front();
}
return msg;
}
@@ -99,6 +136,9 @@ std::string DrumGizmo::drumkitfile()
bool DrumGizmo::loadkit(std::string file)
{
+ if(file == this->kitfile) return 1;
+ if(file == "") return 1;
+
this->kitfile = file;
DEBUG(drumgizmo, "loadkit(%s)\n", kitfile.c_str());
@@ -111,6 +151,8 @@ bool DrumGizmo::loadkit(std::string file)
loader.loadKit(&kit);
+ DEBUG(loadkit, "loadkit: Success\n");
+
return true;
}
@@ -133,6 +175,38 @@ bool DrumGizmo::init(bool preload)
return true;
}
+void DrumGizmo::handleEngineEvents()
+{
+ // DEBUG(msg, "handle?");
+
+ Message *msg = receiveEngineMessage();
+ if(msg) {
+ DEBUG(msg, "got message.");
+ switch(msg->type()) {
+ case Message::LoadDrumKit:
+ {
+ DEBUG(msg, "got LoadDrumKitMessage message.");
+ LoadDrumKitMessage *m = (LoadDrumKitMessage*)msg;
+ loadkit(m->drumkitfile);
+ //init(true);
+ }
+ break;
+ case Message::LoadMidimap:
+ DEBUG(msg, "got LoadMidimapMessage message.");
+ if(!ie->isMidiEngine()) break;
+ {
+ AudioInputEngineMidi *aim = (AudioInputEngineMidi*)ie;
+ LoadMidimapMessage *m = (LoadMidimapMessage*)msg;
+ aim->loadMidiMap(m->midimapfile, kit.instruments);
+ }
+ break;
+ default:
+ break;
+ }
+ // delete msg;
+ }
+}
+
bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
{
#if 0
@@ -156,6 +230,9 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
}
#endif
+ // Handle engine messages, at most one in each iteration:
+ handleEngineEvents();
+
ie->pre();
oe->pre(nsamples);
@@ -418,8 +495,6 @@ bool DrumGizmo::setConfigString(std::string cfg)
return false;
}
- midimapfile = p.value("midimapfile");
-
if(p.value("enable_velocity_modifier") != "") {
Conf::enable_velocity_modifier =
p.value("enable_velocity_modifier") == "true";
@@ -447,8 +522,21 @@ bool DrumGizmo::setConfigString(std::string cfg)
std::string newkit = p.value("drumkitfile");
if(newkit != "" && drumkitfile() != newkit) {
+ /*
if(!loadkit(p.values["drumkitfile"])) return false;
init(true);
+ */
+ LoadDrumKitMessage *msg = new LoadDrumKitMessage();
+ msg->drumkitfile = newkit;
+ sendEngineMessage(msg);
+ }
+
+ std::string newmidimap = p.value("midimapfile");
+ if(midimapfile != newmidimap && newmidimap != "") {
+ midimapfile = newmidimap;
+ LoadMidimapMessage *msg = new LoadMidimapMessage();
+ msg->midimapfile = midimapfile;
+ sendEngineMessage(msg);
}
return true;
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index b7df7b9..c03fd95 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -73,21 +73,41 @@ public:
/*
* Receive message from the engine. The caller takes over the memory.
*/
- Message *receiveMessage();
+ Message *receiveGUIMessage();
/*
* Receive message from the engine without removing it from the queue.
*/
- Message *peekMessage();
+ Message *peekGUIMessage();
/*
* Add a message to the GUI message queue.
*/
- void sendMessage(Message *msg);
+ void sendEngineMessage(Message *msg);
+
+ /*
+ * Receive message from the engine. The caller takes over the memory.
+ */
+ Message *receiveEngineMessage();
+
+ /*
+ * Receive message from the engine without removing it from the queue.
+ */
+ Message *peekEngineMessage();
+
+ /*
+ * Add a message to the GUI message queue.
+ */
+ void sendGUIMessage(Message *msg);
private:
- Mutex message_mutex;
- std::list<Message *> message_queue;
+ void handleEngineEvents();
+
+ Mutex gui_message_mutex;
+ std::list<Message *> gui_message_queue;
+
+ Mutex engine_message_mutex;
+ std::list<Message *> engine_message_queue;
DrumKitLoader loader;
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index c8d1cac..ed1a187 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -74,6 +74,7 @@ void DrumKitLoader::thread_main()
DEBUG(loader, "before sem\n");
semaphore.wait();
DEBUG(loader, "after sem\n");
+ fflush(stdout);
if(quitit) return;
@@ -107,11 +108,11 @@ void DrumKitLoader::thread_main()
af->load();
loaded++;
- LoadStatus *ls = new LoadStatus();
+ LoadStatusMessage *ls = new LoadStatusMessage();
ls->number_of_files = count;
ls->numer_of_files_loaded = loaded;
ls->current_file = af->filename;
- drumgizmo->sendMessage(ls);
+ drumgizmo->sendGUIMessage(ls);
a++;
}
diff --git a/src/message.h b/src/message.h
index 050162a..c37db12 100644
--- a/src/message.h
+++ b/src/message.h
@@ -30,13 +30,19 @@
class Message {
public:
typedef enum {
- LoadStatus,
+ // Engine -> GUI Messages:
+ LoadStatus, // Signal GUI the current load status.
+
+ // GUI -> Engine, Engine -> Engine Messages:
+ LoadDrumKit, // Signal engine to load drumkit.
+ LoadMidimap, // Signal engine to load midimap.
} type_t;
+
virtual ~Message() {}
virtual type_t type() = 0;
};
-class LoadStatus : public Message {
+class LoadStatusMessage : public Message {
public:
type_t type() { return Message::LoadStatus; }
unsigned int number_of_files;
@@ -44,4 +50,16 @@ public:
std::string current_file;
};
+class LoadDrumKitMessage : public Message {
+public:
+ type_t type() { return Message::LoadDrumKit; }
+ std::string drumkitfile;
+};
+
+class LoadMidimapMessage : public Message {
+public:
+ type_t type() { return Message::LoadMidimap; }
+ std::string midimapfile;
+};
+
#endif/*__DRUMGIZMO_MESSAGE_H__*/
diff --git a/src/midimapper.cc b/src/midimapper.cc
index ca0cc21..d4ff94e 100644
--- a/src/midimapper.cc
+++ b/src/midimapper.cc
@@ -33,3 +33,9 @@ int MidiMapper::lookup(int note)
if(instrmap.find(instr) == instrmap.end()) return -1;
return instrmap[instr];
}
+
+void MidiMapper::clear()
+{
+ midimap.clear();
+ instrmap.clear();
+}
diff --git a/src/midimapper.h b/src/midimapper.h
index 74c268c..7439c4b 100644
--- a/src/midimapper.h
+++ b/src/midimapper.h
@@ -35,6 +35,8 @@ typedef std::map<std::string, int> instrmap_t;
class MidiMapper {
public:
+ void clear();
+
int lookup(int note);
instrmap_t instrmap;