grass valley developers

Home > APIs > AppServer API > Examples > Timeline and Transport Control > Context Changes

Context Changes

Often you want to synchronize the playout or recording of a channel or multiple channels at a specific time. Context Triggers and Scheduled Context Conditions are used for this.

To schedule events to happen at specific triggers or conditions, issuing the following sequence of commands:

1. Cue the asset by calling a cue command. The clip must be cued before your can schedule or commit a change.
2. call "BeginContextChange” command
3. make the calls you want to happen at the trigger or condition (i.e. Play() )
4. call "CommitContextChange" or “ScheduleContextChange” command.

Note: see the C# Script Samples section and look at InsertEditTwoHead.cs for different Context Trigger and Scheduled Context examples.

Context Trigger types:

"asap" – Used to apply a context change to the active context or a preview context. Committing with ASAP will make a preview context active. When cueing to a new position with ASAP, the decoder will wait until the correct picture is fetched.

"now" – Used to apply a context change to the active context or a preview context. Committing with NOW will make a preview context active though, generally should only be used with the active context. When cueing to a new position with NOW, the decoder will immediately push out a picture, event if it is not the correct one. Use this context trigger when committing the first context change if you are not immediately playing. The still picture will pushed out sooner. Use the NOW context trigger when implementing a “scrub bar” and you want to push out a lot of pictures rapidly, so don’t care if they are the exact picture. Eventually the decoder will show the appropriate picture.

"manual" – Used to apply a context change to a preview context without activating it. The preview context will never be activated if its last trigger was MANUAL.

"follow" – Used to apply a context change to a preview context without activating it. When a preview context’s last trigger was FOLLOW, then it will automatically be activated when the active context reaches its end limit.

The code below illustrates how to play a second clip immediately after a clip:

// C# Code
// create a player and a background preview context
string channel = "C1";
bool isNewController = false;
ISimpleController controller = connection.AppServer.CreateController(
	appName, channel, out isNewController);
ISimplePlayerRecorder player = (ISimplePlayerRecorder) controller;
ITwoHeadPlayerRecorder preview = (ITwoHeadPlayerRecorder) controller;

// load and start playing clip
player.Load("edl/cmf//local/V:/default/clip1");
player.Play();
						
// while main context is playing, load preview context with a second clip
preview.LoadPreview("edl/cmf//local/V:/default/clip2");

// setup a context change so that the second clip follows the first
preview.BeginPreviewContextChange();
preview.CueStart(); // cue to some position in clip
preview.Play();

// tell preview context to go active after primary context finishes (i.e. follow)
preview.CommitContextChange("follow"); 

// wait awhile...
Thread.Sleep(45000);

// stop and eject the clip
player.Stop();
player.Eject();

// close the channel
controller.CloseChannel();

Scheduled Context Conditions:

Scheduled context changes are always applied with an ASAP trigger when the scheduled condition is met. They include:

"tickcount" tickValue (UINT) – A channel’s tickcount is incremented every field from the time it was started. The condition is met when the channel’s tickcount reaches the given value.

"gpi" gpiInputMask (UINT) – The GPI condition is met when one or more GPI inputs indicated in the gpiInputMask are asserted. The GPI inputs in this mask must have been associated with the channel in the config utility.

"timeofday" timecode (string) – This condition is met when the time of day clock value equals the given timecode string. This is useful when you want to schedule multiple channels to a single clock source. UseAppCenter's System Config panel for setting the TimeOfDay source.

"vitc" timecode (string) – This condition is met when the VITC value on a channel equals the given timecode string.

"ltc" timecode (string) – This condition is met when the LTC value on a channel equals the given timecode string.

"ancvitc" timecode (string) – This condition is met when the ANCVITC value on a channel equals the given timecode string.

"ancltc" timecode (string) – This condition is met when the ANCLTC value on a channel equals the given timecode string.

"int" timecode (string) – This condition is met when the internal timecode source equals the timecode string.

"gen" timecode (string) – Same as INT. This condition is met when the generated timecode source equals the timecode string.

"gang" channelMask(UINT) – The context change is applied simultaneously to all channels indicated in the given channel mask. It is the application’s responsibility to have correctly set up all the channels appropriately.

"transition" duration(int), videoTransition(int), audioTransition(int), matte(UINT) – This condition activates a preview context using the given transition parameters. It is also called a “Flying M/E”. The condition is an array of four values. This condition is only available on K2 Summit.

The code below illustrates how to start playing a clip at a specific timecode. Note: you can specify what the source of Time Of Day clock is for the K2 Client fromAppCenter ’s System Configuration panel. For instance you might set the Time Of Day clock to an LTC input. In this case also make sure that you have a valid LTC source connected to the K2 Client.

C# Code
// create a controller
bool isNewController = false;
ISimpleController icontroller = connection.AppServer.CreateController(
	appName, channel, out isNewController);

// cast it to a player recorder and load a clip
ISimplePlayerRecorder player = (ISimplePlayerRecorder) icontroller;
player.Load("edl/cmf//local/V:/default/Clip");

// must cue clip before you can schedule it!
player.CueStart();

// begin context change, telling it to play at a particular timecode
player.BeginContextChange();
player.Play();
player.ScheduleContextChange("timeofday", "09:00:00.00");

// to cancel schedule change
// player.CancelScheduledChange("timeofday", "09:00:00.00");

// wait awhile...
Thread.Sleep(45000);

// stop and eject the clip
player.Stop();
player.Eject();

// close the channel
icontroller.CloseChannel();