From: <sag...@us...> - 2011-05-26 18:25:47
|
Revision: 881 http://modplug.svn.sourceforge.net/modplug/?rev=881&view=rev Author: saga-games Date: 2011-05-26 18:25:41 +0000 (Thu, 26 May 2011) Log Message: ----------- [Imp] Hack Detection: Envelopes with points that share the same tick are now found. [Ref] Minor refactoring Modified Paths: -------------- trunk/OpenMPT/mptrack/Draw_pat.cpp trunk/OpenMPT/mptrack/MPTHacks.cpp Modified: trunk/OpenMPT/mptrack/Draw_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/Draw_pat.cpp 2011-05-23 21:32:39 UTC (rev 880) +++ trunk/OpenMPT/mptrack/Draw_pat.cpp 2011-05-26 18:25:41 UTC (rev 881) @@ -698,7 +698,7 @@ BOOL bPlaying, UINT yofs, UINT nrows, UINT xofs, CRect &rcClient, int *pypaint) //----------------------------------------------------------------------------------------------------- { - BYTE bColSel[MAX_CHANNELS]; + BYTE bColSel[MAX_BASECHANNELS]; PCPATTERNFONT pfnt = GetCurrentPatternFont(); MODCOMMAND m0, *pPattern = pSndFile->Patterns[nPattern]; CHAR s[256]; @@ -707,7 +707,7 @@ int row_col, row_bkcol; UINT bRowSel, bSpeedUp, nColumnWidth, ncols, maxcol; - ncols = pSndFile->m_nChannels; + ncols = pSndFile->GetNumChannels(); m0.note = m0.instr = m0.vol = m0.volcmd = m0.command = m0.param = 0; nColumnWidth = m_szCell.cx; rect.SetRect(m_szHeader.cx, rcClient.top, m_szHeader.cx+nColumnWidth, rcClient.bottom); @@ -731,7 +731,7 @@ while ((maxcol > xofs) && (bColSel[maxcol-1] & 0x80)) maxcol--; // Init bitmap border { - UINT maxndx = pSndFile->m_nChannels * m_szCell.cx; + UINT maxndx = pSndFile->GetNumChannels() * m_szCell.cx; UINT ibmp = 0; if (maxndx > FASTBMP_MAXWIDTH) maxndx = FASTBMP_MAXWIDTH; do Modified: trunk/OpenMPT/mptrack/MPTHacks.cpp =================================================================== --- trunk/OpenMPT/mptrack/MPTHacks.cpp 2011-05-23 21:32:39 UTC (rev 880) +++ trunk/OpenMPT/mptrack/MPTHacks.cpp 2011-05-26 18:25:41 UTC (rev 881) @@ -84,6 +84,27 @@ bool *foundHacks; }; + +// Find and fix envelopes where two nodes are on the same tick. +bool FindIncompatibleEnvelopes(INSTRUMENTENVELOPE &env, bool autofix) +//------------------------------------------------------------------- +{ + bool found = false; + for(UINT i = 1; i < env.nNodes; i++) + { + if(env.Ticks[i] <= env.Ticks[i - 1]) // "<=" so we can fix envelopes "on the fly" + { + found = true; + if(autofix) + { + env.Ticks[i] = env.Ticks[i - 1] + 1; + } + } + } + return found; +} + + // Go through the module to find out if it contains any hacks introduced by (Open)MPT bool CModDoc::HasMPTHacks(const bool autofix) //------------------------------------------- @@ -139,12 +160,29 @@ { if(m_SndFile.Patterns.IsValidPat(i)) { - if(m_SndFile.Patterns[i].GetNumRows() > originalSpecs->patternRowsMax || m_SndFile.Patterns[i].GetNumRows() < originalSpecs->patternRowsMin) + const ROWINDEX patSize = m_SndFile.Patterns[i].GetNumRows(); + if(patSize > originalSpecs->patternRowsMax) { foundHacks = foundHere = true; - break; + if(autofix) + { + // REQUIRES (INTELLIGENT) AUTOFIX + } else + { + break; + } + } else if(patSize < originalSpecs->patternRowsMin) + { + foundHacks = foundHere = true; + if(autofix) + { + m_SndFile.Patterns[i].Resize(originalSpecs->patternRowsMin); + m_SndFile.TryWriteEffect(i, patSize - 1, CMD_PATTERNBREAK, 0, false, CHANNELINDEX_INVALID, false, weTryNextRow); + } else + { + break; + } } - // REQUIRES (INTELLIGENT) AUTOFIX } } if(foundHere) @@ -182,7 +220,13 @@ message.Format("Found incompatible channel count (must be between %d and %d channels)\n", originalSpecs->channelsMin, originalSpecs->channelsMax); AddToLog(message); foundHacks = true; - // REQUIRES (INTELLIGENT) AUTOFIX + if(autofix) + { + vector<bool> usedChannels; + CheckUsedChannels(usedChannels); + RemoveChannels(usedChannels); + // REQUIRES (INTELLIGENT) AUTOFIX + } } // Check for channel names @@ -221,11 +265,13 @@ // Check for instrument extensions foundHere = false; + bool foundEnvelopes = false; for(INSTRUMENTINDEX i = 1; i <= m_SndFile.GetNumInstruments(); i++) { MODINSTRUMENT *instr = m_SndFile.Instruments[i]; if(instr == nullptr) continue; + // Extended instrument attributes if(instr->nFilterMode != FLTMODE_UNCHANGED || instr->nVolRamp != 0 || instr->nResampling != SRCMODE_DEFAULT || instr->nCutSwing != 0 || instr->nResSwing != 0 || instr->nMixPlug != 0 || instr->wPitchToTempoLock != 0 || instr->nDCT == DCT_PLUGIN || @@ -248,10 +294,16 @@ instr->VolEnv.nReleaseNode = instr->PanEnv.nReleaseNode = instr->PitchEnv.nReleaseNode = ENV_RELEASE_NODE_UNSET; } } - + // Incompatible envelope shape + foundEnvelopes |= FindIncompatibleEnvelopes(instr->VolEnv, autofix); + foundEnvelopes |= FindIncompatibleEnvelopes(instr->PanEnv, autofix); + foundEnvelopes |= FindIncompatibleEnvelopes(instr->PitchEnv, autofix); + foundHacks |= foundEnvelopes; } if(foundHere) AddToLog("Found MPT instrument extensions\n"); + if(foundEnvelopes) + AddToLog("Two envelope points may not share the same tick.\n"); // Check for too many orders if(m_SndFile.Order.GetLengthTailTrimmed() > originalSpecs->ordersMax) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |