GUI: add option to add more systems

This commit is contained in:
tildearrow 2022-01-08 18:18:23 -05:00
parent e961cf79ca
commit c43cc0ae80
3 changed files with 53 additions and 4 deletions

View file

@ -485,7 +485,12 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
if (ds.version>0x0a) {
String hz=reader.readString(3);
if (ds.customTempo) {
ds.hz=std::stoi(hz);
try {
ds.hz=std::stoi(hz);
} catch (std::exception& e) {
logW("invalid custom Hz!\n");
ds.hz=60;
}
}
}
// TODO
@ -1516,6 +1521,28 @@ void DivEngine::changeSystem(int index, DivSystem which) {
isBusy.unlock();
}
bool DivEngine::addSystem(DivSystem which) {
if (song.systemLen>32) {
lastError="cannot add more than 32 systems";
return false;
}
if (chans+getChannelCount(which)>DIV_MAX_CHANS) {
lastError="max number of total channels is 128";
return false;
}
quitDispatch();
isBusy.lock();
song.system[song.systemLen++]=which;
recalcChans();
isBusy.unlock();
initDispatch();
isBusy.lock();
renderSamples();
reset();
isBusy.unlock();
return true;
}
String DivEngine::getLastError() {
return lastError;
}

View file

@ -402,10 +402,10 @@ class DivEngine {
void changeSystem(int index, DivSystem which);
// add system
void addSystem(DivSystem which);
bool addSystem(DivSystem which);
// remove system
void removeSystem(int index);
bool removeSystem(int index);
// get last error
String getLastError();