@@ -49,6 +49,180 @@ TEST_SUITE("tracktion_engine")
4949 // Point should move from 5s to 7s
5050 CHECK (curve.getPointTime (0 ) == 7_tp);
5151 }
52+
53+ TEST_CASE (" insertSpaceIntoEdit: moves global macro parameter automation" )
54+ {
55+ auto & engine = *Engine::getEngines ()[0 ];
56+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
57+ auto um = &edit->getUndoManager ();
58+
59+ auto & globalMacros = edit->getGlobalMacros ();
60+ auto macroParam = globalMacros.getMacroParameterListForWriting ().createMacroParameter ();
61+ REQUIRE (macroParam != nullptr );
62+
63+ auto & curve = macroParam->getCurve ();
64+ curve.addPoint (5_tp, 0 .5f , 0 .0f , um);
65+
66+ CHECK (curve.getPointTime (0 ) == 5_tp);
67+
68+ insertSpaceIntoEdit (*edit, { 2_tp, 2_td });
69+
70+ // Point should move from 5s to 7s
71+ CHECK (curve.getPointTime (0 ) == 7_tp);
72+ }
73+
74+ TEST_CASE (" insertSpaceIntoEdit: moves rack plugin automation" )
75+ {
76+ auto & engine = *Engine::getEngines ()[0 ];
77+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
78+ auto um = &edit->getUndoManager ();
79+
80+ auto rackType = edit->getRackList ().addNewRack ();
81+ auto volumePlugin = edit->getPluginCache ().createNewPlugin (VolumeAndPanPlugin::xmlTypeName, {});
82+ rackType->addPlugin (volumePlugin, {}, true );
83+
84+ auto volAndPan = dynamic_cast <VolumeAndPanPlugin*> (volumePlugin.get ());
85+ REQUIRE (volAndPan != nullptr );
86+
87+ auto volParam = volAndPan->volParam .get ();
88+ auto & curve = volParam->getCurve ();
89+ curve.addPoint (5_tp, 0 .5f , 0 .0f , um);
90+
91+ CHECK (curve.getPointTime (0 ) == 5_tp);
92+
93+ insertSpaceIntoEdit (*edit, { 2_tp, 2_td });
94+
95+ // Point should move from 5s to 7s
96+ CHECK (curve.getPointTime (0 ) == 7_tp);
97+ }
98+
99+ TEST_CASE (" deleteRegionOfTracks: removes and shifts master volume automation" )
100+ {
101+ auto & engine = *Engine::getEngines ()[0 ];
102+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
103+ auto um = &edit->getUndoManager ();
104+
105+ auto masterVol = edit->getMasterVolumePlugin ();
106+ REQUIRE (masterVol != nullptr );
107+
108+ auto volParam = masterVol->volParam .get ();
109+ REQUIRE (volParam != nullptr );
110+
111+ auto & curve = volParam->getCurve ();
112+ // Add points: point within deleted region will be removed, point after will shift
113+ curve.addPoint (2_tp, 0 .5f , 0 .0f , um);
114+ curve.addPoint (10_tp, 0 .5f , 0 .0f , um);
115+
116+ CHECK (curve.getNumPoints () == 2 );
117+
118+ // Delete region from 3s to 6s
119+ deleteRegionOfTracks (*edit, { 3_tp, 6_tp }, false , CloseGap::yes, nullptr );
120+
121+ CHECK (curve.getNumPoints () == 2 );
122+ CHECK (curve.getPointTime (0 ) == 2_tp);
123+ // Point at 10s should shift back by 3s to 7s
124+ CHECK (curve.getPointTime (1 ) == 7_tp);
125+ }
126+
127+ TEST_CASE (" deleteRegionOfTracks: removes and shifts global macro automation" )
128+ {
129+ auto & engine = *Engine::getEngines ()[0 ];
130+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
131+ auto um = &edit->getUndoManager ();
132+
133+ auto & globalMacros = edit->getGlobalMacros ();
134+ auto macroParam = globalMacros.getMacroParameterListForWriting ().createMacroParameter ();
135+ REQUIRE (macroParam != nullptr );
136+
137+ auto & curve = macroParam->getCurve ();
138+ // Use same values to avoid boundary preservation points being added
139+ curve.addPoint (2_tp, 0 .5f , 0 .0f , um);
140+ curve.addPoint (10_tp, 0 .5f , 0 .0f , um);
141+
142+ CHECK (curve.getNumPoints () == 2 );
143+
144+ // Delete region from 3s to 6s
145+ deleteRegionOfTracks (*edit, { 3_tp, 6_tp }, false , CloseGap::yes, nullptr );
146+
147+ CHECK (curve.getNumPoints () == 2 );
148+ CHECK (curve.getPointTime (0 ) == 2_tp);
149+ CHECK (curve.getPointTime (1 ) == 7_tp);
150+ }
151+
152+ TEST_CASE (" deleteRegionOfTracks: removes and shifts rack plugin automation" )
153+ {
154+ auto & engine = *Engine::getEngines ()[0 ];
155+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
156+ auto um = &edit->getUndoManager ();
157+
158+ auto rackType = edit->getRackList ().addNewRack ();
159+ auto volumePlugin = edit->getPluginCache ().createNewPlugin (VolumeAndPanPlugin::xmlTypeName, {});
160+ rackType->addPlugin (volumePlugin, {}, true );
161+
162+ auto volAndPan = dynamic_cast <VolumeAndPanPlugin*> (volumePlugin.get ());
163+ REQUIRE (volAndPan != nullptr );
164+
165+ auto volParam = volAndPan->volParam .get ();
166+ auto & curve = volParam->getCurve ();
167+ // Use same values to avoid boundary preservation points being added
168+ curve.addPoint (2_tp, 0 .5f , 0 .0f , um);
169+ curve.addPoint (10_tp, 0 .5f , 0 .0f , um);
170+
171+ CHECK (curve.getNumPoints () == 2 );
172+
173+ deleteRegionOfTracks (*edit, { 3_tp, 6_tp }, false , CloseGap::yes, nullptr );
174+
175+ CHECK (curve.getNumPoints () == 2 );
176+ CHECK (curve.getPointTime (0 ) == 2_tp);
177+ CHECK (curve.getPointTime (1 ) == 7_tp);
178+ }
179+
180+ TEST_CASE (" deleteRegionOfTracks: shifts pitch sequence" )
181+ {
182+ auto & engine = *Engine::getEngines ()[0 ];
183+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
184+
185+ auto & pitchSeq = edit->pitchSequence ;
186+
187+ // Add pitch changes at various positions
188+ pitchSeq.insertPitch (2_tp);
189+ pitchSeq.insertPitch (5_tp);
190+ pitchSeq.insertPitch (10_tp);
191+
192+ const int numPitchesBefore = pitchSeq.getNumPitches ();
193+ CHECK (numPitchesBefore == 4 ); // Including initial pitch at 0
194+
195+ // Delete region from 3s to 6s
196+ deleteRegionOfTracks (*edit, { 3_tp, 6_tp }, false , CloseGap::yes, nullptr );
197+
198+ // Pitch at 5s should be removed, pitch at 10s should shift back
199+ CHECK (pitchSeq.getNumPitches () == 3 );
200+ }
201+
202+ TEST_CASE (" deleteRegionOfTracks: CloseGap::no does not shift automation" )
203+ {
204+ auto & engine = *Engine::getEngines ()[0 ];
205+ auto edit = Edit::createSingleTrackEdit (engine, Edit::EditRole::forRendering);
206+ auto um = &edit->getUndoManager ();
207+
208+ auto masterVol = edit->getMasterVolumePlugin ();
209+ REQUIRE (masterVol != nullptr );
210+
211+ auto volParam = masterVol->volParam .get ();
212+ auto & curve = volParam->getCurve ();
213+ curve.addPoint (2_tp, 0 .3f , 0 .0f , um);
214+ curve.addPoint (10_tp, 0 .7f , 0 .0f , um);
215+
216+ CHECK (curve.getNumPoints () == 2 );
217+
218+ // Delete region but don't close gap
219+ deleteRegionOfTracks (*edit, { 3_tp, 6_tp }, false , CloseGap::no, nullptr );
220+
221+ // Points should remain unchanged
222+ CHECK (curve.getNumPoints () == 2 );
223+ CHECK (curve.getPointTime (0 ) == 2_tp);
224+ CHECK (curve.getPointTime (1 ) == 10_tp);
225+ }
52226}
53227
54228// ==============================================================================
0 commit comments