diff options
-rw-r--r-- | test/lv2.cc | 546 | ||||
-rw-r--r-- | test/lv2_test_host.cc | 19 | ||||
-rw-r--r-- | test/lv2_test_host.h | 4 |
3 files changed, 282 insertions, 287 deletions
diff --git a/test/lv2.cc b/test/lv2.cc index bfd2ce5..32d896c 100644 --- a/test/lv2.cc +++ b/test/lv2.cc @@ -47,7 +47,7 @@ */ class test_lv2 : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_lv2); + CPPUNIT_TEST_SUITE(test_lv2); CPPUNIT_TEST(open_and_verify); CPPUNIT_TEST(run_no_ports_connected); CPPUNIT_TEST(run_no_output_ports_connected); @@ -58,274 +58,282 @@ public: void setUp() {} void tearDown() {} - void open_and_verify() - { - int res; - - LV2TestHost h(LV2_PATH); - - res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); - } - - void run_no_ports_connected() - { - int res; - - LV2TestHost h(LV2_PATH); - - res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.createInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); - - const char config_fmt[] = - "<config>\n" - " <value name=\"drumkitfile\">%s</value>\n" - " <value name=\"midimapfile\">%s</value>\n" - " <value name=\"enable_velocity_modifier\">%s</value>\n" - " <value name=\"velocity_modifier_falloff\">%f</value>\n" - " <value name=\"velocity_modifier_weight\">%f</value>\n" - " <value name=\"enable_velocity_randomiser\">%s</value>\n" - " <value name=\"velocity_randomiser_weight\">%f</value>\n" - " <value name=\"enable_resampling\">%s</value>\n" - "</config>"; - - const char drumkitfile[] = "kit/kit1.xml"; - const char midimapfile[] = "kit/midimap.xml"; - bool enable_velocity_modifier = true; - float velocity_modifier_falloff = 0.5; - float velocity_modifier_weight = 0.25; - bool enable_velocity_randomiser = false; - float velocity_randomiser_weight = 0.1; - bool enable_resampling = false; - - char config[sizeof(config_fmt) * 2]; - sprintf(config, config_fmt, - drumkitfile, - midimapfile, - enable_velocity_modifier?"true":"false", - velocity_modifier_falloff, - velocity_modifier_weight, - enable_velocity_randomiser?"true":"false", - velocity_randomiser_weight, - enable_resampling?"true":"false" - ); - - res = h.loadConfig(config, strlen(config)); - CPPUNIT_ASSERT_EQUAL(0, res); - - // run for 1 samples to trigger kit loading - res = h.run(1); - CPPUNIT_ASSERT_EQUAL(0, res); - sleep(1); // wait for kit to get loaded (async), - - res = h.run(100); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.destroyInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); - } - - void run_no_output_ports_connected() - { - int res; - - LV2TestHost h(LV2_PATH); - - res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.createInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); - - const char config_fmt[] = - "<config>\n" - " <value name=\"drumkitfile\">%s</value>\n" - " <value name=\"midimapfile\">%s</value>\n" - " <value name=\"enable_velocity_modifier\">%s</value>\n" - " <value name=\"velocity_modifier_falloff\">%f</value>\n" - " <value name=\"velocity_modifier_weight\">%f</value>\n" - " <value name=\"enable_velocity_randomiser\">%s</value>\n" - " <value name=\"velocity_randomiser_weight\">%f</value>\n" - " <value name=\"enable_resampling\">%s</value>\n" - "</config>"; - - const char drumkitfile[] = "kit/kit1.xml"; - const char midimapfile[] = "kit/midimap.xml"; - bool enable_velocity_modifier = true; - float velocity_modifier_falloff = 0.5; - float velocity_modifier_weight = 0.25; - bool enable_velocity_randomiser = false; - float velocity_randomiser_weight = 0.1; - bool enable_resampling = false; - - char config[sizeof(config_fmt) * 2]; - sprintf(config, config_fmt, - drumkitfile, - midimapfile, - enable_velocity_modifier?"true":"false", - velocity_modifier_falloff, - velocity_modifier_weight, - enable_velocity_randomiser?"true":"false", - velocity_randomiser_weight, - enable_resampling?"true":"false" - ); - - res = h.loadConfig(config, strlen(config)); - CPPUNIT_ASSERT_EQUAL(0, res); - - // Port buffers: - char sequence_buffer[4096]; - - LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); - res = h.connectPort(0, seq.data()); - CPPUNIT_ASSERT_EQUAL(0, res); - - // run for 1 samples to trigger kit loading - res = h.run(1); - CPPUNIT_ASSERT_EQUAL(0, res); - sleep(1); // wait for kit to get loaded (async), - - seq.addMidiNote(5, 1, 127); - res = h.run(100); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.destroyInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); - } - - void test1() - { - int res; - - LV2TestHost h(LV2_PATH); - - res = h.open(DG_URI); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.verify(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.createInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); - - const char config_fmt[] = - "<config>\n" - " <value name=\"drumkitfile\">%s</value>\n" - " <value name=\"midimapfile\">%s</value>\n" - " <value name=\"enable_velocity_modifier\">%s</value>\n" - " <value name=\"velocity_modifier_falloff\">%f</value>\n" - " <value name=\"velocity_modifier_weight\">%f</value>\n" - " <value name=\"enable_velocity_randomiser\">%s</value>\n" - " <value name=\"velocity_randomiser_weight\">%f</value>\n" - " <value name=\"enable_resampling\">%s</value>\n" - "</config>"; - - const char drumkitfile[] = "kit/kit1.xml"; - const char midimapfile[] = "kit/midimap.xml"; - bool enable_velocity_modifier = true; - float velocity_modifier_falloff = 0.5; - float velocity_modifier_weight = 0.25; - bool enable_velocity_randomiser = false; - float velocity_randomiser_weight = 0.1; - bool enable_resampling = false; - - char config[sizeof(config_fmt) * 2]; - sprintf(config, config_fmt, - drumkitfile, - midimapfile, - enable_velocity_modifier?"true":"false", - velocity_modifier_falloff, - velocity_modifier_weight, - enable_velocity_randomiser?"true":"false", - velocity_randomiser_weight, - enable_resampling?"true":"false" - ); - - res = h.loadConfig(config, strlen(config)); - CPPUNIT_ASSERT_EQUAL(0, res); - - // Port buffers: - char sequence_buffer[4096]; - float pcm_buffer[16][10]; - - LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); - res = h.connectPort(0, seq.data()); - CPPUNIT_ASSERT_EQUAL(0, res); - - for(int i = 1; i <= 16; i++) { - memset(pcm_buffer, 1, sizeof(pcm_buffer)); - res += h.connectPort(i, pcm_buffer[i-1]); - } - CPPUNIT_ASSERT_EQUAL(0, res); - - // run for 1 samples to trigger kit loading - res = h.run(1); - CPPUNIT_ASSERT_EQUAL(0, res); - sleep(1); // wait for kit to get loaded (async), - - /* - seq.addMidiNote(5, 1, 127); - for(int i = 0; i < 10; i++) { - res = h.run(10); - CPPUNIT_ASSERT_EQUAL(0, res); - - printf("Iteration:\n"); - for(int k = 0; k < 4; k++) { - printf("#%d ", k); - for(int j = 0; j < 10; j++) printf("[%f]", pcm_buffer[k][j]); - printf("\n"); - } - printf("\n"); - - seq.clear(); - } - */ - - seq.addMidiNote(5, 1, 127); - res = h.run(10); - CPPUNIT_ASSERT_EQUAL(0, res); - - union { - float f; - unsigned int u; - } comp_val; - - comp_val.u = 1040744448; - - for(int k = 0; k < 4; k++) { - for(int j = 0; j < 10; j++) { - CPPUNIT_ASSERT(pcm_buffer[k][j] == ((j==4)?comp_val.f:0)); - } - } - seq.clear(); - - res = h.destroyInstance(); - CPPUNIT_ASSERT_EQUAL(0, res); - - res = h.close(); - CPPUNIT_ASSERT_EQUAL(0, res); - } + void open_and_verify() + { + int res; + + LV2TestHost h(LV2_PATH); + + res = h.open(DG_URI); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.verify(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.close(); + CPPUNIT_ASSERT_EQUAL(0, res); + } + + void run_no_ports_connected() + { + int res; + + LV2TestHost h(LV2_PATH); + + res = h.open(DG_URI); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.verify(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.createInstance(); + CPPUNIT_ASSERT_EQUAL(0, res); + + const char config_fmt[] = + "<config>\n" + " <value name=\"drumkitfile\">%s</value>\n" + " <value name=\"midimapfile\">%s</value>\n" + " <value name=\"enable_velocity_modifier\">%s</value>\n" + " <value name=\"velocity_modifier_falloff\">%f</value>\n" + " <value name=\"velocity_modifier_weight\">%f</value>\n" + " <value name=\"enable_velocity_randomiser\">%s</value>\n" + " <value name=\"velocity_randomiser_weight\">%f</value>\n" + " <value name=\"enable_resampling\">%s</value>\n" + "</config>"; + + const char drumkitfile[] = "kit/kit1.xml"; + const char midimapfile[] = "kit/midimap.xml"; + bool enable_velocity_modifier = true; + float velocity_modifier_falloff = 0.5; + float velocity_modifier_weight = 0.25; + bool enable_velocity_randomiser = false; + float velocity_randomiser_weight = 0.1; + bool enable_resampling = false; + + char config[sizeof(config_fmt) * 2]; + sprintf(config, config_fmt, + drumkitfile, + midimapfile, + enable_velocity_modifier?"true":"false", + velocity_modifier_falloff, + velocity_modifier_weight, + enable_velocity_randomiser?"true":"false", + velocity_randomiser_weight, + enable_resampling?"true":"false"); + + res = h.loadConfig(config, strlen(config)); + CPPUNIT_ASSERT_EQUAL(0, res); + + // run for 1 samples to trigger kit loading + res = h.run(1); + CPPUNIT_ASSERT_EQUAL(0, res); + sleep(1); // wait for kit to get loaded (async), + + res = h.run(100); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.destroyInstance(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.close(); + CPPUNIT_ASSERT_EQUAL(0, res); + } + + void run_no_output_ports_connected() + { + int res; + + LV2TestHost h(LV2_PATH); + + res = h.open(DG_URI); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.verify(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.createInstance(); + CPPUNIT_ASSERT_EQUAL(0, res); + + const char config_fmt[] = + "<config>\n" + " <value name=\"drumkitfile\">%s</value>\n" + " <value name=\"midimapfile\">%s</value>\n" + " <value name=\"enable_velocity_modifier\">%s</value>\n" + " <value name=\"velocity_modifier_falloff\">%f</value>\n" + " <value name=\"velocity_modifier_weight\">%f</value>\n" + " <value name=\"enable_velocity_randomiser\">%s</value>\n" + " <value name=\"velocity_randomiser_weight\">%f</value>\n" + " <value name=\"enable_resampling\">%s</value>\n" + "</config>"; + + const char drumkitfile[] = "kit/kit1.xml"; + const char midimapfile[] = "kit/midimap.xml"; + bool enable_velocity_modifier = true; + float velocity_modifier_falloff = 0.5; + float velocity_modifier_weight = 0.25; + bool enable_velocity_randomiser = false; + float velocity_randomiser_weight = 0.1; + bool enable_resampling = false; + + char config[sizeof(config_fmt) * 2]; + sprintf(config, config_fmt, + drumkitfile, + midimapfile, + enable_velocity_modifier?"true":"false", + velocity_modifier_falloff, + velocity_modifier_weight, + enable_velocity_randomiser?"true":"false", + velocity_randomiser_weight, + enable_resampling?"true":"false"); + + res = h.loadConfig(config, strlen(config)); + CPPUNIT_ASSERT_EQUAL(0, res); + + // Port buffers: + char sequence_buffer[4096]; + + LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); + res = h.connectPort(0, seq.data()); + CPPUNIT_ASSERT_EQUAL(0, res); + + // run for 1 samples to trigger kit loading + res = h.run(1); + CPPUNIT_ASSERT_EQUAL(0, res); + sleep(1); // wait for kit to get loaded (async), + + seq.addMidiNote(5, 1, 127); + res = h.run(100); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.destroyInstance(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.close(); + CPPUNIT_ASSERT_EQUAL(0, res); + } + + void test1() + { + int res; + + LV2TestHost h(LV2_PATH); + + res = h.open(DG_URI); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.verify(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.createInstance(); + CPPUNIT_ASSERT_EQUAL(0, res); + + const char config_fmt[] = + "<config>\n" + " <value name=\"drumkitfile\">%s</value>\n" + " <value name=\"midimapfile\">%s</value>\n" + " <value name=\"enable_velocity_modifier\">%s</value>\n" + " <value name=\"velocity_modifier_falloff\">%f</value>\n" + " <value name=\"velocity_modifier_weight\">%f</value>\n" + " <value name=\"enable_velocity_randomiser\">%s</value>\n" + " <value name=\"velocity_randomiser_weight\">%f</value>\n" + " <value name=\"enable_resampling\">%s</value>\n" + "</config>"; + + const char drumkitfile[] = "kit/kit1.xml"; + const char midimapfile[] = "kit/midimap.xml"; + bool enable_velocity_modifier = true; + float velocity_modifier_falloff = 0.5; + float velocity_modifier_weight = 0.25; + bool enable_velocity_randomiser = false; + float velocity_randomiser_weight = 0.1; + bool enable_resampling = false; + + char config[sizeof(config_fmt) * 2]; + sprintf(config, config_fmt, + drumkitfile, + midimapfile, + enable_velocity_modifier?"true":"false", + velocity_modifier_falloff, + velocity_modifier_weight, + enable_velocity_randomiser?"true":"false", + velocity_randomiser_weight, + enable_resampling?"true":"false"); + + res = h.loadConfig(config, strlen(config)); + CPPUNIT_ASSERT_EQUAL(0, res); + + // Port buffers: + char sequence_buffer[4096]; + float pcm_buffer[16][10]; + + LV2TestHost::Sequence seq(sequence_buffer, sizeof(sequence_buffer)); + res = h.connectPort(0, seq.data()); + CPPUNIT_ASSERT_EQUAL(0, res); + + for(int i = 1; i <= 16; i++) { + memset(pcm_buffer, 1, sizeof(pcm_buffer)); + res += h.connectPort(i, pcm_buffer[i-1]); + } + CPPUNIT_ASSERT_EQUAL(0, res); + + // run for 1 samples to trigger kit loading + res = h.run(1); + CPPUNIT_ASSERT_EQUAL(0, res); + sleep(1); // wait for kit to get loaded (async), + + seq.addMidiNote(5, 1, 127); + for(int i = 0; i < 10; i++) { + res = h.run(10); + CPPUNIT_ASSERT_EQUAL(0, res); + + /* + printf("Iteration:\n"); + for(int k = 0; k < 4; k++) { + printf("#%d ", k); + for(int j = 0; j < 10; j++) printf("[%f]", pcm_buffer[k][j]); + printf("\n"); + } + printf("\n"); + */ + + seq.clear(); + } + + + seq.addMidiNote(5, 1, 127); + res = h.run(10); + CPPUNIT_ASSERT_EQUAL(0, res); + + /* + printf("Iteration:\n"); + for(int k = 0; k < 4; k++) { + printf("#%d ", k); + for(int j = 0; j < 10; j++) printf("[%f]", pcm_buffer[k][j]); + printf("\n"); + } + printf("\n"); + */ + + union { + float f; + unsigned int u; + } comp_val; + + comp_val.u = 1040744448; // floating point value 0.133301.... + + for(int k = 0; k < 4; k++) { + for(int j = 0; j < 10; j++) { + CPPUNIT_ASSERT_EQUAL(((j==0)?comp_val.f:0), pcm_buffer[k][j]); + } + } + seq.clear(); + + res = h.destroyInstance(); + CPPUNIT_ASSERT_EQUAL(0, res); + + res = h.close(); + CPPUNIT_ASSERT_EQUAL(0, res); + } }; // Registers the fixture into the 'registry' diff --git a/test/lv2_test_host.cc b/test/lv2_test_host.cc index 927f94c..375ae40 100644 --- a/test/lv2_test_host.cc +++ b/test/lv2_test_host.cc @@ -40,17 +40,7 @@ // #include <openssl/bio.h> #include <openssl/err.h> - -#ifdef final -// final is used as variable name in evp.h so we need to undef it before we -// include it. - #undef final - #include <openssl/evp.h> - #define final -#else - #include <openssl/evp.h> -#endif - +#include <openssl/evp.h> #include <string> class Base64 { public: @@ -176,10 +166,11 @@ void LV2TestHost::Sequence::clear() // Keep this to support atom extension from lv2 < 1.10 static inline LV2_Atom_Event* _lv2_atom_sequence_append_event(LV2_Atom_Sequence* seq, - uint32_t capacity, - const LV2_Atom_Event* event) + uint32_t capacity, + const LV2_Atom_Event* event) { const uint32_t total_size = (uint32_t)sizeof(*event) + event->body.size; + if (capacity - seq->atom.size < total_size) { return NULL; } @@ -205,7 +196,7 @@ void LV2TestHost::Sequence::addMidiNote(uint64_t pos, MIDINoteEvent ev; ev.event.time.frames = pos;// sample position ev.event.body.type = map.map(map.handle, LV2_MIDI__MidiEvent); - ev.event.body.size = sizeof(MIDINoteEvent); + ev.event.body.size = sizeof(ev.msg); ev.msg[0] = note_on; ev.msg[1] = key; diff --git a/test/lv2_test_host.h b/test/lv2_test_host.h index 04f48c6..f0677c7 100644 --- a/test/lv2_test_host.h +++ b/test/lv2_test_host.h @@ -67,8 +67,6 @@ public: int loadConfig(const char *config, size_t size); int run(int num_samples); - - private: LilvWorld* world; const LilvPlugins* plugins; @@ -76,8 +74,6 @@ private: const LilvPlugin* plugin; LilvInstance* instance; - - size_t buffer_size; }; #endif/*__DRUMGIZMO_LV2_TEST_HOST_H__*/ |