From 44d0f794312f2ff4629d37761f096b0a49e53e6f Mon Sep 17 00:00:00 2001 From: Lars Bisballe Jensen Date: Mon, 7 Sep 2015 12:33:03 +0200 Subject: Updated README with compile and install info taken from website and updated further as necessary. Procedure as described is untested though. --- README | 93 +++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/README b/README index e8e3e24..f75599a 100644 --- a/README +++ b/README @@ -1,42 +1,71 @@ Installation Instructions ************************* +NOTE1: Certain audio-centric Linux distros such as KxStudio has DrumGizmo +included in the repository. To install it on such systems, use the distros +package manager, search for it and install it. Please refer to each distro's +documentation for detailed instructions on how to do this. -Compiling and installing the LV2 plugin +NOTE2: Be aware that if you are planning on running the LV2 plugin from within +one of the binary releases of Ardour, you must make sure that drumgizmo is using +the same version of libpng, pthread and expat as Ardour was compiled with (or +at least versions matching the ABI), otherwise the plugin will show strange +behaviour or even crash upon load. + +Compiling and Installing on linux (LV2) ======================================= -If you extracted the code from a tar-ball skip to the "Configuring" section. - -Preparing code from git ------------------------ -If you cloned the repository from git, make sure to run the following commands -in order to obtain the hugin debug code: - git submodule init - git submodule update - -After that you need to run ./autogen.sh - -Configuring ------------ -Run ./configure --enable-lv2 --prefix=/usr -Then run 'make && make install' and the plugin should be installed in -/usr/lib/lv2/drumgizmo.lv2 +This guide will show you how to unpack, compile and install the lv2 version +of the drumgizmo plugin. It will also show how to make it usable for the LV2 +host Ardour3. + +Prerequisites +------------- +* lv2-devel package >= 1.0 +* libsndfile-devel >= 1.0.21 +* zita-resampler-devel (no minimal version specified) +* libexpat-devel (no minimal version specified) +* pkg-config >= 0.23 +* Xlib >= 1.0 +* libpng >= 1.2 +* libsmf (no minimal version specified) +* pthread (no minimal version specified) +* libcppunit-dev (only necessary when compiling from git sources) + +Compiling source tarball +------------------------ +$ tar xvzf drumgizmo-[version].tar.gz (you probably already did this) +$ cd drumgizmo-[version] +$ ./configure --prefix=$PWD/install --enable-lv2 +$ make +$ make install + +Compiling from git sources +-------------------------- +$ git clone http://git.drumgizmo.org/drumgizmo.git +$ git submodule init +$ git submodule update +$ ./autogen.sh +$ ./configure --prefix=$PWD/install --enable-lv2 + If you want to compile only the LV2 parts of the plugin use '--disable-editor --disable-cli' as additional parameters to the configure script. -The LV2 plugin requires the following dependencies: -pkg-config >= 0.23 -lv2 >= 1.0 -Xlib >= 1.0 -sndfile >= 1.0.21 -libpng >= 1.2 -libsmf -pthread (no minimal version specified) -expat (no minimal version specified) - -Be aware that if you are planning on running the LV2 plugin from within one -of the binary releases of Ardour, you must make sure that drumgizmo is using -the same version of libpng, pthread and expat as Ardour was compiled with (or -at least versions matching the ABI), otherwise the plugin will show strange -behaviour or even crash upon load. +Now compile and install +$ make +$ make install + +Installing for use with Ardour3 +------------------------------- +When the make install step has been successfully performed the source directory +will contain a folder named install. In this folder the: + + install/lib/lv2/drumgizmo.lv2 + +... is located. This folder contain all the files needed for the plugin to run. +In order to make it work with Ardour3, either copy this directory to the lv2 +plugin dir (usually /usr/lib/lv2) or create a symbolic link to the directory +$ ln -s [dg path]/install/lib/lv2/drumgizmo.lv2 /usr/lib/lv2/drumgizmo.lv2 +You need to be root to do this. Keep in mind that the lv2 directory differs from +distro to distro, so do a search for it in order to verify the correct location. \ No newline at end of file -- cgit v1.2.3 From e31f083731a183425767b032fb5292c88fcd302f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 19 Oct 2015 22:09:39 +0200 Subject: Added missing DIST file. --- test/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Makefile.am b/test/Makefile.am index 90373e1..defd63d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -49,3 +49,6 @@ configfile_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ test.cc \ configtest.cc + +EXTRA_DIST = \ + lv2_test_host.h \ No newline at end of file -- cgit v1.2.3 From 37f12cacce3ed1de57d96849b9ba4489ccbb3fe6 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 27 Oct 2015 19:01:50 +0100 Subject: Added missing expat lib to jackmidi and midifile plugins. --- drumgizmo/input/jackmidi/Makefile.am | 3 ++- drumgizmo/input/midifile/Makefile.am | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drumgizmo/input/jackmidi/Makefile.am b/drumgizmo/input/jackmidi/Makefile.am index fd63944..d392f19 100644 --- a/drumgizmo/input/jackmidi/Makefile.am +++ b/drumgizmo/input/jackmidi/Makefile.am @@ -26,7 +26,8 @@ libdir = $(INPUT_PLUGIN_DIR) AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/hugin jackmidi_la_LDFLAGS = -module -avoid-version -shared -jackmidi_la_LIBADD = +jackmidi_la_LIBADD = $(EXPAT_LIBS) +jackmidi_la_CXXFLAGS = $(EXPAT_CFLAGS) jackmidi_la_SOURCES = $(jackmidibuildsources) install-exec-hook: diff --git a/drumgizmo/input/midifile/Makefile.am b/drumgizmo/input/midifile/Makefile.am index f95a289..9ade475 100644 --- a/drumgizmo/input/midifile/Makefile.am +++ b/drumgizmo/input/midifile/Makefile.am @@ -27,8 +27,9 @@ libdir = $(INPUT_PLUGIN_DIR) AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SMF_CFLAGS) \ $(EXPAT_CFLAGS) -I$(top_srcdir)/hugin -DWITH_HUG_MUTEX -midifile_la_LDFLAGS = $(SMF_LIBS) $(EXPAT_LIBS) -module -avoid-version -shared -midifile_la_LIBADD = +midifile_la_LDFLAGS = -module -avoid-version -shared +midifile_la_LIBADD = $(EXPAT_LIBS) $(SMF_LIBS) +midifile_la_CXXFLAGS =$(EXPAT_CFLAGS) midifile_la_SOURCES = $(midifilebuildsources) install-exec-hook: -- cgit v1.2.3 From 8a410c2c6cd0ac5c0c63d522f6ccd39c778f1496 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 27 Oct 2015 19:04:48 +0100 Subject: Remove unneeded zlib reference. --- configure.ac | 5 ----- plugingui/Makefile.am.plugingui | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 7934cc2..274a6cc 100644 --- a/configure.ac +++ b/configure.ac @@ -444,11 +444,6 @@ AS_IF([test x$enable_resampler == xsrc], )] ) -#dnl ====================== -#dnl Check for zlib -#dnl ====================== -PKG_CHECK_MODULES(ZLIB, zlib >= 1.2.3) - dnl ====================== dnl Check for the pthread library dnl ====================== diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui index b1698e4..c964a78 100644 --- a/plugingui/Makefile.am.plugingui +++ b/plugingui/Makefile.am.plugingui @@ -37,9 +37,9 @@ PLUGIN_GUI_SOURCES = \ $(top_srcdir)/plugingui/resource_data.cc \ $(top_srcdir)/plugingui/lodepng/lodepng.cpp -PLUGIN_GUI_LIBS = $(GUI_LIBS) $(PTHREAD_LIBS) $(ZLIB_LIBS) +PLUGIN_GUI_LIBS = $(GUI_LIBS) $(PTHREAD_LIBS) -PLUGIN_GUI_CFLAGS = $(GUI_CFLAGS) $(ZLIB_CFLAGS) -I$(top_srcdir)/hugin \ +PLUGIN_GUI_CFLAGS = $(GUI_CFLAGS) -I$(top_srcdir)/hugin \ -DWITH_HUG_SYSLOG -DWITH_HUG_MUTEX $(PTHREAD_CFLAGS) \ -I$(top_srcdir)/pugl/pugl \ -DLODEPNG_NO_COMPILE_ENCODER \ -- cgit v1.2.3 From 5656f572f1fac2a32033927ff184a81103cd60b9 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 18 Dec 2015 19:01:55 +0100 Subject: Experimental tempo change for midifile input module. --- drumgizmo/input/midifile/midifile.cc | 451 ++++++++++++++++++++--------------- 1 file changed, 257 insertions(+), 194 deletions(-) diff --git a/drumgizmo/input/midifile/midifile.cc b/drumgizmo/input/midifile/midifile.cc index d73d382..54865ef 100644 --- a/drumgizmo/input/midifile/midifile.cc +++ b/drumgizmo/input/midifile/midifile.cc @@ -38,91 +38,154 @@ class MidiFile { public: - MidiFile(); - ~MidiFile() {} + MidiFile() = default; + ~MidiFile() = default; - bool init(int instruments, char *inames[]); + bool init(int instruments, char *inames[]); - void setParm(std::string parm, std::string value); + void setParm(std::string parm, std::string value); - bool start(); - void stop(); - - void pre(); - event_t *run(size_t pos, size_t len, size_t *nevents); - void post(); + bool start(); + void stop(); + + void pre(); + event_t *run(size_t pos, size_t len, size_t *nevents); + void post(); private: - smf_t *smf; - smf_event_t *cur_event; - - MidiMapper mmap; - - // Parameters - std::string filename; - float speed; - int track; - std::string midimapfile; - bool loop; - double offset; + smf_t *smf{nullptr}; + smf_event_t *cur_event{nullptr}; + + MidiMapper mmap; + + // Parameters + std::string filename; + float speed{1.0}; + int track{-1}; // -1 is omni ie. all tracks + std::string midimapfile; + bool loop{false}; + double offset{0}; + double tempoOverrideBpm{-1}; // -1 is disabled. }; -MidiFile::MidiFile() -{ - cur_event = NULL; - smf = NULL; - - speed = 1.0; - track = -1; // -1 is OMNI/all tracks - loop = false; - offset = 0; -} - bool MidiFile::init(int instruments, char *inames[]) { - if(filename == "") { - fprintf(stderr, "Missing midifile argument 'file'\n"); - return false; - } - - if(midimapfile == "") { - fprintf(stderr, "Missing midimapfile argument 'midimap'.\n"); - return false; - } - - smf = smf_load(filename.c_str()); - - if(!smf) { - fprintf(stderr, "Could not open midifile '%s'.\n", filename.c_str()); - return false; - } - - MidiMapParser p(midimapfile); - if(p.parse()) { - fprintf(stderr, "Could not parse midimapfile '%s'.\n", midimapfile.c_str()); - return false; - } - mmap.midimap = p.midimap; - - for(int i = 0; i < instruments; i++) { - mmap.instrmap[inames[i]] = i; - } - - return true; + if(filename == "") + { + fprintf(stderr, "Missing midifile argument 'file'\n"); + return false; + } + + if(midimapfile == "") + { + fprintf(stderr, "Missing midimapfile argument 'midimap'.\n"); + return false; + } + + smf = smf_load(filename.c_str()); + + if(!smf) + { + fprintf(stderr, "Could not open midifile '%s'.\n", filename.c_str()); + return false; + } + + // Override tempo is supplied by the user + if(tempoOverrideBpm > 0) + { + // Tempo change event format: + // FF 51 03 tttttt - Set Tempo, in microseconds per MIDI quarter-note + unsigned char midiData[] = { 0xff, 0x51, 0x03, 0, 0, 0 }; + + unsigned int usecPerMinute = 60000000; + unsigned int mpqn = usecPerMinute / tempoOverrideBpm; + midiData[3] = (mpqn >> 0) & 0xff; + midiData[4] = (mpqn >> 8) & 0xff; + midiData[5] = (mpqn >> 16) & 0xff; + + smf_event_t* tempoChangeEvent = + smf_event_new_from_pointer(midiData, sizeof(midiData)); + + while(true) + { + smf_event_t* event = smf_peek_next_event(smf); + + // Skip all initial tempo events. + if((!smf_event_is_metadata(event)) && + (event->midi_buffer[1] == 0x51) && (event->midi_buffer[1] == 0x58)) + //if(smf_event_is_tempo_change_or_time_signature(event)) // only in latest smf + { + smf_skip_next_event(smf); + } + else + { + // No more tempo change event; stop searching. + break; + } + } + + // Add tempo change event to all tracks. + smf_track_t *track; + unsigned int trackNumber = 1; + while((track = smf_get_track_by_number(smf, trackNumber))) + { + smf_track_add_event_seconds(track, tempoChangeEvent, 0); + ++trackNumber; + } + } + + MidiMapParser p(midimapfile); + if(p.parse()) + { + fprintf(stderr, "Could not parse midimapfile '%s'.\n", midimapfile.c_str()); + return false; + } + mmap.midimap = p.midimap; + + for(int i = 0; i < instruments; ++i) + { + mmap.instrmap[inames[i]] = i; + } + + return true; } void MidiFile::setParm(std::string parm, std::string value) { - if(parm == "file") filename = value; - if(parm == "speed") speed = atof(value.c_str()); - if(parm == "track") track = atoi(value.c_str()); - if(parm == "midimap") midimapfile = value; - if(parm == "loop") loop = true; + if(parm == "file") + { + filename = value; + } + + if(parm == "speed") + { + speed = atof(value.c_str()); + } + + if(parm == "track") + { + track = atoi(value.c_str()); + } + + if(parm == "midimap") + { + midimapfile = value; + } + + if(parm == "loop") + { + loop = true; + } + + if(parm == "tempo") + { + tempoOverrideBpm = atof(value.c_str()); + } } bool MidiFile::start() { - return true; + return true; } void MidiFile::stop() @@ -135,63 +198,80 @@ void MidiFile::pre() event_t *MidiFile::run(size_t pos, size_t len, size_t *nevents) { - event_t *evs = NULL; - size_t nevs = 0; - - double cur_max_time = (double)(pos + len) / (44100.0 / speed); - cur_max_time -= offset; - // double cur_min_time = (double)(pos) / (44100.0 / speed); - - if(!cur_event) cur_event = smf_get_next_event(smf); - - while(cur_event && cur_event->time_seconds < cur_max_time) { - if(!smf_event_is_metadata(cur_event)) { - if( (cur_event->midi_buffer_length == 3) && - ((cur_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) && - (track == -1 || cur_event->track_number == track) && - cur_event->midi_buffer[2] > 0) { - - if(evs == NULL) evs = (event_t *)malloc(sizeof(event_t) * 1000); - - int key = cur_event->midi_buffer[1]; - int velocity = cur_event->midi_buffer[2]; - - evs[nevs].type = TYPE_ONSET; - size_t evpos = cur_event->time_seconds * (44100.0 / speed); - evs[nevs].offset = evpos - pos; - - int i = mmap.lookup(key); - if(i != -1) { - evs[nevs].instrument = i; - evs[nevs].velocity = velocity / 127.0; - - nevs++; - if(nevs > 999) { - fprintf(stderr, "PANIC!\n"); - break; - } - } - } - } - - cur_event = smf_get_next_event(smf); - } - - if(!cur_event) { - if(loop) { - smf_rewind(smf); - offset += cur_max_time; - } else { - if(evs == NULL) evs = (event_t *)malloc(sizeof(event_t) * 1000); - evs[nevs].type = TYPE_STOP; - evs[nevs].offset = len - 1; - nevs++; - } - } - - *nevents = nevs; - - return evs; + event_t *evs = nullptr; + size_t nevs = 0; + + double cur_max_time = (double)(pos + len) / (44100.0 / speed); + cur_max_time -= offset; + // double cur_min_time = (double)(pos) / (44100.0 / speed); + + if(!cur_event) + { + cur_event = smf_get_next_event(smf); + } + + while(cur_event && cur_event->time_seconds < cur_max_time) + { + if(!smf_event_is_metadata(cur_event)) + { + if( (cur_event->midi_buffer_length == 3) && + ((cur_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) && + (track == -1 || cur_event->track_number == track) && + cur_event->midi_buffer[2] > 0) + { + if(evs == nullptr) + { + evs = (event_t *)malloc(sizeof(event_t) * 1000); + } + + int key = cur_event->midi_buffer[1]; + int velocity = cur_event->midi_buffer[2]; + + evs[nevs].type = TYPE_ONSET; + size_t evpos = cur_event->time_seconds * (44100.0 / speed); + evs[nevs].offset = evpos - pos; + + int i = mmap.lookup(key); + if(i != -1) + { + evs[nevs].instrument = i; + evs[nevs].velocity = velocity / 127.0; + + ++nevs; + if(nevs > 999) + { + fprintf(stderr, "Midi event overflow\n"); + break; + } + } + } + } + + cur_event = smf_get_next_event(smf); + } + + if(!cur_event) + { + if(loop) + { + smf_rewind(smf); + offset += cur_max_time; + } + else + { + if(evs == nullptr) + { + evs = (event_t *)malloc(sizeof(event_t) * 1000); + } + evs[nevs].type = TYPE_STOP; + evs[nevs].offset = len - 1; + ++nevs; + } + } + + *nevents = nevs; + + return evs; } void MidiFile::post() @@ -199,73 +279,56 @@ void MidiFile::post() } extern "C" { - void *create() - { - return new MidiFile(); - } - - void destroy(void *h) - { - MidiFile *midifile = (MidiFile*)h; - delete midifile; - } - - bool init(void *h, int i, char *inames[]) - { - MidiFile *midifile = (MidiFile*)h; - return midifile->init(i, inames); - } - - void setparm(void *h, const char *parm, const char *value) - { - MidiFile *midifile = (MidiFile*)h; - midifile->setParm(parm, value); - } - - bool start(void *h) - { - MidiFile *midifile = (MidiFile*)h; - return midifile->start(); - } - - void stop(void *h) - { - MidiFile *midifile = (MidiFile*)h; - midifile->stop(); - } - - void pre(void *h) - { - MidiFile *midifile = (MidiFile*)h; - midifile->pre(); - } - - event_t *run(void *h, size_t pos, size_t len, size_t *nev) - { - MidiFile *midifile = (MidiFile*)h; - return midifile->run(pos, len, nev); - } - - void post(void *h) - { - MidiFile *midifile = (MidiFile*)h; - midifile->post(); - } + void *create() + { + return new MidiFile(); + } + + void destroy(void *h) + { + MidiFile *midifile = (MidiFile*)h; + delete midifile; + } + + bool init(void *h, int i, char *inames[]) + { + MidiFile *midifile = (MidiFile*)h; + return midifile->init(i, inames); + } + + void setparm(void *h, const char *parm, const char *value) + { + MidiFile *midifile = (MidiFile*)h; + midifile->setParm(parm, value); + } + + bool start(void *h) + { + MidiFile *midifile = (MidiFile*)h; + return midifile->start(); + } + + void stop(void *h) + { + MidiFile *midifile = (MidiFile*)h; + midifile->stop(); + } + + void pre(void *h) + { + MidiFile *midifile = (MidiFile*)h; + midifile->pre(); + } + + event_t *run(void *h, size_t pos, size_t len, size_t *nev) + { + MidiFile *midifile = (MidiFile*)h; + return midifile->run(pos, len, nev); + } + + void post(void *h) + { + MidiFile *midifile = (MidiFile*)h; + midifile->post(); + } } - -#ifdef TEST_AUDIOINPUTENGINEMIDIFILE -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" - -TEST_BEGIN; - -// TODO: Put some testcode here (see test.h for usable macros). - -TEST_END; - -#endif/*TEST_AUDIOINPUTENGINEMIDIFILE*/ -- cgit v1.2.3 From 89cfec5ae70d3770bc1fb55c658c2551c9a9dd42 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 19 Dec 2015 11:25:40 +0100 Subject: Revert "Experimental tempo change for midifile input module." This reverts commit 5656f572f1fac2a32033927ff184a81103cd60b9. --- drumgizmo/input/midifile/midifile.cc | 451 +++++++++++++++-------------------- 1 file changed, 194 insertions(+), 257 deletions(-) diff --git a/drumgizmo/input/midifile/midifile.cc b/drumgizmo/input/midifile/midifile.cc index 54865ef..d73d382 100644 --- a/drumgizmo/input/midifile/midifile.cc +++ b/drumgizmo/input/midifile/midifile.cc @@ -38,154 +38,91 @@ class MidiFile { public: - MidiFile() = default; - ~MidiFile() = default; + MidiFile(); + ~MidiFile() {} - bool init(int instruments, char *inames[]); + bool init(int instruments, char *inames[]); - void setParm(std::string parm, std::string value); + void setParm(std::string parm, std::string value); - bool start(); - void stop(); - - void pre(); - event_t *run(size_t pos, size_t len, size_t *nevents); - void post(); + bool start(); + void stop(); + + void pre(); + event_t *run(size_t pos, size_t len, size_t *nevents); + void post(); private: - smf_t *smf{nullptr}; - smf_event_t *cur_event{nullptr}; - - MidiMapper mmap; - - // Parameters - std::string filename; - float speed{1.0}; - int track{-1}; // -1 is omni ie. all tracks - std::string midimapfile; - bool loop{false}; - double offset{0}; - double tempoOverrideBpm{-1}; // -1 is disabled. + smf_t *smf; + smf_event_t *cur_event; + + MidiMapper mmap; + + // Parameters + std::string filename; + float speed; + int track; + std::string midimapfile; + bool loop; + double offset; }; +MidiFile::MidiFile() +{ + cur_event = NULL; + smf = NULL; + + speed = 1.0; + track = -1; // -1 is OMNI/all tracks + loop = false; + offset = 0; +} + bool MidiFile::init(int instruments, char *inames[]) { - if(filename == "") - { - fprintf(stderr, "Missing midifile argument 'file'\n"); - return false; - } - - if(midimapfile == "") - { - fprintf(stderr, "Missing midimapfile argument 'midimap'.\n"); - return false; - } - - smf = smf_load(filename.c_str()); - - if(!smf) - { - fprintf(stderr, "Could not open midifile '%s'.\n", filename.c_str()); - return false; - } - - // Override tempo is supplied by the user - if(tempoOverrideBpm > 0) - { - // Tempo change event format: - // FF 51 03 tttttt - Set Tempo, in microseconds per MIDI quarter-note - unsigned char midiData[] = { 0xff, 0x51, 0x03, 0, 0, 0 }; - - unsigned int usecPerMinute = 60000000; - unsigned int mpqn = usecPerMinute / tempoOverrideBpm; - midiData[3] = (mpqn >> 0) & 0xff; - midiData[4] = (mpqn >> 8) & 0xff; - midiData[5] = (mpqn >> 16) & 0xff; - - smf_event_t* tempoChangeEvent = - smf_event_new_from_pointer(midiData, sizeof(midiData)); - - while(true) - { - smf_event_t* event = smf_peek_next_event(smf); - - // Skip all initial tempo events. - if((!smf_event_is_metadata(event)) && - (event->midi_buffer[1] == 0x51) && (event->midi_buffer[1] == 0x58)) - //if(smf_event_is_tempo_change_or_time_signature(event)) // only in latest smf - { - smf_skip_next_event(smf); - } - else - { - // No more tempo change event; stop searching. - break; - } - } - - // Add tempo change event to all tracks. - smf_track_t *track; - unsigned int trackNumber = 1; - while((track = smf_get_track_by_number(smf, trackNumber))) - { - smf_track_add_event_seconds(track, tempoChangeEvent, 0); - ++trackNumber; - } - } - - MidiMapParser p(midimapfile); - if(p.parse()) - { - fprintf(stderr, "Could not parse midimapfile '%s'.\n", midimapfile.c_str()); - return false; - } - mmap.midimap = p.midimap; - - for(int i = 0; i < instruments; ++i) - { - mmap.instrmap[inames[i]] = i; - } - - return true; + if(filename == "") { + fprintf(stderr, "Missing midifile argument 'file'\n"); + return false; + } + + if(midimapfile == "") { + fprintf(stderr, "Missing midimapfile argument 'midimap'.\n"); + return false; + } + + smf = smf_load(filename.c_str()); + + if(!smf) { + fprintf(stderr, "Could not open midifile '%s'.\n", filename.c_str()); + return false; + } + + MidiMapParser p(midimapfile); + if(p.parse()) { + fprintf(stderr, "Could not parse midimapfile '%s'.\n", midimapfile.c_str()); + return false; + } + mmap.midimap = p.midimap; + + for(int i = 0; i < instruments; i++) { + mmap.instrmap[inames[i]] = i; + } + + return true; } void MidiFile::setParm(std::string parm, std::string value) { - if(parm == "file") - { - filename = value; - } - - if(parm == "speed") - { - speed = atof(value.c_str()); - } - - if(parm == "track") - { - track = atoi(value.c_str()); - } - - if(parm == "midimap") - { - midimapfile = value; - } - - if(parm == "loop") - { - loop = true; - } - - if(parm == "tempo") - { - tempoOverrideBpm = atof(value.c_str()); - } + if(parm == "file") filename = value; + if(parm == "speed") speed = atof(value.c_str()); + if(parm == "track") track = atoi(value.c_str()); + if(parm == "midimap") midimapfile = value; + if(parm == "loop") loop = true; } bool MidiFile::start() { - return true; + return true; } void MidiFile::stop() @@ -198,80 +135,63 @@ void MidiFile::pre() event_t *MidiFile::run(size_t pos, size_t len, size_t *nevents) { - event_t *evs = nullptr; - size_t nevs = 0; - - double cur_max_time = (double)(pos + len) / (44100.0 / speed); - cur_max_time -= offset; - // double cur_min_time = (double)(pos) / (44100.0 / speed); - - if(!cur_event) - { - cur_event = smf_get_next_event(smf); - } - - while(cur_event && cur_event->time_seconds < cur_max_time) - { - if(!smf_event_is_metadata(cur_event)) - { - if( (cur_event->midi_buffer_length == 3) && - ((cur_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) && - (track == -1 || cur_event->track_number == track) && - cur_event->midi_buffer[2] > 0) - { - if(evs == nullptr) - { - evs = (event_t *)malloc(sizeof(event_t) * 1000); - } - - int key = cur_event->midi_buffer[1]; - int velocity = cur_event->midi_buffer[2]; - - evs[nevs].type = TYPE_ONSET; - size_t evpos = cur_event->time_seconds * (44100.0 / speed); - evs[nevs].offset = evpos - pos; - - int i = mmap.lookup(key); - if(i != -1) - { - evs[nevs].instrument = i; - evs[nevs].velocity = velocity / 127.0; - - ++nevs; - if(nevs > 999) - { - fprintf(stderr, "Midi event overflow\n"); - break; - } - } - } - } - - cur_event = smf_get_next_event(smf); - } - - if(!cur_event) - { - if(loop) - { - smf_rewind(smf); - offset += cur_max_time; - } - else - { - if(evs == nullptr) - { - evs = (event_t *)malloc(sizeof(event_t) * 1000); - } - evs[nevs].type = TYPE_STOP; - evs[nevs].offset = len - 1; - ++nevs; - } - } - - *nevents = nevs; - - return evs; + event_t *evs = NULL; + size_t nevs = 0; + + double cur_max_time = (double)(pos + len) / (44100.0 / speed); + cur_max_time -= offset; + // double cur_min_time = (double)(pos) / (44100.0 / speed); + + if(!cur_event) cur_event = smf_get_next_event(smf); + + while(cur_event && cur_event->time_seconds < cur_max_time) { + if(!smf_event_is_metadata(cur_event)) { + if( (cur_event->midi_buffer_length == 3) && + ((cur_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) && + (track == -1 || cur_event->track_number == track) && + cur_event->midi_buffer[2] > 0) { + + if(evs == NULL) evs = (event_t *)malloc(sizeof(event_t) * 1000); + + int key = cur_event->midi_buffer[1]; + int velocity = cur_event->midi_buffer[2]; + + evs[nevs].type = TYPE_ONSET; + size_t evpos = cur_event->time_seconds * (44100.0 / speed); + evs[nevs].offset = evpos - pos; + + int i = mmap.lookup(key); + if(i != -1) { + evs[nevs].instrument = i; + evs[nevs].velocity = velocity / 127.0; + + nevs++; + if(nevs > 999) { + fprintf(stderr, "PANIC!\n"); + break; + } + } + } + } + + cur_event = smf_get_next_event(smf); + } + + if(!cur_event) { + if(loop) { + smf_rewind(smf); + offset += cur_max_time; + } else { + if(evs == NULL) evs = (event_t *)malloc(sizeof(event_t) * 1000); + evs[nevs].type = TYPE_STOP; + evs[nevs].offset = len - 1; + nevs++; + } + } + + *nevents = nevs; + + return evs; } void MidiFile::post() @@ -279,56 +199,73 @@ void MidiFile::post() } extern "C" { - void *create() - { - return new MidiFile(); - } - - void destroy(void *h) - { - MidiFile *midifile = (MidiFile*)h; - delete midifile; - } - - bool init(void *h, int i, char *inames[]) - { - MidiFile *midifile = (MidiFile*)h; - return midifile->init(i, inames); - } - - void setparm(void *h, const char *parm, const char *value) - { - MidiFile *midifile = (MidiFile*)h; - midifile->setParm(parm, value); - } - - bool start(void *h) - { - MidiFile *midifile = (MidiFile*)h; - return midifile->start(); - } - - void stop(void *h) - { - MidiFile *midifile = (MidiFile*)h; - midifile->stop(); - } - - void pre(void *h) - { - MidiFile *midifile = (MidiFile*)h; - midifile->pre(); - } - - event_t *run(void *h, size_t pos, size_t len, size_t *nev) - { - MidiFile *midifile = (MidiFile*)h; - return midifile->run(pos, len, nev); - } - - void post(void *h) - { - MidiFile *midifile = (MidiFile*)h; - midifile->post(); - } + void *create() + { + return new MidiFile(); + } + + void destroy(void *h) + { + MidiFile *midifile = (MidiFile*)h; + delete midifile; + } + + bool init(void *h, int i, char *inames[]) + { + MidiFile *midifile = (MidiFile*)h; + return midifile->init(i, inames); + } + + void setparm(void *h, const char *parm, const char *value) + { + MidiFile *midifile = (MidiFile*)h; + midifile->setParm(parm, value); + } + + bool start(void *h) + { + MidiFile *midifile = (MidiFile*)h; + return midifile->start(); + } + + void stop(void *h) + { + MidiFile *midifile = (MidiFile*)h; + midifile->stop(); + } + + void pre(void *h) + { + MidiFile *midifile = (MidiFile*)h; + midifile->pre(); + } + + event_t *run(void *h, size_t pos, size_t len, size_t *nev) + { + MidiFile *midifile = (MidiFile*)h; + return midifile->run(pos, len, nev); + } + + void post(void *h) + { + MidiFile *midifile = (MidiFile*)h; + midifile->post(); + } } + +#ifdef TEST_AUDIOINPUTENGINEMIDIFILE +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEMIDIFILE*/ -- cgit v1.2.3 From 4c5b1b6713628d91554d934ee72661b83232bbf7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Dec 2015 16:54:07 +0100 Subject: Free dlopen resources. --- drumgizmo/audioinputenginedl.cc | 4 +++- drumgizmo/audioinputenginedl.h | 24 +++++++++++++----------- drumgizmo/audiooutputenginedl.cc | 4 +++- drumgizmo/audiooutputenginedl.h | 28 +++++++++++++++------------- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/drumgizmo/audioinputenginedl.cc b/drumgizmo/audioinputenginedl.cc index 93c7079..cba59fa 100644 --- a/drumgizmo/audioinputenginedl.cc +++ b/drumgizmo/audioinputenginedl.cc @@ -41,7 +41,7 @@ AudioInputEngineDL::AudioInputEngineDL(std::string name) is_jack_plugin = strstr(name.c_str(), "jack"); std::string plugin = INPUT_PLUGIN_DIR"/" + name + ".so"; - void *lib = dlopen(plugin.c_str(), RTLD_LAZY); + lib = dlopen(plugin.c_str(), RTLD_LAZY); if(!lib) { printf("Cannot load device: %s\n", dlerror()); return; @@ -124,6 +124,8 @@ AudioInputEngineDL::~AudioInputEngineDL() { i_destroy(ptr); if(is_jack_plugin) close_jack_client(); + dlclose(lib); + lib = nullptr; } bool AudioInputEngineDL::init(Instruments &instruments) diff --git a/drumgizmo/audioinputenginedl.h b/drumgizmo/audioinputenginedl.h index ed1fb27..94bd89d 100644 --- a/drumgizmo/audioinputenginedl.h +++ b/drumgizmo/audioinputenginedl.h @@ -57,19 +57,21 @@ public: void post(); private: - void *ptr; - input_create_func_t i_create; - input_destroy_func_t i_destroy; - input_init_func_t i_init; - input_setparm_func_t i_setparm; - input_start_func_t i_start; - input_stop_func_t i_stop; - input_pre_func_t i_pre; - input_run_func_t i_run; - input_post_func_t i_post; + void *ptr{nullptr}; + input_create_func_t i_create{nullptr}; + input_destroy_func_t i_destroy{nullptr}; + input_init_func_t i_init{nullptr}; + input_setparm_func_t i_setparm{nullptr}; + input_start_func_t i_start{nullptr}; + input_stop_func_t i_stop{nullptr}; + input_pre_func_t i_pre{nullptr}; + input_run_func_t i_run{nullptr}; + input_post_func_t i_post{nullptr}; bool is_jack_plugin; - JackClient *jackclient; + JackClient *jackclient{nullptr}; + + void *lib{nullptr}; }; #endif/*__DRUMGIZMO_AUDIOINPUTENGINEDL_H__*/ diff --git a/drumgizmo/audiooutputenginedl.cc b/drumgizmo/audiooutputenginedl.cc index dad2c5c..042db4a 100644 --- a/drumgizmo/audiooutputenginedl.cc +++ b/drumgizmo/audiooutputenginedl.cc @@ -36,7 +36,7 @@ AudioOutputEngineDL::AudioOutputEngineDL(std::string name) is_jack_plugin = strstr(name.c_str(), "jack"); std::string plugin = OUTPUT_PLUGIN_DIR"/" + name + ".so"; - void *lib = dlopen(plugin.c_str(), RTLD_LAZY); + lib = dlopen(plugin.c_str(), RTLD_LAZY); if(!lib) { printf("Cannot load device: %s\n", dlerror()); return; @@ -132,6 +132,8 @@ AudioOutputEngineDL::~AudioOutputEngineDL() { o_destroy(ptr); if(is_jack_plugin) close_jack_client(); + dlclose(lib); + lib = nullptr; } bool AudioOutputEngineDL::init(Channels channels) diff --git a/drumgizmo/audiooutputenginedl.h b/drumgizmo/audiooutputenginedl.h index 75460f3..4b31015 100644 --- a/drumgizmo/audiooutputenginedl.h +++ b/drumgizmo/audiooutputenginedl.h @@ -68,21 +68,23 @@ public: size_t samplerate(); private: - void *ptr; - output_create_func_t o_create; - output_destroy_func_t o_destroy; - output_init_func_t o_init; - output_setparm_func_t o_setparm; - output_start_func_t o_start; - output_stop_func_t o_stop; - output_pre_func_t o_pre; - output_run_func_t o_run; - output_post_func_t o_post; - output_bufsize_func_t o_bufsize; - output_samplerate_func_t o_samplerate; + void *ptr{nullptr}; + output_create_func_t o_create{nullptr}; + output_destroy_func_t o_destroy{nullptr}; + output_init_func_t o_init{nullptr}; + output_setparm_func_t o_setparm{nullptr}; + output_start_func_t o_start{nullptr}; + output_stop_func_t o_stop{nullptr}; + output_pre_func_t o_pre{nullptr}; + output_run_func_t o_run{nullptr}; + output_post_func_t o_post{nullptr}; + output_bufsize_func_t o_bufsize{nullptr}; + output_samplerate_func_t o_samplerate{nullptr}; bool is_jack_plugin; - JackClient *jackclient; + JackClient *jackclient{nullptr}; + + void* lib{nullptr}; }; #endif/*__DRUMGIZMO_AUDIOOUTPUTENGINEDL_H__*/ -- cgit v1.2.3 From 02321ff4d595db763074080b3e55d040fc403a99 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Dec 2015 16:54:56 +0100 Subject: Fix uninitialised warning. --- drumgizmo/input/jackmidi/jackmidi.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drumgizmo/input/jackmidi/jackmidi.cc b/drumgizmo/input/jackmidi/jackmidi.cc index 5496195..a6b49b7 100644 --- a/drumgizmo/input/jackmidi/jackmidi.cc +++ b/drumgizmo/input/jackmidi/jackmidi.cc @@ -60,8 +60,8 @@ public: private: void loadMap(std::string map) {} - JackClient *jackclient; - jack_port_t *midi_port; + JackClient *jackclient{nullptr}; + jack_port_t *midi_port{nullptr}; size_t pos; -- cgit v1.2.3 From c4f5bbfab513cd5291fbec7f0781be18c9aeb4f4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Dec 2015 16:55:52 +0100 Subject: Fix uninitialised warning. --- drumgizmo/output/alsa/alsa.cc | 12 ++++++------ drumgizmo/output/jackaudio/jackaudio.cc | 8 ++++---- drumgizmo/output/wavfile/wavfile.cc | 6 ++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/drumgizmo/output/alsa/alsa.cc b/drumgizmo/output/alsa/alsa.cc index dc2ac73..71e0c3d 100644 --- a/drumgizmo/output/alsa/alsa.cc +++ b/drumgizmo/output/alsa/alsa.cc @@ -52,15 +52,15 @@ public: size_t samplerate(); private: - snd_pcm_t *handle; - snd_pcm_hw_params_t *params; - sample_t *data; - size_t channels; + snd_pcm_t *handle{nullptr}; + snd_pcm_hw_params_t *params{nullptr}; + sample_t *data{nullptr}; + size_t channels{0}; // Parameters std::string device; - unsigned int srate; - snd_pcm_uframes_t frames; + unsigned int srate{0}; + snd_pcm_uframes_t frames{0}; }; Alsa::Alsa() diff --git a/drumgizmo/output/jackaudio/jackaudio.cc b/drumgizmo/output/jackaudio/jackaudio.cc index 5c04146..511c145 100644 --- a/drumgizmo/output/jackaudio/jackaudio.cc +++ b/drumgizmo/output/jackaudio/jackaudio.cc @@ -57,10 +57,10 @@ public: size_t samplerate(); private: - JackClient *jackclient; - jack_port_t *output_port[64]; - size_t nchannels; - sample_t **channels; + JackClient *jackclient{nullptr}; + jack_port_t *output_port[64] = {}; + size_t nchannels{0}; + sample_t **channels{nullptr}; Semaphore sem; }; diff --git a/drumgizmo/output/wavfile/wavfile.cc b/drumgizmo/output/wavfile/wavfile.cc index fa4128e..8401f80 100644 --- a/drumgizmo/output/wavfile/wavfile.cc +++ b/drumgizmo/output/wavfile/wavfile.cc @@ -28,6 +28,7 @@ #include #include +#include #include @@ -48,8 +49,8 @@ public: private: SF_INFO sf_info; - SNDFILE **fh; - size_t channels; + SNDFILE **fh{nullptr}; + size_t channels{0}; // Parameters std::string filename; @@ -60,6 +61,7 @@ WavFile::WavFile() fh = NULL; filename = "output"; + memset(&sf_info, 0, sizeof(sf_info)); sf_info.channels = 1;//channels; sf_info.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; sf_info.samplerate = 44100; -- cgit v1.2.3 From 5f2350251bddaa3be7fe2fbc510cf253e7fc971f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Dec 2015 16:56:49 +0100 Subject: Fix memory leak. --- src/configfile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configfile.cc b/src/configfile.cc index 6b0d14f..7a063d8 100644 --- a/src/configfile.cc +++ b/src/configfile.cc @@ -65,7 +65,7 @@ static std::string configPath() configpath = szPath; } #else - std::string configpath = strdup(getenv("HOME")); + std::string configpath = getenv("HOME"); #endif configpath += SEP; configpath += CONFIGDIRNAME; -- cgit v1.2.3 From 03ee8f797ddf8ba4701e394998a28aa7ee5c7ffb Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Dec 2015 16:57:52 +0100 Subject: Fix uninitialised warning. --- lv2/input_lv2.h | 4 ++-- src/drumkit.h | 4 ++-- src/drumkitloader.h | 8 ++++---- src/instrumentparser.h | 8 ++++---- src/thread.h | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lv2/input_lv2.h b/lv2/input_lv2.h index 32e2fd8..3e3ef31 100644 --- a/lv2/input_lv2.h +++ b/lv2/input_lv2.h @@ -47,10 +47,10 @@ public: event_t *run(size_t pos, size_t len, size_t *nevents); void post(); - LV2_Atom_Sequence *eventPort; + LV2_Atom_Sequence *eventPort{nullptr}; private: - Instruments *instruments; + Instruments *instruments{nullptr}; }; #endif/*__DRUMGIZMO_INPUT_LV2_H__*/ diff --git a/src/drumkit.h b/src/drumkit.h index 04b2c56..a9ceb80 100644 --- a/src/drumkit.h +++ b/src/drumkit.h @@ -56,13 +56,13 @@ public: size_t samplerate(); private: - void *magic; + void *magic{nullptr}; std::string _file; std::string _name; std::string _description; - size_t _samplerate; + size_t _samplerate{0}; VersionStr _version; }; diff --git a/src/drumkitloader.h b/src/drumkitloader.h index 2c0ea8e..b4a0a69 100644 --- a/src/drumkitloader.h +++ b/src/drumkitloader.h @@ -89,11 +89,11 @@ private: Semaphore run_semaphore; Semaphore semaphore; Mutex mutex; - volatile bool running; + volatile bool running{false}; std::list load_queue; - size_t total_num_audiofiles; - size_t fraction; - size_t loaded; + size_t total_num_audiofiles{0}; + size_t fraction{1}; + size_t loaded{0}; }; #endif/*__DRUMGIZMO_DRUMKITLOADER_H__*/ diff --git a/src/instrumentparser.h b/src/instrumentparser.h index 2a7a9c9..60a6261 100644 --- a/src/instrumentparser.h +++ b/src/instrumentparser.h @@ -47,14 +47,14 @@ protected: int readData(char *data, size_t size); private: - FILE *fd; + FILE *fd{nullptr}; Instrument &instrument; - Sample *s; + Sample *s{nullptr}; std::string path; - level_t lower; - level_t upper; + level_t lower{0}; + level_t upper{0}; }; #endif/*__DRUMGIZMO_INSTRUMENTPARSER_H__*/ diff --git a/src/thread.h b/src/thread.h index f2c1dd0..33435e6 100644 --- a/src/thread.h +++ b/src/thread.h @@ -46,10 +46,10 @@ protected: private: #ifdef WIN32 - HANDLE tid; + HANDLE tid{nullptr}; static DWORD WINAPI #else - pthread_t tid; + pthread_t tid{0}; static void* #endif/*WIN32*/ thread_run(void *data); -- cgit v1.2.3 From 0fa481dabf620181c852f43923a3c4b049294ab4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Dec 2015 16:59:00 +0100 Subject: Fix numeric limits and uninitialised warnings. --- src/semaphore.cc | 6 ++++-- src/semaphore.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/semaphore.cc b/src/semaphore.cc index 47ce8e0..3f5781f 100644 --- a/src/semaphore.cc +++ b/src/semaphore.cc @@ -28,6 +28,8 @@ #include +#include + #ifdef WIN32 #include #else @@ -53,7 +55,7 @@ Semaphore::Semaphore(const char *name) #ifdef WIN32 prv->semaphore = CreateSemaphore(NULL, // default security attributes 0, // initial count - 2147483647, // maximum count (Max LONG) + std::numeric_limits::max(), NULL); // unnamed semaphore #else sem_init(&prv->semaphore, 0, 0); @@ -70,7 +72,7 @@ Semaphore::~Semaphore() sem_destroy(&prv->semaphore); #endif - if(prv) delete prv; + delete prv; } void Semaphore::post() diff --git a/src/semaphore.h b/src/semaphore.h index 7e39f5a..ed284de 100644 --- a/src/semaphore.h +++ b/src/semaphore.h @@ -38,8 +38,8 @@ public: void wait(); private: - struct semaphore_private_t *prv; - const char *name; + struct semaphore_private_t *prv{nullptr}; + const char *name{nullptr}; }; #endif/*__PRACRO_SEMAPHORE_H__*/ -- cgit v1.2.3