summaryrefslogtreecommitdiff
path: root/drumgizmo
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-07-10 09:32:38 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:30:25 +0100
commit939515986c20c32dbebc8a95ebd10b5f192877b9 (patch)
treec6591ce865b5a015f23b07bbae953fd31b73330a /drumgizmo
parente9f7a6cf9ad65526d71bddbf71f4c53fe5451001 (diff)
Make test input module work in a more logical way.
Diffstat (limited to 'drumgizmo')
-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;
}