Skip to content

Commit 71743e3

Browse files
author
larspalo
committed
Attempted to improve BAS/MEL coupler hit rate without having tones jump between voices too much
1 parent aca2058 commit 71743e3

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/grandorgue/model/GOCoupler.cpp

+29-9
Original file line numberDiff line numberDiff line change
@@ -309,20 +309,40 @@ void GOCoupler::ChangeKey(int note, unsigned velocity) {
309309
m_CurrentTone = -1;
310310
}
311311

312-
if (
313-
((velocity > 0 && nextNote == note)
314-
|| (velocity == 0 && nextNote == m_LastTone))
315-
|| m_CurrentTone == -1)
312+
if (((velocity > 0 && nextNote == note)
313+
|| (velocity == 0 && nextNote == m_LastTone)))
316314
m_CurrentTone = nextNote;
317315

318316
if (m_CurrentTone != -1)
319317
SetOut(m_CurrentTone + m_Keyshift, m_KeyVelocity[m_CurrentTone]);
320318

321-
if (velocity > 0)
322-
m_LastTone = note;
323-
else
324-
m_LastTone = -1;
325-
return;
319+
int nextCandidate = nextNote;
320+
if (m_CouplerType == COUPLER_BASS) {
321+
for (nextCandidate += 1; nextCandidate < (int)m_KeyVelocity.size();
322+
nextCandidate++)
323+
if (m_KeyVelocity[nextCandidate] > 0)
324+
break;
325+
if (nextCandidate == (int)m_KeyVelocity.size())
326+
nextCandidate = -1;
327+
if (velocity > 0)
328+
m_LastTone = (note < nextCandidate)
329+
? note
330+
: (nextCandidate < 0 ? note : nextCandidate);
331+
else
332+
m_LastTone = (note < nextCandidate) ? -1 : nextCandidate;
333+
return;
334+
} else {
335+
for (nextCandidate -= 1; nextCandidate >= 0; nextCandidate--)
336+
if (m_KeyVelocity[nextCandidate] > 0)
337+
break;
338+
if (velocity > 0)
339+
m_LastTone = (note > nextCandidate)
340+
? note
341+
: (nextCandidate > 0 ? nextCandidate : note);
342+
else
343+
m_LastTone = (note > nextCandidate) ? -1 : nextCandidate;
344+
return;
345+
}
326346
}
327347
SetOut(note + m_Keyshift, velocity);
328348
}

0 commit comments

Comments
 (0)