Rewrite per-system effect handling (#548)

* Rewrite per-system effect handling

* fix build

* C64: fix fine cutoff regression

* fix some more crashes

Co-authored-by: tildearrow <tildearrow@protonmail.com>
This commit is contained in:
Natt Akuma 2022-08-18 13:26:22 +07:00 committed by GitHub
parent 5c5d9368bc
commit 7c42453422
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 477 additions and 2571 deletions

View file

@ -292,13 +292,39 @@ int DivEngine::dispatchCmd(DivCommand c) {
}
bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effectVal) {
if (sysDefs[sysOfChan[ch]]==NULL) return false;
return sysDefs[sysOfChan[ch]]->effectFunc(ch,effect,effectVal);
DivSysDef* sysDef=sysDefs[sysOfChan[ch]];
if (sysDef==NULL) return false;
auto iter=sysDef->effectHandlers.find(effect);
if (iter==sysDef->effectHandlers.end()) return false;
EffectHandler handler=iter->second;
int val=0;
int val2=0;
try {
val=handler.val?handler.val(effect,effectVal):effectVal;
val2=handler.val2?handler.val2(effect,effectVal):0;
} catch (DivDoNotHandleEffect& e) {
return false;
}
// wouldn't this cause problems if it were to return 0?
return dispatchCmd(DivCommand(handler.dispatchCmd,ch,val,val2));
}
bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal) {
if (sysDefs[sysOfChan[ch]]==NULL) return false;
return sysDefs[sysOfChan[ch]]->postEffectFunc(ch,effect,effectVal);
DivSysDef* sysDef=sysDefs[sysOfChan[ch]];
if (sysDef==NULL) return false;
auto iter=sysDef->postEffectHandlers.find(effect);
if (iter==sysDef->postEffectHandlers.end()) return false;
EffectHandler handler=iter->second;
int val=0;
int val2=0;
try {
val=handler.val?handler.val(effect,effectVal):effectVal;
val2=handler.val2?handler.val2(effect,effectVal):0;
} catch (DivDoNotHandleEffect& e) {
return true;
}
// wouldn't this cause problems if it were to return 0?
return dispatchCmd(DivCommand(handler.dispatchCmd,ch,val,val2));
}
void DivEngine::processRow(int i, bool afterDelay) {
@ -609,9 +635,6 @@ void DivEngine::processRow(int i, bool afterDelay) {
clockDrift=0;
subticks=0;
break;
case 0xdf: // set sample direction
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_DIR,i,effectVal));
break;
case 0xe0: // arp speed
if (effectVal>0) {
curSubSong->arpLen=effectVal;