dev80 - increase song limits

up to 256 patterns
up to 256 orders
This commit is contained in:
tildearrow 2022-04-08 17:21:36 -05:00
parent ff0c1f427f
commit 9e0e8f3345
11 changed files with 54 additions and 22 deletions

View file

@ -1281,7 +1281,7 @@ void DivEngine::delInstrument(int index) {
song.ins.erase(song.ins.begin()+index);
song.insLen=song.ins.size();
for (int i=0; i<chans; i++) {
for (int j=0; j<128; j++) {
for (int j=0; j<256; j++) {
if (song.pat[i].data[j]==NULL) continue;
for (int k=0; k<song.patLen; k++) {
if (song.pat[i].data[j]->data[k][2]>index) {
@ -1556,7 +1556,7 @@ void DivEngine::delSample(int index) {
void DivEngine::addOrder(bool duplicate, bool where) {
unsigned char order[DIV_MAX_CHANS];
if (song.ordersLen>=0x7e) return;
if (song.ordersLen>=0xff) return;
BUSY_BEGIN_SOFT;
if (duplicate) {
for (int i=0; i<DIV_MAX_CHANS; i++) {
@ -1569,7 +1569,7 @@ void DivEngine::addOrder(bool duplicate, bool where) {
for (int j=0; j<song.ordersLen; j++) {
used[song.orders.ord[i][j]]=true;
}
order[i]=0x7e;
order[i]=0xff;
for (int j=0; j<256; j++) {
if (!used[j]) {
order[i]=j;
@ -1605,7 +1605,7 @@ void DivEngine::addOrder(bool duplicate, bool where) {
void DivEngine::deepCloneOrder(bool where) {
unsigned char order[DIV_MAX_CHANS];
if (song.ordersLen>=0x7e) return;
if (song.ordersLen>=0xff) return;
warnings="";
BUSY_BEGIN_SOFT;
for (int i=0; i<chans; i++) {
@ -1613,7 +1613,7 @@ void DivEngine::deepCloneOrder(bool where) {
logD("channel %d\n",i);
order[i]=song.orders.ord[i][curOrder];
// find free slot
for (int j=0; j<128; j++) {
for (int j=0; j<256; j++) {
logD("finding free slot in %d...\n",j);
if (song.pat[i].data[j]==NULL) {
int origOrd=order[i];
@ -1715,7 +1715,7 @@ void DivEngine::moveOrderDown() {
void DivEngine::exchangeIns(int one, int two) {
for (int i=0; i<chans; i++) {
for (int j=0; j<128; j++) {
for (int j=0; j<256; j++) {
if (song.pat[i].data[j]==NULL) continue;
for (int k=0; k<song.patLen; k++) {
if (song.pat[i].data[j]->data[k][2]==one) {

View file

@ -42,8 +42,8 @@
#define BUSY_BEGIN_SOFT softLocked=true; isBusy.lock();
#define BUSY_END isBusy.unlock(); softLocked=false;
#define DIV_VERSION "dev79"
#define DIV_ENGINE_VERSION 79
#define DIV_VERSION "dev80"
#define DIV_ENGINE_VERSION 80
// for imports
#define DIV_VERSION_MOD 0xff01

View file

@ -959,7 +959,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
delete[] file;
return false;
}
if (ds.ordersLen>127) {
if (ds.ordersLen>256) {
logE("song is too long!\n");
lastError="song is too long!";
delete[] file;
@ -1407,6 +1407,8 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
int index=reader.readS();
reader.readI();
logD("- %d, %d\n",chan,index);
if (chan<0 || chan>=tchans) {
logE("pattern channel out of range!\n",i);
lastError="pattern channel out of range!";
@ -1414,7 +1416,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
delete[] file;
return false;
}
if (index<0 || index>127) {
if (index<0 || index>255) {
logE("pattern index out of range!\n",i);
lastError="pattern index out of range!";
ds.unload();
@ -1422,8 +1424,6 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
return false;
}
logD("- %d, %d\n",chan,index);
DivPattern* pat=ds.pat[chan].getPattern(index,true);
for (int j=0; j<ds.patLen; j++) {
pat->data[j][0]=reader.readS();
@ -2292,6 +2292,31 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) {
lastError="this system is not possible on .dmf";
return NULL;
}
// fail if values are out of range
if (song.ordersLen>127) {
logE("maximum .dmf song length is 127!\n");
lastError="maximum .dmf song length is 127";
return NULL;
}
if (song.ins.size()>128) {
logE("maximum number of instruments in .dmf is 128!\n");
lastError="maximum number of instruments in .dmf is 128";
return NULL;
}
if (song.wave.size()>64) {
logE("maximum number of wavetables in .dmf is 64!\n");
lastError="maximum number of wavetables in .dmf is 64";
return NULL;
}
for (int i=0; i<chans; i++) {
for (int j=0; j<song.ordersLen; j++) {
if (song.orders.ord[i][j]>0x7f) {
logE("order %d, %d is out of range (0-127)!\n",song.orders.ord[i][j]);
lastError=fmt::sprintf("order %d, %d is out of range (0-127)",song.orders.ord[i][j]);
return NULL;
}
}
}
saveLock.lock();
warnings="";
song.version=version;

View file

@ -21,10 +21,10 @@
#define _ORDERS_H
struct DivOrders {
unsigned char ord[DIV_MAX_CHANS][128];
unsigned char ord[DIV_MAX_CHANS][256];
DivOrders() {
memset(ord,0,DIV_MAX_CHANS*128);
memset(ord,0,DIV_MAX_CHANS*256);
}
};

View file

@ -41,7 +41,7 @@ DivPattern* DivChannelData::getPattern(int index, bool create) {
}
void DivChannelData::wipePatterns() {
for (int i=0; i<128; i++) {
for (int i=0; i<256; i++) {
if (data[i]!=NULL) {
delete data[i];
data[i]=NULL;
@ -131,5 +131,5 @@ SafeReader* DivPattern::compile(int len, int fxRows) {
DivChannelData::DivChannelData():
effectRows(1) {
memset(data,0,128*sizeof(void*));
memset(data,0,256*sizeof(void*));
}

View file

@ -49,7 +49,7 @@ struct DivChannelData {
// 3: volume
// 4-5+: effect/effect value
// do NOT access directly unless you know what you're doing!
DivPattern* data[128];
DivPattern* data[256];
/**
* get a pattern from this channel, or the empty pattern if not initialized.