@@ -267,7 +267,7 @@ void AutomationServiceTest::test_renderMidiCcToEventsByLine_withModulation_shoul
267267 quint8 value0 = 64 ;
268268 quint8 value1 = 64 ;
269269 const auto automationId = automationService.addMidiCcAutomation (pattern, track, column, controller, line0, line1, value0, value1, {}, true , 8 , 0 );
270- automationService.addMidiCcModulation (automationId, 1 , 50 .0f , 0 .0f , false );
270+ automationService.addMidiCcModulation (automationId, 0 , 1 , 50 .0f , 0 .0f , false );
271271
272272 const auto tick = 0 ;
273273 // Line 0: Base 64, Phase 0, Sine 0, Modulation 0
@@ -282,6 +282,39 @@ void AutomationServiceTest::test_renderMidiCcToEventsByLine_withModulation_shoul
282282 QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 4 , tick).at (0 )->midiCcData ()->value (), 64 );
283283}
284284
285+ void AutomationServiceTest::test_renderMidiCcToEventsByLine_withRandomModulation_shouldRenderModulatedEvents ()
286+ {
287+ AutomationService automationService;
288+
289+ quint64 pattern = 0 ;
290+ quint64 track = 1 ;
291+ quint64 column = 2 ;
292+ quint8 controller = 64 ;
293+ quint8 line0 = 0 ;
294+ quint8 line1 = 4 ;
295+ quint8 value0 = 64 ;
296+ quint8 value1 = 64 ;
297+ // ID will be 1
298+ const auto automationId = automationService.addMidiCcAutomation (pattern, track, column, controller, line0, line1, value0, value1, {}, true , 8 , 0 );
299+ // Type 1 = Random, 1 cycle, 100% amplitude
300+ automationService.addMidiCcModulation (automationId, 1 , 1 , 100 .0f , 0 .0f , false );
301+
302+ const auto tick = 0 ;
303+ // For automationId = 1 and sampleIndex = 0, std::mt19937 seeded with 1:
304+ // first value from dist(-1, 1) is roughly -0.131538
305+ // value = 64 + 64 * (-0.131538) = 64 - 8.4 = 55.6 -> 56
306+ const auto val0 = automationService.renderToEventsByLine (pattern, track, column, 0 , tick).at (0 )->midiCcData ()->value ();
307+ QVERIFY (val0 != 64 );
308+
309+ // Should stay same for line 1, 2, 3 (within same cycle)
310+ QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 1 , tick).at (0 )->midiCcData ()->value (), val0);
311+ QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 2 , tick).at (0 )->midiCcData ()->value (), val0);
312+ QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 3 , tick).at (0 )->midiCcData ()->value (), val0);
313+
314+ // Return to 0 at the end (line 4, phase 1.0)
315+ QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 4 , tick).at (0 )->midiCcData ()->value (), 64 );
316+ }
317+
285318void AutomationServiceTest::test_renderMidiCcToEventsByLine_withInvertedModulation_shouldRenderModulatedEvents ()
286319{
287320 AutomationService automationService;
@@ -295,7 +328,7 @@ void AutomationServiceTest::test_renderMidiCcToEventsByLine_withInvertedModulati
295328 quint8 value0 = 64 ;
296329 quint8 value1 = 64 ;
297330 const auto automationId = automationService.addMidiCcAutomation (pattern, track, column, controller, line0, line1, value0, value1, {}, true , 8 , 0 );
298- automationService.addMidiCcModulation (automationId, 1 , 50 .0f , 0 .0f , true );
331+ automationService.addMidiCcModulation (automationId, 0 , 1 , 50 .0f , 0 .0f , true );
299332
300333 const auto tick = 0 ;
301334 // Line 0: Base 64, Phase 0, Sine 0, Modulation 0
@@ -325,13 +358,13 @@ void AutomationServiceTest::test_renderMidiCcToEventsByLine_withOffset_shouldRen
325358 const auto automationId = automationService.addMidiCcAutomation (pattern, track, column, controller, line0, line1, value0, value1, {}, true , 8 , 0 );
326359
327360 // Test positive offset (+50%)
328- automationService.addMidiCcModulation (automationId, 0 , 0 .0f , 50 .0f , false );
361+ automationService.addMidiCcModulation (automationId, 0 , 0 , 0 .0f , 50 .0f , false );
329362 const auto tick = 0 ;
330363 // 64 + 64 * 0.5 = 96
331364 QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 0 , tick).at (0 )->midiCcData ()->value (), 96 );
332365
333366 // Test negative offset (-50%)
334- automationService.addMidiCcModulation (automationId, 0 , 0 .0f , -50 .0f , false );
367+ automationService.addMidiCcModulation (automationId, 0 , 0 , 0 .0f , -50 .0f , false );
335368 // 64 + 64 * -0.5 = 32
336369 QCOMPARE (automationService.renderToEventsByLine (pattern, track, column, 0 , tick).at (0 )->midiCcData ()->value (), 32 );
337370}
0 commit comments