Counting with the timecode values?

lnetzel wrote on 7/11/2003, 1:12 PM
I'm trying to make a Selected Event longer. (I want to add about 20 frames in the beggining and in the end)

I guess this means adjusting the startingpoint and making the clip 40 frames longer and I have found the event I want inmy script (all selected) but Now I got confused about this TimeCode thing, how do you count with it and add things and so on... and what's the scale? If you print the Length of an Event as String you get the RulerFormat so that's dynamic. I want to add "Frames"!


---------------------------------------------

If CType(EventEnum.Current, SonicFoundry.Vegas.TrackEvent).Selected Then
'NEED HELP WITH CODE HERE
'CType(EventEnum.Current, SonicFoundry.Vegas.TrackEvent).Length?????
End If
---------------------------------------------


Any Help appriciated!

Comments

SonyPJM wrote on 7/11/2003, 4:33 PM

Try this:


Dim evnt As TrackEvent
evnt = CType(EventEnum.Current, SonicFoundry.Vegas.TrackEvent)
If evnt.Selected Then
Dim twentyFrames As Timecode
Dim start As Timecode
Dim length As Timecode

twentyFrames = new Timecode()
twentyFrames.FrameCount = 20

start = evnt.Start
length = evnt.Length

' expand the right
length += twentyFrames
evnt.AdjustStartLength(start, length, true)

' expand the left
start -= twentyFrames
length += twentyFrames
evnt.AdjustStartLength(start, length, false)

End If
lnetzel wrote on 7/11/2003, 7:11 PM
Yeah I understand the logic and that clears my question, thanx, but not the syntax. My VS.NET won't do the operator thingies with TimeCode ...

This Line for example will be underlined:

"length += twentyFrames"

With Errormessage:
"Operator '+' is not defined for types 'SonicFoundry.Vegas.Timecode' and 'SonicFoundry.Vegas.Timecode' "

Same thing with the ' - ' and '&' operators...

/Lars



jetdv wrote on 7/11/2003, 8:26 PM
What if you use:

length = length + twentyFrames
lnetzel wrote on 7/12/2003, 3:01 AM
Nope, does'nt work! Even Vegas says the same when I try to run the script (Or is it the .NET Framework that says this?)

I tried a workarond by casting to integer types to make the mathatic work but that did'nt work either.

-------------------
Dim iStart As Integer
Dim iLength As Integer

iStart = CInt(TrackEvent.Start.FrameCount)
iLength = CInt(TrackEvent.Length.FrameCount)
iStart += 20
iLength += 20

' expand the right
length.FrameCount = CType(iLength, SonicFoundry.Vegas.Timecode)
TrackEvent.AdjustStartLength(start, length, True)
------------------------------
This row give the error:
"length.FrameCount = CType(iLength, SonicFoundry.Vegas.Timecode)"

Error: "Value of type 'Integer' cannot be converted to 'SonicFoundy.Vegas.TimeCode'

I also tried With Data Type "Long" and "Double", did'nt work either!

This is a problem, what's up with the timecode?
lnetzel wrote on 7/12/2003, 3:41 AM
This is about the ugliest code I've ever done, hopefully this may be written a lot nicer! Please come up with better ways to write this!

I found a Method on the TimeCode Class called "FromString" and That of course only let me work with Strings. So I use Integer to do the mathmatics and then I use Strings to assing the value to the timecode. It actually works... I got really supriced!

------------------------------------------------------------------------------------------
TrackEvent = CType(EventEnum.Current, SonicFoundry.Vegas.TrackEvent)
If TrackEvent.Selected Then
Dim start As Timecode
Dim length As Timecode
Dim iStart As Integer
Dim iLength As Integer
Dim sStart As String
Dim sLength As String

start = TrackEvent.Start
length = TrackEvent.Length
iStart = CInt(TrackEvent.Start.FrameCount)
iLength = CInt(TrackEvent.Length.FrameCount)
iStart -= 20
iLength += 20
sLength = CStr(iLength)
sStart = CStr(iStart)

' expand the right
length.FromString(sLength)
TrackEvent.AdjustStartLength(start, length, True)

'expand the left
iLength += 20
sLength = CStr(iLength)
length.FromString(sLength)
start.FromString(sStart)
TrackEvent.AdjustStartLength(start, length, False)
MessageBox.Show("Start: " & TrackEvent.Start.ToString & Chr(10) & "Length: " & TrackEvent.Length.ToString)
End If
-----------------------------------------------------------------

roger_74 wrote on 7/12/2003, 3:56 AM
Try this workaround:

length = new Timecode (length.ToMilliseconds() + twentyFrames.ToMilliseconds())

It's not ideal, but it works.
roger_74 wrote on 7/12/2003, 4:04 AM
Just to be on the safe side... The FrameCount is an unsigned integer, I think.
lnetzel wrote on 7/12/2003, 4:13 AM
Maybe this is actually how you are supposed to do? I now also added a Argument... so this Sub has a Variable Called "NumberofFrames" sent to is so you can make this more dymanic!

I wonder why the "op_Addition()" did'nt show up in the Code Complete list!

-----------------------------------------------------------------
If TrackEvent.Selected Then
MessageBox.Show("Start: " & TrackEvent.Start.ToString & Chr(10) & "Length: " & TrackEvent.Length.ToString, "Before Change")
Dim addFrames As Timecode
Dim start As Timecode
Dim length As Timecode

start = TrackEvent.Start
length = TrackEvent.Length
addFrames = New Timecode()

'Event length will be added with NumberofFrames*2 long but start NumberofFrames earlier
addFrames.FrameCount = (0 - NumberofFrames)
start = TrackEvent.Start.op_Addition(TrackEvent.Start, addFrames)
addFrames.FrameCount = (NumberofFrames * 2)
length = TrackEvent.Length.op_Addition(TrackEvent.Length, addFrames)
'Make change
TrackEvent.AdjustStartLength(start, length, False)

MessageBox.Show("Start: " & TrackEvent.Start.ToString & Chr(10) & "Length: " & TrackEvent.Length.ToString, "After Change")
End If
------------------------------------------------------------

/Lars
roger_74 wrote on 7/12/2003, 4:25 AM
Nice. I always wondered why the operators didn't work. Now it strikes me that only C# has operator overloading, right?
lnetzel wrote on 7/12/2003, 4:38 AM
No, I think VB.NET does that too now, but Vegas.TimeCodet does'nt seem to work with operators like that.
SonyPJM wrote on 7/14/2003, 7:37 AM
I'm sorry I didn't test my code first... Here's how you can use the overloaded operators in Timecode from VB:

------------------------------------------------------------------------------------------


' expand the right
length = Timecode.op_Addition(length, twentyFrames)
evnt.AdjustStartLength(start, length, true)

' expand the left
start = Timecode.op_Subtraction(start, twentyFrames)
length = Timecode.op_Addition(length, twentyFrames)
evnt.AdjustStartLength(start, length, false)




-------------------------------------------------------------------------------------


This will be better than converting to and from milliseconds or strings.