summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-10-08 15:29:28 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-10-08 15:29:28 +0200
commit068bbbba9248fc11c7c852508c916579bd2621e2 (patch)
tree435e45d4e5706989c7b254b9f9bdde38d8f82127 /src
parente0d30c06949552671d95a6b75bd905d8162f72e7 (diff)
Humaniser added. Speedy strokes get lower velocity levels.
Diffstat (limited to 'src')
-rw-r--r--src/configuration.cc51
-rw-r--r--src/configuration.h40
-rw-r--r--src/drumgizmo.cc2
-rw-r--r--src/instrument.cc27
-rw-r--r--src/instrument.h5
5 files changed, 121 insertions, 4 deletions
diff --git a/src/configuration.cc b/src/configuration.cc
new file mode 100644
index 0000000..b71dfac
--- /dev/null
+++ b/src/configuration.cc
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * configuration.cc
+ *
+ * Sat Oct 8 14:37:14 CEST 2011
+ * Copyright 2011 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 "configuration.h"
+
+bool Conf::enable_velocity_modifier = true;
+float Conf::velocity_modifier_falloff = 0.5;
+float Conf::velocity_modifier_weight = 0.25;
+
+bool Conf::enable_velocity_randomiser = false;
+float Conf::velocity_randomiser_weight = 0.1;
+
+#ifdef TEST_CONFIGURATION
+//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_CONFIGURATION*/
diff --git a/src/configuration.h b/src/configuration.h
new file mode 100644
index 0000000..2690104
--- /dev/null
+++ b/src/configuration.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * configuration.h
+ *
+ * Sat Oct 8 14:37:13 CEST 2011
+ * Copyright 2011 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_CONFIGURATION_H__
+#define __DRUMGIZMO_CONFIGURATION_H__
+
+namespace Conf {
+ extern bool enable_velocity_modifier;
+ extern float velocity_modifier_falloff;
+ extern float velocity_modifier_weight;
+
+ extern bool enable_velocity_randomiser;
+ extern float velocity_randomiser_weight;
+};
+
+
+#endif/*__DRUMGIZMO_CONFIGURATION_H__*/
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index b7b2841..7da5947 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -122,7 +122,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
continue;
}
- Sample *s = i->sample(evs[e].velocity);
+ Sample *s = i->sample(evs[e].velocity, evs[e].offset + pos);
if(s == NULL) {
printf("Missing Sample.\n");
diff --git a/src/instrument.cc b/src/instrument.cc
index 1b3c31a..8cfaec7 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -30,17 +30,40 @@
#include <stdio.h>
#include "sample.h"
+#include "configuration.h"
Instrument::Instrument()
{
+ mod = 1.0;
+ lastpos = 0;
}
-Sample *Instrument::sample(level_t level)
+Sample *Instrument::sample(level_t level, size_t pos)
{
+ if(Conf::enable_velocity_randomiser) {
+ float r = (float)rand() / (float)RAND_MAX; // random number: [0;1]
+ r -= 0.5; // random number [-0.5;0.5]
+ r *= Conf::velocity_randomiser_weight * 2; // ex. random number [-0.1;0.1]
+ level += r;
+ if(level > 1.0) level = 1.0;
+ if(level < 0.0) level = 0.0;
+ }
+
+ if(Conf::enable_velocity_modifier) {
+ mod += (pos - lastpos) / (44100.0 * Conf::velocity_modifier_falloff);
+ if(mod > 1.0) mod = 1.0;
+ }
+
// printf("Find level %f\n", level);
- std::vector<Sample*> s = samples.get(level);
+ std::vector<Sample*> s = samples.get(level * mod);
if(s.size() == 0) return NULL;
size_t idx = rand()%(s.size());
+
+ if(Conf::enable_velocity_modifier) {
+ lastpos = pos;
+ mod *= Conf::velocity_modifier_weight;
+ }
+
return s[idx];
}
diff --git a/src/instrument.h b/src/instrument.h
index fb8aeac..e61d2b8 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -40,7 +40,7 @@ class Instrument {
public:
Instrument();
- Sample *sample(level_t level);
+ Sample *sample(level_t level, size_t pos);
std::string name();
std::string description();
@@ -56,6 +56,9 @@ private:
void addSample(level_t a, level_t b, Sample *s);
std::vector<Sample*> samplelist;
+
+ size_t lastpos;
+ float mod;
};
//typedef std::map< std::string, Instrument > Instruments;