Skip to content

Commit

Permalink
ChannelSplit Tests and Corrections (#1480)
Browse files Browse the repository at this point in the history
1. Add a collection of unit tests to Channel Split mode in
   both MPE and Non-MPE mode

2. From running those tests, fix the bug in non-MPE mode with
   channel mask; and fix the bug with < vs <=

Closes #1476
  • Loading branch information
baconpaul authored Jan 15, 2020
1 parent 97d364e commit e9ec2b6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int SurgeSynthesizer::calculateChannelMask(int channel, int key)
*/
int channelmask = channel;

if ((channel == 0) || (channel > 2) || mpeEnabled)
if ((channel == 0) || (channel > 2) || mpeEnabled || storage.getPatch().scenemode.val.i == sm_chsplit )
{
switch (storage.getPatch().scenemode.val.i)
{
Expand All @@ -226,7 +226,7 @@ int SurgeSynthesizer::calculateChannelMask(int channel, int key)
channelmask = 2;
break;
case sm_chsplit:
if( channel <= ( (int)( storage.getPatch().splitkey.val.i / 8 ) + 1 ) )
if( channel < ( (int)( storage.getPatch().splitkey.val.i / 8 ) + 1 ) )
channelmask = 1;
else
channelmask = 2;
Expand All @@ -241,7 +241,7 @@ int SurgeSynthesizer::calculateChannelMask(int channel, int key)
else
channelmask = 1;
}

return channelmask;
}

Expand Down
4 changes: 2 additions & 2 deletions src/headless/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ playerEvents_t makeHoldMiddleC(int forSamples, int withTail)
return makeHoldNoteFor(60, forSamples, withTail );
}

playerEvents_t makeHoldNoteFor( int note, int forSamples, int withTail )
playerEvents_t makeHoldNoteFor( int note, int forSamples, int withTail, int midiChannel )
{
playerEvents_t result;

Event on;
on.type = Event::NOTE_ON;
on.channel = 0;
on.channel = midiChannel;
on.data1 = note;
on.data2 = 100;
on.atSample = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/headless/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef std::vector<Event> playerEvents_t; // We assume these are monotonic in E
*/
playerEvents_t makeHoldMiddleC(int forSamples, int withTail = 0);

playerEvents_t makeHoldNoteFor(int note, int forSamples, int withTail = 0);
playerEvents_t makeHoldNoteFor(int note, int forSamples, int withTail = 0, int midiChannel = 0);

playerEvents_t make120BPMCMajorQuarterNoteScale(long sample0 = 0, int sr = 44100);

Expand Down
48 changes: 45 additions & 3 deletions src/headless/UnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ std::shared_ptr<SurgeSynthesizer> surgeOnSine()
** frequency measure (which works great for the sine patch and poorly for others
** At one day we could do this with autocorrelation instead but no need now.
*/
double frequencyForNote( std::shared_ptr<SurgeSynthesizer> surge, int note, int seconds = 2, bool channel = 0 )
double frequencyForNote( std::shared_ptr<SurgeSynthesizer> surge, int note,
int seconds = 2, bool audioChannel = 0,
int midiChannel = 0 )
{
auto events = Surge::Headless::makeHoldNoteFor( note, 44100 * seconds, 64 );
auto events = Surge::Headless::makeHoldNoteFor( note, 44100 * seconds, 64, midiChannel );
float *buffer;
int nS, nC;
Surge::Headless::playAsConfigured( surge.get(), events, &buffer, &nS, &nC );
Expand All @@ -156,7 +158,7 @@ double frequencyForNote( std::shared_ptr<SurgeSynthesizer> surge, int note, int
float *leftTrimmed = new float[nSTrim];

for( int i=0; i<nSTrim; ++i )
leftTrimmed[i] = buffer[ (i + start) * 2 + channel ];
leftTrimmed[i] = buffer[ (i + start) * 2 + audioChannel ];

// OK so now look for sample times between positive/negative crosses
int v = -1;
Expand Down Expand Up @@ -1432,6 +1434,46 @@ TEST_CASE( "ADSR Envelope Behaviour", "[mod]" )
}


TEST_CASE( "Channel Split Routes on Channel", "[midi]" )
{
auto surge = std::shared_ptr<SurgeSynthesizer>( Surge::Headless::createSurge(44100) );
REQUIRE( surge );
REQUIRE( surge->loadPatchByPath( "test-data/patches/ChannelSplit-Sin-2OctaveB.fxp", -1, "Test" ) );

SECTION( "Regular (non-MPE)" )
{
surge->mpeEnabled = false;
for( auto splitChan = 2; splitChan < 14; splitChan ++ )
{
auto smc = splitChan * 8;
surge->storage.getPatch().splitkey.val.i = smc;
for( auto mc=0; mc<16; ++mc )
{
auto fr = frequencyForNote( surge, 69, 2, 0, mc );
auto targetfr = mc <= splitChan ? 440 : 440 * 4;
REQUIRE( fr == Approx( targetfr ).margin( 0.1 ) );
}
}
}


SECTION( "MPE Enabled" )
{
surge->mpeEnabled = true;
for( auto splitChan = 2; splitChan < 14; splitChan ++ )
{
auto smc = splitChan * 8;
surge->storage.getPatch().splitkey.val.i = smc;
for( auto mc=0; mc<16; ++mc )
{
auto fr = frequencyForNote( surge, 69, 2, 0, mc );
auto targetfr = mc <= splitChan ? 440 : 440 * 4;
REQUIRE( fr == Approx( targetfr ).margin( 0.1 ) );
}
}
}
}


int runAllTests(int argc, char **argv)
{
Expand Down
Binary file added test-data/patches/ChannelSplit-Sin-2OctaveB.fxp
Binary file not shown.

0 comments on commit e9ec2b6

Please sign in to comment.