From: <man...@us...> - 2015-06-02 10:21:47
|
Revision: 5233 http://sourceforge.net/p/modplug/code/5233 Author: manxorist Date: 2015-06-02 10:21:40 +0000 (Tue, 02 Jun 2015) Log Message: ----------- [Ref] Tuning: The one single builtin tuning (standard 12TET) can easily be created from scratch using the CTuning interface. There is no need to load it from a resource or bin2h data. Additionally, there is no global tuning dialog in OpenMPT which means that tuning data can only ever be viewed/accessed via an open module, which makes it easy to move the one builtin tuning from global data to CSoundFile member data (i.e. the very same thing libopenmpt has always done). The memory overhead and construction cost is negligable compared to CSoundFile as a whole, thus, in order to keep things simple, the tuning is always contructed (as in libopenmpt) even if only strictly required for MPTM files. The created builtin tuning is verified to be identical to the old serialized data via a test cast. This is a small first step towards converting the custom tuning handling to the same style as patterns, samples and instruments are handled (i.e. strictly per module, in order to make modules easily portable). There are no user visible changes. Modified Paths: -------------- trunk/OpenMPT/build/autotools/Makefile.am trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/mptrack/resource.h trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/test/test.cpp Removed Paths: ------------- trunk/OpenMPT/soundlib/Tunings/ Modified: trunk/OpenMPT/build/autotools/Makefile.am =================================================================== --- trunk/OpenMPT/build/autotools/Makefile.am 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/build/autotools/Makefile.am 2015-06-02 10:21:40 UTC (rev 5233) @@ -224,7 +224,6 @@ libopenmpt_la_SOURCES += soundlib/XMTools.cpp libopenmpt_la_SOURCES += soundlib/XMTools.h libopenmpt_la_SOURCES += soundlib/plugins/PlugInterface.h -libopenmpt_la_SOURCES += soundlib/Tunings/built-inTunings.h libopenmpt_la_SOURCES += libopenmpt/libopenmpt_c.cpp libopenmpt_la_SOURCES += libopenmpt/libopenmpt_cxx.cpp libopenmpt_la_SOURCES += libopenmpt/libopenmpt_ext.cpp @@ -427,7 +426,6 @@ libopenmpttest_SOURCES += soundlib/XMTools.cpp libopenmpttest_SOURCES += soundlib/XMTools.h libopenmpttest_SOURCES += soundlib/plugins/PlugInterface.h -libopenmpttest_SOURCES += soundlib/Tunings/built-inTunings.h libopenmpttest_SOURCES += libopenmpt/libopenmpt_c.cpp libopenmpttest_SOURCES += libopenmpt/libopenmpt_cxx.cpp libopenmpttest_SOURCES += libopenmpt/libopenmpt_ext.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2015-06-02 10:21:40 UTC (rev 5233) @@ -2549,11 +2549,11 @@ sel -= 1; CTuningCollection* tc = 0; - if(sel < CSoundFile::GetBuiltInTunings().GetNumTunings()) - tc = &CSoundFile::GetBuiltInTunings(); + if(sel < m_sndFile.GetBuiltInTunings().GetNumTunings()) + tc = &m_sndFile.GetBuiltInTunings(); else { - sel -= CSoundFile::GetBuiltInTunings().GetNumTunings(); + sel -= m_sndFile.GetBuiltInTunings().GetNumTunings(); if(sel < CSoundFile::GetLocalTunings().GetNumTunings()) tc = &CSoundFile::GetLocalTunings(); else @@ -2613,9 +2613,9 @@ return; } - for(size_t i = 0; i < CSoundFile::GetBuiltInTunings().GetNumTunings(); i++) + for(size_t i = 0; i < m_sndFile.GetBuiltInTunings().GetNumTunings(); i++) { - if(pIns->pTuning == &CSoundFile::GetBuiltInTunings().GetTuning(i)) + if(pIns->pTuning == &m_sndFile.GetBuiltInTunings().GetTuning(i)) { m_ComboTuning.SetCurSel((int)(i + 1)); return; @@ -2626,7 +2626,7 @@ { if(pIns->pTuning == &CSoundFile::GetLocalTunings().GetTuning(i)) { - m_ComboTuning.SetCurSel((int)(i + CSoundFile::GetBuiltInTunings().GetNumTunings() + 1)); + m_ComboTuning.SetCurSel((int)(i + m_sndFile.GetBuiltInTunings().GetNumTunings() + 1)); return; } } @@ -2635,7 +2635,7 @@ { if(pIns->pTuning == &m_sndFile.GetTuneSpecificTunings().GetTuning(i)) { - m_ComboTuning.SetCurSel((int)(i + CSoundFile::GetBuiltInTunings().GetNumTunings() + CSoundFile::GetLocalTunings().GetNumTunings() + 1)); + m_ComboTuning.SetCurSel((int)(i + m_sndFile.GetBuiltInTunings().GetNumTunings() + CSoundFile::GetLocalTunings().GetNumTunings() + 1)); return; } } @@ -2829,9 +2829,9 @@ m_ComboTuning.ResetContent(); m_ComboTuning.AddString("OMPT IT behavior"); //<-> Instrument pTuning pointer == NULL - for(size_t i = 0; i<CSoundFile::GetBuiltInTunings().GetNumTunings(); i++) + for(size_t i = 0; i<m_sndFile.GetBuiltInTunings().GetNumTunings(); i++) { - m_ComboTuning.AddString(CSoundFile::GetBuiltInTunings().GetTuning(i).GetName().c_str()); + m_ComboTuning.AddString(m_sndFile.GetBuiltInTunings().GetTuning(i).GetName().c_str()); } for(size_t i = 0; i<CSoundFile::GetLocalTunings().GetNumTunings(); i++) { Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/mptrack/mptrack.rc 2015-06-02 10:21:40 UTC (rev 5233) @@ -2909,12 +2909,6 @@ IDR_DEFAULT_KEYBINDINGS KEYBINDINGS "res\\defaultKeybindings.mkb" -///////////////////////////////////////////////////////////////////////////// -// -// TUNING -// - -IDR_BUILTIN_TUNINGS TUNING "..\\soundlib\\Tunings\\built-inTunings.tc" #endif // English (United Kingdom) resources ///////////////////////////////////////////////////////////////////////////// Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2015-06-02 10:21:40 UTC (rev 5233) @@ -1130,7 +1130,6 @@ <ClInclude Include="WelcomeDialog.h" /> </ItemGroup> <ItemGroup> - <None Include="..\soundlib\Tunings\built-inTunings.tc" /> <None Include="res\bitmap1.bmp" /> <None Include="res\colors.bmp" /> <None Include="res\dragging.cur" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2015-06-02 10:21:40 UTC (rev 5233) @@ -1169,9 +1169,6 @@ <None Include="res\vispcnode.bmp"> <Filter>Resource Files</Filter> </None> - <None Include="..\soundlib\Tunings\built-inTunings.tc"> - <Filter>Resource Files</Filter> - </None> <None Include="res\envelope_toolbar.png"> <Filter>Resource Files</Filter> </None> Modified: trunk/OpenMPT/mptrack/resource.h =================================================================== --- trunk/OpenMPT/mptrack/resource.h 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/mptrack/resource.h 2015-06-02 10:21:40 UTC (rev 5233) @@ -114,7 +114,6 @@ #define IDD_MSGBOX_HIDABLE 516 #define IDD_ADDSILENCE 517 #define IDR_DEFAULT_KEYBINDINGS 519 -#define IDR_BUILTIN_TUNINGS 520 #define IDD_CLEANUP_SONG 521 #define IDD_CHANNELSETTINGS 522 #define IDD_KEYBOARD_SPLIT 523 Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2015-06-02 10:21:40 UTC (rev 5233) @@ -67,7 +67,6 @@ // CSoundFile #ifdef MODPLUG_TRACKER -CTuningCollection* CSoundFile::s_pTuningsSharedBuiltIn(0); CTuningCollection* CSoundFile::s_pTuningsSharedLocal(0); #endif @@ -134,10 +133,7 @@ m_PlayState.m_lTotalSampleCount = 0; m_PlayState.m_bPositionChanged = true; -#ifndef MODPLUG_TRACKER - m_pTuningsBuiltIn = new CTuningCollection(); LoadBuiltInTunings(); -#endif m_pTuningsTuneSpecific = new CTuningCollection("Tune specific tunings"); } @@ -148,10 +144,7 @@ Destroy(); delete m_pTuningsTuneSpecific; m_pTuningsTuneSpecific = nullptr; -#ifndef MODPLUG_TRACKER - delete m_pTuningsBuiltIn; - m_pTuningsBuiltIn = nullptr; -#endif + UnloadBuiltInTunings(); } @@ -1126,7 +1119,6 @@ //--------------------------------- { delete s_pTuningsSharedLocal; s_pTuningsSharedLocal = nullptr; - delete s_pTuningsSharedBuiltIn; s_pTuningsSharedBuiltIn = nullptr; } #endif @@ -1149,32 +1141,12 @@ bool CSoundFile::LoadStaticTunings() //---------------------------------- { - if(s_pTuningsSharedLocal || s_pTuningsSharedBuiltIn) return true; + if(s_pTuningsSharedLocal) return true; //For now not allowing to reload tunings(one should be careful when reloading them //since various parts may use addresses of the tuningobjects). - s_pTuningsSharedBuiltIn = new CTuningCollection; s_pTuningsSharedLocal = new CTuningCollection("Local tunings"); - // Load built-in tunings. - const char* pData = nullptr; - HGLOBAL hglob = nullptr; - size_t nSize = 0; - if (LoadResource(MAKEINTRESOURCE(IDR_BUILTIN_TUNINGS), TEXT("TUNING"), pData, nSize, hglob) != nullptr) - { - std::istringstream iStrm(std::string(pData, nSize)); - s_pTuningsSharedBuiltIn->Deserialize(iStrm); - } - if(s_pTuningsSharedBuiltIn->GetNumTunings() == 0) - { - MPT_ASSERT(false); - CTuningRTI* pT = new CTuningRTI; - //Note: Tuning collection class handles deleting. - pT->CreateGeometric(1,1); - if(s_pTuningsSharedBuiltIn->AddTuning(pT)) - delete pT; - } - // Load local tunings. s_pTuningsSharedLocal->SetSavefilePath( TrackerSettings::Instance().PathTunings.GetDefaultDir() @@ -1183,28 +1155,37 @@ ); s_pTuningsSharedLocal->Deserialize(); - // Enabling adding/removing of tunings for standard collection - // only for debug builds. - #ifdef DEBUG - s_pTuningsSharedBuiltIn->SetConstStatus(CTuningCollection::EM_ALLOWALL); - #else - s_pTuningsSharedBuiltIn->SetConstStatus(CTuningCollection::EM_CONST); - #endif - return false; } -#else -#include "Tunings/built-inTunings.h" +#endif + + void CSoundFile::LoadBuiltInTunings() //----------------------------------- { - std::string data(built_inTunings_tc_data, built_inTunings_tc_data + built_inTunings_tc_size); - std::istringstream iStrm(data); - m_pTuningsBuiltIn->Deserialize(iStrm); + m_pTuningsBuiltIn = new CTuningCollection("Built-in tunings"); + CTuningRTI* pT = new CTuningRTI; + pT->SetName("12TET [[fs15 1.17.02.49]]"); + pT->CreateGeometric(12, 2); + pT->SetFineStepCount(15); + for(ModCommand::NOTE note = NOTE_MIDDLEC; note < NOTE_MIDDLEC + 12; ++note) + { + pT->SetNoteName(note - NOTE_MIDDLEC, GetNoteName(note).substr(0, 2)); + } + pT->SetEditMask(CTuningBase::EM_CONST_STRICT); + // Note: Tuning collection class handles deleting. + m_pTuningsBuiltIn->AddTuning(pT); } -#endif +void CSoundFile::UnloadBuiltInTunings() +//------------------------------------- +{ + delete m_pTuningsBuiltIn; + m_pTuningsBuiltIn = nullptr; +} + + std::string CSoundFile::GetNoteName(const ModCommand::NOTE note, const INSTRUMENTINDEX inst) const //------------------------------------------------------------------------------------------------ { Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/soundlib/Sndfile.h 2015-06-02 10:21:40 UTC (rev 5233) @@ -320,12 +320,11 @@ static bool LoadStaticTunings(); bool SaveStaticTunings(); static void DeleteStaticdata(); - static CTuningCollection& GetBuiltInTunings() {return *s_pTuningsSharedBuiltIn;} static CTuningCollection& GetLocalTunings() {return *s_pTuningsSharedLocal;} -#else +#endif void LoadBuiltInTunings(); + void UnloadBuiltInTunings(); CTuningCollection& GetBuiltInTunings() {return *m_pTuningsBuiltIn;} -#endif static CTuning *GetDefaultTuning() {return nullptr;} CTuningCollection& GetTuneSpecificTunings() {return *m_pTuningsTuneSpecific;} @@ -334,11 +333,9 @@ private: CTuningCollection* m_pTuningsTuneSpecific; #ifdef MODPLUG_TRACKER - static CTuningCollection* s_pTuningsSharedBuiltIn; static CTuningCollection* s_pTuningsSharedLocal; -#else +#endif CTuningCollection* m_pTuningsBuiltIn; -#endif //<--Tuning public: // get 'controllers' Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2015-06-02 08:57:02 UTC (rev 5232) +++ trunk/OpenMPT/test/test.cpp 2015-06-02 10:21:40 UTC (rev 5233) @@ -26,6 +26,8 @@ #include "../soundlib/MIDIMacros.h" #include "../soundlib/SampleFormatConverters.h" #include "../soundlib/ITCompression.h" +#include "../soundlib/tuningcollection.h" +#include "../soundlib/tuning.h" #ifdef MODPLUG_TRACKER #include "../mptrack/mptrack.h" #include "../mptrack/moddoc.h" @@ -75,6 +77,7 @@ static MPT_NOINLINE void TestMIDIEvents(); static MPT_NOINLINE void TestSampleConversion(); static MPT_NOINLINE void TestITCompression(); +static MPT_NOINLINE void TestTunings(); static MPT_NOINLINE void TestPCnoteSerialization(); static MPT_NOINLINE void TestLoadSaveFile(); @@ -138,6 +141,7 @@ DO_TEST(TestMIDIEvents); DO_TEST(TestSampleConversion); DO_TEST(TestITCompression); + DO_TEST(TestTunings); // slower tests, require opening a CModDoc DO_TEST(TestPCnoteSerialization); @@ -2108,6 +2112,110 @@ } + +static bool RatioEqual(CTuningBase::RATIOTYPE a, CTuningBase::RATIOTYPE b) +//------------------------------------------------------------------------ +{ + if(a == CTuningBase::RATIOTYPE(0) && b == CTuningBase::RATIOTYPE(0)) + { + return true; + } + if(a == CTuningBase::RATIOTYPE(0) || b == CTuningBase::RATIOTYPE(0)) + { + return false; + } + return (std::fabs(CTuningBase::RATIOTYPE(1) - (a/b)) < CTuningBase::RATIOTYPE(0.0001)); +} + + +static void CheckEualTuningCollections(const CTuningCollection &a, const CTuningCollection &b) +//-------------------------------------------------------------------------------------------- +{ + VERIFY_EQUAL(a.GetName(), b.GetName()); + VERIFY_EQUAL(a.GetNumTunings(), b.GetNumTunings()); + for(std::size_t tuning = 0; tuning < std::min(a.GetNumTunings(), b.GetNumTunings()); ++tuning) + { + VERIFY_EQUAL(a.GetTuning(tuning).GetName(), b.GetTuning(tuning).GetName()); + VERIFY_EQUAL(a.GetTuning(tuning).GetTuningType(), b.GetTuning(tuning).GetTuningType()); + VERIFY_EQUAL(a.GetTuning(tuning).GetGroupSize(), b.GetTuning(tuning).GetGroupSize()); + VERIFY_EQUAL(a.GetTuning(tuning).GetFineStepCount(), b.GetTuning(tuning).GetFineStepCount()); + VERIFY_EQUAL(RatioEqual(a.GetTuning(tuning).GetGroupRatio(), b.GetTuning(tuning).GetGroupRatio()), true); + VERIFY_EQUAL(a.GetTuning(tuning).GetValidityRange(), b.GetTuning(tuning).GetValidityRange()); + for(ModCommand::NOTE note = NOTE_MIN; note <= NOTE_MAX; ++note) + { + VERIFY_EQUAL(a.GetTuning(tuning).GetNoteName(note - NOTE_MIDDLEC), b.GetTuning(tuning).GetNoteName(note - NOTE_MIDDLEC)); + VERIFY_EQUAL(RatioEqual(a.GetTuning(tuning).GetRatio(note - NOTE_MIDDLEC), b.GetTuning(tuning).GetRatio(note - NOTE_MIDDLEC)), true); + } + } +} + + +static MPT_NOINLINE void TestTunings() +//------------------------------------ +{ + + // check that the generated builtin tunings match the old resource data + + CSoundFile *emptyFile = new CSoundFile(); + emptyFile->Create(FileReader()); + + static const size_t built_inTunings_tc_size = 244; + static const unsigned char built_inTunings_tc_data[244]= + { + 0x32,0x32,0x38,0x02,0x54,0x43,0x1F,0x08,0x00,0x01,0x0C, + 0x01,0x0D,0x00,0x9F,0x03,0x00,0x00,0x00,0x00,0x00,0x00, + 0x40,0x42,0x75,0x69,0x6C,0x74,0x2D,0x69,0x6E,0x20,0x74, + 0x75,0x6E,0x69,0x6E,0x67,0x73,0xFF,0xFF,0x32,0x32,0x38, + 0x09,0x43,0x54,0x42,0x32,0x34,0x34,0x52,0x54,0x49,0x1F, + 0x08,0x00,0x01,0x12,0x00,0x00,0x10,0x01,0x25,0x00,0x27, + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x31,0x32,0x54, + 0x45,0x54,0x20,0x5B,0x5B,0x66,0x73,0x31,0x35,0x20,0x31, + 0x2E,0x31,0x37,0x2E,0x30,0x32,0x2E,0x34,0x39,0x5D,0x5D, + 0x00,0x00,0x03,0x00,0x30,0x00,0x00,0x02,0x43,0x2D,0x01, + 0x00,0x02,0x43,0x23,0x02,0x00,0x02,0x44,0x2D,0x03,0x00, + 0x02,0x44,0x23,0x04,0x00,0x02,0x45,0x2D,0x05,0x00,0x02, + 0x46,0x2D,0x06,0x00,0x02,0x46,0x23,0x07,0x00,0x02,0x47, + 0x2D,0x08,0x00,0x02,0x47,0x23,0x09,0x00,0x02,0x41,0x2D, + 0x0A,0x00,0x02,0x41,0x23,0x0B,0x00,0x02,0x42,0x2D,0x0F, + 0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x0C,0x00,0x80,0x00, + 0xC0,0xFF,0x02,0x30,0x80,0x68,0x02,0x31,0xE8,0x08,0x02, + 0x32,0xF0,0x08,0x02,0x33,0xF8,0xF4,0x02,0x34,0xED,0x01, + 0x10,0x08,0x52,0x54,0x49,0x33,0xFD,0x01,0x10,0x08,0x52, + 0x54,0x49,0x32,0x0D,0x02,0x08,0x08,0x52,0x54,0x49,0x34, + 0x15,0x02,0x08,0x08,0x52,0x54,0x49,0x31,0x1D,0x02,0x08, + 0x02,0x30,0x58,0x44,0x02,0x31,0x9C,0x08,0x02,0x32,0xA4, + 0xF9,0x02 + }; + CTuningCollection *oldBuiltin = new CTuningCollection(); + std::string builtindata(built_inTunings_tc_data, built_inTunings_tc_data + built_inTunings_tc_size); + std::istringstream iStrm(builtindata); + oldBuiltin->Deserialize(iStrm); + + CheckEualTuningCollections(emptyFile->GetBuiltInTunings(), *oldBuiltin); + +#if MPT_COMPILER_MSVC + + // Test that the serialization exactly matches the old data. + // This depends on exactly identical floating point representations (and thus rounding), which is why we limit this test to MSVC. + + std::ostringstream stream; + stream.imbue(std::locale::classic()); + emptyFile->GetBuiltInTunings().Serialize(stream); + std::string str = stream.str(); + std::vector<char> data = std::vector<char>(str.data(), str.data() + str.size()); + + VERIFY_EQUAL(data, std::vector<char>(built_inTunings_tc_data, built_inTunings_tc_data + built_inTunings_tc_size)); + +#endif + + delete oldBuiltin; + + emptyFile->Destroy(); + delete emptyFile; +} + + + static double Rand01() {return rand() / double(RAND_MAX);} template <class T> T Rand(const T min, const T max) {return Util::Round<T>(min + Rand01() * (max - min));} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |