84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
![]() |
/**
|
||
|
* Furnace Tracker - multi-system chiptune tracker
|
||
|
* Copyright (C) 2021-2024 tildearrow and contributors
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License along
|
||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||
|
*/
|
||
|
|
||
|
#include "fileOpsCommon.h"
|
||
|
|
||
|
bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
||
|
struct InvalidHeaderException {};
|
||
|
bool success=false;
|
||
|
char magic[4];
|
||
|
SafeReader reader=SafeReader(file,len);
|
||
|
warnings="";
|
||
|
|
||
|
try {
|
||
|
DivSong ds;
|
||
|
ds.version=DIV_VERSION_XM;
|
||
|
//ds.linearPitch=0;
|
||
|
//ds.pitchMacroIsLinear=false;
|
||
|
ds.noSlidesOnFirstTick=true;
|
||
|
ds.rowResetsArpPos=true;
|
||
|
ds.ignoreJumpAtEnd=false;
|
||
|
ds.pitchSlideSpeed=12;
|
||
|
|
||
|
logV("Impulse Tracker module");
|
||
|
|
||
|
// load here
|
||
|
if (!reader.seek(0,SEEK_SET)) {
|
||
|
logE("premature end of file!");
|
||
|
lastError="incomplete file";
|
||
|
delete[] file;
|
||
|
return false;
|
||
|
}
|
||
|
reader.read(magic,4);
|
||
|
|
||
|
if (memcmp(magic,DIV_IT_MAGIC,4)!=0) {
|
||
|
logW("the magic isn't complete");
|
||
|
throw EndOfFileException(&reader,reader.tell());
|
||
|
}
|
||
|
|
||
|
ds.name=reader.readString(26);
|
||
|
|
||
|
if (active) quitDispatch();
|
||
|
BUSY_BEGIN_SOFT;
|
||
|
saveLock.lock();
|
||
|
song.unload();
|
||
|
song=ds;
|
||
|
changeSong(0);
|
||
|
recalcChans();
|
||
|
saveLock.unlock();
|
||
|
BUSY_END;
|
||
|
if (active) {
|
||
|
initDispatch();
|
||
|
BUSY_BEGIN;
|
||
|
renderSamples();
|
||
|
reset();
|
||
|
BUSY_END;
|
||
|
}
|
||
|
success=true;
|
||
|
} catch (EndOfFileException& e) {
|
||
|
//logE("premature end of file!");
|
||
|
lastError="incomplete file";
|
||
|
} catch (InvalidHeaderException& e) {
|
||
|
//logE("invalid header!");
|
||
|
lastError="invalid header!";
|
||
|
}
|
||
|
return success;
|
||
|
}
|
||
|
|