diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2011-10-08 15:29:28 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2011-10-08 15:29:28 +0200 |
commit | 068bbbba9248fc11c7c852508c916579bd2621e2 (patch) | |
tree | 435e45d4e5706989c7b254b9f9bdde38d8f82127 | |
parent | e0d30c06949552671d95a6b75bd905d8162f72e7 (diff) |
Humaniser added. Speedy strokes get lower velocity levels.
-rw-r--r-- | drumgizmo/Makefile.am | 1 | ||||
-rw-r--r-- | lv2/Makefile.am | 17 | ||||
-rw-r--r-- | src/configuration.cc | 51 | ||||
-rw-r--r-- | src/configuration.h | 40 | ||||
-rw-r--r-- | src/drumgizmo.cc | 2 | ||||
-rw-r--r-- | src/instrument.cc | 27 | ||||
-rw-r--r-- | src/instrument.h | 5 | ||||
-rw-r--r-- | vst/Makefile | 1 |
8 files changed, 131 insertions, 13 deletions
diff --git a/drumgizmo/Makefile.am b/drumgizmo/Makefile.am index 1bdbfd4..5866fcb 100644 --- a/drumgizmo/Makefile.am +++ b/drumgizmo/Makefile.am @@ -15,6 +15,7 @@ drumgizmo_SOURCES = \ $(top_srcdir)/src/audiofile.cc \ $(top_srcdir)/src/channel.cc \ $(top_srcdir)/src/channelmixer.cc \ + $(top_srcdir)/src/configuration.cc \ $(top_srcdir)/src/drumgizmo.cc \ $(top_srcdir)/src/drumkit.cc \ $(top_srcdir)/src/drumkitparser.cc \ diff --git a/lv2/Makefile.am b/lv2/Makefile.am index da5a8a0..529b52c 100644 --- a/lv2/Makefile.am +++ b/lv2/Makefile.am @@ -2,18 +2,21 @@ if ENABLE_LV2 INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SNDFILE_CXXFLAGS) \ $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) $(LV2_CFLAGS) -lv2plugindir = $(libdir)/lv2/drumgizmo.lv2 -lv2plugin_LTLIBRARIES = drumgizmo.la -lv2plugin_DATA = manifest.ttl drumgizmo.ttl + +plugindir = $(libdir)/lv2/drumgizmo.lv2 +plugin_LTLIBRARIES = drumgizmo.la +plugin_DATA = manifest.ttl drumgizmo.ttl + EXTRA_DIST = $(lv2plugin_DATA) -drumgizmo_la_SOURCES = +drumgizmo_la_SOURCES = \ lv2.cc \ input_lv2.cc \ output_lv2.cc \ $(top_srcdir)/src/audiofile.cc \ $(top_srcdir)/src/channel.cc \ $(top_srcdir)/src/channelmixer.cc \ + $(top_srcdir)/src/configuration.cc \ $(top_srcdir)/src/drumgizmo.cc \ $(top_srcdir)/src/drumkit.cc \ $(top_srcdir)/src/drumkitparser.cc \ @@ -27,12 +30,8 @@ drumgizmo_la_SOURCES = $(top_srcdir)/src/sample.cc \ $(top_srcdir)/src/saxparser.cc \ $(top_srcdir)/src/velocity.cc - lv2_event.h \ - lv2-saverestore.h - -# $(top_srcdir)/plugingui/gui.cc drumgizmo_la_LDFLAGS = -module -avoid-version -drumgizmo_la_LIBADD = $(SNDFILE_LIBS) $(EXPAT_LIBS) $(LV2_LIBS) -lX11 +drumgizmo_la_LIBADD = $(SNDFILE_LIBS) $(EXPAT_LIBS) $(LV2_LIBS) -lX11 endif 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; diff --git a/vst/Makefile b/vst/Makefile index b6d1a10..5701259 100644 --- a/vst/Makefile +++ b/vst/Makefile @@ -10,6 +10,7 @@ DG_SRC = \ ${DG_BASE}/src/audiofile.cc \ ${DG_BASE}/src/channel.cc \ ${DG_BASE}/src/channelmixer.cc \ + ${DG_BASE}/src/configuration.cc \ ${DG_BASE}/src/drumgizmo.cc \ ${DG_BASE}/src/drumkit.cc \ ${DG_BASE}/src/drumkitparser.cc \ |