From b06eaaff85cb086829a58d152e1ba7d3206fc368 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 19 Jul 2015 14:03:09 +0200 Subject: Added new nth argument to test input module which plays a note each nth sample. Overrides/disables p argument. --- drumgizmo/input/test/test.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'drumgizmo/input') diff --git a/drumgizmo/input/test/test.cc b/drumgizmo/input/test/test.cc index 225a7a2..6032f02 100644 --- a/drumgizmo/input/test/test.cc +++ b/drumgizmo/input/test/test.cc @@ -34,6 +34,8 @@ public: Test() : p(0.1) , instr(-1) + , nth(-1) + , nth_counter(0) {} ~Test() {} @@ -52,6 +54,8 @@ public: private: float p; int instr; + int nth; + int nth_counter; int num_instruments; }; @@ -65,6 +69,7 @@ void Test::setParm(std::string parm, std::string value) { if(parm == "p") p = atof(value.c_str()); if(parm == "instr") instr = atoi(value.c_str()); + if(parm == "nth") nth = atoi(value.c_str()); } bool Test::start() @@ -87,8 +92,17 @@ event_t *Test::run(size_t pos, size_t nsamples, size_t *nevents) event_t *evs = (event_t *)malloc(sizeof(event_t) * BUFFER_MAX); for(size_t i = 0; i < nsamples; ++i) { - if((float)rand() / (float)RAND_MAX > p) { - continue; + + if(nth != -1) { + if(nth_counter < nth) { + ++nth_counter; + continue; + } + nth_counter = 0; + } else { + if((float)rand() / (float)RAND_MAX > p) { + continue; + } } evs[*nevents].type = TYPE_ONSET; -- cgit v1.2.3