Skip to content

Commit

Permalink
[Ref] Clean up CModDoc::InitializeMod.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22142 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 10, 2024
1 parent 90055c0 commit 392b4b0
Showing 1 changed file with 60 additions and 74 deletions.
134 changes: 60 additions & 74 deletions mptrack/Moddoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,9 @@ BOOL CModDoc::OnNewDocument()
if (!CDocument::OnNewDocument()) return FALSE;

m_SndFile.Create(FileReader(), CSoundFile::loadCompleteModule, this);
m_SndFile.ChangeModTypeTo(CTrackApp::GetDefaultDocType());

theApp.GetDefaultMidiMacro(m_SndFile.m_MidiCfg);
m_SndFile.m_SongFlags.set((SONG_LINEARSLIDES | SONG_ISAMIGA) & m_SndFile.GetModSpecifications().songFlags);
InitializeMod();

ReinitRecordState();
InitializeMod();
SetModified(false);
return TRUE;
}
Expand Down Expand Up @@ -617,89 +613,79 @@ void CModDoc::OnAppendModule()

void CModDoc::InitializeMod()
{
// New module ?
if (!m_SndFile.GetNumChannels())
const auto defaultType = CTrackApp::GetDefaultDocType();
m_SndFile.ChangeModTypeTo((defaultType == MOD_TYPE_MOD_PC) ? MOD_TYPE_MOD : defaultType);

theApp.GetDefaultMidiMacro(m_SndFile.m_MidiCfg);
m_SndFile.m_SongFlags.set(SONG_LINEARSLIDES & m_SndFile.GetModSpecifications().songFlags);

switch(defaultType)
{
switch(GetModType())
{
case MOD_TYPE_MOD:
m_SndFile.ChnSettings.resize(4);
break;
case MOD_TYPE_MOD_PC:
m_SndFile.ChangeModTypeTo(MOD_TYPE_MOD);
m_SndFile.ChnSettings.resize(8);
break;
case MOD_TYPE_S3M:
m_SndFile.ChnSettings.resize(16);
break;
default:
m_SndFile.ChnSettings.resize(32);
break;
}
case MOD_TYPE_MOD:
m_SndFile.ChnSettings.resize(4);
break;
case MOD_TYPE_MOD_PC:
m_SndFile.ChnSettings.resize(8);
break;
case MOD_TYPE_S3M:
m_SndFile.ChnSettings.resize(16);
break;
default:
m_SndFile.ChnSettings.resize(32);
break;
}

SetDefaultChannelColors();
SetDefaultChannelColors();

if(GetModType() == MOD_TYPE_MPT)
{
m_SndFile.m_nTempoMode = TempoMode::Modern;
m_SndFile.m_SongFlags.set(SONG_EXFILTERRANGE);
}
m_SndFile.SetDefaultPlaybackBehaviour(GetModType());
if(GetModType() == MOD_TYPE_MPT)
{
m_SndFile.m_nTempoMode = TempoMode::Modern;
m_SndFile.m_SongFlags.set(SONG_EXFILTERRANGE);
}
m_SndFile.SetDefaultPlaybackBehaviour(GetModType());

// Refresh mix levels now that the correct mod type has been set
m_SndFile.SetMixLevels(m_SndFile.GetModSpecifications().defaultMixLevels);
// Refresh mix levels now that the correct mod type has been set
m_SndFile.SetMixLevels(m_SndFile.GetModSpecifications().defaultMixLevels);

m_SndFile.Order().assign(1, 0);
if (!m_SndFile.Patterns.IsValidPat(0))
{
m_SndFile.Patterns.Insert(0, 64);
}
m_SndFile.Order().assign(1, 0);
if(!m_SndFile.Patterns.IsValidPat(0))
m_SndFile.Patterns.Insert(0, 64);

Clear(m_SndFile.m_szNames);
Clear(m_SndFile.m_szNames);

m_SndFile.Order().SetDefaultTempoInt(125);
m_SndFile.Order().SetDefaultSpeed(6);
m_SndFile.Order().SetDefaultTempoInt(125);
m_SndFile.Order().SetDefaultSpeed(6);

// Set up mix levels
m_SndFile.m_PlayState.m_nGlobalVolume = m_SndFile.m_nDefaultGlobalVolume = MAX_GLOBAL_VOLUME;
m_SndFile.m_nSamplePreAmp = m_SndFile.m_nVSTiVolume = 48;
// Setup LRRL panning scheme for MODs
m_SndFile.SetupMODPanning();
// Set up mix levels
m_SndFile.m_PlayState.m_nGlobalVolume = m_SndFile.m_nDefaultGlobalVolume = MAX_GLOBAL_VOLUME;
m_SndFile.m_nSamplePreAmp = m_SndFile.m_nVSTiVolume = 48;
// Setup LRRL panning scheme for MODs
m_SndFile.SetupMODPanning();

if(GetModType() == MOD_TYPE_MOD)
{
const bool isAmiga = GetNumChannels() == 4;
m_SndFile.m_SongFlags.set(SONG_ISAMIGA | SONG_AMIGALIMITS | SONG_PT_MODE, isAmiga);
m_SndFile.m_playBehaviour.set(kMODOneShotLoops, isAmiga);
m_SndFile.m_playBehaviour.set(kMODSampleSwap, isAmiga);
m_SndFile.m_playBehaviour.set(kMODOutOfRangeNoteDelay, isAmiga);
m_SndFile.m_playBehaviour.set(kMODTempoOnSecondTick, isAmiga);
m_SndFile.m_playBehaviour.set(kFT2MODTremoloRampWaveform);
}
}
if (!m_SndFile.m_nSamples)
if(GetModType() == MOD_TYPE_MOD)
{
m_SndFile.m_szNames[1] = "untitled";
m_SndFile.m_nSamples = (GetModType() == MOD_TYPE_MOD) ? 31 : 1;
const bool isAmiga = (defaultType != MOD_TYPE_MOD_PC);
m_SndFile.m_SongFlags.set(SONG_ISAMIGA | SONG_AMIGALIMITS | SONG_PT_MODE, isAmiga);
m_SndFile.m_playBehaviour.set(kMODOneShotLoops, isAmiga);
m_SndFile.m_playBehaviour.set(kMODSampleSwap, isAmiga);
m_SndFile.m_playBehaviour.set(kMODOutOfRangeNoteDelay, isAmiga);
m_SndFile.m_playBehaviour.set(kMODTempoOnSecondTick, isAmiga);
m_SndFile.m_playBehaviour.set(kFT2MODTremoloRampWaveform);
}

