diff options
Diffstat (limited to 'quantum/sequencer/tests/sequencer_tests.cpp')
| -rw-r--r-- | quantum/sequencer/tests/sequencer_tests.cpp | 590 |
1 files changed, 590 insertions, 0 deletions
diff --git a/quantum/sequencer/tests/sequencer_tests.cpp b/quantum/sequencer/tests/sequencer_tests.cpp new file mode 100644 index 000000000..e81984e5b --- /dev/null +++ b/quantum/sequencer/tests/sequencer_tests.cpp | |||
| @@ -0,0 +1,590 @@ | |||
| 1 | /* Copyright 2020 Rodolphe Belouin | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "gtest/gtest.h" | ||
| 18 | |||
| 19 | extern "C" { | ||
| 20 | #include "sequencer.h" | ||
| 21 | #include "midi_mock.h" | ||
| 22 | #include "quantum/quantum_keycodes.h" | ||
| 23 | } | ||
| 24 | |||
| 25 | extern "C" { | ||
| 26 | void set_time(uint32_t t); | ||
| 27 | void advance_time(uint32_t ms); | ||
| 28 | } | ||
| 29 | |||
| 30 | class SequencerTest : public ::testing::Test { | ||
| 31 | protected: | ||
| 32 | void SetUp() override { | ||
| 33 | config_copy.enabled = sequencer_config.enabled; | ||
| 34 | |||
| 35 | for (int i = 0; i < SEQUENCER_STEPS; i++) { | ||
| 36 | config_copy.steps[i] = sequencer_config.steps[i]; | ||
| 37 | } | ||
| 38 | |||
| 39 | for (int i = 0; i < SEQUENCER_TRACKS; i++) { | ||
| 40 | config_copy.track_notes[i] = sequencer_config.track_notes[i]; | ||
| 41 | } | ||
| 42 | |||
| 43 | config_copy.tempo = sequencer_config.tempo; | ||
| 44 | config_copy.resolution = sequencer_config.resolution; | ||
| 45 | |||
| 46 | state_copy.active_tracks = sequencer_internal_state.active_tracks; | ||
| 47 | state_copy.current_track = sequencer_internal_state.current_track; | ||
| 48 | state_copy.current_step = sequencer_internal_state.current_step; | ||
| 49 | state_copy.timer = sequencer_internal_state.timer; | ||
| 50 | |||
| 51 | last_noteon = 0; | ||
| 52 | last_noteoff = 0; | ||
| 53 | |||
| 54 | set_time(0); | ||
| 55 | } | ||
| 56 | |||
| 57 | void TearDown() override { | ||
| 58 | sequencer_config.enabled = config_copy.enabled; | ||
| 59 | |||
| 60 | for (int i = 0; i < SEQUENCER_STEPS; i++) { | ||
| 61 | sequencer_config.steps[i] = config_copy.steps[i]; | ||
| 62 | } | ||
| 63 | |||
| 64 | for (int i = 0; i < SEQUENCER_TRACKS; i++) { | ||
| 65 | sequencer_config.track_notes[i] = config_copy.track_notes[i]; | ||
| 66 | } | ||
| 67 | |||
| 68 | sequencer_config.tempo = config_copy.tempo; | ||
| 69 | sequencer_config.resolution = config_copy.resolution; | ||
| 70 | |||
| 71 | sequencer_internal_state.active_tracks = state_copy.active_tracks; | ||
| 72 | sequencer_internal_state.current_track = state_copy.current_track; | ||
| 73 | sequencer_internal_state.current_step = state_copy.current_step; | ||
| 74 | sequencer_internal_state.timer = state_copy.timer; | ||
| 75 | } | ||
| 76 | |||
| 77 | sequencer_config_t config_copy; | ||
| 78 | sequencer_state_t state_copy; | ||
| 79 | }; | ||
| 80 | |||
| 81 | TEST_F(SequencerTest, TestOffByDefault) { EXPECT_EQ(is_sequencer_on(), false); } | ||
| 82 | |||
| 83 | TEST_F(SequencerTest, TestOn) { | ||
| 84 | sequencer_config.enabled = false; | ||
| 85 | |||
| 86 | sequencer_on(); | ||
| 87 | EXPECT_EQ(is_sequencer_on(), true); | ||
| 88 | |||
| 89 | // sequencer_on is idempotent | ||
| 90 | sequencer_on(); | ||
| 91 | EXPECT_EQ(is_sequencer_on(), true); | ||
| 92 | } | ||
| 93 | |||
| 94 | TEST_F(SequencerTest, TestOff) { | ||
| 95 | sequencer_config.enabled = true; | ||
| 96 | |||
| 97 | sequencer_off(); | ||
| 98 | EXPECT_EQ(is_sequencer_on(), false); | ||
| 99 | |||
| 100 | // sequencer_off is idempotent | ||
| 101 | sequencer_off(); | ||
| 102 | EXPECT_EQ(is_sequencer_on(), false); | ||
| 103 | } | ||
| 104 | |||
| 105 | TEST_F(SequencerTest, TestToggle) { | ||
| 106 | sequencer_config.enabled = false; | ||
| 107 | |||
| 108 | sequencer_toggle(); | ||
| 109 | EXPECT_EQ(is_sequencer_on(), true); | ||
| 110 | |||
| 111 | sequencer_toggle(); | ||
| 112 | EXPECT_EQ(is_sequencer_on(), false); | ||
| 113 | } | ||
| 114 | |||
| 115 | TEST_F(SequencerTest, TestNoActiveTrackByDefault) { | ||
| 116 | for (int i = 0; i < SEQUENCER_TRACKS; i++) { | ||
| 117 | EXPECT_EQ(is_sequencer_track_active(i), false); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | TEST_F(SequencerTest, TestGetActiveTracks) { | ||
| 122 | sequencer_internal_state.active_tracks = (1 << 7) + (1 << 6) + (1 << 3) + (1 << 1) + (1 << 0); | ||
| 123 | |||
| 124 | EXPECT_EQ(is_sequencer_track_active(0), true); | ||
| 125 | EXPECT_EQ(is_sequencer_track_active(1), true); | ||
| 126 | EXPECT_EQ(is_sequencer_track_active(2), false); | ||
| 127 | EXPECT_EQ(is_sequencer_track_active(3), true); | ||
| 128 | EXPECT_EQ(is_sequencer_track_active(4), false); | ||
| 129 | EXPECT_EQ(is_sequencer_track_active(5), false); | ||
| 130 | EXPECT_EQ(is_sequencer_track_active(6), true); | ||
| 131 | EXPECT_EQ(is_sequencer_track_active(7), true); | ||
| 132 | } | ||
| 133 | |||
| 134 | TEST_F(SequencerTest, TestGetActiveTracksOutOfBound) { | ||
| 135 | sequencer_set_track_activation(-1, true); | ||
| 136 | sequencer_set_track_activation(8, true); | ||
| 137 | |||
| 138 | EXPECT_EQ(is_sequencer_track_active(-1), false); | ||
| 139 | EXPECT_EQ(is_sequencer_track_active(8), false); | ||
| 140 | } | ||
| 141 | |||
| 142 | TEST_F(SequencerTest, TestToggleTrackActivation) { | ||
| 143 | sequencer_internal_state.active_tracks = (1 << 7) + (1 << 6) + (1 << 3) + (1 << 1) + (1 << 0); | ||
| 144 | |||
| 145 | sequencer_toggle_track_activation(6); | ||
| 146 | |||
| 147 | EXPECT_EQ(is_sequencer_track_active(0), true); | ||
| 148 | EXPECT_EQ(is_sequencer_track_active(1), true); | ||
| 149 | EXPECT_EQ(is_sequencer_track_active(2), false); | ||
| 150 | EXPECT_EQ(is_sequencer_track_active(3), true); | ||
| 151 | EXPECT_EQ(is_sequencer_track_active(4), false); | ||
| 152 | EXPECT_EQ(is_sequencer_track_active(5), false); | ||
| 153 | EXPECT_EQ(is_sequencer_track_active(6), false); | ||
| 154 | EXPECT_EQ(is_sequencer_track_active(7), true); | ||
| 155 | } | ||
| 156 | |||
| 157 | TEST_F(SequencerTest, TestToggleSingleTrackActivation) { | ||
| 158 | sequencer_internal_state.active_tracks = (1 << 7) + (1 << 6) + (1 << 3) + (1 << 1) + (1 << 0); | ||
| 159 | |||
| 160 | sequencer_toggle_single_active_track(2); | ||
| 161 | |||
| 162 | EXPECT_EQ(is_sequencer_track_active(0), false); | ||
| 163 | EXPECT_EQ(is_sequencer_track_active(1), false); | ||
| 164 | EXPECT_EQ(is_sequencer_track_active(2), true); | ||
| 165 | EXPECT_EQ(is_sequencer_track_active(3), false); | ||
| 166 | EXPECT_EQ(is_sequencer_track_active(4), false); | ||
| 167 | EXPECT_EQ(is_sequencer_track_active(5), false); | ||
| 168 | EXPECT_EQ(is_sequencer_track_active(6), false); | ||
| 169 | EXPECT_EQ(is_sequencer_track_active(7), false); | ||
| 170 | } | ||
| 171 | |||
| 172 | TEST_F(SequencerTest, TestStepOffByDefault) { | ||
| 173 | for (int i = 0; i < SEQUENCER_STEPS; i++) { | ||
| 174 | EXPECT_EQ(is_sequencer_step_on(i), false); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | TEST_F(SequencerTest, TestIsStepOffWithNoActiveTracks) { | ||
| 179 | sequencer_config.steps[3] = 0xFF; | ||
| 180 | EXPECT_EQ(is_sequencer_step_on(3), false); | ||
| 181 | } | ||
| 182 | |||
| 183 | TEST_F(SequencerTest, TestIsStepOffWithGivenActiveTracks) { | ||
| 184 | sequencer_set_track_activation(2, true); | ||
| 185 | sequencer_set_track_activation(3, true); | ||
| 186 | |||
| 187 | sequencer_config.steps[3] = (1 << 0) + (1 << 1); | ||
| 188 | |||
| 189 | // No active tracks have the step enabled, so it is off | ||
| 190 | EXPECT_EQ(is_sequencer_step_on(3), false); | ||
| 191 | } | ||
| 192 | |||
| 193 | TEST_F(SequencerTest, TestIsStepOnWithGivenActiveTracks) { | ||
| 194 | sequencer_set_track_activation(2, true); | ||
| 195 | sequencer_set_track_activation(3, true); | ||
| 196 | |||
| 197 | sequencer_config.steps[3] = (1 << 2); | ||
| 198 | |||
| 199 | // Track 2 has the step enabled, so it is on | ||
| 200 | EXPECT_EQ(is_sequencer_step_on(3), true); | ||
| 201 | } | ||
| 202 | |||
| 203 | TEST_F(SequencerTest, TestIsStepOffForGivenTrack) { | ||
| 204 | sequencer_config.steps[3] = 0x00; | ||
| 205 | EXPECT_EQ(is_sequencer_step_on_for_track(3, 5), false); | ||
| 206 | } | ||
| 207 | |||
| 208 | TEST_F(SequencerTest, TestIsStepOnForGivenTrack) { | ||
| 209 | sequencer_config.steps[3] = (1 << 5); | ||
| 210 | EXPECT_EQ(is_sequencer_step_on_for_track(3, 5), true); | ||
| 211 | } | ||
| 212 | |||
| 213 | TEST_F(SequencerTest, TestSetStepOn) { | ||
| 214 | sequencer_internal_state.active_tracks = (1 << 6) + (1 << 3) + (1 << 2); | ||
| 215 | sequencer_config.steps[2] = (1 << 5) + (1 << 2); | ||
| 216 | |||
| 217 | sequencer_set_step(2, true); | ||
| 218 | |||
| 219 | EXPECT_EQ(sequencer_config.steps[2], (1 << 6) + (1 << 5) + (1 << 3) + (1 << 2)); | ||
| 220 | } | ||
| 221 | |||
| 222 | TEST_F(SequencerTest, TestSetStepOff) { | ||
| 223 | sequencer_internal_state.active_tracks = (1 << 6) + (1 << 3) + (1 << 2); | ||
| 224 | sequencer_config.steps[2] = (1 << 5) + (1 << 2); | ||
| 225 | |||
| 226 | sequencer_set_step(2, false); | ||
| 227 | |||
| 228 | EXPECT_EQ(sequencer_config.steps[2], (1 << 5)); | ||
| 229 | } | ||
| 230 | |||
| 231 | TEST_F(SequencerTest, TestToggleStepOff) { | ||
| 232 | sequencer_internal_state.active_tracks = (1 << 6) + (1 << 3) + (1 << 2); | ||
| 233 | sequencer_config.steps[2] = (1 << 5) + (1 << 2); | ||
| 234 | |||
| 235 | sequencer_toggle_step(2); | ||
| 236 | |||
| 237 | EXPECT_EQ(sequencer_config.steps[2], (1 << 5)); | ||
| 238 | } | ||
| 239 | |||
| 240 | TEST_F(SequencerTest, TestToggleStepOn) { | ||
| 241 | sequencer_internal_state.active_tracks = (1 << 6) + (1 << 3) + (1 << 2); | ||
| 242 | sequencer_config.steps[2] = 0; | ||
| 243 | |||
| 244 | sequencer_toggle_step(2); | ||
| 245 | |||
| 246 | EXPECT_EQ(sequencer_config.steps[2], (1 << 6) + (1 << 3) + (1 << 2)); | ||
| 247 | } | ||
| 248 | |||
| 249 | TEST_F(SequencerTest, TestSetAllStepsOn) { | ||
| 250 | sequencer_internal_state.active_tracks = (1 << 6) + (1 << 3) + (1 << 2); | ||
| 251 | sequencer_config.steps[2] = (1 << 7) + (1 << 6); | ||
| 252 | sequencer_config.steps[4] = (1 << 3) + (1 << 1); | ||
| 253 | |||
| 254 | sequencer_set_all_steps(true); | ||
| 255 | |||
| 256 | EXPECT_EQ(sequencer_config.steps[2], (1 << 7) + (1 << 6) + (1 << 3) + (1 << 2)); | ||
| 257 | EXPECT_EQ(sequencer_config.steps[4], (1 << 6) + (1 << 3) + (1 << 2) + (1 << 1)); | ||
| 258 | } | ||
| 259 | |||
| 260 | TEST_F(SequencerTest, TestSetAllStepsOff) { | ||
| 261 | sequencer_internal_state.active_tracks = (1 << 6) + (1 << 3) + (1 << 2); | ||
| 262 | sequencer_config.steps[2] = (1 << 7) + (1 << 6); | ||
| 263 | sequencer_config.steps[4] = (1 << 3) + (1 << 1); | ||
| 264 | |||
| 265 | sequencer_set_all_steps(false); | ||
| 266 | |||
| 267 | EXPECT_EQ(sequencer_config.steps[2], (1 << 7)); | ||
| 268 | EXPECT_EQ(sequencer_config.steps[4], (1 << 1)); | ||
| 269 | } | ||
| 270 | |||
| 271 | TEST_F(SequencerTest, TestSetTempoZero) { | ||
| 272 | sequencer_config.tempo = 123; | ||
| 273 | |||
| 274 | sequencer_set_tempo(0); | ||
| 275 | |||
| 276 | EXPECT_EQ(sequencer_config.tempo, 123); | ||
| 277 | } | ||
| 278 | |||
| 279 | TEST_F(SequencerTest, TestIncreaseTempoMax) { | ||
| 280 | sequencer_config.tempo = UINT8_MAX; | ||
| 281 | |||
| 282 | sequencer_increase_tempo(); | ||
| 283 | |||
| 284 | EXPECT_EQ(sequencer_config.tempo, UINT8_MAX); | ||
| 285 | } | ||
| 286 | |||
| 287 | TEST_F(SequencerTest, TestSetResolutionLowerBound) { | ||
| 288 | sequencer_config.resolution = SQ_RES_4; | ||
| 289 | |||
| 290 | sequencer_set_resolution((sequencer_resolution_t)-1); | ||
| 291 | |||
| 292 | EXPECT_EQ(sequencer_config.resolution, SQ_RES_4); | ||
| 293 | } | ||
| 294 | |||
| 295 | TEST_F(SequencerTest, TestSetResolutionUpperBound) { | ||
| 296 | sequencer_config.resolution = SQ_RES_4; | ||
| 297 | |||
| 298 | sequencer_set_resolution(SEQUENCER_RESOLUTIONS); | ||
| 299 | |||
| 300 | EXPECT_EQ(sequencer_config.resolution, SQ_RES_4); | ||
| 301 | } | ||
| 302 | |||
| 303 | TEST_F(SequencerTest, TestGetBeatDuration) { | ||
| 304 | EXPECT_EQ(get_beat_duration(60), 1000); | ||
| 305 | EXPECT_EQ(get_beat_duration(120), 500); | ||
| 306 | EXPECT_EQ(get_beat_duration(240), 250); | ||
| 307 | EXPECT_EQ(get_beat_duration(0), 1000); | ||
| 308 | } | ||
| 309 | |||
| 310 | TEST_F(SequencerTest, TestGetStepDuration60) { | ||
| 311 | /** | ||
| 312 | * Resolution cheatsheet: | ||
| 313 | * 1/2 => 2 steps per 4 beats | ||
| 314 | * 1/2T => 3 steps per 4 beats | ||
| 315 | * 1/4 => 4 steps per 4 beats | ||
| 316 | * 1/4T => 6 steps per 4 beats | ||
| 317 | * 1/8 => 8 steps per 4 beats | ||
| 318 | * 1/8T => 12 steps per 4 beats | ||
| 319 | * 1/16 => 16 steps per 4 beats | ||
| 320 | * 1/16T => 24 steps per 4 beats | ||
| 321 | * 1/32 => 32 steps per 4 beats | ||
| 322 | * | ||
| 323 | * The number of steps for binary resolutions follows the powers of 2. | ||
| 324 | * The ternary variants are simply 1.5x faster. | ||
| 325 | */ | ||
| 326 | EXPECT_EQ(get_step_duration(60, SQ_RES_2), 2000); | ||
| 327 | EXPECT_EQ(get_step_duration(60, SQ_RES_4), 1000); | ||
| 328 | EXPECT_EQ(get_step_duration(60, SQ_RES_8), 500); | ||
| 329 | EXPECT_EQ(get_step_duration(60, SQ_RES_16), 250); | ||
| 330 | EXPECT_EQ(get_step_duration(60, SQ_RES_32), 125); | ||
| 331 | |||
| 332 | EXPECT_EQ(get_step_duration(60, SQ_RES_2T), 1333); | ||
| 333 | EXPECT_EQ(get_step_duration(60, SQ_RES_4T), 666); | ||
| 334 | EXPECT_EQ(get_step_duration(60, SQ_RES_8T), 333); | ||
| 335 | EXPECT_EQ(get_step_duration(60, SQ_RES_16T), 166); | ||
| 336 | } | ||
| 337 | |||
| 338 | TEST_F(SequencerTest, TestGetStepDuration120) { | ||
| 339 | /** | ||
| 340 | * Resolution cheatsheet: | ||
| 341 | * 1/2 => 2 steps per 4 beats | ||
| 342 | * 1/2T => 3 steps per 4 beats | ||
| 343 | * 1/4 => 4 steps per 4 beats | ||
| 344 | * 1/4T => 6 steps per 4 beats | ||
| 345 | * 1/8 => 8 steps per 4 beats | ||
| 346 | * 1/8T => 12 steps per 4 beats | ||
| 347 | * 1/16 => 16 steps per 4 beats | ||
| 348 | * 1/16T => 24 steps per 4 beats | ||
| 349 | * 1/32 => 32 steps per 4 beats | ||
| 350 | * | ||
| 351 | * The number of steps for binary resolutions follows the powers of 2. | ||
| 352 | * The ternary variants are simply 1.5x faster. | ||
| 353 | */ | ||
| 354 | EXPECT_EQ(get_step_duration(30, SQ_RES_2), 4000); | ||
| 355 | EXPECT_EQ(get_step_duration(30, SQ_RES_4), 2000); | ||
| 356 | EXPECT_EQ(get_step_duration(30, SQ_RES_8), 1000); | ||
| 357 | EXPECT_EQ(get_step_duration(30, SQ_RES_16), 500); | ||
| 358 | EXPECT_EQ(get_step_duration(30, SQ_RES_32), 250); | ||
| 359 | |||
| 360 | EXPECT_EQ(get_step_duration(30, SQ_RES_2T), 2666); | ||
| 361 | EXPECT_EQ(get_step_duration(30, SQ_RES_4T), 1333); | ||
| 362 | EXPECT_EQ(get_step_duration(30, SQ_RES_8T), 666); | ||
| 363 | EXPECT_EQ(get_step_duration(30, SQ_RES_16T), 333); | ||
| 364 | } | ||
| 365 | |||
| 366 | void setUpMatrixScanSequencerTest(void) { | ||
| 367 | sequencer_config.enabled = true; | ||
| 368 | sequencer_config.tempo = 120; | ||
| 369 | sequencer_config.resolution = SQ_RES_16; | ||
| 370 | |||
| 371 | // Configure the notes for each track | ||
| 372 | sequencer_config.track_notes[0] = MI_C; | ||
| 373 | sequencer_config.track_notes[1] = MI_D; | ||
| 374 | sequencer_config.track_notes[2] = MI_E; | ||
| 375 | sequencer_config.track_notes[3] = MI_F; | ||
| 376 | sequencer_config.track_notes[4] = MI_G; | ||
| 377 | sequencer_config.track_notes[5] = MI_A; | ||
| 378 | sequencer_config.track_notes[6] = MI_B; | ||
| 379 | sequencer_config.track_notes[7] = MI_C; | ||
| 380 | |||
| 381 | // Turn on some steps | ||
| 382 | sequencer_config.steps[0] = (1 << 0); | ||
| 383 | sequencer_config.steps[2] = (1 << 1) + (1 << 0); | ||
| 384 | } | ||
| 385 | |||
| 386 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldAttackFirstTrackOfFirstStep) { | ||
| 387 | setUpMatrixScanSequencerTest(); | ||
| 388 | |||
| 389 | matrix_scan_sequencer(); | ||
| 390 | EXPECT_EQ(last_noteon, MI_C); | ||
| 391 | EXPECT_EQ(last_noteoff, 0); | ||
| 392 | } | ||
| 393 | |||
| 394 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldAttackSecondTrackAfterFirstTrackOfFirstStep) { | ||
| 395 | setUpMatrixScanSequencerTest(); | ||
| 396 | |||
| 397 | matrix_scan_sequencer(); | ||
| 398 | EXPECT_EQ(sequencer_internal_state.current_step, 0); | ||
| 399 | EXPECT_EQ(sequencer_internal_state.current_track, 1); | ||
| 400 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_ATTACK); | ||
| 401 | } | ||
| 402 | |||
| 403 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldNotAttackInactiveTrackFirstStep) { | ||
| 404 | setUpMatrixScanSequencerTest(); | ||
| 405 | |||
| 406 | sequencer_internal_state.current_step = 0; | ||
| 407 | sequencer_internal_state.current_track = 1; | ||
| 408 | |||
| 409 | // Wait some time after the first track has been attacked | ||
| 410 | advance_time(SEQUENCER_TRACK_THROTTLE); | ||
| 411 | |||
| 412 | matrix_scan_sequencer(); | ||
| 413 | EXPECT_EQ(last_noteon, 0); | ||
| 414 | EXPECT_EQ(last_noteoff, 0); | ||
| 415 | } | ||
| 416 | |||
| 417 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldAttackThirdTrackAfterSecondTrackOfFirstStep) { | ||
| 418 | setUpMatrixScanSequencerTest(); | ||
| 419 | |||
| 420 | sequencer_internal_state.current_step = 0; | ||
| 421 | sequencer_internal_state.current_track = 1; | ||
| 422 | |||
| 423 | // Wait some time after the second track has been attacked | ||
| 424 | advance_time(2 * SEQUENCER_TRACK_THROTTLE); | ||
| 425 | |||
| 426 | matrix_scan_sequencer(); | ||
| 427 | EXPECT_EQ(sequencer_internal_state.current_step, 0); | ||
| 428 | EXPECT_EQ(sequencer_internal_state.current_track, 2); | ||
| 429 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_ATTACK); | ||
| 430 | } | ||
| 431 | |||
| 432 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldEnterReleasePhaseAfterLastTrackHasBeenProcessedFirstStep) { | ||
| 433 | setUpMatrixScanSequencerTest(); | ||
| 434 | |||
| 435 | sequencer_internal_state.current_step = 0; | ||
| 436 | sequencer_internal_state.current_track = SEQUENCER_TRACKS - 1; | ||
| 437 | |||
| 438 | // Wait until all notes have been attacked | ||
| 439 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 440 | |||
| 441 | matrix_scan_sequencer(); | ||
| 442 | EXPECT_EQ(last_noteon, 0); | ||
| 443 | EXPECT_EQ(last_noteoff, 0); | ||
| 444 | EXPECT_EQ(sequencer_internal_state.current_step, 0); | ||
| 445 | EXPECT_EQ(sequencer_internal_state.current_track, SEQUENCER_TRACKS - 1); | ||
| 446 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_RELEASE); | ||
| 447 | } | ||
| 448 | |||
| 449 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldReleaseBackwards) { | ||
| 450 | setUpMatrixScanSequencerTest(); | ||
| 451 | |||
| 452 | sequencer_internal_state.current_step = 0; | ||
| 453 | sequencer_internal_state.current_track = SEQUENCER_TRACKS - 1; | ||
| 454 | sequencer_internal_state.phase = SEQUENCER_PHASE_RELEASE; | ||
| 455 | |||
| 456 | // Wait until all notes have been attacked | ||
| 457 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 458 | // + the release timeout | ||
| 459 | advance_time(SEQUENCER_PHASE_RELEASE_TIMEOUT); | ||
| 460 | |||
| 461 | matrix_scan_sequencer(); | ||
| 462 | EXPECT_EQ(sequencer_internal_state.current_step, 0); | ||
| 463 | EXPECT_EQ(sequencer_internal_state.current_track, SEQUENCER_TRACKS - 2); | ||
| 464 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_RELEASE); | ||
| 465 | } | ||
| 466 | |||
| 467 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldNotReleaseInactiveTrackFirstStep) { | ||
| 468 | setUpMatrixScanSequencerTest(); | ||
| 469 | |||
| 470 | sequencer_internal_state.current_step = 0; | ||
| 471 | sequencer_internal_state.current_track = SEQUENCER_TRACKS - 1; | ||
| 472 | sequencer_internal_state.phase = SEQUENCER_PHASE_RELEASE; | ||
| 473 | |||
| 474 | // Wait until all notes have been attacked | ||
| 475 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 476 | // + the release timeout | ||
| 477 | advance_time(SEQUENCER_PHASE_RELEASE_TIMEOUT); | ||
| 478 | |||
| 479 | matrix_scan_sequencer(); | ||
| 480 | EXPECT_EQ(last_noteon, 0); | ||
| 481 | EXPECT_EQ(last_noteoff, 0); | ||
| 482 | } | ||
| 483 | |||
| 484 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldReleaseFirstTrackFirstStep) { | ||
| 485 | setUpMatrixScanSequencerTest(); | ||
| 486 | |||
| 487 | sequencer_internal_state.current_step = 0; | ||
| 488 | sequencer_internal_state.current_track = 0; | ||
| 489 | sequencer_internal_state.phase = SEQUENCER_PHASE_RELEASE; | ||
| 490 | |||
| 491 | // Wait until all notes have been attacked | ||
| 492 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 493 | // + the release timeout | ||
| 494 | advance_time(SEQUENCER_PHASE_RELEASE_TIMEOUT); | ||
| 495 | // + all the other notes have been released | ||
| 496 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 497 | |||
| 498 | matrix_scan_sequencer(); | ||
| 499 | EXPECT_EQ(last_noteon, 0); | ||
| 500 | EXPECT_EQ(last_noteoff, MI_C); | ||
| 501 | } | ||
| 502 | |||
| 503 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldEnterPausePhaseAfterRelease) { | ||
| 504 | setUpMatrixScanSequencerTest(); | ||
| 505 | |||
| 506 | sequencer_internal_state.current_step = 0; | ||
| 507 | sequencer_internal_state.current_track = 0; | ||
| 508 | sequencer_internal_state.phase = SEQUENCER_PHASE_RELEASE; | ||
| 509 | |||
| 510 | // Wait until all notes have been attacked | ||
| 511 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 512 | // + the release timeout | ||
| 513 | advance_time(SEQUENCER_PHASE_RELEASE_TIMEOUT); | ||
| 514 | // + all the other notes have been released | ||
| 515 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 516 | |||
| 517 | matrix_scan_sequencer(); | ||
| 518 | EXPECT_EQ(sequencer_internal_state.current_step, 0); | ||
| 519 | EXPECT_EQ(sequencer_internal_state.current_track, 0); | ||
| 520 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_PAUSE); | ||
| 521 | } | ||
| 522 | |||
| 523 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldProcessFirstTrackOfSecondStepAfterPause) { | ||
| 524 | setUpMatrixScanSequencerTest(); | ||
| 525 | |||
| 526 | sequencer_internal_state.current_step = 0; | ||
| 527 | sequencer_internal_state.current_track = 0; | ||
| 528 | sequencer_internal_state.phase = SEQUENCER_PHASE_PAUSE; | ||
| 529 | |||
| 530 | // Wait until all notes have been attacked | ||
| 531 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 532 | // + the release timeout | ||
| 533 | advance_time(SEQUENCER_PHASE_RELEASE_TIMEOUT); | ||
| 534 | // + all the other notes have been released | ||
| 535 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 536 | // + the step duration (one 16th at tempo=120 lasts 125ms) | ||
| 537 | advance_time(125); | ||
| 538 | |||
| 539 | matrix_scan_sequencer(); | ||
| 540 | EXPECT_EQ(sequencer_internal_state.current_step, 1); | ||
| 541 | EXPECT_EQ(sequencer_internal_state.current_track, 1); | ||
| 542 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_ATTACK); | ||
| 543 | } | ||
| 544 | |||
| 545 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldProcessSecondTrackTooEarly) { | ||
| 546 | setUpMatrixScanSequencerTest(); | ||
| 547 | |||
| 548 | sequencer_internal_state.current_step = 2; | ||
| 549 | sequencer_internal_state.current_track = 1; | ||
| 550 | |||
| 551 | matrix_scan_sequencer(); | ||
| 552 | EXPECT_EQ(last_noteon, 0); | ||
| 553 | EXPECT_EQ(last_noteoff, 0); | ||
| 554 | } | ||
| 555 | |||
| 556 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldProcessSecondTrackOnTime) { | ||
| 557 | setUpMatrixScanSequencerTest(); | ||
| 558 | |||
| 559 | sequencer_internal_state.current_step = 2; | ||
| 560 | sequencer_internal_state.current_track = 1; | ||
| 561 | |||
| 562 | // Wait until first track has been attacked | ||
| 563 | advance_time(SEQUENCER_TRACK_THROTTLE); | ||
| 564 | |||
| 565 | matrix_scan_sequencer(); | ||
| 566 | EXPECT_EQ(last_noteon, MI_D); | ||
| 567 | EXPECT_EQ(last_noteoff, 0); | ||
| 568 | } | ||
| 569 | |||
| 570 | TEST_F(SequencerTest, TestMatrixScanSequencerShouldLoopOnceSequenceIsOver) { | ||
| 571 | setUpMatrixScanSequencerTest(); | ||
| 572 | |||
| 573 | sequencer_internal_state.current_step = SEQUENCER_STEPS - 1; | ||
| 574 | sequencer_internal_state.current_track = 0; | ||
| 575 | sequencer_internal_state.phase = SEQUENCER_PHASE_PAUSE; | ||
| 576 | |||
| 577 | // Wait until all notes have been attacked | ||
| 578 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 579 | // + the release timeout | ||
| 580 | advance_time(SEQUENCER_PHASE_RELEASE_TIMEOUT); | ||
| 581 | // + all the other notes have been released | ||
| 582 | advance_time((SEQUENCER_TRACKS - 1) * SEQUENCER_TRACK_THROTTLE); | ||
| 583 | // + the step duration (one 16th at tempo=120 lasts 125ms) | ||
| 584 | advance_time(125); | ||
| 585 | |||
| 586 | matrix_scan_sequencer(); | ||
| 587 | EXPECT_EQ(sequencer_internal_state.current_step, 0); | ||
| 588 | EXPECT_EQ(sequencer_internal_state.current_track, 1); | ||
| 589 | EXPECT_EQ(sequencer_internal_state.phase, SEQUENCER_PHASE_ATTACK); | ||
| 590 | } | ||
