From bc26b2ffd80890003948c2f1c7f50acb5a9dfc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Tue, 22 Mar 2016 00:22:14 +0100 Subject: Modernized InputEngine::run() --- plugin/drumgizmo_plugin.cc | 21 +++++---------------- plugin/drumgizmo_plugin.h | 2 +- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'plugin') diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 150d13e..61c0b17 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -205,16 +205,12 @@ void DrumGizmoPlugin::Input::pre() { } -event_t *DrumGizmoPlugin::Input::run(size_t pos, size_t len, size_t* nevents) +void DrumGizmoPlugin::Input::run(size_t pos, size_t len, std::vector& events) { - + assert(events.empty()); assert(plugin.input_events); - event_t* list; - size_t listsize; - - list = (event_t*)malloc(sizeof(event_t) * plugin.input_events->size()); - listsize = 0; + events.reserve(plugin.input_events->size()); for(auto& event : *plugin.input_events) { @@ -226,16 +222,9 @@ event_t *DrumGizmoPlugin::Input::run(size_t pos, size_t len, size_t* nevents) int i = mmap.lookup(event.key); if(event.velocity && (i != -1)) { - list[listsize].type = TYPE_ONSET; - list[listsize].instrument = i; - list[listsize].velocity = (float)event.velocity / 127.0f; - list[listsize].offset = event.getTime(); - ++listsize; - } + events.push_back({TYPE_ONSET, (size_t)i, (size_t)event.getTime(), event.velocity / 127.0f}); + } } - - *nevents = listsize; - return list; } void DrumGizmoPlugin::Input::post() diff --git a/plugin/drumgizmo_plugin.h b/plugin/drumgizmo_plugin.h index acefbf2..a0ce8b9 100644 --- a/plugin/drumgizmo_plugin.h +++ b/plugin/drumgizmo_plugin.h @@ -116,7 +116,7 @@ private: void stop() override; void pre() override; - event_t *run(size_t pos, size_t len, size_t* nevents) override; + void run(size_t pos, size_t len, std::vector& events) override; void post() override; protected: -- cgit v1.2.3