prepare to add asset directories

This commit is contained in:
tildearrow 2023-03-12 04:10:46 -05:00
parent 2c66e2d1d6
commit 40e153300f
3 changed files with 60 additions and 0 deletions

View File

@ -1567,6 +1567,49 @@ void DivEngine::changeSong(size_t songIndex) {
prevRow=0;
}
void DivEngine::checkAssetDir(std::vector<DivAssetDir>& dir, size_t entries) {
bool* inAssetDir=new bool[entries];
memset(inAssetDir,0,entries*sizeof(bool));
for (DivAssetDir& i: dir) {
for (size_t j=0; j<i.entries.size(); j++) {
// erase invalid entry
if (i.entries[j]<0 || i.entries[j]>=(int)entries) {
i.entries.erase(i.entries.begin()+j);
j--;
continue;
}
// mark entry as present
inAssetDir[j]=true;
}
}
// get unsorted directory
DivAssetDir* unsortedDir=NULL;
for (DivAssetDir& i: dir) {
if (i.name=="Unsorted") {
unsortedDir=&i;
break;
}
}
// create unsorted directory if it doesn't exist
if (unsortedDir==NULL) {
dir.push_back(DivAssetDir("Unsorted"));
unsortedDir=&(*dir.rbegin());
}
// add missing items to unsorted directory
for (size_t i=0; i<entries; i++) {
if (!inAssetDir[i]) {
unsortedDir->entries.push_back(i);
}
}
delete[] inAssetDir;
}
void DivEngine::swapChannelsP(int src, int dest) {
if (src<0 || src>=chans) return;
if (dest<0 || dest>=chans) return;

View File

@ -490,6 +490,9 @@ class DivEngine {
// change song (UNSAFE)
void changeSong(size_t songIndex);
// check whether an asset directory is complete
void checkAssetDir(std::vector<DivAssetDir>& dir, size_t entries);
public:
DivSong song;
DivOrders* curOrders;

View File

@ -181,6 +181,16 @@ struct DivSubSong {
}
};
struct DivAssetDir {
String name;
std::vector<int> entries;
DivAssetDir():
name("New Directory") {}
DivAssetDir(String n):
name(n) {}
};
struct DivSong {
// version number used for saving the song.
// Furnace will save using the latest possible version,
@ -351,6 +361,10 @@ struct DivSong {
std::vector<unsigned int> patchbay;
std::vector<DivGroovePattern> grooves;
std::vector<DivAssetDir> insDir;
std::vector<DivAssetDir> waveDir;
std::vector<DivAssetDir> sampleDir;
DivInstrument nullIns, nullInsOPLL, nullInsOPL, nullInsOPLDrums, nullInsQSound;
DivWavetable nullWave;
DivSample nullSample;