SampleEdit::ResetSamples(m_SndFile, SampleEdit::SmpResetInit);
m_SndFile.m_szNames[1] = "untitled";
m_SndFile.m_nSamples = (GetModType() == MOD_TYPE_MOD) ? 31 : 1;

m_SndFile.GetSample(1).Initialize(m_SndFile.GetType());
SampleEdit::ResetSamples(m_SndFile, SampleEdit::SmpResetInit);

if ((!m_SndFile.m_nInstruments) && (m_SndFile.GetType() & MOD_TYPE_XM))
{
if(m_SndFile.AllocateInstrument(1, 1))
{
m_SndFile.m_nInstruments = 1;
InitializeInstrument(m_SndFile.Instruments[1]);
}
}
if (m_SndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT | MOD_TYPE_XM))
{
m_SndFile.m_SongFlags.set(SONG_LINEARSLIDES);
}
m_SndFile.GetSample(1).Initialize(m_SndFile.GetType());

if(m_SndFile.GetType() == MOD_TYPE_XM)
{
if(ModInstrument *ins = m_SndFile.AllocateInstrument(1, 1))
InitializeInstrument(ins);
}
m_SndFile.ResetPlayPos();

m_SndFile.m_songArtist = TrackerSettings::Instance().defaultArtist;
}

Expand Down

0 comments on commit 392b4b0

Please sign in to comment.