summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-05-16 08:35:39 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2015-05-16 08:35:39 +0200
commit0adc05286d97536637d01ed0a295d45f7bb60c1d (patch)
tree7f06e82a515d4ab47f5c944eaec98c2b43b8c146 /src
parentc91ae2624f3d3c003c6b2065f3cc128b1b039801 (diff)
parentceda77eb38f0b0824f03348f5291e3a42d8f7306 (diff)
Merge remote-tracking branch 'origin' into diskstreaming
Conflicts: src/Makefile.am.drumgizmo src/drumgizmo.h
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am.drumgizmo1
-rw-r--r--src/audioinputenginemidi.cc30
-rw-r--r--src/audioinputenginemidi.h4
-rw-r--r--src/configfile.cc215
-rw-r--r--src/configfile.h56
-rw-r--r--src/drumgizmo.h3
-rw-r--r--src/drumkitparser.cc14
-rw-r--r--src/drumkitparser.h3
-rw-r--r--src/midimapparser.cc17
-rw-r--r--src/powerlist.cc8
10 files changed, 312 insertions, 39 deletions
diff --git a/src/Makefile.am.drumgizmo b/src/Makefile.am.drumgizmo
index d8be9fc..ae50497 100644
--- a/src/Makefile.am.drumgizmo
+++ b/src/Makefile.am.drumgizmo
@@ -5,6 +5,7 @@ DRUMGIZMO_SOURCES = \
$(top_srcdir)/src/channelmixer.cc \
$(top_srcdir)/src/chresampler.cc \
$(top_srcdir)/src/cachemanager.cc \
+ $(top_srcdir)/src/configfile.cc \
$(top_srcdir)/src/configuration.cc \
$(top_srcdir)/src/configparser.cc \
$(top_srcdir)/src/drumgizmo.cc \
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc
index 82cafbf..5494462 100644
--- a/src/audioinputenginemidi.cc
+++ b/src/audioinputenginemidi.cc
@@ -28,15 +28,24 @@
#include "midimapparser.h"
+#include "drumgizmo.h"
+
#include <hugin.hpp>
AudioInputEngineMidi::AudioInputEngineMidi()
+ : refs(REFSFILE)
{
+ refs.load();
is_valid = false;
}
-bool AudioInputEngineMidi::loadMidiMap(std::string f, Instruments &instruments)
+bool AudioInputEngineMidi::loadMidiMap(std::string _f, Instruments &instruments)
{
+ std::string f = _f;
+ if(_f.size() > 1 && _f[0] == '@') {
+ f = refs.getValue(_f.substr(1));
+ }
+
file = "";
is_valid = false;
@@ -57,7 +66,7 @@ bool AudioInputEngineMidi::loadMidiMap(std::string f, Instruments &instruments)
mmap.instrmap[instruments[i]->name()] = i;
}
- file = f;
+ file = _f;
is_valid = true;
return true;
@@ -72,20 +81,3 @@ bool AudioInputEngineMidi::isValid()
{
return is_valid;
}
-
-#ifdef TEST_AUDIOINPUTENGINEMIDI
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
-
-TEST_END;
-
-#endif/*TEST_AUDIOINPUTENGINEMIDI*/
diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h
index b01fef0..0868730 100644
--- a/src/audioinputenginemidi.h
+++ b/src/audioinputenginemidi.h
@@ -34,6 +34,8 @@
#include "midimapper.h"
#include "instrument.h"
+#include "configfile.h"
+
class AudioInputEngineMidi : public AudioInputEngine {
public:
AudioInputEngineMidi();
@@ -62,6 +64,8 @@ protected:
MidiMapper mmap;
std::string file;
bool is_valid;
+
+ ConfigFile refs;
};
#endif/*__DRUMGIZMO_AUDIOINPUTENGINEMIDI_H__*/
diff --git a/src/configfile.cc b/src/configfile.cc
new file mode 100644
index 0000000..bb7155f
--- /dev/null
+++ b/src/configfile.cc
@@ -0,0 +1,215 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * configfile.cc
+ *
+ * Thu May 14 14:51:39 CEST 2015
+ * Copyright 2015 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "configfile.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef WIN32
+#include <direct.h>
+#include <windows.h>
+#include <Shlobj.h>
+#include <Shlwapi.h>
+#else
+#endif
+
+#include <hugin.hpp>
+
+#ifdef WIN32
+ #define SEP "\\"
+ #define CONFIGDIRNAME ".drumgizmo"
+#else
+ #define SEP "/"
+ #define CONFIGDIRNAME ".drumgizmo"
+#endif
+
+/**
+ * Return the path containing the config files.
+ */
+static std::string configPath()
+{
+#ifdef WIN32
+ std::string configpath;
+ TCHAR szPath[256];
+ if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
+ NULL, 0, szPath))) {
+ configpath = szPath;
+ }
+#else
+ std::string configpath = strdup(getenv("HOME"));
+#endif
+ configpath += SEP;
+ configpath += CONFIGDIRNAME;
+
+ return configpath;
+}
+
+/**
+ * Calling this makes sure that the config path exists
+ */
+static bool createConfigPath()
+{
+ std::string configpath = configPath();
+
+ struct stat st;
+ if(stat(configpath.c_str(), &st) == 0) {
+ DEBUG(configfile, "No configuration exists, creating directory '%s'\n",
+ configpath.c_str());
+#ifdef WIN32
+ if(mkdir(configpath.c_str()) < 0) {
+#else
+ if(mkdir(configpath.c_str(), 0755) < 0) {
+#endif
+ DEBUG(pluginconfig, "Could not create config directory\n");
+ }
+
+ return false;
+ }
+
+ return true;
+}
+
+ConfigFile::ConfigFile(std::string filename)
+ : filename(filename)
+ , fp(NULL)
+{
+}
+
+ConfigFile::~ConfigFile()
+{
+}
+
+void ConfigFile::load()
+{
+ DEBUG(pluginconfig, "Loading config file...\n");
+ if(!open("r")) return;
+
+ values.clear();
+
+ std::string line;
+ while(true) {
+ line = readLine();
+
+ if(line == "") break;
+
+ if(line[line.size() - 1] == '\n') {
+ line = line.substr(0, line.size() - 1); // strip ending newline.
+ }
+
+ std::size_t colon = line.find(':');
+
+ if(colon == std::string::npos) break; // malformed line
+
+ std::string key = line.substr(0, colon);
+ std::string value = line.substr(colon + 1);
+
+ printf("key['%s'] value['%s']\n", key.c_str(), value.c_str());
+
+ if(key != "") {
+ values[key] = value;
+ }
+ }
+
+ close();
+}
+
+void ConfigFile::save()
+{
+ DEBUG(pluginconfig, "Saving configuration...\n");
+
+ createConfigPath();
+
+ if(!open("w")) return;
+
+ std::map<std::string, std::string>::iterator v = values.begin();
+ for(; v != values.end(); ++v) {
+ fprintf(fp, "%s:%s\n", v->first.c_str(), v->second.c_str());
+ }
+
+ close();
+}
+
+std::string ConfigFile::getValue(const std::string& key)
+{
+ if(values.find(key) != values.end()) {
+ return values[key];
+ }
+
+ return "";
+}
+
+void ConfigFile::setValue(const std::string& key, const std::string& value)
+{
+ values[key] = value;
+}
+
+bool ConfigFile::open(std::string mode)
+{
+ if(fp) close();
+
+ std::string configpath = configPath();
+
+ std::string configfile = configpath;
+ configfile += SEP;
+ configfile += filename;
+
+ DEBUG(pluginconfig, "Opening config file '%s'\n", configfile.c_str());
+ fp = fopen(configfile.c_str(), mode.c_str());
+
+ if(!fp) return false;
+
+ return true;
+}
+
+void ConfigFile::close()
+{
+ fclose(fp);
+ fp = NULL;
+}
+
+std::string ConfigFile::readLine()
+{
+ if(!fp) return "";
+
+ std::string line;
+
+ char buf[1024];
+ while(!feof(fp)) {
+ char *s = fgets(buf, sizeof(buf), fp);
+ if(s) {
+ line += buf;
+ if(buf[strlen(buf) - 1] == '\n') break;
+ }
+ }
+
+ return line;
+}
diff --git a/src/configfile.h b/src/configfile.h
new file mode 100644
index 0000000..21a6b88
--- /dev/null
+++ b/src/configfile.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * configfile.h
+ *
+ * Thu May 14 14:51:38 CEST 2015
+ * Copyright 2015 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_CONFIGFILE_H__
+#define __DRUMGIZMO_CONFIGFILE_H__
+
+#include <string>
+#include <map>
+#include <stdio.h>
+
+class ConfigFile {
+public:
+ ConfigFile(std::string filename);
+ virtual ~ConfigFile();
+
+ virtual void load();
+ virtual void save();
+
+ virtual std::string getValue(const std::string& key);
+ virtual void setValue(const std::string& key, const std::string& value);
+
+protected:
+ std::map<std::string, std::string> values;
+ std::string filename;
+
+ bool open(std::string mode);
+ void close();
+ std::string readLine();
+
+ FILE* fp;
+};
+
+#endif/*__DRUMGIZMO_CONFIGFILE_H__*/
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index b6711b4..a8f007a 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -48,7 +48,10 @@
#include "chresampler.h"
+#include "configfile.h"
+
#define MAX_NUM_CHANNELS 64
+#define REFSFILE "refs.conf"
class DrumGizmo : public MessageReceiver {
public:
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index 2c21c52..00232b2 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -32,10 +32,20 @@
#include "instrumentparser.h"
#include "path.h"
+#include "drumgizmo.h"
-DrumKitParser::DrumKitParser(const std::string &kitfile, DrumKit &k)
+DrumKitParser::DrumKitParser(const std::string &file, DrumKit &k)
: kit(k)
+ , refs(REFSFILE)
{
+ refs.load();
+
+ std::string kitfile = file;
+
+ if(file.size() > 1 && file[0] == '@') {
+ kitfile = refs.getValue(file.substr(1));
+ }
+
// instr = NULL;
path = getPath(kitfile);
@@ -45,7 +55,7 @@ DrumKitParser::DrumKitParser(const std::string &kitfile, DrumKit &k)
if(!fd) return;
- kit._file = kitfile;
+ kit._file = file;
}
DrumKitParser::~DrumKitParser()
diff --git a/src/drumkitparser.h b/src/drumkitparser.h
index 907b09d..6311609 100644
--- a/src/drumkitparser.h
+++ b/src/drumkitparser.h
@@ -29,6 +29,7 @@
#include "saxparser.h"
#include "drumkit.h"
+#include "configfile.h"
class DrumKitParser : public SAXParser {
public:
@@ -52,6 +53,8 @@ private:
std::string instr_file;
std::string instr_name;
std::string instr_group;
+
+ ConfigFile refs;
};
#endif/*__DRUMGIZMO_DRUMKITPARSER_H__*/
diff --git a/src/midimapparser.cc b/src/midimapparser.cc
index 07210a5..9d30a05 100644
--- a/src/midimapparser.cc
+++ b/src/midimapparser.cc
@@ -50,20 +50,3 @@ int MidiMapParser::readData(char *data, size_t size)
if(!fd) return -1;
return fread(data, 1, size, fd);
}
-
-#ifdef TEST_MIDIMAPPARSER
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
-
-TEST_END;
-
-#endif/*TEST_MIDIMAPPARSER*/
diff --git a/src/powerlist.cc b/src/powerlist.cc
index 6fc77ad..4248b30 100644
--- a/src/powerlist.cc
+++ b/src/powerlist.cc
@@ -27,11 +27,17 @@
#include "powerlist.h"
#include <stdlib.h>
-#include <math.h>
+
#include <string.h>
#include <hugin.hpp>
+// M_PI is not defined in math.h if __STRICT_ANSI__ is defined.
+#ifdef __STRICT_ANSI__
+#undef __STRICT_ANSI__
+#endif
+#include <math.h>
+
/**
* Minimum sample set size.
* Smaller means wider 'velocity groups'.