Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Sourcecode/include/mx/api/PitchData.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ namespace mx
// default construction is middle c (c4)
PitchData();

constexpr explicit PitchData(
Step inStep,
int inAlter = 0,
int inOctave = 4,
Accidental inAccidental = Accidental::none,

// less-often used params last
double inCents = 0.0,
bool inIsAccidentalParenthetical = false,
bool inIsAccidentalCautionary = false,
bool inIsAccidentalEditorial = false,
bool inIsAccidentalBracketed = false
)
: step{ inStep }
, alter{ inAlter }
, cents{ inCents }
, accidental{ inAccidental }
, isAccidentalParenthetical{ inIsAccidentalParenthetical }
, isAccidentalCautionary{ inIsAccidentalCautionary }
, isAccidentalEditorial{ inIsAccidentalEditorial }
, isAccidentalBracketed{ inIsAccidentalBracketed }
, octave{ inOctave }
{

}

// the note name. i.e. c, d, e, f, g, a, b
Step step;

Expand All @@ -82,8 +108,8 @@ namespace mx
// additional alteration to the sounding pitch (in hundredths of a semitone). the MusicXML alter value is
// a floating point number to facilitate microtonal music. however for mx::api we wanted the simplicity of
// dealing with integrals for the more common case on non-microtonal music. in order to still support
// microtones without resording to a floating-point alter value, we break out microtonal adjustments to a
// separate 'cents' field, which will be addeded to the alter integral:
// microtones without resorting to a floating-point alter value, we break out microtonal adjustments to a
// separate 'cents' field, which will be added to the alter integral:
// <alter> = (double)alter + (cents / 100.0)
double cents;

Expand Down
13 changes: 2 additions & 11 deletions Sourcecode/private/mx/api/PitchData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@ namespace mx
namespace api
{
PitchData::PitchData()
: step{ Step::c }
, alter{ 0 }
, cents{ 0.0 }
, accidental{Accidental::none}
, isAccidentalParenthetical{ false }
, isAccidentalCautionary{ false }
, isAccidentalEditorial{ false }
, isAccidentalBracketed{ false }
, octave{ 4 }
: PitchData{ Step::c }
{

}



void PitchData::showAccidental()
{
switch( alter )
Expand Down
30 changes: 30 additions & 0 deletions Sourcecode/private/mxtest/api/PitchDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "mx/core/elements/Pedal.h"
#include "ezxml/ezxml.h"

#include <unordered_map>

using namespace std;
using namespace mx::api;

Expand Down Expand Up @@ -271,4 +273,32 @@ TEST( CrazyEdgeCase2, PitchData )
}
T_END;

namespace
{
struct PitchHash
{
constexpr inline size_t operator()(const mx::api::PitchData& p) const {
size_t h1 = size_t(p.step) << 32;
size_t h2 = size_t(p.alter);
return h1 ^ h2;
}
};
}

TEST( ConstructorTest, PitchData )
{
// duplicate the feature request from https://github.com/webern/mx/issues/69
std::unordered_map<mx::api::PitchData, int, PitchHash> root_to_key_circle {
{ PitchData{ Step::f, 0, 4 }, -1 },
{ PitchData{ Step::c, 0, 4 }, 0 },
{ PitchData{ Step::g, 0, 4 }, 1 },
};

PitchData g{ Step::g };
const auto find_iter = root_to_key_circle.find( g );
REQUIRE( find_iter != std::cend( root_to_key_circle ) );
CHECK_EQUAL( 1, find_iter->second );
}
T_END;

#endif
8 changes: 4 additions & 4 deletions Sourcecode/private/mxtest/import/ExpectedFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ namespace mxtest
{
for( auto qIter = q.begin(); qIter != q.end(); ++qIter )
{
if( qIter->wait_for( std::chrono::milliseconds(0) ) == std::future_status::ready )
if( qIter->wait_for( std::chrono::milliseconds(2) ) == std::future_status::ready )
{
qIter->wait();
q.erase( qIter );
Expand All @@ -311,17 +311,17 @@ namespace mxtest
q.push_front( std::move( fut ) );
}

while( q.empty() )
while( !q.empty() )
{
for( auto qIter = q.begin(); qIter != q.end(); ++qIter )
{
if( qIter->wait_for( std::chrono::milliseconds(0) ) == std::future_status::ready )
if( qIter->wait_for( std::chrono::milliseconds(10) ) == std::future_status::ready )
{
qIter->wait();
q.erase( qIter );
break;
}
std::this_thread::sleep_for( std::chrono::milliseconds(10) );
std::this_thread::sleep_for( std::chrono::milliseconds(50) );
}
}
std::cout << "done" << std::endl;
Expand Down