2012-10-08 00:32:12 -04:00
|
|
|
#include "MidnamTest.hpp"
|
|
|
|
|
|
|
|
#include <glibmm/fileutils.h>
|
2014-12-01 09:41:40 -05:00
|
|
|
#include <glibmm/miscutils.h>
|
2012-10-08 00:32:12 -04:00
|
|
|
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
#include "pbd/file_utils.h"
|
2012-10-08 23:13:38 -04:00
|
|
|
#include "pbd/compose.h"
|
2012-10-08 00:32:12 -04:00
|
|
|
#include "midi++/midnam_patch.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2014-12-01 09:41:40 -05:00
|
|
|
using namespace PBD;
|
2012-10-08 00:32:12 -04:00
|
|
|
using namespace MIDI::Name;
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MidnamTest );
|
|
|
|
|
2014-12-01 09:41:40 -05:00
|
|
|
PBD::Searchpath
|
|
|
|
test_search_path ()
|
|
|
|
{
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
2015-09-13 09:30:00 -04:00
|
|
|
if (!getenv("MIDIPP_TEST_PATH")) {
|
|
|
|
std::vector<std::string> path_tok;
|
|
|
|
path_tok.push_back (g_win32_get_package_installation_directory_of_module(NULL));
|
|
|
|
path_tok.push_back ("share");
|
|
|
|
path_tok.push_back ("ardour3");
|
|
|
|
path_tok.push_back ("patchfiles");
|
|
|
|
return Glib::build_filename (path_tok);
|
|
|
|
}
|
2014-12-01 09:41:40 -05:00
|
|
|
#endif
|
2015-09-13 09:30:00 -04:00
|
|
|
return Glib::getenv("MIDIPP_TEST_PATH");
|
2014-12-01 09:41:40 -05:00
|
|
|
}
|
2012-10-08 00:32:12 -04:00
|
|
|
|
2012-10-08 23:13:38 -04:00
|
|
|
void
|
|
|
|
MidnamTest::protools_patchfile_test()
|
|
|
|
{
|
2014-12-01 09:41:40 -05:00
|
|
|
std::string test_file_path;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(find_file (test_search_path (), "Roland_SC-88_Pro.midnam", test_file_path));
|
|
|
|
XMLTree xmldoc(test_file_path);
|
2012-10-08 00:32:12 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> result = xmldoc.find(
|
|
|
|
"//MIDINameDocument");
|
|
|
|
CPPUNIT_ASSERT(result->size() == 1);
|
|
|
|
|
|
|
|
result = xmldoc.find("//ChannelNameSet");
|
|
|
|
CPPUNIT_ASSERT(result->size() == 2);
|
|
|
|
|
2014-12-01 09:41:40 -05:00
|
|
|
MIDINameDocument doc(test_file_path);
|
2012-10-08 00:32:12 -04:00
|
|
|
CPPUNIT_ASSERT(doc.all_models().size() == 1);
|
|
|
|
CPPUNIT_ASSERT(doc.author().find("Mark of the Unicorn") == 0);
|
|
|
|
|
2013-01-20 13:23:42 -05:00
|
|
|
const string model = *doc.all_models().begin();
|
2012-10-08 00:32:12 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("SC-88 Pro"), model);
|
|
|
|
boost::shared_ptr<MasterDeviceNames> masterDeviceNames =
|
|
|
|
doc.master_device_names_by_model().find(model)->second;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("Roland"), masterDeviceNames->manufacturer());
|
|
|
|
|
|
|
|
string modename = masterDeviceNames->custom_device_mode_names().front();
|
2013-01-20 13:23:42 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("Default"), modename);
|
2012-10-08 00:32:12 -04:00
|
|
|
|
|
|
|
boost::shared_ptr<CustomDeviceMode> mode =
|
|
|
|
masterDeviceNames->custom_device_mode_by_name(modename);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(modename, mode->name());
|
|
|
|
|
|
|
|
string ns1 = string("Name Set 1");
|
|
|
|
string ns2 = string("Name Set 2");
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i <= 15; i++) {
|
|
|
|
if (i != 9)
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ns1,
|
|
|
|
mode->channel_name_set_name_by_channel(i));
|
|
|
|
else
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ns2,
|
|
|
|
mode->channel_name_set_name_by_channel(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<ChannelNameSet> nameSet1 =
|
2014-01-06 17:02:55 -05:00
|
|
|
masterDeviceNames->channel_name_set_by_channel(modename, 0);
|
2012-10-08 00:32:12 -04:00
|
|
|
boost::shared_ptr<ChannelNameSet> nameSet2 =
|
2014-01-06 17:02:55 -05:00
|
|
|
masterDeviceNames->channel_name_set_by_channel(modename, 9);
|
2012-10-08 00:32:12 -04:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ns1, nameSet1->name());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ns2, nameSet2->name());
|
|
|
|
|
|
|
|
const ChannelNameSet::PatchBanks& banks1 = nameSet1->patch_banks();
|
|
|
|
const ChannelNameSet::PatchBanks& banks2 = nameSet2->patch_banks();
|
|
|
|
CPPUNIT_ASSERT(banks1.size() == 16);
|
|
|
|
CPPUNIT_ASSERT(banks2.size() == 1);
|
|
|
|
|
|
|
|
boost::shared_ptr<PatchBank> bank = banks1.front();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("Piano"), bank->name());
|
2013-01-20 13:23:42 -05:00
|
|
|
const PatchNameList& plist1 = bank->patch_name_list();
|
2012-10-08 00:32:12 -04:00
|
|
|
CPPUNIT_ASSERT(plist1.size() == 110);
|
|
|
|
|
|
|
|
bank = banks2.front();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("Drum sets"), bank->name());
|
2013-01-20 03:56:00 -05:00
|
|
|
const PatchNameList& plist2 = bank->patch_name_list();
|
2012-10-08 00:32:12 -04:00
|
|
|
CPPUNIT_ASSERT(plist2.size() == 49);
|
|
|
|
}
|
|
|
|
|
2012-10-08 23:13:38 -04:00
|
|
|
void
|
|
|
|
MidnamTest::yamaha_PSRS900_patchfile_test()
|
|
|
|
{
|
2014-12-01 09:41:40 -05:00
|
|
|
std::string test_file_path;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(find_file (test_search_path (), "Yamaha_PSR-S900.midnam", test_file_path));
|
|
|
|
XMLTree xmldoc(test_file_path);
|
2012-10-08 23:13:38 -04:00
|
|
|
boost::shared_ptr<XMLSharedNodeList> result = xmldoc.find(
|
|
|
|
"//MIDINameDocument");
|
|
|
|
CPPUNIT_ASSERT(result->size() == 1);
|
|
|
|
|
|
|
|
result = xmldoc.find("//ChannelNameSet");
|
|
|
|
CPPUNIT_ASSERT(result->size() == 3);
|
|
|
|
|
2014-12-01 09:41:40 -05:00
|
|
|
MIDINameDocument doc(test_file_path);
|
2012-10-08 23:13:38 -04:00
|
|
|
CPPUNIT_ASSERT(doc.all_models().size() == 1);
|
|
|
|
CPPUNIT_ASSERT(doc.author().find("Hans Baier") == 0);
|
|
|
|
|
2013-01-20 13:23:42 -05:00
|
|
|
const string model = *doc.all_models().begin();
|
2012-10-08 23:13:38 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("PSR-S900"), model);
|
|
|
|
boost::shared_ptr<MasterDeviceNames> masterDeviceNames =
|
|
|
|
doc.master_device_names_by_model().find(model)->second;
|
2013-01-20 13:23:42 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(string("Yamaha"), masterDeviceNames->manufacturer());
|
2012-10-08 23:13:38 -04:00
|
|
|
|
|
|
|
const MasterDeviceNames::CustomDeviceModeNames& modes = masterDeviceNames->custom_device_mode_names();
|
|
|
|
CPPUNIT_ASSERT(masterDeviceNames->custom_device_mode_names().size() == 3);
|
|
|
|
|
|
|
|
string modename = modes.front();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("Standard"), modename);
|
|
|
|
|
|
|
|
modename = (*(++modes.begin()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("GM+XG"), modename);
|
|
|
|
|
|
|
|
modename = modes.back();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(string("GM2"), modename);
|
|
|
|
|
|
|
|
for (list<string>::const_iterator modename = modes.begin(); modename != modes.end(); ++modename) {
|
|
|
|
boost::shared_ptr<CustomDeviceMode> mode =
|
|
|
|
masterDeviceNames->custom_device_mode_by_name(*modename);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(*modename, mode->name());
|
|
|
|
|
|
|
|
string ns = mode->name();
|
|
|
|
|
|
|
|
if (ns != string("Standard"))
|
|
|
|
for (uint8_t i = 0; i <= 15; i++) {
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ns,
|
|
|
|
mode->channel_name_set_name_by_channel(i));
|
|
|
|
boost::shared_ptr<ChannelNameSet> nameSet =
|
2014-01-06 17:02:55 -05:00
|
|
|
masterDeviceNames->channel_name_set_by_channel(ns, 1);
|
2012-10-08 23:13:38 -04:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ns, nameSet->name());
|
|
|
|
|
|
|
|
const ChannelNameSet::PatchBanks& banks1 = nameSet->patch_banks();
|
|
|
|
CPPUNIT_ASSERT(banks1.size() > 1);
|
|
|
|
|
|
|
|
boost::shared_ptr<PatchBank> bank = banks1.front();
|
2013-01-20 03:56:00 -05:00
|
|
|
const PatchNameList& list = bank->patch_name_list();
|
2012-10-08 23:13:38 -04:00
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
for(PatchNameList::const_iterator p = list.begin(); p != list.end(); ++p) {
|
2012-10-08 23:13:38 -04:00
|
|
|
|
|
|
|
if (ns == string("GM+XG")) {
|
|
|
|
uint8_t msb = (((*p)->bank_number()) >> 7) & 0x7f;
|
|
|
|
CPPUNIT_ASSERT( msb == 0 || msb == 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ns == string("GM2")) {
|
|
|
|
CPPUNIT_ASSERT((*p)->bank_number() >= (uint16_t(120) << 7));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 15:11:15 -04:00
|
|
|
void
|
2012-10-08 23:13:38 -04:00
|
|
|
MidnamTest::load_all_midnams_test ()
|
2012-10-08 00:32:12 -04:00
|
|
|
{
|
|
|
|
vector<std::string> result;
|
|
|
|
|
2014-12-01 09:41:40 -05:00
|
|
|
PBD::find_files_matching_pattern (result, test_search_path (), "*.midnam");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!result.empty());
|
2012-10-08 00:32:12 -04:00
|
|
|
|
2014-12-01 09:41:40 -05:00
|
|
|
cout << "Loading " << result.size() << " MIDI patches from " << test_search_path ().to_string () << endl;
|
2012-10-08 00:32:12 -04:00
|
|
|
|
|
|
|
for (vector<std::string>::iterator i = result.begin(); i != result.end(); ++i) {
|
2014-12-06 17:51:33 -05:00
|
|
|
cout << "Processing file " << Glib::path_get_basename(*i) << endl;
|
2012-10-08 00:32:12 -04:00
|
|
|
boost::shared_ptr<MIDINameDocument> document(new MIDINameDocument(*i));
|
|
|
|
|
|
|
|
XMLTree xmldoc(*i);
|
|
|
|
boost::shared_ptr<XMLSharedNodeList> result = xmldoc.find("//MIDINameDocument");
|
|
|
|
CPPUNIT_ASSERT(result->size() == 1);
|
|
|
|
|
|
|
|
result = xmldoc.find("//MasterDeviceNames");
|
|
|
|
CPPUNIT_ASSERT(result->size() == 1);
|
|
|
|
|
|
|
|
result = xmldoc.find("//PatchBank");
|
2012-10-08 23:13:38 -04:00
|
|
|
//int banks = result->size();
|
2012-10-08 00:32:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
result = xmldoc.find("//CustomDeviceMode[1]");
|
|
|
|
string deviceModeName = result->front()->property("Name")->value();
|
|
|
|
|
|
|
|
MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
|
|
|
document->master_device_names_by_model().begin();
|
|
|
|
|
|
|
|
string modename = device->second->custom_device_mode_names().front();
|
|
|
|
boost::shared_ptr<CustomDeviceMode> mode = device->second->custom_device_mode_by_name(modename);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(deviceModeName, mode->name());
|
|
|
|
|
2014-01-06 17:02:55 -05:00
|
|
|
boost::shared_ptr<ChannelNameSet> nameSet = device->second->channel_name_set_by_channel(modename, 0);
|
2012-10-08 00:32:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|