From: <sag...@us...> - 2011-12-10 18:53:53
|
Revision: 1146 http://modplug.svn.sourceforge.net/modplug/?rev=1146&view=rev Author: saga-games Date: 2011-12-10 18:53:45 +0000 (Sat, 10 Dec 2011) Log Message: ----------- [Ref] Various small rewrites. [Mod] OpenMPT: Version is now 1.20.00.57 Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_seq.cpp trunk/OpenMPT/mptrack/ModConvert.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/version.h trunk/OpenMPT/soundlib/Dlsbank.cpp trunk/OpenMPT/soundlib/Load_imf.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_mdl.cpp trunk/OpenMPT/soundlib/Load_mod.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/PlaybackEventer.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -382,7 +382,7 @@ { bool bModified = false; BYTE n = pIns->NoteMap[m_nNote]; - for (NOTEINDEXTYPE i = 0; i < NOTE_MAX; i++) if (pIns->NoteMap[i] != n) + for (NOTEINDEXTYPE i = 0; i < CountOf(pIns->NoteMap); i++) if (pIns->NoteMap[i] != n) { pIns->NoteMap[i] = n; bModified = true; @@ -408,7 +408,7 @@ { bool bModified = false; SAMPLEINDEX n = pIns->Keyboard[m_nNote]; - for (NOTEINDEXTYPE i = 0; i < NOTE_MAX; i++) if (pIns->Keyboard[i] != n) + for (NOTEINDEXTYPE i = 0; i < CountOf(pIns->Keyboard); i++) if (pIns->Keyboard[i] != n) { pIns->Keyboard[i] = n; bModified = true; @@ -435,7 +435,7 @@ if (pIns) { bool bModified = false; - for (NOTEINDEXTYPE i = 0; i < NOTE_MAX; i++) if (pIns->NoteMap[i] != i + 1) + for (NOTEINDEXTYPE i = 0; i < CountOf(pIns->NoteMap); i++) if (pIns->NoteMap[i] != i + 1) { pIns->NoteMap[i] = i + 1; bModified = true; Modified: trunk/OpenMPT/mptrack/Ctrl_seq.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -902,8 +902,10 @@ { CRect rect; GetClientRect(&rect); - bool bSelection = IsSelectionKeyPressed(); + // Copy or move orders? + const bool copyOrders = IsSelectionKeyPressed(); + if (m_bDragging) { m_bDragging = false; @@ -916,46 +918,47 @@ // drag multiple orders (not quite as easy...) ORD_SELECTION selection = GetCurSel(false); // move how many orders from where? - ORDERINDEX nMoveCount = (selection.nOrdHi - selection.nOrdLo), nMovePos = selection.nOrdLo; + ORDERINDEX moveCount = (selection.nOrdHi - selection.nOrdLo), nMovePos = selection.nOrdLo; // drop before or after the selection - bool bMoveBack = !(m_nDragOrder < (UINT)m_nDropPos); + bool moveBack = !(m_nDragOrder < m_nDropPos); // don't do anything if drop position is inside the selection if((m_nDropPos >= selection.nOrdLo && m_nDropPos <= selection.nOrdHi) || m_nDragOrder == m_nDropPos) return; // drag one order or multiple orders? - bool bMultiSelection = (selection.nOrdLo != selection.nOrdHi); + bool multiSelection = (selection.nOrdLo != selection.nOrdHi); - for(int i = 0; i <= nMoveCount; i++) + for(int i = 0; i <= moveCount; i++) { - if(!m_pModDoc->MoveOrder(nMovePos, m_nDropPos, true, bSelection)) return; - if((bMoveBack ^ bSelection) == true && bMultiSelection) + if(!m_pModDoc->MoveOrder(nMovePos, m_nDropPos, true, copyOrders)) return; + if((moveBack ^ copyOrders) == true && multiSelection) { nMovePos++; m_nDropPos++; } - if(bMoveBack && bSelection && bMultiSelection) { + if(moveBack && copyOrders && multiSelection) + { nMovePos += 2; m_nDropPos++; } } - if(bMultiSelection) + + if(multiSelection) { // adjust selection m_nScrollPos2nd = m_nDropPos - 1; - m_nDropPos -= nMoveCount + (bMoveBack ? 0 : 1); - SetCurSel((bMoveBack && (!bSelection)) ? m_nDropPos - 1 : m_nDropPos); + m_nDropPos -= moveCount + (moveBack ? 0 : 1); + SetCurSel((moveBack && !copyOrders) ? m_nDropPos - 1 : m_nDropPos); } else { - SetCurSel(((m_nDragOrder < m_nDropPos) && (!bSelection)) ? m_nDropPos - 1 : m_nDropPos); + SetCurSel((m_nDragOrder < m_nDropPos && !copyOrders) ? m_nDropPos - 1 : m_nDropPos); } m_pModDoc->SetModified(); - } - else + } else { ORDERINDEX nOrder = GetOrderFromPoint(rect, pt); ORD_SELECTION selection = GetCurSel(false); // this should actually have equal signs but that breaks multiselect: nOrder >= selection.nOrdLo && nOrder <= section.nOrdHi - if (pt.y < rect.bottom && m_nScrollPos2nd != ORDERINDEX_INVALID && nOrder > selection.nOrdLo && nOrder < selection.nOrdHi) + if(pt.y < rect.bottom && m_nScrollPos2nd != ORDERINDEX_INVALID && nOrder > selection.nOrdLo && nOrder < selection.nOrdHi) { // Remove selection if we didn't drag anything but multiselect was active m_nScrollPos2nd = ORDERINDEX_INVALID; Modified: trunk/OpenMPT/mptrack/ModConvert.cpp =================================================================== --- trunk/OpenMPT/mptrack/ModConvert.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/mptrack/ModConvert.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -312,7 +312,7 @@ { for (size_t i = 0; i < CountOf(pIns->NoteMap); i++) { - if ((pIns->NoteMap[i]) && (pIns->NoteMap[i] != (BYTE)(i + 1))) + if (pIns->NoteMap[i] && pIns->NoteMap[i] != static_cast<BYTE>(i + 1)) { CHANGEMODTYPE_WARNING(wBrokenNoteMap); break; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -2163,14 +2163,15 @@ { RelativePathToAbsolute(s); - if(failedPlugin.Compare(s) != 0) + if(!failedPlugin.Compare(s)) { - m_pPluginManager->AddPlugin(s, TRUE, true, &nonFoundPlugs); - } else - { - const CString text = "The following plugin has previously crashed OpenMPT during initialisation and will thus not be loaded:\n\n" + failedPlugin; - Reporting::Information(text); + const CString text = "The following plugin has previously crashed OpenMPT during initialisation:\n\n" + failedPlugin + "\n\nDo you still want to load it?"; + if(Reporting::Confirm(text, false, true) == cnfNo) + { + continue; + } } + m_pPluginManager->AddPlugin(s, TRUE, true, &nonFoundPlugs); } } if(nonFoundPlugs.GetLength() > 0) @@ -2458,6 +2459,7 @@ } void CTrackApp::RemoveMruItem(const int nItem) +//-------------------------------------------- { if (m_pRecentFileList && nItem >= 0 && nItem < m_pRecentFileList->GetSize()) m_pRecentFileList->Remove(nItem); Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -1693,7 +1693,6 @@ if (minParam == 0 && maxParam == 0) { - minParam = 0; maxParam = m_pEffect->numParams; } @@ -1986,11 +1985,14 @@ //reset some stuff m_MixState.nVolDecayL = 0; m_MixState.nVolDecayR = 0; - Dispatch(effStopProcess, 0, 0, NULL, 0.0f); - Dispatch(effMainsChanged, 0, 0, NULL, 0.0f); // calls plugin's suspend + if(m_bPlugResumed) + { + Dispatch(effStopProcess, 0, 0, NULL, 0.0f); + Dispatch(effMainsChanged, 0, 0, NULL, 0.0f); // calls plugin's suspend + } if (sampleRate != m_nSampleRate) { - m_nSampleRate=sampleRate; + m_nSampleRate = sampleRate; Dispatch(effSetSampleRate, 0, 0, NULL, static_cast<float>(m_nSampleRate)); } Dispatch(effSetBlockSize, 0, MIXBUFFERSIZE, NULL, 0); @@ -2014,7 +2016,7 @@ if(m_bPlugResumed) { Dispatch(effStopProcess, 0, 0, NULL, 0.0f); - Dispatch(effMainsChanged, 0, 0, NULL, 0.0f); // calls plugin's suspend + Dispatch(effMainsChanged, 0, 0, NULL, 0.0f); // calls plugin's suspend (theoretically, plugins should clean their buffers here, but oh well, the number of plugins which don't do this is surprisingly high.) m_bPlugResumed = false; } } catch (...) @@ -2139,6 +2141,8 @@ // SetEvent(processCalled); } + ASSERT(m_pTempBuffer != nullptr); + //mix outputs of multi-output VSTs: if(m_nOutputs>2) { @@ -2813,7 +2817,7 @@ && (Dispatch(effIdentify, 0,0, NULL, 0) == 'NvEf') && (m_pEffect->uniqueID != CCONST('S', 'y', 't', 'r'))) //special case: imageline sytrus pretends to support chunks but gives us garbage. { - PVOID p = NULL; + void *p = NULL; LONG nByteSize = 0; // Try to get whole bank @@ -2898,7 +2902,7 @@ if ((Dispatch(effIdentify, 0, nullptr, nullptr, 0) == 'NvEf') && (nType == 'NvEf')) { - PVOID p = NULL; + void *p = NULL; Dispatch(effGetChunk, 0,0, &p, 0); //init plug for chunk reception if ((nProgram>=0) && (nProgram < m_pEffect->numPrograms)) @@ -3765,7 +3769,7 @@ break; case effClose: - m_Effect.object = NULL; + m_Effect.object = nullptr; delete this; return 0; @@ -3854,7 +3858,7 @@ wfx.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; wfx.nChannels = 2; wfx.nSamplesPerSec = m_nSamplesPerSec; - wfx.wBitsPerSample = 32; + wfx.wBitsPerSample = sizeof(float) * 8; wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample >> 3); wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; wfx.cbSize = 0; @@ -3934,7 +3938,7 @@ fMax = 1; } fValue -= fMin; - if (fMax > fMin) fValue /= (fMax-fMin); + if (fMax > fMin) fValue /= (fMax - fMin); return fValue; } } @@ -3986,7 +3990,8 @@ WCHAR w[100]; CLSID clsid; - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pLib->szDllPath,-1,(LPWSTR)w,98); + MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pLib->szDllPath, -1, (LPWSTR)w, CountOf(w)); + w[99] = 0; if (CLSIDFromString(w, &clsid) == S_OK) { IMediaObject *pMO = NULL; @@ -3998,12 +4003,10 @@ if ((pMO) && (pMOIP)) { DWORD dwInputs, dwOutputs; - BOOL bError; dwInputs = dwOutputs = 0; pMO->GetStreamCount(&dwInputs, &dwOutputs); - bError = ((dwInputs == 1) && (dwOutputs == 1)) ? FALSE : TRUE; - if (!bError) + if (dwInputs == 1 && dwOutputs == 1) { CDmo2Vst *p = new CDmo2Vst(pMO, pMOIP, clsid.Data1); return (p) ? p->GetEffect() : NULL; Modified: trunk/OpenMPT/mptrack/version.h =================================================================== --- trunk/OpenMPT/mptrack/version.h 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/mptrack/version.h 2011-12-10 18:53:45 UTC (rev 1146) @@ -15,7 +15,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 20 #define VER_MINOR 00 -#define VER_MINORMINOR 56 +#define VER_MINORMINOR 57 //Creates version number from version parts that appears in version string. //For example MAKE_VERSION_NUMERIC(1,17,02,28) gives version number of Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -1683,10 +1683,9 @@ int nTranspose = 0; for (UINT iNoteMap=0; iNoteMap<NOTE_MAX; iNoteMap++) { - pIns->NoteMap[iNoteMap] = (BYTE)(iNoteMap+1); if (pDlsIns->ulBank & F_INSTRUMENT_DRUMS) { - if (pSndFile->m_nType & (MOD_TYPE_IT|MOD_TYPE_MID|MOD_TYPE_MPT)) + if (pSndFile->GetType() & (MOD_TYPE_IT|MOD_TYPE_MID|MOD_TYPE_MPT)) { if (iNoteMap < pDlsIns->Regions[nDrumRgn].uKeyMin) pIns->NoteMap[iNoteMap] = (BYTE)(pDlsIns->Regions[nDrumRgn].uKeyMin + 1); if (iNoteMap > pDlsIns->Regions[nDrumRgn].uKeyMax) pIns->NoteMap[iNoteMap] = (BYTE)(pDlsIns->Regions[nDrumRgn].uKeyMax + 1); Modified: trunk/OpenMPT/soundlib/Load_imf.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_imf.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Load_imf.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -38,7 +38,7 @@ uint8 unused2[8]; char im10[4]; // 'IM10' IMFCHANNEL channels[32]; // Channel settings - uint8 orderlist[256]; // Order list (0xff = +++; blank out anything beyond ordnum) + uint8 orderlist[256]; // Order list (0xFF = +++; blank out anything beyond ordnum) }; enum @@ -80,9 +80,9 @@ { char filename[13]; // Sample filename (12345678.ABC) */ uint8 unused1[3]; - uint32 length; // Length - uint32 loop_start; // Loop start - uint32 loop_end; // Loop end + uint32 length; // Length (in bytes) + uint32 loop_start; // Loop start (in bytes) + uint32 loop_end; // Loop end (in bytes) uint32 C5Speed; // Samplerate uint8 volume; // Default volume (0...64) uint8 panning; // Default pan (0...255) @@ -152,27 +152,27 @@ // fix some of them switch (note->command) { - case 0xe: // fine volslide + case 0xE: // fine volslide // hackaround to get almost-right behavior for fine slides (i think!) - if (note->param == 0) + if(note->param == 0) /* nothing */; - else if (note->param == 0xf0) - note->param = 0xef; - else if (note->param == 0x0f) - note->param = 0xfe; - else if (note->param & 0xf0) - note->param |= 0xf; + else if(note->param == 0xF0) + note->param = 0xEF; + else if(note->param == 0x0F) + note->param = 0xFE; + else if(note->param & 0xF0) + note->param |= 0x0F; else - note->param |= 0xf0; + note->param |= 0xF0; break; - case 0xf: // set finetune + case 0xF: // set finetune // we don't implement this, but let's at least import the value note->param = 0x20 | min(note->param >> 4, 0xf); break; case 0x14: // fine slide up case 0x15: // fine slide down // this is about as close as we can do... - if (note->param >> 4) + if(note->param >> 4) note->param = 0xf0 | min(note->param >> 4, 0xf); else note->param |= 0xe0; @@ -180,7 +180,7 @@ case 0x16: // cutoff note->param >>= 1; break; - case 0x1f: // set global volume + case 0x1F: // set global volume note->param = min(note->param << 1, 0xff); break; case 0x21: @@ -194,7 +194,7 @@ break; default: // undefined case 0x1: // set filter - case 0xf: // invert loop + case 0xF: // invert loop note->command = CMD_NONE; break; case 0x3: // glissando @@ -206,17 +206,17 @@ case 0x8: // tremolo waveform n = 0x40; break; - case 0xa: // pattern loop - n = 0xb0; + case 0xA: // pattern loop + n = 0xB0; break; - case 0xb: // pattern delay - n = 0xe0; + case 0xB: // pattern delay + n = 0xE0; break; - case 0xc: // note cut - case 0xd: // note delay + case 0xC: // note cut + case 0xD: // note delay // no change break; - case 0xe: // ignore envelope + case 0xE: // ignore envelope /* predicament: we can only disable one envelope at a time. volume is probably most noticeable, so let's go with that. (... actually, orpheus doesn't even seem to implement this at all) */ @@ -224,16 +224,16 @@ break; case 0x18: // sample offset // O00 doesn't pick up the previous value - if (!note->param) + if(!note->param) note->command = CMD_NONE; break; } - if (n) - note->param = n | (note->param & 0xf); + if(n) + note->param = n | (note->param & 0x0F); break; } note->command = (note->command < CountOf(imfEffects)) ? imfEffects[note->command] : CMD_NONE; - if (note->command == CMD_VOLUME && note->volcmd == VOLCMD_NONE) + if(note->command == CMD_VOLUME && note->volcmd == VOLCMD_NONE) { note->volcmd = VOLCMD_VOLUME; note->vol = note->param; @@ -249,7 +249,8 @@ const int shift = (e == IMF_ENV_VOL) ? 0 : 2; env->dwFlags = ((imfins->env[e].flags & 1) ? ENV_ENABLED : 0) | ((imfins->env[e].flags & 2) ? ENV_SUSTAIN : 0) | ((imfins->env[e].flags & 4) ? ENV_LOOP : 0); - env->nNodes = CLAMP(imfins->env[e].points, 2, 25); + env->nNodes = imfins->env[e].points; + Limit(env->nNodes, 2u, 16u); env->nLoopStart = imfins->env[e].loop_start; env->nLoopEnd = imfins->env[e].loop_end; env->nSustainStart = env->nSustainEnd = imfins->env[e].sustain; @@ -269,12 +270,10 @@ //----------------------------------------------------------------------- { DWORD dwMemPos = 0; - IMFHEADER hdr; - MODSAMPLE *pSample = Samples + 1; - WORD firstsample = 1; // first pSample for the current instrument vector<bool> ignoreChannels(32, false); // bit set for each channel that's completely disabled ASSERT_CAN_READ(sizeof(IMFHEADER)); + IMFHEADER hdr; memcpy(&hdr, lpStream, sizeof(IMFHEADER)); dwMemPos = sizeof(IMFHEADER); @@ -290,11 +289,11 @@ SetModFlag(MSF_COMPATIBLE_PLAY, true); // song name - memset(m_szNames, 0, sizeof(m_szNames)); + MemsetZero(m_szNames); memcpy(m_szNames[0], hdr.title, 31); StringFixer::SpaceToNullStringFixed<31>(m_szNames[0]); - if (hdr.flags & 1) + if(hdr.flags & 1) m_dwSongFlags |= SONG_LINEARSLIDES; m_nDefaultSpeed = hdr.tempo; m_nDefaultTempo = hdr.bpm; @@ -335,29 +334,29 @@ if(!m_nChannels) return false; //From mikmod: work around an Orpheus bug - if (hdr.channels[0].status == 0) + if(hdr.channels[0].status == 0) { CHANNELINDEX nChn; for(nChn = 1; nChn < 16; nChn++) if(hdr.channels[nChn].status != 1) break; - if (nChn == 16) + if(nChn == 16) for(nChn = 1; nChn < 16; nChn++) ChnSettings[nChn].dwFlags &= ~CHN_MUTE; } Order.resize(hdr.ordnum); for(ORDERINDEX nOrd = 0; nOrd < hdr.ordnum; nOrd++) - Order[nOrd] = ((hdr.orderlist[nOrd] == 0xff) ? Order.GetIgnoreIndex() : (PATTERNINDEX)hdr.orderlist[nOrd]); + Order[nOrd] = ((hdr.orderlist[nOrd] == 0xFF) ? Order.GetIgnoreIndex() : (PATTERNINDEX)hdr.orderlist[nOrd]); // read patterns for(PATTERNINDEX nPat = 0; nPat < hdr.patnum; nPat++) { uint16 length, nrows; - BYTE mask, channel; + uint8 mask, channel; int row; unsigned int lostfx = 0; - MODCOMMAND *row_data, *note, junk_note; + MODCOMMAND *note, junk_note; ASSERT_CAN_READ(4); length = LittleEndianW(*((uint16 *)(lpStream + dwMemPos))); @@ -367,22 +366,19 @@ if(Patterns.Insert(nPat, nrows)) break; - row_data = Patterns[nPat]; - row = 0; while(row < nrows) { ASSERT_CAN_READ(1); - mask = *((BYTE *)(lpStream + dwMemPos)); + mask = *((uint8 *)(lpStream + dwMemPos)); dwMemPos += 1; - if (mask == 0) + if(mask == 0) { row++; - row_data += m_nChannels; continue; } - channel = mask & 0x1f; + channel = mask & 0x1F; if(ignoreChannels[channel]) { @@ -392,7 +388,7 @@ note = &junk_note; } else { - note = row_data + channel; + note = Patterns[nPat].GetpModCommand(row, channel); } if(mask & 0x20) @@ -403,15 +399,15 @@ note->instr = *((BYTE *)(lpStream + dwMemPos + 1)); dwMemPos += 2; - if (note->note == 160) + if(note->note == 160) { note->note = NOTE_KEYOFF; /* ??? */ - } else if (note->note == 255) + } else if(note->note == 255) { note->note = NOTE_NONE; /* ??? */ } else { - note->note = (note->note >> 4) * 12 + (note->note & 0xf) + 12 + 1; + note->note = (note->note >> 4) * 12 + (note->note & 0x0F) + 12 + 1; if(note->note > NOTE_MAX) { /*printf("%d.%d.%d: funny note 0x%02x\n", @@ -420,37 +416,35 @@ } } } - if((mask & 0xc0) == 0xc0) + if((mask & 0xc0) == 0xC0) { - uint8 e1c, e1d, e2c, e2d; - // read both effects and figure out what to do with them ASSERT_CAN_READ(4); - e1c = *((uint8 *)(lpStream + dwMemPos)); - e1d = *((uint8 *)(lpStream + dwMemPos + 1)); - e2c = *((uint8 *)(lpStream + dwMemPos + 2)); - e2d = *((uint8 *)(lpStream + dwMemPos + 3)); + uint8 e1c = *((uint8 *)(lpStream + dwMemPos)); // Command 1 + uint8 e1d = *((uint8 *)(lpStream + dwMemPos + 1)); // Data 1 + uint8 e2c = *((uint8 *)(lpStream + dwMemPos + 2)); // Command 2 + uint8 e2d = *((uint8 *)(lpStream + dwMemPos + 3)); // Data 2 dwMemPos += 4; - if (e1c == 0xc) + if(e1c == 0x0C) { note->vol = min(e1d, 0x40); note->volcmd = VOLCMD_VOLUME; note->command = e2c; note->param = e2d; - } else if (e2c == 0xc) + } else if(e2c == 0x0C) { note->vol = min(e2d, 0x40); note->volcmd = VOLCMD_VOLUME; note->command = e1c; note->param = e1d; - } else if (e1c == 0xa) + } else if(e1c == 0x0A) { note->vol = e1d * 64 / 255; note->volcmd = VOLCMD_PANNING; note->command = e2c; note->param = e2d; - } else if (e2c == 0xa) + } else if(e2c == 0x0A) { note->vol = e2d * 64 / 255; note->volcmd = VOLCMD_PANNING; @@ -465,7 +459,7 @@ note->command = e2c; note->param = e2d; } - } else if(mask & 0xc0) + } else if(mask & 0xC0) { // there's one effect, just stick it in the effect column ASSERT_CAN_READ(2); @@ -478,8 +472,10 @@ } } + SAMPLEINDEX firstsample = 1; // first sample index of the current instrument + // read instruments - for (INSTRUMENTINDEX nIns = 0; nIns < hdr.insnum; nIns++) + for(INSTRUMENTINDEX nIns = 0; nIns < hdr.insnum; nIns++) { IMFINSTRUMENT imfins; MODINSTRUMENT *pIns; @@ -510,9 +506,9 @@ if(imfins.smpnum) { - for(BYTE cNote = 0; cNote < 120; cNote++) + STATIC_ASSERT(CountOf(pIns->Keyboard) >= CountOf(imfins.map)); + for(size_t cNote = 0; cNote < CountOf(imfins.map); cNote++) { - pIns->NoteMap[cNote] = cNote + 1; pIns->Keyboard[cNote] = firstsample + imfins.map[cNote]; } } @@ -532,9 +528,8 @@ // read this instrument's samples for(SAMPLEINDEX nSmp = 0; nSmp < imfins.smpnum; nSmp++) { - IMFSAMPLE imfsmp; - uint32 blen; ASSERT_CAN_READ(sizeof(IMFSAMPLE)); + IMFSAMPLE imfsmp; memcpy(&imfsmp, lpStream + dwMemPos, sizeof(IMFSAMPLE)); dwMemPos += sizeof(IMFSAMPLE); m_nSamples++; @@ -542,39 +537,40 @@ if(memcmp(imfsmp.is10, "IS10", 4) != 0) return false; - memcpy(pSample->filename, imfsmp.filename, 12); - StringFixer::SpaceToNullStringFixed<12>(pSample->filename); - strcpy(m_szNames[m_nSamples], pSample->filename); + MODSAMPLE &sample = Samples[firstsample + nSmp]; - blen = pSample->nLength = LittleEndian(imfsmp.length); - pSample->nLoopStart = LittleEndian(imfsmp.loop_start); - pSample->nLoopEnd = LittleEndian(imfsmp.loop_end); - pSample->nC5Speed = LittleEndian(imfsmp.C5Speed); - pSample->nVolume = imfsmp.volume * 4; - pSample->nGlobalVol = 256; - pSample->nPan = imfsmp.panning; - if (imfsmp.flags & 1) - pSample->uFlags |= CHN_LOOP; - if (imfsmp.flags & 2) - pSample->uFlags |= CHN_PINGPONGLOOP; - if (imfsmp.flags & 4) + memcpy(sample.filename, imfsmp.filename, 12); + StringFixer::SpaceToNullStringFixed<12>(sample.filename); + strcpy(m_szNames[m_nSamples], sample.filename); + + uint32 byteLen = sample.nLength = LittleEndian(imfsmp.length); + sample.nLoopStart = LittleEndian(imfsmp.loop_start); + sample.nLoopEnd = LittleEndian(imfsmp.loop_end); + sample.nC5Speed = LittleEndian(imfsmp.C5Speed); + sample.nVolume = imfsmp.volume * 4; + sample.nGlobalVol = 256; + sample.nPan = imfsmp.panning; + if(imfsmp.flags & 1) + sample.uFlags |= CHN_LOOP; + if(imfsmp.flags & 2) + sample.uFlags |= CHN_PINGPONGLOOP; + if(imfsmp.flags & 4) { - pSample->uFlags |= CHN_16BIT; - pSample->nLength >>= 1; - pSample->nLoopStart >>= 1; - pSample->nLoopEnd >>= 1; + sample.uFlags |= CHN_16BIT; + sample.nLength /= 2; + sample.nLoopStart /= 2; + sample.nLoopEnd /= 2; } - if (imfsmp.flags & 8) - pSample->uFlags |= CHN_PANNING; + if(imfsmp.flags & 8) + sample.uFlags |= CHN_PANNING; - if(blen) + if(byteLen) { - ASSERT_CAN_READ(blen); - ReadSample(pSample, (imfsmp.flags & 4) ? RS_PCM16S : RS_PCM8S, reinterpret_cast<LPCSTR>(lpStream + dwMemPos), blen); + ASSERT_CAN_READ(byteLen); + ReadSample(&sample, (imfsmp.flags & 4) ? RS_PCM16S : RS_PCM8S, reinterpret_cast<LPCSTR>(lpStream + dwMemPos), byteLen); } - dwMemPos += blen; - pSample++; + dwMemPos += byteLen; } firstsample += imfins.smpnum; } Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -2476,28 +2476,26 @@ if (nInstruments == 0) return; - MODINSTRUMENT *sizeIns = nullptr; + WriteInstrumentPropertyForAllInstruments('VR..', sizeof(MODINSTRUMENT().nVolRampUp), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('MiP.', sizeof(MODINSTRUMENT().nMixPlug), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('MC..', sizeof(MODINSTRUMENT().nMidiChannel),f, nInstruments); + WriteInstrumentPropertyForAllInstruments('MP..', sizeof(MODINSTRUMENT().nMidiProgram),f, nInstruments); + WriteInstrumentPropertyForAllInstruments('MB..', sizeof(MODINSTRUMENT().wMidiBank), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('P...', sizeof(MODINSTRUMENT().nPan), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('GV..', sizeof(MODINSTRUMENT().nGlobalVol), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('FO..', sizeof(MODINSTRUMENT().nFadeOut), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('R...', sizeof(MODINSTRUMENT().nResampling), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('CS..', sizeof(MODINSTRUMENT().nCutSwing), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('RS..', sizeof(MODINSTRUMENT().nResSwing), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('FM..', sizeof(MODINSTRUMENT().nFilterMode), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PERN', sizeof(MODINSTRUMENT().PitchEnv.nReleaseNode ), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('AERN', sizeof(MODINSTRUMENT().PanEnv.nReleaseNode), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('VERN', sizeof(MODINSTRUMENT().VolEnv.nReleaseNode), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PTTL', sizeof(MODINSTRUMENT().wPitchToTempoLock), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PVEH', sizeof(MODINSTRUMENT().nPluginVelocityHandling), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PVOH', sizeof(MODINSTRUMENT().nPluginVolumeHandling), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('VR..', sizeof(sizeIns->nVolRampUp), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('MiP.', sizeof(sizeIns->nMixPlug), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('MC..', sizeof(sizeIns->nMidiChannel),f, nInstruments); - WriteInstrumentPropertyForAllInstruments('MP..', sizeof(sizeIns->nMidiProgram),f, nInstruments); - WriteInstrumentPropertyForAllInstruments('MB..', sizeof(sizeIns->wMidiBank), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('P...', sizeof(sizeIns->nPan), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('GV..', sizeof(sizeIns->nGlobalVol), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('FO..', sizeof(sizeIns->nFadeOut), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('R...', sizeof(sizeIns->nResampling), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('CS..', sizeof(sizeIns->nCutSwing), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('RS..', sizeof(sizeIns->nResSwing), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('FM..', sizeof(sizeIns->nFilterMode), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PERN', sizeof(sizeIns->PitchEnv.nReleaseNode ), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('AERN', sizeof(sizeIns->PanEnv.nReleaseNode), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('VERN', sizeof(sizeIns->VolEnv.nReleaseNode), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PTTL', sizeof(sizeIns->wPitchToTempoLock), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PVEH', sizeof(sizeIns->nPluginVelocityHandling), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PVOH', sizeof(sizeIns->nPluginVolumeHandling), f, nInstruments); - - if(m_nType & MOD_TYPE_MPT) + if(GetType() & MOD_TYPE_MPT) { UINT maxNodes = 0; for(INSTRUMENTINDEX nIns = 1; nIns <= m_nInstruments; nIns++) if(Instruments[nIns] != nullptr) @@ -2509,17 +2507,17 @@ // write full envelope information for MPTM files (more env points) if(maxNodes > 25) { - WriteInstrumentPropertyForAllInstruments('VE..', sizeof(sizeIns->VolEnv.nNodes), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('VP[.', sizeof(sizeIns->VolEnv.Ticks ), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('VE[.', sizeof(sizeIns->VolEnv.Values), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('VE..', sizeof(MODINSTRUMENT().VolEnv.nNodes), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('VP[.', sizeof(MODINSTRUMENT().VolEnv.Ticks ), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('VE[.', sizeof(MODINSTRUMENT().VolEnv.Values), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PE..', sizeof(sizeIns->PanEnv.nNodes), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PP[.', sizeof(sizeIns->PanEnv.Ticks), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PE[.', sizeof(sizeIns->PanEnv.Values), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PE..', sizeof(MODINSTRUMENT().PanEnv.nNodes), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PP[.', sizeof(MODINSTRUMENT().PanEnv.Ticks), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PE[.', sizeof(MODINSTRUMENT().PanEnv.Values), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PiE.', sizeof(sizeIns->PitchEnv.nNodes), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PiP[', sizeof(sizeIns->PitchEnv.Ticks), f, nInstruments); - WriteInstrumentPropertyForAllInstruments('PiE[', sizeof(sizeIns->PitchEnv.Values), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PiE.', sizeof(MODINSTRUMENT().PitchEnv.nNodes), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PiP[', sizeof(MODINSTRUMENT().PitchEnv.Ticks), f, nInstruments); + WriteInstrumentPropertyForAllInstruments('PiE[', sizeof(MODINSTRUMENT().PitchEnv.Values), f, nInstruments); } } Modified: trunk/OpenMPT/soundlib/Load_mdl.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mdl.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Load_mdl.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -81,11 +81,14 @@ break; case 0x0F: command = CMD_SPEED; break; case 0x10: - if ((param & 0xF0) != 0xE0) { + if ((param & 0xF0) != 0xE0) + { command = CMD_VOLUMESLIDE; - if ((param & 0xF0) == 0xF0) { + if ((param & 0xF0) == 0xF0) + { param = ((param << 4) | 0x0F); - } else { + } else + { param >>= 2; if (param > 0xF) param = 0xF; @@ -94,9 +97,11 @@ } break; case 0x20: - if ((param & 0xF0) != 0xE0) { + if ((param & 0xF0) != 0xE0) + { command = CMD_VOLUMESLIDE; - if ((param & 0xF0) != 0xF0) { + if ((param & 0xF0) != 0xF0) + { param >>= 2; if (param > 0xF) param = 0xF; @@ -419,7 +424,7 @@ pIns->nFadeOut = 8192; } } - dwPos += 34 + 14*lpStream[dwPos+1]; + dwPos += 34 + 14 * lpStream[dwPos + 1]; } for (j=1; j<=m_nInstruments; j++) if (!Instruments[j]) { Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -219,7 +219,7 @@ #pragma pack() -bool IsMagic(LPCSTR s1, LPCSTR s2) +bool IsMagic(const LPCSTR s1, const LPCSTR s2) { return ((*(DWORD *)s1) == (*(DWORD *)s2)); } Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -306,7 +306,7 @@ XMINSTRUMENTHEADER pih; BYTE flags[32]; DWORD samplesize[32]; - UINT samplemap[32]; + vector<SAMPLEINDEX>samplemap(32, 0); WORD nsamples; if (dwMemPos + sizeof(DWORD) >= dwMemLength) return true; @@ -359,7 +359,6 @@ else dwMemPos += sizeof(XMINSTRUMENTHEADER); - MemsetZero(samplemap); if (nsamples > 32) return true; UINT newsamples = m_nSamples; @@ -380,7 +379,7 @@ for (UINT clrs=1; clrs<iIns; clrs++) if (Instruments[clrs]) { MODINSTRUMENT *pks = Instruments[clrs]; - for (UINT ks=0; ks<128; ks++) + for (size_t ks = 0; ks < CountOf(pks->Keyboard); ks++) { if (pks->Keyboard[ks] == n) pks->Keyboard[ks] = 0; } @@ -484,7 +483,7 @@ } } } - for (UINT j=0; j<96; j++) + for (size_t j = 0; j < CountOf(xmsh.snum); j++) { if (xmsh.snum[j] < nsamples) pIns->Keyboard[j + 12] = samplemap[xmsh.snum[j]]; Modified: trunk/OpenMPT/soundlib/PlaybackEventer.cpp =================================================================== --- trunk/OpenMPT/soundlib/PlaybackEventer.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/PlaybackEventer.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -17,7 +17,7 @@ { m_rSndFile.m_bChannelMuteTogglePending[i] = (m_rSndFile.ChnSettings[i].dwFlags & CHN_MUTE) ? false : true; } - m_rSndFile.m_bChannelMuteTogglePending[chnIndex] = (m_rSndFile.ChnSettings[chnIndex].dwFlags & CHN_MUTE) ? true : false; + m_rSndFile.m_bChannelMuteTogglePending[chnIndex] = (m_rSndFile.ChnSettings[chnIndex].dwFlags & CHN_MUTE) != 0; } @@ -26,6 +26,6 @@ { for(CHANNELINDEX i = 0; i<m_rSndFile.m_nChannels; i++) { - m_rSndFile.m_bChannelMuteTogglePending[i] = (m_rSndFile.ChnSettings[i].dwFlags & CHN_MUTE) ? true : false; + m_rSndFile.m_bChannelMuteTogglePending[i] = (m_rSndFile.ChnSettings[i].dwFlags & CHN_MUTE) != 0; } -} \ No newline at end of file +} Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Sndfile.h 2011-12-10 18:53:45 UTC (rev 1146) @@ -996,6 +996,8 @@ protected: // Channel effect processing + int GetVibratoDelta(int type, int position) const; + void ProcessVolumeSwing(MODCHANNEL *pChn, int &vol); void ProcessPanningSwing(MODCHANNEL *pChn); void ProcessTremolo(MODCHANNEL *pChn, int &vol); Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2011-12-10 17:34:18 UTC (rev 1145) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2011-12-10 18:53:45 UTC (rev 1146) @@ -69,9 +69,9 @@ extern short int ModRampDownTable[64]; extern short int ModSquareTable[64]; extern short int ModRandomTable[64]; -extern short int ITSinusTable[64]; -extern short int ITRampDownTable[64]; -extern short int ITSquareTable[64]; +extern short int ITSinusTable[256]; +extern short int ITRampDownTable[256]; +extern short int ITSquareTable[256]; extern DWORD LinearSlideUpTable[256]; extern DWORD LinearSlideDownTable[256]; extern DWORD FineLinearSlideUpTable[16]; @@ -910,6 +910,36 @@ // Channel effect processing +// Calculate delta for Vibrato / Tremolo / Panbrello effect +int CSoundFile::GetVibratoDelta(int type, int position) const +//----------------------------------------------------------- +{ + switch(type & 0x03) + { + case 0: + default: + // IT compatibility: IT has its own, more precise tables + return IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSinusTable[position] : ModSinusTable[position]; + + case 1: + // IT compatibility: IT has its own, more precise tables + return IsCompatibleMode(TRK_IMPULSETRACKER) ? ITRampDownTable[position] : ModRampDownTable[position]; + + case 2: + // IT compatibility: IT has its own, more precise tables + return IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSquareTable[position] : ModSquareTable[position]; + + case 3: + //IT compatibility 19. Use random values + if(IsCompatibleMode(TRK_IMPULSETRACKER)) + // TODO delay is not taken into account! + return (rand() & 0x7F) - 0x40; + else + return ModRandomTable[position]; + } +} + + void CSoundFile::ProcessVolumeSwing(MODCHANNEL *pChn, int &vol) //------------------------------------------------------------- { @@ -959,27 +989,8 @@ { // IT compatibility: We don't need a different attenuation here because of the different tables we're going to use const int tremattn = ((GetType() & MOD_TYPE_XM) || IsCompatibleMode(TRK_IMPULSETRACKER)) ? 5 : 6; - switch (pChn->nTremoloType & 0x03) - { - case 1: - // IT compatibility: IT has its own, more precise tables - vol += ((IsCompatibleMode(TRK_IMPULSETRACKER) ? ITRampDownTable[trempos] : ModRampDownTable[trempos]) * (int)pChn->nTremoloDepth) >> tremattn; - break; - case 2: - // IT compatibility: IT has its own, more precise tables - vol += ((IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSquareTable[trempos] : ModSquareTable[trempos]) * (int)pChn->nTremoloDepth) >> tremattn; - break; - case 3: - //IT compatibility 19. Use random values - if(IsCompatibleMode(TRK_IMPULSETRACKER)) - vol += (((rand() & 0x7F) - 0x40) * (int)pChn->nTremoloDepth) >> tremattn; - else - vol += (ModRandomTable[trempos] * (int)pChn->nTremoloDepth) >> tremattn; - break; - default: - // IT compatibility: IT has its own, more precise tables - vol += ((IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSinusTable[trempos] : ModSinusTable[trempos]) * (int)pChn->nTremoloDepth) >> tremattn; - } + + vol += (GetVibratoDelta(pChn->nTremoloType, trempos) * (int)pChn->nTremoloDepth) >> tremattn; } if (!(m_dwSongFlags & SONG_FIRSTTICK) || ((GetType() & (MOD_TYPE_STM|MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT)) && (!(m_dwSongFlags & SONG_ITOLDEFFECTS)))) { @@ -1390,33 +1401,14 @@ panpos = pChn->nPanbrelloPos & 0xFF; else panpos = ((pChn->nPanbrelloPos + 0x10) >> 2) & 0x3F; - LONG pdelta; - switch (pChn->nPanbrelloType & 0x03) - { - case 1: - // IT compatibility: IT has its own, more precise tables - pdelta = IsCompatibleMode(TRK_IMPULSETRACKER) ? ITRampDownTable[panpos] : ModRampDownTable[panpos]; - break; - case 2: - // IT compatibility: IT has its own, more precise tables - pdelta = IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSquareTable[panpos] : ModSquareTable[panpos]; - break; - case 3: - //IT compatibility 19. Use random values - if(IsCompatibleMode(TRK_IMPULSETRACKER)) - pdelta = (rand() & 0x7f) - 0x40; - else - pdelta = ModRandomTable[panpos]; - break; - default: - // IT compatibility: IT has its own, more precise tables - pdelta = IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSinusTable[panpos] : ModSinusTable[panpos]; - } + + LONG pdelta = GetVibratoDelta(pChn->nPanbrelloType, panpos); + pChn->nPanbrelloPos += pChn->nPanbrelloSpeed; pdelta = ((pdelta * (int)pChn->nPanbrelloDepth) + 2) >> 3; pdelta += pChn->nRealPan; - pChn->nRealPan = CLAMP(pdelta, 0, 256); + pChn->nRealPan = Clamp(pdelta, 0, 256); //if(IsCompatibleMode(TRK_IMPULSETRACKER)) pChn->nPan = pChn->nRealPan; // TODO } } @@ -1477,7 +1469,7 @@ arpeggioSteps = pChn->nArpeggio >> 4; // >> 4 <-> division by 16. This gives the first number in the parameter. break; case 2: - arpeggioSteps = pChn->nArpeggio % 16; //Gives the latter number in the parameter. + arpeggioSteps = pChn->nArpeggio & 0x0F; //Gives the latter number in the parameter. break; } pChn->m_CalculateFreq = true; @@ -1540,30 +1532,10 @@ if (pChn->dwFlags & CHN_VIBRATO) { UINT vibpos = pChn->nVibratoPos; - LONG vdelta; - switch (pChn->nVibratoType & 0x03) - { - case 1: - // IT compatibility: IT has its own, more precise tables - vdelta = IsCompatibleMode(TRK_IMPULSETRACKER) ? ITRampDownTable[vibpos] : ModRampDownTable[vibpos]; - break; - case 2: - // IT compatibility: IT has its own, more precise tables - vdelta = IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSquareTable[vibpos] : ModSquareTable[vibpos]; - break; - case 3: - //IT compatibility 19. Use random values - if(IsCompatibleMode(TRK_IMPULSETRACKER)) - vdelta = (rand() & 0x7F) - 0x40; - else - vdelta = ModRandomTable[vibpos]; - break; - default: - // IT compatibility: IT has its own, more precise tables - vdelta = IsCompatibleMode(TRK_IMPULSETRACKER) ? ITSinusTable[vibpos] : ModSinusTable[vibpos]; - } - if(m_nType == MOD_TYPE_MPT && pChn->pModInstrument && pChn->pModInstrument->pTuning) + LONG vdelta = GetVibratoDelta(pChn->nVibratoType, vibpos); + + if(GetType() == MOD_TYPE_MPT && pChn->pModInstrument && pChn->pModInstrument->pTuning) { //Hack implementation: Scaling vibratofactor to [0.95; 1.05] //using figure from above tables and vibratodepth parameter @@ -1592,7 +1564,7 @@ } else { - vdepth = ((!(m_nType & (MOD_TYPE_IT|MOD_TYPE_MPT))) || (m_dwSongFlags & SONG_ITOLDEFFECTS)) ? 6 : 7; + vdepth = ((!(GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT))) || (m_dwSongFlags & SONG_ITOLDEFFECTS)) ? 6 : 7; } vdelta = (vdelta * (int)pChn->nVibratoDepth) >> vdepth; if ((m_dwSongFlags & SONG_LINEARSLIDES) && (m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT))) @@ -1611,7 +1583,7 @@ } period += vdelta; } - if ((m_nTickCount) || ((m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT)) && (!(m_dwSongFlags & SONG_ITOLDEFFECTS)))) + if ((m_nTickCount) || ((GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT)) && (!(m_dwSongFlags & SONG_ITOLDEFFECTS)))) { // IT compatibility: IT has its own, more precise tables if(IsCompatibleMode(TRK_IMPULSETRACKER)) @@ -1624,7 +1596,7 @@ void CSoundFile::ProcessSampleAutoVibrato(MODCHANNEL *pChn, int &period, CTuning::RATIOTYPE &vibratoFactor, int &nPeriodFrac) -//-------------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------------- { // Sample Auto-Vibrato if ((pChn->pModSample) && (pChn->pModSample->nVibDepth)) @@ -1730,7 +1702,7 @@ vdelta = ((0x40 - (pChn->nAutoVibPos >> 1)) & 0x7F) - 0x40; break; case VIB_RAMP_UP: - vdelta = ((0x40 + (pChn->nAutoVibPos >> 1)) & 0x7f) - 0x40; + vdelta = ((0x40 + (pChn->nAutoVibPos >> 1)) & 0x7F) - 0x40; break; case VIB_SQUARE: vdelta = (pChn->nAutoVibPos & 128) ? +64 : -64; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |