@@ -21,7 +21,7 @@ internal partial class TasMovie
2121 public override void RecordFrame ( int frame , IController source )
2222 {
2323 ChangeLog . AddGeneralUndo ( frame , frame , $ "Record Frame: { frame } ") ;
24- SetFrameAt ( frame , Bk2LogEntryGenerator . GenerateLogEntry ( source ) ) ;
24+ base . PokeFrame ( frame , source ) ;
2525 ChangeLog . SetGeneralRedo ( ) ;
2626
2727 LagLog [ frame ] = _inputPollable . IsLagFrame ;
@@ -32,7 +32,7 @@ public override void RecordFrame(int frame, IController source)
3232
3333 public override void Truncate ( int frame )
3434 {
35- if ( frame >= Log . Count - 1 ) return ;
35+ if ( frame >= Log . Count ) return ;
3636
3737 bool endBatch = ChangeLog . BeginNewBatch ( $ "Truncate Movie: { frame } ", true ) ;
3838
@@ -56,22 +56,17 @@ public override void PokeFrame(int frame, IController source)
5656 InvalidateAfter ( frame ) ;
5757 }
5858
59- public void SetFrame ( int frame , string source )
59+ public void PokeFrame ( int frame , string source )
6060 {
61- ChangeLog . AddGeneralUndo ( frame , frame , $ "Set Frame At: { frame } ") ;
62- SetFrameAt ( frame , source ) ;
63- ChangeLog . SetGeneralRedo ( ) ;
64-
65- InvalidateAfter ( frame ) ;
61+ Bk2Controller controller = new ( Session . MovieController . Definition , LogKey ) ;
62+ controller . SetFromMnemonic ( source ) ;
63+ PokeFrame ( frame , controller ) ;
6664 }
6765
6866 public void ClearFrame ( int frame )
6967 {
70- string empty = Bk2LogEntryGenerator . EmptyEntry ( Session . MovieController ) ;
71- if ( GetInputLogEntry ( frame ) == empty ) return ;
72-
7368 ChangeLog . AddGeneralUndo ( frame , frame , $ "Clear Frame: { frame } ") ;
74- SetFrameAt ( frame , empty ) ;
69+ base . PokeFrame ( frame , DefaultValueController ) ;
7570 ChangeLog . SetGeneralRedo ( ) ;
7671
7772 InvalidateAfter ( frame ) ;
@@ -118,6 +113,7 @@ public void RemoveFrames(ICollection<int> frames)
118113
119114 public void RemoveFrames ( int removeStart , int removeUpTo )
120115 {
116+ // TODO: column limiting
121117 bool endBatch = ChangeLog . BeginNewBatch ( $ "Remove frames { removeStart } -{ removeUpTo - 1 } ", true ) ;
122118 if ( BindMarkersToInput )
123119 {
@@ -133,12 +129,22 @@ public void RemoveFrames(int removeStart, int removeUpTo)
133129 // Log.GetRange() might be preferrable, but Log's type complicates that.
134130 string [ ] removedInputs = new string [ removeUpTo - removeStart ] ;
135131 Log . CopyTo ( removeStart , removedInputs , 0 , removedInputs . Length ) ;
136- Log . RemoveRange ( removeStart , removeUpTo - removeStart ) ;
132+
133+ if ( ActiveControllerInputs == null )
134+ {
135+ Log . RemoveRange ( removeStart , removeUpTo - removeStart ) ;
136+ }
137+ else
138+ {
139+ int count = removeUpTo - removeStart ;
140+ for ( int i = removeStart ; i < Log . Count ; i ++ )
141+ base . PokeFrame ( i , GetInputState ( i + count ) ?? DefaultValueController ) ;
142+ }
137143
138144 ChangeLog . AddRemoveFrames (
139145 removeStart ,
140- removeUpTo ,
141146 removedInputs . ToList ( ) ,
147+ ActiveControllerInputs ,
142148 BindMarkersToInput
143149 ) ;
144150 if ( endBatch ) ChangeLog . EndBatch ( ) ;
@@ -155,9 +161,29 @@ public void InsertInput(int frame, string inputState)
155161 public void InsertInput ( int frame , IEnumerable < string > inputLog )
156162 {
157163 var inputLogCopy = inputLog . ToList ( ) ;
158- Log . InsertRange ( frame , inputLogCopy ) ;
164+ if ( ActiveControllerInputs == null )
165+ {
166+ Log . InsertRange ( frame , inputLogCopy ) ;
167+ }
168+ else
169+ {
170+ int count = inputLogCopy . Count ;
171+ // add empty frames at the end
172+ Log . AddRange ( Enumerable . Repeat ( Bk2LogEntryGenerator . EmptyEntry ( Session . MovieController ) , count ) ) ;
173+ // shift inputs to future frames
174+ for ( int i = Log . Count - 1 ; i >= frame + count ; i -- )
175+ base . PokeFrame ( i , GetInputState ( i - count ) ) ;
176+ // write the new inputs
177+ Bk2Controller controller = new ( Session . MovieController . Definition , LogKey ) ;
178+ for ( int i = 0 ; i < count ; i ++ )
179+ {
180+ controller . SetFromMnemonic ( inputLogCopy [ i ] ) ;
181+ base . PokeFrame ( frame + i , controller ) ;
182+ }
183+ }
184+
159185 ShiftBindedMarkers ( frame , inputLogCopy . Count ) ;
160- ChangeLog . AddInsertInput ( frame , inputLogCopy , BindMarkersToInput , $ "Insert { inputLogCopy . Count } frame(s) at { frame } ") ;
186+ ChangeLog . AddInsertInput ( frame , inputLogCopy , ActiveControllerInputs , BindMarkersToInput , $ "Insert { inputLogCopy . Count } frame(s) at { frame } ") ;
161187 InvalidateAfter ( frame ) ;
162188 }
163189
@@ -175,6 +201,7 @@ public void InsertInput(int frame, IEnumerable<IController> inputStates)
175201
176202 public void CopyOverInput ( int frame , IEnumerable < IController > inputStates )
177203 {
204+ // TODO: column limiting
178205 var states = inputStates . ToList ( ) ;
179206
180207 bool endBatch = ChangeLog . BeginNewBatch ( $ "Copy Over Input: { frame } ", true ) ;
@@ -187,7 +214,10 @@ public void CopyOverInput(int frame, IEnumerable<IController> inputStates)
187214 ChangeLog . AddGeneralUndo ( frame , frame + states . Count - 1 , $ "Copy Over Input: { frame } ") ;
188215 for ( int i = 0 ; i < states . Count ; i ++ )
189216 {
190- Log [ frame + i ] = Bk2LogEntryGenerator . GenerateLogEntry ( states [ i ] ) ;
217+ IController controller = states [ i ] ;
218+ if ( ActiveControllerInputs != null )
219+ controller = new MultitrackAdapter ( controller , GetInputState ( frame + i ) , ActiveControllerInputs ) ;
220+ Log [ frame + i ] = Bk2LogEntryGenerator . GenerateLogEntry ( controller ) ;
191221 }
192222 int firstChangedFrame = ChangeLog . SetGeneralRedo ( ) ;
193223
@@ -203,9 +233,24 @@ public void InsertEmptyFrame(int frame, int count = 1)
203233 {
204234 frame = Math . Min ( frame , Log . Count ) ;
205235
206- Log . InsertRange ( frame , Enumerable . Repeat ( Bk2LogEntryGenerator . EmptyEntry ( Session . MovieController ) , count ) ) ;
236+ if ( ActiveControllerInputs == null )
237+ {
238+ Log . InsertRange ( frame , Enumerable . Repeat ( Bk2LogEntryGenerator . EmptyEntry ( Session . MovieController ) , count ) ) ;
239+ }
240+ else
241+ {
242+ // add empty frames at the end
243+ Log . AddRange ( Enumerable . Repeat ( Bk2LogEntryGenerator . EmptyEntry ( Session . MovieController ) , count ) ) ;
244+ // shift inputs to future frames
245+ for ( int i = Log . Count - 1 ; i >= frame + count ; i -- )
246+ base . PokeFrame ( i , GetInputState ( i - count ) ) ;
247+ // clear frames
248+ for ( int i = frame ; i < frame + count ; i ++ )
249+ base . PokeFrame ( i , DefaultValueController ) ;
250+ }
251+
207252 ShiftBindedMarkers ( frame , count ) ;
208- ChangeLog . AddInsertFrames ( frame , count , BindMarkersToInput , $ "Insert { count } empty frame(s) at { frame } ") ;
253+ ChangeLog . AddInsertFrames ( frame , count , ActiveControllerInputs , BindMarkersToInput , $ "Insert { count } empty frame(s) at { frame } ") ;
209254
210255 InvalidateAfter ( frame ) ;
211256 }
@@ -214,7 +259,6 @@ private void ExtendMovieForEdit(int numFrames)
214259 {
215260 int oldLength = InputLogLength ;
216261
217- // account for autohold TODO: What about auto-fire?
218262 string inputs = Bk2LogEntryGenerator . GenerateLogEntry ( Session . StickySource ) ;
219263 for ( int i = 0 ; i < numFrames ; i ++ )
220264 {
0 commit comments