From 358867e7342e6419b05ed02081de54dd539e4be7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 27 Aug 2012 04:13:11 +0100 Subject: [PATCH] Removed memory allocation when reading MIDI data. --- dssi-vst.cpp | 4 +--- rdwrops.cpp | 13 ++----------- rdwrops.h | 3 +++ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/dssi-vst.cpp b/dssi-vst.cpp index 15cf97c..2635934 100644 --- a/dssi-vst.cpp +++ b/dssi-vst.cpp @@ -7,6 +7,7 @@ */ #include "remotevstclient.h" +#include "rdwrops.h" #include "dssi/ladspa.h" #include "dssi/dssi.h" @@ -21,9 +22,6 @@ #include #include -// Should be divisible by three -#define MIDI_BUFFER_SIZE 1023 - class DSSIVSTPluginInstance { public: diff --git a/rdwrops.cpp b/rdwrops.cpp index e321592..86b706e 100644 --- a/rdwrops.cpp +++ b/rdwrops.cpp @@ -138,20 +138,11 @@ rdwr_readFloat(int fd, const char *file, int line) extern unsigned char * rdwr_readMIDIData(int fd, int **frameoffsets, int &events, const char *file, int line) { - static unsigned char *buf = 0; - static int *frameoffbuf = 0; - static int bufEvts = 0; + static unsigned char buf[MIDI_BUFFER_SIZE * 3]; + static int frameoffbuf[MIDI_BUFFER_SIZE]; rdwr_tryRead(fd, &events, sizeof(int), file, line); - if (events > bufEvts) { - delete buf; - delete frameoffbuf; - buf = new unsigned char[events * 3]; - frameoffbuf = new int[events]; - bufEvts = events; - } - rdwr_tryRead(fd, buf, events * 3, file, line); rdwr_tryRead(fd, frameoffbuf, events * sizeof(int), file, line); diff --git a/rdwrops.h b/rdwrops.h index bbeceea..d223cbb 100644 --- a/rdwrops.h +++ b/rdwrops.h @@ -11,6 +11,9 @@ #include #include "remoteplugin.h" +// Should be divisible by three +#define MIDI_BUFFER_SIZE 1023 + extern void rdwr_tryRead(int fd, void *buf, size_t count, const char *file, int line); extern void rdwr_tryWrite(int fd, const void *buf, size_t count, const char *file, int line); extern void rdwr_writeOpcode(int fd, RemotePluginOpcode opcode, const char *file, int line);