diff options
Diffstat (limited to 'test/domloadertest.cc')
-rw-r--r-- | test/domloadertest.cc | 163 |
1 files changed, 79 insertions, 84 deletions
diff --git a/test/domloadertest.cc b/test/domloadertest.cc index 55d49a7..2cd6aa8 100644 --- a/test/domloadertest.cc +++ b/test/domloadertest.cc @@ -70,29 +70,40 @@ public: " </samples>\n" \ "</instrument>"); + // Version 1.0 format ScopedFile scoped_instrument_file2( "<?xml version='1.0' encoding='UTF-8'?>\n" \ - "<instrument version=\"2.0\" name=\"Snare2\">\n" \ + "<instrument name=\"Snare2\">\n" \ " <samples>\n" \ - " <sample name=\"Snare-1\" power=\"0.00985718\">\n" \ - " <audiofile channel=\"AmbLeft2\" file=\"1-Snare.wav\" filechannel=\"1\"/>\n" \ - " <audiofile channel=\"AmbRight2\" file=\"1-Snare.wav\" filechannel=\"2\"/>\n" \ - " <audiofile channel=\"SnareBottom2\" file=\"1-Snare.wav\" filechannel=\"12\"/>\n" \ - " <audiofile channel=\"SnareTop2\" file=\"1-Snare.wav\" filechannel=\"13\"/>\n" \ + " <sample name=\"Snare-1\">\n" \ + " <audiofile channel=\"AmbLeft2\" file=\"1-Snare-1.wav\"/>\n" \ + " <audiofile channel=\"AmbRight2\" file=\"1-Snare-2.wav\"/>\n" \ + " <audiofile channel=\"SnareBottom2\" file=\"1-Snare-3.wav\"/>\n" \ + " <audiofile channel=\"SnareTop2\" file=\"1-Snare-4.wav\"/>\n" \ " </sample>\n" \ - " <sample name=\"Snare-2\" power=\"0.0124808\">\n" \ - " <audiofile channel=\"AmbLeft2\" file=\"2-Snare.wav\" filechannel=\"1\"/>\n" \ - " <audiofile channel=\"AmbRight2\" file=\"2-Snare.wav\" filechannel=\"2\"/>\n" \ - " <audiofile channel=\"SnareBottom2\" file=\"2-Snare.wav\" filechannel=\"12\"/>\n" \ - " <audiofile channel=\"SnareTop2\" file=\"2-Snare.wav\" filechannel=\"13\"/>\n" \ + " <sample name=\"Snare-2\">\n" \ + " <audiofile channel=\"AmbLeft2\" file=\"2-Snare-1.wav\"/>\n" \ + " <audiofile channel=\"AmbRight2\" file=\"2-Snare-2.wav\"/>\n" \ + " <audiofile channel=\"SnareBottom2\" file=\"2-Snare-3.wav\"/>\n" \ + " <audiofile channel=\"SnareTop2\" file=\"2-Snare-4.wav\"/>\n" \ " </sample>\n" \ " </samples>\n" \ + " <velocities>\n" \ + " <velocity lower=\"0\" upper=\"0.6\">\n" \ + " <sampleref probability=\"0.6\" name=\"Snare-1\"/>\n" \ + " <sampleref probability=\"0.4\" name=\"Snare-2\"/>\n" \ + " </velocity>" \ + " <velocity lower=\"0.6\" upper=\"1.0\">" \ + " <sampleref probability=\"0.4\" name=\"Snare-2\"/>" \ + " <sampleref probability=\"0.6\" name=\"Snare-1\"/>" \ + " </velocity>" \ + " </velocities>" \ "</instrument>"); ScopedFile scoped_file( std::string( "<?xml version='1.0' encoding='UTF-8'?>\n" \ - "<drumkit name=\"CrocellKit\" description=\"my description\" samplerate=\"48000\" version=\"2.0.0\">\n" \ + "<drumkit samplerate=\"48000\" version=\"2.0.0\">\n" \ " <channels>\n" \ " <channel name=\"AmbLeft\"/>\n" \ " <channel name=\"AmbRight\"/>\n" \ @@ -142,8 +153,6 @@ public: DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), drumkit.channels[2].name); DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), drumkit.channels[3].name); - DGUNIT_ASSERT_EQUAL(std::string("CrocellKit"), drumkit._name); - DGUNIT_ASSERT_EQUAL(std::string("my description"), drumkit._description); DGUNIT_ASSERT_EQUAL(std::size_t(48000), drumkit._samplerate); DGUNIT_ASSERT(VersionStr("2.0.0") == drumkit._version); @@ -231,86 +240,72 @@ public: } // - // Instrument2 'Snare2': + // Instrument2 'Snare2' (version 1.0 instrument): // { - auto& instrument = *drumkit.instruments[1]; - DGUNIT_ASSERT_EQUAL(std::string(""), instrument._group); - DGUNIT_ASSERT_EQUAL(std::string("Snare2"), instrument._name); - DGUNIT_ASSERT_EQUAL(std::string(""), instrument._description); + auto& instrument = *drumkit.instruments[1]; + DGUNIT_ASSERT_EQUAL(std::string(""), instrument._group); + DGUNIT_ASSERT_EQUAL(std::string("Snare2"), instrument._name); + DGUNIT_ASSERT_EQUAL(std::string(""), instrument._description); - DGUNIT_ASSERT(VersionStr("2.0.0") == instrument.version); + DGUNIT_ASSERT(VersionStr("1.0.0") == instrument.version); - // NOTE: instrument.samples are the sample map belonging to version 1.0 - DGUNIT_ASSERT_EQUAL(std::size_t(2), instrument.samplelist.size()); - { - const auto& sample = *instrument.samplelist[0]; - DGUNIT_ASSERT_EQUAL(std::string("Snare-1"), sample.name); - DGUNIT_ASSERT_EQUAL(0.00985718f, sample.power); - DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); - for(const auto& audiofile : sample.audiofiles) + // NOTE: instrument.samples are the sample map belonging to version 1.0 + DGUNIT_ASSERT_EQUAL(std::size_t(2), instrument.samplelist.size()); { - DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare.wav"), audiofile.second->filename); - switch(audiofile.second->filechannel) - { - // NOTE: Channel numbers are zero based - they are 1 based in the xml - case 0: - DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), - audiofile.second->instrument_channel->name); - break; - case 1: - DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), - audiofile.second->instrument_channel->name); - break; - case 11: - DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), - audiofile.second->instrument_channel->name); - break; - case 12: - DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), - audiofile.second->instrument_channel->name); - break; - default: - DGUNIT_ASSERT(false); - break; - } + const auto& sample = *instrument.samplelist[0]; + DGUNIT_ASSERT_EQUAL(std::string("Snare-1"), sample.name); + DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); + auto afile = sample.audiofiles.begin(); + DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare-1.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), afile->second->instrument_channel->name); + ++afile; + DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare-2.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), afile->second->instrument_channel->name); + ++afile; + DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare-3.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), afile->second->instrument_channel->name); + ++afile; + DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare-4.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), afile->second->instrument_channel->name); } - } - { - const auto& sample = *instrument.samplelist[1]; - DGUNIT_ASSERT_EQUAL(std::string("Snare-2"), sample.name); - DGUNIT_ASSERT_EQUAL(0.0124808f, sample.power); - DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); - for(const auto& audiofile : sample.audiofiles) { - DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare.wav"), audiofile.second->filename); - switch(audiofile.second->filechannel) - { - // NOTE: Channel numbers are zero based - they are 1 based in the xml - case 0: - DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), - audiofile.second->instrument_channel->name); - break; - case 1: - DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), - audiofile.second->instrument_channel->name); - break; - case 11: - DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), - audiofile.second->instrument_channel->name); - break; - case 12: - DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), - audiofile.second->instrument_channel->name); - break; - default: - DGUNIT_ASSERT(false); - break; - } + const auto& sample = *instrument.samplelist[1]; + DGUNIT_ASSERT_EQUAL(std::string("Snare-2"), sample.name); + DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size()); + auto afile = sample.audiofiles.begin(); + DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare-1.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), afile->second->instrument_channel->name); + ++afile; + DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare-2.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), afile->second->instrument_channel->name); + ++afile; + DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare-3.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), afile->second->instrument_channel->name); + ++afile; + DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare-4.wav"), afile->second->filename); + DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), afile->second->instrument_channel->name); } - } + + DGUNIT_ASSERT_EQUAL(std::size_t(4), instrument.samples.values.size()); + auto value = instrument.samples.values.begin(); + DGUNIT_ASSERT_EQUAL(0.0, value->first.first); // lower + DGUNIT_ASSERT_EQUAL(0.6, value->first.second); // upper + DGUNIT_ASSERT_EQUAL(std::string("Snare-1"), value->second->name); + ++value; + DGUNIT_ASSERT_EQUAL(0.0, value->first.first); // lower + DGUNIT_ASSERT_EQUAL(0.6, value->first.second); // upper + DGUNIT_ASSERT_EQUAL(std::string("Snare-2"), value->second->name); + ++value; + DGUNIT_ASSERT_EQUAL(0.6, value->first.first); // lower + DGUNIT_ASSERT_EQUAL(1.0, value->first.second); // upper + DGUNIT_ASSERT_EQUAL(std::string("Snare-2"), value->second->name); + ++value; + DGUNIT_ASSERT_EQUAL(0.6, value->first.first); // lower + DGUNIT_ASSERT_EQUAL(1.0, value->first.second); // upper + DGUNIT_ASSERT_EQUAL(std::string("Snare-1"), value->second->name); } } }; |