Deep copy of TrackEvent

nonam3 wrote on 10/21/2024, 2:19 PM

Hello,

Does anyone know a way to make a copy (deep copy) of TrackEvent ?

What I want to achieve is copy / paste like feature in my c# script.

The problem that I face is that when I keep reference to TrackEvent event, and later on modify it, and then paste I do paste event with all it's new modifications (as my "copy" references event) but I would want to paste event with old state.

Any help are more than welcome
Regards

Comments

jetdv wrote on 10/21/2024, 2:55 PM
event.Copy(NewTrack, NewStartTime);

Copy the event and place it in the given track at the given start time.

Parameters:

  • destination: destination track of duplicate event.
  • startTime: start time of duplicate event.

@nonam3 is that what you mean? That copies the original to somewhere else then you can modify the original as much as you want and still keep that copy. Maybe, if needed, create you a scratch track to hold the copy then you could move it from the scratch track when you "paste" it.

nonam3 wrote on 10/21/2024, 3:02 PM

Sorry for not being specific and I know that method.

What I mean is copy in memory, not on project (i.e. disabled scratch Track)

For example (pseudo code):

List<TrackEvent> events = new List<TrackEvent>();
...
private copyMethod() {
...
TrackEvent te = tracks.ElementAt(i).Events.ElementAt(j);
events.Add(te);
...
}

So than I have copy (deep copy) of an event in `List<TrackEvent> events` list and I can i.e. paste them later.

Edit:

I tried `BinaryFormatter` and, as checked before, it's a no go. Class `TrackEvent` is not serializable so it will not work and I'm afraid that only way to achieve this through disabled temporary track ;/.

System.Runtime.Serialization.SerializationException: Type 'ScriptPortal.Vegas.VideoEvent' in Assembly 'ScriptPortal.Vegas ...' is not marked as serializable.

Edit2:

Technically I could serialize myself via keeping all the information needed to re-create later that `TrackEvent` but the problem is that I would have to handle all it's features like all effects / cuts / key-frames etc. and that's just PITA.

jetdv wrote on 10/21/2024, 3:55 PM

TrackEvent te = tracks.ElementAt(i).Events.ElementAt(j);

Why do you need "ElementAt(i)"??? Would this not do the same thing?

TrackEvent te = tracks[i].Events[j];

but the problem is that I would have to handle all it's features like all effects / cuts / key-frames etc. and that's just PITA.

And you, technically, CAN'T handle everything! Pan/Crop Masks, DirectX effect keyframes, etc...

Really believe a "scratch track" is probably your best option.

nonam3 wrote on 10/21/2024, 4:10 PM

Just a matter of habit from c++/Qt, at() vs [] and there the difference is that former returns const T& (read only object with range checks, and exception out-of-range) second is modifiable reference. And there are also copy (deep copy) gotcha with [].

I'm not familiar with c# so I assumed something similar could happen and there is a reason why there is this accessor.

`ElementAt()` - https://stackoverflow.com/questions/5326874/why-would-i-use-enumerable-elementat-versus-the-operator

Unfortunately It seams like there is no other way than using temp Track (that is also visible in the project) to achieve such simple task ... ;/. I already tried crafting invisible Track but that is no go, same for TrackEvent object (that object is invalid until it is placed on Track).

Such "copy" operation seams like useful thing to have in scripting API yet it's missing, don't understand why this was not exposed via API.

 

jetdv wrote on 10/21/2024, 7:49 PM

Just make sure you mute the temp track so you won't have to worry about the temp event from accidentally showing.