summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audioinputengine.h3
-rw-r--r--src/audioinputenginemidi.h2
-rw-r--r--src/drumgizmo.cc24
-rw-r--r--src/drumgizmo.h2
4 files changed, 18 insertions, 13 deletions
diff --git a/src/audioinputengine.h b/src/audioinputengine.h
index 22963ee..9dfd8f2 100644
--- a/src/audioinputengine.h
+++ b/src/audioinputengine.h
@@ -28,6 +28,7 @@
#define __DRUMGIZMO_AUDIOINPUTENGINE_H__
#include <string>
+#include <vector>
#include <event.h>
@@ -47,7 +48,7 @@ public:
virtual void stop() = 0;
virtual void pre() = 0;
- virtual event_t *run(size_t pos, size_t len, size_t *nevents) = 0;
+ virtual void run(size_t pos, size_t len, std::vector<event_t>& events) = 0;
virtual void post() = 0;
};
diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h
index f53343f..68b82bb 100644
--- a/src/audioinputenginemidi.h
+++ b/src/audioinputenginemidi.h
@@ -51,7 +51,7 @@ public:
virtual void stop() = 0;
virtual void pre() = 0;
- virtual event_t *run(size_t pos, size_t len, size_t *nevents) = 0;
+ virtual void run(size_t pos, size_t len, std::vector<event_t>& events) = 0;
virtual void post() = 0;
bool loadMidiMap(std::string file, Instruments &i);
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 6bcb7bb..1c437d6 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -53,9 +53,12 @@ DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i)
, ie(i)
, framesize(0)
, freewheel(false)
+ , events{}
{
is_stopping = false;
audioCache.init(10000); // start thread
+
+ events.reserve(1000);
}
DrumGizmo::~DrumGizmo()
@@ -268,15 +271,14 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
//DEBUG(engine, "Number of active events: %d\n", activeevents[0].size());
- size_t nev;
- event_t *evs = ie->run(pos, nsamples, &nev);
+ ie->run(pos, nsamples, events);
- for(size_t e = 0; e < nev; ++e)
+ for(const auto& event: events)
{
- if(evs[e].type == TYPE_ONSET)
+ if(event.type == TYPE_ONSET)
{
Instrument *i = nullptr;
- int d = evs[e].instrument;
+ int d = event.instrument;
/*
Instruments::iterator it = kit.instruments.begin();
while(d-- && it != kit.instruments.end())
@@ -298,7 +300,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
if(i == nullptr || !i->isValid())
{
- ERR(drumgizmo, "Missing Instrument %d.\n", evs[e].instrument);
+ ERR(drumgizmo, "Missing Instrument %d.\n", event.instrument);
continue;
}
@@ -330,7 +332,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
}
}
- Sample *s = i->sample(evs[e].velocity, evs[e].offset + pos);
+ Sample *s = i->sample(event.velocity, event.offset + pos);
if(s == nullptr)
{
@@ -355,16 +357,16 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
}
else
{
- //DEBUG(drumgizmo, "Adding event %d.\n", evs[e].offset);
+ //DEBUG(drumgizmo, "Adding event %d.\n", event.offset);
Event *evt = new EventSample(ch.num, 1.0, af, i->group(), i);
- evt->offset = (evs[e].offset + pos) * resampler[0].ratio();
+ evt->offset = (event.offset + pos) * resampler[0].ratio();
activeevents[ch.num].push_back(evt);
}
++j;
}
}
- if(evs[e].type == TYPE_STOP)
+ if(event.type == TYPE_STOP)
{
is_stopping = true;
}
@@ -390,7 +392,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
}
- free(evs);
+ events.clear();
//
// Write audio
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index e0aea85..55f4590 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -106,4 +106,6 @@ protected:
size_t framesize;
bool freewheel;
+
+ std::vector<event_t> events;
};