summaryrefslogtreecommitdiff
path: root/drumgizmo/input/test
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-07-10 09:32:38 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2015-07-10 09:32:38 +0200
commita73382d1685fa864a3d4a46be486caf028523dae (patch)
treefc37a435277a0eb20bc6bda66843396a5b30dbed /drumgizmo/input/test
parent79e1c5eb90fb754f6cd40f5e32d9a1b7284c9717 (diff)
Make test input module work in a more logical way.
Diffstat (limited to 'drumgizmo/input/test')
-rw-r--r--drumgizmo/input/test/test.cc48
1 files changed, 33 insertions, 15 deletions
diff --git a/drumgizmo/input/test/test.cc b/drumgizmo/input/test/test.cc
index b7b4a7d..225a7a2 100644
--- a/drumgizmo/input/test/test.cc
+++ b/drumgizmo/input/test/test.cc
@@ -31,7 +31,11 @@
class Test {
public:
- Test() { p = 0.1; instr = -1; len = -1; }
+ Test()
+ : p(0.1)
+ , instr(-1)
+ {}
+
~Test() {}
bool init(int instruments, char *inames[]);
@@ -48,11 +52,12 @@ public:
private:
float p;
int instr;
- int len;
+ int num_instruments;
};
bool Test::init(int instruments, char *inames[])
{
+ num_instruments = instruments;
return true;
}
@@ -60,7 +65,6 @@ 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 == "len") len = atoi(value.c_str());
}
bool Test::start()
@@ -76,23 +80,37 @@ void Test::pre()
{
}
+#define BUFFER_MAX 1000
event_t *Test::run(size_t pos, size_t nsamples, size_t *nevents)
{
- if((float)rand() / (float)RAND_MAX > p) {
- *nevents = 0;
- return NULL;
- }
+ *nevents = 0;
+ 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;
+ }
+
+ evs[*nevents].type = TYPE_ONSET;
- *nevents = 1;
- event_t *evs = (event_t *)malloc(sizeof(event_t));
- evs[0].type = TYPE_ONSET;
- if(len != -1 && (int)pos > len * 44100) evs[0].type = TYPE_STOP;
+ if(instr != -1) {
+ // Use specified instrument
+ evs[*nevents].instrument = instr;
+ } else {
+ // Use random instrument
+ evs[*nevents].instrument = rand() % num_instruments;
+ }
- if(instr != -1) evs[0].instrument = instr;
- else evs[0].instrument = rand() % 32;
+ evs[*nevents].velocity = (float)rand()/(float)RAND_MAX;
+ evs[*nevents].offset = nsamples?rand()%nsamples:0;
+
+ (*nevents)++;
+
+ if(*nevents == BUFFER_MAX) {
+ break;
+ }
+ }
- evs[0].velocity = (float)rand()/(float)RAND_MAX;
- evs[0].offset = nsamples?rand()%nsamples:0;
return evs;
}