Skip to content

Commit 5c5896c

Browse files
committed
add convinience conversions between controller_value and pitch_7_25
1 parent 823caef commit 5c5896c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

inc/midi/types.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ struct pitch_7_9
156156

157157
//--------------------------------------------------------------------------
158158

159+
struct controller_value;
160+
161+
//--------------------------------------------------------------------------
162+
159163
struct pitch_7_25
160164
{
161165
uint32_t value{ 0 };
@@ -164,6 +168,7 @@ struct pitch_7_25
164168
constexpr explicit pitch_7_25(uint32_t);
165169
constexpr explicit pitch_7_25(pitch_7_9);
166170
constexpr explicit pitch_7_25(note_nr_t);
171+
constexpr explicit pitch_7_25(const controller_value&);
167172
constexpr explicit pitch_7_25(float);
168173
constexpr explicit pitch_7_25(double);
169174

@@ -216,6 +221,7 @@ struct controller_value
216221
constexpr explicit controller_value(uint32_t);
217222
constexpr explicit controller_value(uint14_t);
218223
constexpr explicit controller_value(uint7_t);
224+
constexpr explicit controller_value(const pitch_7_25&);
219225
constexpr explicit controller_value(float);
220226
constexpr explicit controller_value(double);
221227

@@ -352,6 +358,10 @@ constexpr pitch_7_25::pitch_7_25(pitch_7_9 p)
352358
{
353359
this->operator=(p);
354360
}
361+
constexpr pitch_7_25::pitch_7_25(const controller_value& v)
362+
: value(v.value)
363+
{
364+
}
355365

356366
constexpr note_nr_t pitch_7_25::note_nr() const
357367
{
@@ -401,6 +411,11 @@ constexpr controller_value::controller_value(uint7_t v)
401411
: value(upsample_7_to_32bit(v))
402412
{
403413
}
414+
constexpr controller_value::controller_value(const pitch_7_25& p)
415+
: value(p.value)
416+
{
417+
}
418+
404419
constexpr uint14_t controller_value::as_uint14() const
405420
{
406421
return downsample_32_to_14bit(value);

tests/type_tests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,19 @@ TEST(pitch_7_25, construct_from_pitch7_9)
14221422

14231423
//-----------------------------------------------
14241424

1425+
TEST(pitch_7_25, construct_from_controller_value)
1426+
{
1427+
using namespace midi;
1428+
1429+
{
1430+
pitch_7_25 p{ controller_value{ 0x12345678u } };
1431+
1432+
EXPECT_EQ(0x12345678u, p.value);
1433+
}
1434+
}
1435+
1436+
//-----------------------------------------------
1437+
14251438
TEST(pitch_7_25, construct_from_float)
14261439
{
14271440
using namespace midi;
@@ -2060,6 +2073,20 @@ TEST(controller_value, construct_from_uint7)
20602073

20612074
//-----------------------------------------------
20622075

2076+
TEST(controller_value, construct_from_pitch_7_25)
2077+
{
2078+
using namespace midi;
2079+
2080+
{
2081+
pitch_7_25 p{ 74.63 };
2082+
controller_value v{ p };
2083+
2084+
EXPECT_EQ(p.value, v.value);
2085+
}
2086+
}
2087+
2088+
//-----------------------------------------------
2089+
20632090
TEST(controller_value, construct_from_float)
20642091
{
20652092
using namespace midi;

0 commit comments

Comments
 (0)