summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-08-08 22:28:31 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-08-08 22:28:31 +0200
commit4920ff67f81b9f0c92ec8330136e6f1e949b040f (patch)
tree3f2c5ec1b7e8012df348733cc7924c4ff8579b96
parent0829acfd11e529503ccfdff296d5e87bff7ec26f (diff)
Missing midimap changes
-rw-r--r--drumgizmo/input/midifile/Makefile.am10
-rw-r--r--drumgizmo/input/midifile/midifile.cc28
-rw-r--r--src/saxparser.h5
3 files changed, 29 insertions, 14 deletions
diff --git a/drumgizmo/input/midifile/Makefile.am b/drumgizmo/input/midifile/Makefile.am
index 30a2db4..b5af68e 100644
--- a/drumgizmo/input/midifile/Makefile.am
+++ b/drumgizmo/input/midifile/Makefile.am
@@ -1,7 +1,10 @@
midifilesources = \
midifile.cc \
- midimap.cc
+ $(top_srcdir)/src/midimapper.cc \
+ $(top_srcdir)/src/midimapparser.cc \
+ $(top_srcdir)/src/saxparser.cc
+
if HAVE_INPUT_MIDIFILE
@@ -21,7 +24,8 @@ lib_LTLIBRARIES = $(midifileltlibs)
libdir = $(INPUT_PLUGIN_DIR)
-INCLUDES = -I$(top_srcdir)/include $(SMF_CFLAGS)
-libmidifile_la_LDFLAGS = $(SMF_LIBS)
+INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SMF_CFLAGS) \
+ $(EXPAT_CFLAGS)
+libmidifile_la_LDFLAGS = $(SMF_LIBS) $(EXPAT_LIBS)
libmidifile_la_LIBADD =
libmidifile_la_SOURCES = $(midifilebuildsources)
diff --git a/drumgizmo/input/midifile/midifile.cc b/drumgizmo/input/midifile/midifile.cc
index 7b17028..b2c9ba5 100644
--- a/drumgizmo/input/midifile/midifile.cc
+++ b/drumgizmo/input/midifile/midifile.cc
@@ -31,7 +31,8 @@
#include <smf.h>
-#include "midimap.h"
+#include <midimapper.h>
+#include <midimapparser.h>
#define NOTE_ON 0x90
@@ -55,7 +56,7 @@ private:
smf_t *smf;
smf_event_t *cur_event;
- MidiMap mmap;
+ MidiMapper mmap;
// Parameters
std::string filename;
@@ -78,7 +79,13 @@ bool MidiFile::init(int instruments, char *inames[])
{
smf = smf_load(filename.c_str());
- mmap.load(midimapfile);
+ MidiMapParser p(midimapfile);
+ if(p.parse()) return false;
+ mmap.midimap = p.midimap;
+
+ for(int i = 0; i < instruments; i++) {
+ mmap.instrmap[inames[i]] = i;
+ }
return true;
}
@@ -132,13 +139,16 @@ event_t *MidiFile::run(size_t pos, size_t len, size_t *nevents)
printf("evpos: %d, sec: %f, pos: %d, len: %d, max_time: %f\n",
evpos, cur_event->time_seconds, pos, len, cur_max_time);
*/
- evs[nevs].instrument = mmap.lookup(key);
- evs[nevs].velocity = velocity / 127.0;
+ int i = mmap.lookup(key);
+ if(i != -1) {
+ evs[nevs].instrument = i;
+ evs[nevs].velocity = velocity / 127.0;
- nevs++;
- if(nevs > 999) {
- printf("PANIC!\n");
- break;
+ nevs++;
+ if(nevs > 999) {
+ printf("PANIC!\n");
+ break;
+ }
}
}
}
diff --git a/src/saxparser.h b/src/saxparser.h
index 8415b6b..c3700bf 100644
--- a/src/saxparser.h
+++ b/src/saxparser.h
@@ -31,6 +31,8 @@
#include <map>
#include <expat.h>
+typedef std::map< std::string, std::string> attr_t;
+
class SAXParser {
public:
SAXParser();
@@ -39,8 +41,7 @@ public:
int parse();
virtual void characterData(std::string &data) {}
- virtual void startTag(std::string name,
- std::map< std::string, std::string> attributes) {}
+ virtual void startTag(std::string name, attr_t attr) {}
virtual void endTag(std::string name) {}
virtual void parseError(char *buf, size_t len, std::string error, int lineno);