Skip to content

Commit

Permalink
fix new system logic #52 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
webern authored Feb 20, 2020
1 parent b6ef06f commit 0271965
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sourcecode/private/mx/impl/MeasureWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ namespace mx
const bool isSystemDataSpecified =
systemData.isMarginSpecified
|| systemData.isSystemDistanceSpecified
|| systemData.isTopSystemDistanceSpecified;
|| systemData.isTopSystemDistanceSpecified
|| systemData.measureIndex >= 0;

if( !isSystemDataSpecified && !myHistory.getCursor().isFirstMeasureInPart )
{
Expand Down
2 changes: 1 addition & 1 deletion Sourcecode/private/mx/impl/OrnamentsFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace mx
{
outMark.name = "this tremolo is not a mark";
outMark.markType = api::MarkType::unknownOrnament;
MX_LOG( "This tremolo is not supported because it starts and stops on different notes." );
// MX_LOG( "This tremolo is not supported because it starts and stops on different notes." );
return;
}

Expand Down
150 changes: 150 additions & 0 deletions Sourcecode/private/mxtest/api/NewSystemTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// MusicXML Class Library
// Copyright (c) by Matthew James Briggs
// Distributed under the MIT License

#include "mxtest/control/CompileControl.h"
#ifdef MX_COMPILE_API_TESTS

#include "cpul/cpulTestHarness.h"
#include "mx/api/DocumentManager.h"
#include "mx/core/Document.h"

using namespace std;
using namespace mx::api;

TEST( newSystem, doesItWork )
{
std::vector<MeasureData> measures;
const auto addMeasure = [&]()
{
VoiceData voiceData;
NoteData n;
n.tickTimePosition = 0;
n.pitchData.step = Step::c;
n.pitchData.octave = 5;
n.durationData.durationName = DurationName::quarter;
n.durationData.durationTimeTicks = DEFAULT_TICKS_PER_QUARTER;
voiceData.notes.push_back( n );
n.tickTimePosition += DEFAULT_TICKS_PER_QUARTER;
n.pitchData.step = Step::d;
voiceData.notes.push_back( n );
n.tickTimePosition += DEFAULT_TICKS_PER_QUARTER;
n.pitchData.step = Step::e;
voiceData.notes.push_back( n );
n.tickTimePosition += DEFAULT_TICKS_PER_QUARTER;
n.pitchData.step = Step::f;
voiceData.notes.push_back( n );
StaffData staff{};
staff.voices.emplace( 0, voiceData );
MeasureData m;
m.staves.push_back( staff );
measures.push_back( m );
};

for( int i = 0; i < 100; ++i )
{
addMeasure();
}

PartData pd;
pd.name = "Flute";
pd.displayName = "Flute";
pd.measures = measures;
ScoreData s;
s.parts.push_back( pd );
SystemData system;
system.measureIndex = 0;
s.systems.insert( system );
system.measureIndex = 3;
s.systems.insert( system );
system.measureIndex = 7;
s.systems.insert( system );
system.measureIndex = 13;
s.systems.insert( system );
system.measureIndex = 17;
s.systems.insert( system );
system.measureIndex = 25;
s.systems.insert( system );
system.measureIndex = 50;
s.systems.insert( system );
system.measureIndex = 75;
s.systems.insert( system );
auto& docMgr = DocumentManager::getInstance();
const auto id = docMgr.createFromScore( s );
const auto doc = docMgr.getDocument( id );
docMgr.destroyDocument( id );
const auto sp = doc->getScorePartwise();
const auto p = sp->getPartwisePartSet().at( 0 );

size_t index = 0;
auto mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
auto print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 3;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 7;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 13;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 17;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 25;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 50;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

index = 75;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( print->getAttributes()->hasNewSystem );
CHECK( print->getAttributes()->newSystem == mx::core::YesNo::yes );

// check a couple of negative cases to make sure not every measure is new system

index = 76;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( !print->getAttributes()->hasNewSystem );

index = 4;
mdg = p->getPartwiseMeasureSet().at( index );
CHECK( mdg->getAttributes()->number.getValue() == std::to_string( index + 1 ) );
print = mdg->getMusicDataGroup()->getMusicDataChoiceSet().at( 0 )->getPrint();
CHECK( !print->getAttributes()->hasNewSystem );
}

#endif

0 comments on commit 0271965

Please sign in to comment.