Skip to content

Commit

Permalink
add convinience conversions between controller_value and pitch_7_25
Browse files Browse the repository at this point in the history
  • Loading branch information
fdetro committed Oct 24, 2024
1 parent 38a6a18 commit af7857d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions inc/midi/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ struct pitch_7_9

//--------------------------------------------------------------------------

struct controller_value;

//--------------------------------------------------------------------------

struct pitch_7_25
{
uint32_t value{ 0 };
Expand All @@ -164,6 +168,7 @@ struct pitch_7_25
constexpr explicit pitch_7_25(uint32_t);
constexpr explicit pitch_7_25(pitch_7_9);
constexpr explicit pitch_7_25(note_nr_t);
constexpr explicit pitch_7_25(const controller_value&);
constexpr explicit pitch_7_25(float);
constexpr explicit pitch_7_25(double);

Expand Down Expand Up @@ -216,6 +221,7 @@ struct controller_value
constexpr explicit controller_value(uint32_t);
constexpr explicit controller_value(uint14_t);
constexpr explicit controller_value(uint7_t);
constexpr explicit controller_value(const pitch_7_25&);
constexpr explicit controller_value(float);
constexpr explicit controller_value(double);

Expand Down Expand Up @@ -352,6 +358,10 @@ constexpr pitch_7_25::pitch_7_25(pitch_7_9 p)
{
this->operator=(p);
}
constexpr pitch_7_25::pitch_7_25(const controller_value& v)
: value(v.value)
{
}

constexpr note_nr_t pitch_7_25::note_nr() const
{
Expand Down Expand Up @@ -401,6 +411,11 @@ constexpr controller_value::controller_value(uint7_t v)
: value(upsample_7_to_32bit(v))
{
}
constexpr controller_value::controller_value(const pitch_7_25& p)
: value(p.value)
{
}

constexpr uint14_t controller_value::as_uint14() const
{
return downsample_32_to_14bit(value);
Expand Down
27 changes: 27 additions & 0 deletions tests/type_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,19 @@ TEST(pitch_7_25, construct_from_pitch7_9)

//-----------------------------------------------

TEST(pitch_7_25, construct_from_controller_value)
{
using namespace midi;

{
pitch_7_25 p{ controller_value{ 0x12345678u } };

EXPECT_EQ(0x12345678u, p.value);
}
}

//-----------------------------------------------

TEST(pitch_7_25, construct_from_float)
{
using namespace midi;
Expand Down Expand Up @@ -2060,6 +2073,20 @@ TEST(controller_value, construct_from_uint7)

//-----------------------------------------------

TEST(controller_value, construct_from_pitch_7_25)
{
using namespace midi;

{
pitch_7_25 p{ 74.63 };
controller_value v{ p };

EXPECT_EQ(p.value, v.value);
}
}

//-----------------------------------------------

TEST(controller_value, construct_from_float)
{
using namespace midi;
Expand Down

0 comments on commit af7857d

Please sign in to comment.