commit 8354fc681c9091444eef6752b786675fd144ba55
parent 7e19b5c55bd9f1012315ebc3a4d17be0a7153cbf
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Tue, 19 Jan 2016 22:02:01 -0500
NotePool: Fixup Test Failure
Diffstat:
3 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/src/Containers/NotePool.cpp b/src/Containers/NotePool.cpp
@@ -185,15 +185,25 @@ int NotePool::getRunningNotes(void) const
void NotePool::enforceKeyLimit(int limit)
{
int notes_to_kill = getRunningNotes() - limit;
- if(notes_to_kill < 0)
+ if(notes_to_kill <= 0)
return;
NoteDescriptor *to_kill = NULL;
unsigned oldest = 0;
for(auto &nd : activeDesc()) {
- if(nd.age > oldest || to_kill == NULL) {
+ if(to_kill == NULL) {
+ //There must be something to kill
oldest = nd.age;
to_kill = &nd;
+ } else if(to_kill->status == Part::KEY_RELEASED && nd.status == Part::KEY_PLAYING) {
+ //Prefer to kill off a running note
+ oldest = nd.age;
+ to_kill = &nd;
+ } else if(nd.age > oldest && !(to_kill->status == Part::KEY_PLAYING &&
+ nd.status == Part::KEY_RELEASED)) {
+ //Get an older note when it doesn't move from running to released
+ oldest = nd.age;
+ to_kill = &nd;
}
}
diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp
@@ -726,7 +726,7 @@ void Part::setkeylimit(unsigned char Pkeylimit_)
if(keylimit == 0)
keylimit = POLYPHONY - 5;
- if(notePool.getRunningNotes() > keylimit)
+ if(notePool.getRunningNotes() >= keylimit)
notePool.enforceKeyLimit(keylimit);
}
diff --git a/src/Tests/KitTest.h b/src/Tests/KitTest.h
@@ -560,9 +560,9 @@ class KitTest:public CxxTest::TestSuite
part->NoteOn(68, 127, 0);
//Verify that notes are spawned as expected with limit
- TS_ASSERT_EQUALS(pool.getRunningNotes(), 3);
- TS_ASSERT_EQUALS(pool.usedNoteDesc(), 3);
- TS_ASSERT_EQUALS(pool.usedSynthDesc(), 3);
+ TS_ASSERT_EQUALS(pool.getRunningNotes(), 3);//2 entombed
+ TS_ASSERT_EQUALS(pool.usedNoteDesc(), 5);
+ TS_ASSERT_EQUALS(pool.usedSynthDesc(), 5);
//Reset the part
part->monomemClear();
@@ -587,24 +587,32 @@ class KitTest:public CxxTest::TestSuite
pool.ndesc[1].age = 50;
pool.ndesc[2].age = 500;
+ printf("-------------------------------------\n");
+
//Inject two more notes which should steal the note
//descriptors for #66 and #65
part->NoteOn(67, 127, 0);
pool.cleanup();
TS_ASSERT_EQUALS(pool.ndesc[0].note, 64);
TS_ASSERT_EQUALS(pool.ndesc[1].note, 65);
- TS_ASSERT_EQUALS(pool.ndesc[2].note, 67);
+ TS_ASSERT_EQUALS(pool.ndesc[2].note, 66);
+ TS_ASSERT_EQUALS(pool.ndesc[2].status, Part::KEY_RELEASED);
+ TS_ASSERT_EQUALS(pool.ndesc[3].note, 67);
part->NoteOn(68, 127, 0);
- //Verify that note pool is still full
- TS_ASSERT_EQUALS(pool.usedNoteDesc(), 3);
- TS_ASSERT_EQUALS(pool.usedSynthDesc(), 3);
+ //Verify that note pool is still full and entombed
+ TS_ASSERT_EQUALS(pool.usedNoteDesc(), 5);
+ TS_ASSERT_EQUALS(pool.usedSynthDesc(), 5);
//Check that the result is {64, 68, 67}
TS_ASSERT_EQUALS(pool.ndesc[0].note, 64);
- TS_ASSERT_EQUALS(pool.ndesc[1].note, 67);
- TS_ASSERT_EQUALS(pool.ndesc[2].note, 68);
+ TS_ASSERT_EQUALS(pool.ndesc[1].note, 65);
+ TS_ASSERT_EQUALS(pool.ndesc[1].status, Part::KEY_RELEASED);
+ TS_ASSERT_EQUALS(pool.ndesc[2].note, 66);
+ TS_ASSERT_EQUALS(pool.ndesc[2].status, Part::KEY_RELEASED);
+ TS_ASSERT_EQUALS(pool.ndesc[3].note, 67);
+ TS_ASSERT_EQUALS(pool.ndesc[4].note, 68);
}
void tearDown() {