From: <sag...@us...> - 2011-03-23 20:48:15
|
Revision: 825 http://modplug.svn.sourceforge.net/modplug/?rev=825&view=rev Author: saga-games Date: 2011-03-23 20:48:08 +0000 (Wed, 23 Mar 2011) Log Message: ----------- [Ref] MIDI Macro code cleanup. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_pat.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/dlg_misc.cpp trunk/OpenMPT/soundlib/Snd_defs.h trunk/OpenMPT/soundlib/Snd_fx.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/Ctrl_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_pat.cpp 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/mptrack/Ctrl_pat.cpp 2011-03-23 20:48:08 UTC (rev 825) @@ -1119,18 +1119,8 @@ m_pSndFile->m_dwSongFlags &= ~SONG_EMBEDMIDICFG; // If this macro is not the default IT macro, display a warning. - bool isDefault = (CModDoc::GetMacroType(&(dlg.m_MidiCfg.szMidiSFXExt[0])) == sfx_cutoff) - && (CModDoc::GetZxxType(dlg.m_MidiCfg.szMidiZXXExt) == 1); - for(size_t i = 1; i <= 15; i++) + if(!m_pModDoc->IsMacroDefaultSetupUsed()) { - if(CModDoc::GetMacroType(&(dlg.m_MidiCfg.szMidiSFXExt[i * 32])) != sfx_unused) - { - isDefault = false; - break; - } - } - if(!isDefault) - { if(AfxMessageBox(_T("You have chosen not to embed MIDI macros. However, the current macro configuration differs from the default macro configuration that is assumed when loading a file that has no macros embedded. This can result in data loss and broken playback.\nWould you like to embed MIDI macros now?"), MB_YESNO) == IDYES) { m_pSndFile->m_dwSongFlags |= SONG_EMBEDMIDICFG; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2011-03-23 20:48:08 UTC (rev 825) @@ -3165,8 +3165,8 @@ } -int CModDoc::GetMacroType(CString value) -//-------------------------------------- +enmParameteredMacroType CModDoc::GetMacroType(CString value) +//---------------------------------------------------------- { if (value.Compare("")==0) return sfx_unused; if (value.Compare("F0F000z")==0) return sfx_cutoff; @@ -3185,24 +3185,23 @@ { int code=0; char* param = (char *) (LPCTSTR) macro; - param +=4; + param += 4; if ((param[0] >= '0') && (param[0] <= '9')) code = (param[0] - '0') << 4; else if ((param[0] >= 'A') && (param[0] <= 'F')) code = (param[0] - 'A' + 0x0A) << 4; if ((param[1] >= '0') && (param[1] <= '9')) code += (param[1] - '0'); else if ((param[1] >= 'A') && (param[1] <= 'F')) code += (param[1] - 'A' + 0x0A); - if (macro.GetLength()>=4 && macro.GetAt(3)=='0') { - return (code-128); - } else { - return (code+128); - } + if (macro.GetLength()>=4 && macro.GetAt(3)=='0') + return (code - 128); + else + return (code + 128); } int CModDoc::MacroToMidiCC(CString macro) //--------------------------------------- { int code=0; char* param = (char *) (LPCTSTR) macro; - param +=2; + param += 2; if ((param[0] >= '0') && (param[0] <= '9')) code = (param[0] - '0') << 4; else if ((param[0] >= 'A') && (param[0] <= 'F')) code = (param[0] - 'A' + 0x0A) << 4; if ((param[1] >= '0') && (param[1] <= '9')) code += (param[1] - '0'); else @@ -3211,12 +3210,19 @@ return code; } -int CModDoc::FindMacroForParam(long param) -//---------------------------------------- +int CModDoc::FindMacroForParam(long param) const +//---------------------------------------------- { - for (int macro=0; macro<16; macro++) { //what's the named_const for num macros?? :D - CString macroString = &(GetSoundFile()->m_MidiCfg.szMidiSFXExt[macro*32]); - if (GetMacroType(macroString) == sfx_plug && MacroToPlugParam(macroString) == param) { + const CSoundFile *pSndFile = GetSoundFile(); + if(pSndFile == nullptr) + { + return -1; + } + for (int macro = 0; macro < NUM_MACROS; macro++) + { + CString macroString = &(pSndFile->m_MidiCfg.szMidiSFXExt[macro * 32]); + if (GetMacroType(macroString) == sfx_plug && MacroToPlugParam(macroString) == param) + { return macro; } } @@ -3225,15 +3231,15 @@ } // Retrieve Zxx (Z80-ZFF) type from current macro configuration -int CModDoc::GetZxxType(const CHAR (&szMidiZXXExt)[128 * 32]) -//----------------------------------------------------------- +enmFixedMacroType CModDoc::GetZxxType(const CHAR (&szMidiZXXExt)[128 * 32]) +//------------------------------------------------------------------------- { // Compare with all possible preset patterns - for(int i = 1; i <= 5; i++) + for(int i = 1; i < sfx_fixed_max; i++) { // Prepare pattern to compare CHAR szPatterns[128 * 32]; - CreateZxxFromType(szPatterns, i); + CreateZxxFromType(szPatterns, static_cast<enmFixedMacroType>(i)); bool bFound = true; for(int j = 0; j < 128; j++) @@ -3244,41 +3250,41 @@ break; } } - if(bFound) return i; + if(bFound) return static_cast<enmFixedMacroType>(i); } - return 0; // Type 0 - Custom setup + return sfx_fixed_custom; // Custom setup } // Create Zxx (Z80 - ZFF) from one out of five presets -void CModDoc::CreateZxxFromType(CHAR (&szMidiZXXExt)[128 * 32], int iZxxType) -//--------------------------------------------------------------------------- +void CModDoc::CreateZxxFromType(CHAR (&szMidiZXXExt)[128 * 32], enmFixedMacroType iZxxType) +//----------------------------------------------------------------------------------------- { for(int i = 0; i < 128; i++) { switch(iZxxType) { - case 1: + case sfx_fixed_reso4Bit: // Type 1 - Z80 - Z8F controls resonance if (i < 16) wsprintf(&szMidiZXXExt[i * 32], "F0F001%02X", i * 8); else szMidiZXXExt[i * 32] = 0; break; - case 2: + case sfx_fixed_reso7Bit: // Type 2 - Z80 - ZFF controls resonance wsprintf(&szMidiZXXExt[i * 32], "F0F001%02X", i); break; - case 3: + case sfx_fixed_cutoff: // Type 3 - Z80 - ZFF controls cutoff wsprintf(&szMidiZXXExt[i * 32], "F0F000%02X", i); break; - case 4: + case sfx_fixed_mode: // Type 4 - Z80 - ZFF controls filter mode wsprintf(&szMidiZXXExt[i * 32], "F0F002%02X", i); break; - case 5: + case sfx_fixed_resomode: // Type 5 - Z80 - Z9F controls resonance + filter mode if (i < 16) wsprintf(&szMidiZXXExt[i * 32], "F0F001%02X", i * 8); else if (i < 32) wsprintf(&szMidiZXXExt[i * 32], "F0F002%02X", (i - 16) * 8); @@ -3289,6 +3295,38 @@ } +// Check if the MIDI Macro configuration used is the default one, +// i.e. the configuration that is assumed when loading a file that has no macros embedded. +bool CModDoc::IsMacroDefaultSetupUsed() const +//------------------------------------------- +{ + const CSoundFile *pSndFile = GetSoundFile(); + if(pSndFile == nullptr) + { + return false; + } + // SF0: Z00-Z7F controls cutoff + if(GetMacroType(&(pSndFile->m_MidiCfg.szMidiSFXExt[0])) != sfx_cutoff) + { + return false; + } + // Z80-Z8F controls resonance + if(GetZxxType(pSndFile->m_MidiCfg.szMidiZXXExt) != sfx_fixed_reso4Bit) + { + return false; + } + // All other parametered macros are unused + for(size_t i = 1; i < NUM_MACROS; i++) + { + if(GetMacroType(&(pSndFile->m_MidiCfg.szMidiSFXExt[i * 32])) != sfx_unused) + { + return false; + } + } + return true; +} + + //////////////////////////////////////////////////////////////////////////////////////// // Playback Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/mptrack/Moddoc.h 2011-03-23 20:48:08 UTC (rev 825) @@ -90,20 +90,35 @@ STATIC_ASSERT( ((-1 << HINT_SHIFT_SEQUENCE) & HINT_MASK_ITEM) == (-1 << HINT_SHIFT_SEQUENCE) ); -//parametered macro presets: -enum +// parametered macro presets: +enum enmParameteredMacroType { - sfx_unused=0, + sfx_unused = 0, sfx_cutoff, sfx_reso, sfx_mode, sfx_drywet, sfx_plug, sfx_cc, - sfx_custom + sfx_custom, + + sfx_max }; +// fixed macro presets: +enum enmFixedMacroType +{ + sfx_fixed_custom = 0, + sfx_fixed_reso4Bit, // Type 1 - Z80 - Z8F controls resonance + sfx_fixed_reso7Bit, // Type 2 - Z80 - ZFF controls resonance + sfx_fixed_cutoff, // Type 3 - Z80 - ZFF controls cutoff + sfx_fixed_mode, // Type 4 - Z80 - ZFF controls filter mode + sfx_fixed_resomode, // Type 5 - Z80 - Z9F controls resonance + filter mode + sfx_fixed_max +}; + + // pattern paste modes enum enmPatternPasteModes { @@ -191,8 +206,10 @@ // public members public: + CSoundFile *GetSoundFile() { return &m_SndFile; } + const CSoundFile *GetSoundFile() const { return &m_SndFile; } + void InitPlayer(); - CSoundFile *GetSoundFile() { return &m_SndFile; } void SetPause(BOOL bPause) { m_bPaused = bPause; } void SetModified(BOOL bModified=TRUE) { SetModifiedFlag(bModified); bModifiedAutosave = (bModified != FALSE); } bool ModifiedSinceLastAutosave() { bool bRetval = bModifiedAutosave; bModifiedAutosave = false; return bRetval; } // return "IsModified" value and reset it until the next SetModified() (as this is only used for polling) @@ -235,12 +252,16 @@ LONG GetIndexFromVolCmd(UINT volcmd); UINT GetVolCmdFromIndex(UINT ndx); BOOL GetVolCmdInfo(UINT ndx, LPSTR s, DWORD *prangeMin=NULL, DWORD *prangeMax=NULL); - static int GetMacroType(CString value); //rewbs.xinfo - int MacroToPlugParam(CString value); //rewbs.xinfo - int MacroToMidiCC(CString value); - int FindMacroForParam(long param); - static int GetZxxType(const CHAR (&szMidiZXXExt)[128 * 32]); - static void CreateZxxFromType(CHAR (&szMidiZXXExt)[128 * 32], int iZxxType); + + // Various MIDI Macro helpers + static enmParameteredMacroType GetMacroType(CString value); //rewbs.xinfo + static int MacroToPlugParam(CString value); //rewbs.xinfo + static int MacroToMidiCC(CString value); + static enmFixedMacroType GetZxxType(const CHAR (&szMidiZXXExt)[128 * 32]); + static void CreateZxxFromType(CHAR (&szMidiZXXExt)[128 * 32], enmFixedMacroType iZxxType); + bool IsMacroDefaultSetupUsed() const; + int FindMacroForParam(long param) const; + void SongProperties(); CPatternUndo *GetPatternUndo() { return &m_PatternUndo; } Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2011-03-23 20:48:08 UTC (rev 825) @@ -614,7 +614,7 @@ strcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEOFF*32], "9c n 0"); strcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_PROGRAM*32], "Cc p"); strcpy(&m_MidiCfg.szMidiSFXExt[0], "F0F000z"); - CModDoc::CreateZxxFromType(m_MidiCfg.szMidiZXXExt, 1); + CModDoc::CreateZxxFromType(m_MidiCfg.szMidiZXXExt, sfx_fixed_reso4Bit); #ifdef UPDATECHECKENABLED m_pRequestContext = NULL; Modified: trunk/OpenMPT/mptrack/dlg_misc.cpp =================================================================== --- trunk/OpenMPT/mptrack/dlg_misc.cpp 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/mptrack/dlg_misc.cpp 2011-03-23 20:48:08 UTC (rev 825) @@ -946,9 +946,9 @@ void CMidiMacroSetup::OnZxxPresetChanged() //---------------------------------------- { - UINT zxx_preset = m_CbnZxxPreset.GetCurSel(); + enmFixedMacroType zxx_preset = static_cast<enmFixedMacroType>(m_CbnZxxPreset.GetCurSel()); - if (zxx_preset && m_pModDoc != nullptr) + if (zxx_preset != sfx_fixed_custom && m_pModDoc != nullptr) { m_pModDoc->CreateZxxFromType(m_MidiCfg.szMidiZXXExt, zxx_preset); UpdateDialog(); Modified: trunk/OpenMPT/soundlib/Snd_defs.h =================================================================== --- trunk/OpenMPT/soundlib/Snd_defs.h 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/soundlib/Snd_defs.h 2011-03-23 20:48:08 UTC (rev 825) @@ -409,6 +409,11 @@ INST_NUMFILTERMODES };*/ +// MIDI Macros +#define MACRO_MASK 0x7F5F7F5F +#define MACRO_INTERNAL 0x30463046 // internal macro, low 7 bits (f.e. cutoff, resonance, low plugin params) +#define MACRO_INTERNALEX 0x31463046 // internal macro, high 7 bits (high plugin params) + // Vibrato Types #define VIB_SINE 0 #define VIB_SQUARE 1 Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2011-03-23 20:48:08 UTC (rev 825) @@ -3012,11 +3012,11 @@ //--------------------------------------------------------------------------- { MODCHANNEL *pChn = &Chn[nChn]; - DWORD dwMacro = (*((LPDWORD)pszMidiMacro)) & 0x7F5F7F5F; + DWORD dwMacro = (*((LPDWORD)pszMidiMacro)) & MACRO_MASK; int nInternalCode; // Not Internal Device ? - if (dwMacro != 0x30463046 && dwMacro != 0x31463046) + if (dwMacro != MACRO_INTERNAL && dwMacro != MACRO_INTERNALEX) { UINT pos = 0, nNib = 0, nBytes = 0; DWORD dwMidiCode = 0, dwByteCode = 0; @@ -3070,10 +3070,7 @@ // Internal device //HACK: - bool extendedParam = false; - if (dwMacro == 0x31463046) { - extendedParam = true; - } + const bool extendedParam = (dwMacro == MACRO_INTERNALEX); pszMidiMacro += 4; nInternalCode = -256; @@ -3179,14 +3176,13 @@ //--------------------------------------------------------------------------- { MODCHANNEL *pChn = &Chn[nChn]; - DWORD dwMacro = (*((LPDWORD)pszMidiMacro)) & 0x7F5F7F5F; + DWORD dwMacro = (*((LPDWORD)pszMidiMacro)) & MACRO_MASK; int nInternalCode; CHAR cData1; // rewbs.smoothVST: DWORD dwParam; // increased scope to fuction. - bool extendedParam = false; - - if (dwMacro != 0x30463046 && dwMacro != 0x31463046) { + if (dwMacro != MACRO_INTERNAL && dwMacro != MACRO_INTERNALEX) + { // we don't cater for external devices at tick resolution. if(m_dwSongFlags & SONG_FIRSTTICK) { ProcessMidiMacro(nChn, pszMidiMacro, param); @@ -3195,9 +3191,7 @@ } //HACK: - if (dwMacro == 0x31463046) { - extendedParam = true; - } + const bool extendedParam = (dwMacro == MACRO_INTERNALEX); // not sure what we're doing here; some sort of info gathering from the macros pszMidiMacro += 4; Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2011-03-22 22:12:56 UTC (rev 824) +++ trunk/OpenMPT/soundlib/Sndfile.h 2011-03-23 20:48:08 UTC (rev 825) @@ -446,6 +446,7 @@ }; +#define NUM_MACROS 16 // number of parametered macros struct MODMIDICFG { CHAR szMidiGlb[9*32]; @@ -1006,9 +1007,6 @@ static LPSTR AllocateSample(UINT nbytes); static void FreeSample(LPVOID p); static UINT Normalize24BitBuffer(LPBYTE pbuffer, UINT cbsizebytes, DWORD lmax24, DWORD dwByteInc); -//private: - static MODCOMMAND *AllocatePattern(UINT rows, UINT nchns); - static void FreePattern(LPVOID pat); // Song message helper functions public: @@ -1067,7 +1065,7 @@ size_t GetVisitedRowsVectorSize(const PATTERNINDEX nPat); public: - // "importance" of every FX command. Table is used for importing from formats with multiple effect colums + // "importance" of every FX command. Table is used for importing from formats with multiple effect columns // and is approximately the same as in SchismTracker. static uint16 CSoundFile::GetEffectWeight(MODCOMMAND::COMMAND cmd); // try to convert a an effect into a volume column effect. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |