From cc1d6a0bc6a6f783981367956370489130a659f1 Mon Sep 17 00:00:00 2001
From: Casper Jeukendrup <48658420+cbjeukendrup@users.noreply.github.com>
Date: Sun, 8 Sep 2024 04:19:01 +0200
Subject: [PATCH] Add test
---
.../dynamics/dynamics_niente.mscx | 413 ++++++++++++++++++
.../tests/playback/playbackcontext_tests.cpp | 58 +++
2 files changed, 471 insertions(+)
create mode 100644 src/engraving/tests/playback/playbackcontext_data/dynamics/dynamics_niente.mscx
diff --git a/src/engraving/tests/playback/playbackcontext_data/dynamics/dynamics_niente.mscx b/src/engraving/tests/playback/playbackcontext_data/dynamics/dynamics_niente.mscx
new file mode 100644
index 0000000000000..8cbb5c48afd19
--- /dev/null
+++ b/src/engraving/tests/playback/playbackcontext_data/dynamics/dynamics_niente.mscx
@@ -0,0 +1,413 @@
+
+
+ 4.5.0
+
+ 491
+
+ 480
+ 1
+ 1
+ 1
+ 0
+ 1
+
+
+ Componist / arrangeur
+
+ 2024-09-08
+
+
+
+ Apple Macintosh
+
+
+ Ondertitel
+
+
+ Naamloze partituur
+
+ Orchestra
+
+ Orkest strijkers
+
+
+ flutes
+ oboes
+ clarinets
+ saxophones
+ bassoons
+
+
+
+ horns
+ trumpets
+ cornets
+ flugelhorns
+ trombones
+ tubas
+
+
+
+
+ keyboard-percussion
+
+ drums
+ unpitched-metal-percussion
+ unpitched-wooden-percussion
+ other-percussion
+
+
+ keyboards
+ harps
+ organs
+ synths
+
+
+
+ voices
+ voice-groups
+
+
+
+
+
+
+ stdNormal
+
+
+ Viool
+
+ Viool
+ Vl.
+ Viool
+ 55
+ 103
+ 55
+ 88
+ strings.violin
+
+
+ Fluid
+
+
+
+ Fluid
+
+
+
+ Fluid
+
+
+
+
+
+ 10
+ 592705486970
+
+ 597000454149
+
+ Naamloze partituur
+
+
+ 601295421445
+
+ Ondertitel
+
+
+ 605590388741
+
+ Componist / arrangeur
+
+
+
+
+
+ 47244640279
+ 0
+
+
+ 38654705689
+ 4
+ 4
+
+
+ f
+ 96
+ 7344394076196
+
+
+
+ 1
+ 2589865279582
+
+
+
+ 1
+
+
+
+
+ 2456721293427
+ whole
+
+ 2452426326036
+
+
+ 11166914969631
+
+
+
+ 1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+ n
+ 49
+ 2585570312228
+
+
+
+
+ -1
+
+
+
+
+ 11154030067827
+ whole
+
+ 11149735100436
+
+
+
+ -1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+ f
+ 96
+ 7348689043492
+
+
+
+ 1
+ 1
+ 2589865279582
+
+
+
+ 1
+
+
+
+
+ 2456721293427
+ whole
+
+ 2452426326036
+
+
+ 11222749544479
+
+
+
+ 1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+
+
+ -1
+
+
+
+
+ 11209864642675
+ whole
+
+ 11205569675284
+
+
+
+ -1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+ n
+ 49
+ 2100239007780
+
+
+
+ 0
+ 1743756722270
+
+
+
+ 1
+
+
+
+
+ 1636382539891
+ whole
+
+ 1632087572500
+
+
+ 1653562408991
+
+
+
+ 1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+ f
+ 96
+ 2104533975076
+
+
+
+
+ -1
+
+
+
+
+ 1662152343667
+ whole
+
+ 1657857376276
+
+
+
+ -1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+
+ 0
+ 1
+ 2070174236766
+
+
+
+ 1
+
+
+
+
+ 1692217114739
+ whole
+
+ 1687922147348
+
+
+ 1709396983839
+
+
+
+ 1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
+ f
+ 96
+ 2108828942372
+
+
+
+
+ -1
+
+
+
+
+ 1717986918515
+ whole
+
+ 1713691951124
+
+
+
+ -1
+
+
+
+ 74
+ 16
+
+
+
+
+
+
+
diff --git a/src/engraving/tests/playback/playbackcontext_tests.cpp b/src/engraving/tests/playback/playbackcontext_tests.cpp
index ea1e12d3e40ad..0b8b7da10727d 100644
--- a/src/engraving/tests/playback/playbackcontext_tests.cpp
+++ b/src/engraving/tests/playback/playbackcontext_tests.cpp
@@ -330,6 +330,64 @@ TEST_F(Engraving_PlaybackContextTests, Dynamics_Overlap)
}
}
+TEST_F(Engraving_PlaybackContextTests, Dynamics_Niente)
+{
+ // [GIVEN]
+ Score* score = ScoreRW::readScore(PLAYBACK_CONTEXT_TEST_FILES_DIR + "dynamics/dynamics_niente.mscx");
+
+ const std::vector& parts = score->parts();
+ ASSERT_FALSE(parts.empty());
+
+ // [GIVEN] Context for parsing dynamics
+ PlaybackContext ctx;
+
+ // [WHEN] Parse dynamics
+ const Part* part = parts.front();
+ ctx.update(part->id(), score);
+
+ // [WHEN] Get the actual dynamics
+ DynamicLevelLayers actualLayers = ctx.dynamicLevelLayers(score);
+
+ // [THEN] The dynamics match the expectation
+ DynamicLevelMap expectedDynamics;
+
+ constexpr mpe::dynamic_level_t f = dynamicLevelFromType(mpe::DynamicType::f);
+ constexpr mpe::dynamic_level_t n = dynamicLevelFromType(mpe::DynamicType::ppppppppp);
+
+ const std::map f_to_n_curve = TConv::easingValueCurve(1920, HAIRPIN_STEPS, static_cast(n - f), ChangeMethod::NORMAL);
+ const std::map n_to_f_curve = TConv::easingValueCurve(1920, HAIRPIN_STEPS, static_cast(f - n), ChangeMethod::NORMAL);
+
+ // 1st measure: Decresc. al niente with 'n' dynamic
+ for (const auto& pair : f_to_n_curve) {
+ mpe::timestamp_t time = timestampFromTicks(score, pair.first);
+ expectedDynamics.emplace(time, f + static_cast(pair.second));
+ }
+
+ // 3rd measure: same, now with niente circle
+ for (const auto& pair : f_to_n_curve) {
+ mpe::timestamp_t time = timestampFromTicks(score, 3840 + pair.first);
+ expectedDynamics.emplace(time, f + static_cast(pair.second));
+ }
+
+ // 5th measure: Cresc. dal niente with 'n' dynamic
+ for (const auto& pair : n_to_f_curve) {
+ mpe::timestamp_t time = timestampFromTicks(score, 7680 + pair.first);
+ expectedDynamics.emplace(time, n + static_cast(pair.second));
+ }
+
+ // 7th measure: same, now with niente circle
+ for (const auto& pair : n_to_f_curve) {
+ mpe::timestamp_t time = timestampFromTicks(score, 11520 + pair.first);
+ expectedDynamics.emplace(time, n + static_cast(pair.second));
+ }
+
+ EXPECT_FALSE(actualLayers.empty());
+ for (const auto& layer : actualLayers) {
+ const DynamicLevelMap& actualDynamics = layer.second;
+ EXPECT_EQ(actualDynamics, expectedDynamics);
+ }
+}
+
TEST_F(Engraving_PlaybackContextTests, PlayTechniques)
{
// [GIVEN] Score with playing technique annotations