using System; using System.Threading; using Interop.TimecodeLib; using GrassValley.Mseries.AppServer; using GrassValley.Mseries.AppServerLog; using GrassValley.Mseries.ChanStatus; using GrassValley.Mseries.ConfigMgr; using GrassValley.Mseries.Control; using GrassValley.Mseries.DVCapture; using GrassValley.Mseries.Editor; using GrassValley.Mseries.MediaMgr; using GrassValley.Mseries.Security; using GrassValley.Mseries.Status; using GrassValley.Mseries.TransferQueue; // Leave the following "css_reference" lines in when running with CS-Script. They're // more than just comments - they tell CS-Script which DLLs to load if the DLL // name does not match the namespace that it implements. //css_reference Credentials.dll; //css_reference ServerUtil.dll; /// /// This sample demonstrates how to create flying mix effects between the foreground and background contexts of a channel. /// namespace K2Script { class Test { public enum MatteColor { Black = 0x108080, White = 0xEB8080, Yellow = 0xD68A10, Cyan = 0xBC1099, Green = 0xAC1A29, Magenta = 0x4EE5D6, Red = 0x3EF066, Blue = 0x2075F0 }; public enum VideoTransition { None = 0, // standard video cut Dissolve = 1, // dissolve between 2 video tracks (available with both flying and playlist mix effects) FadeFromMatte = 2, // fades from matte color to video (available with playlist section mix effects only) FadeToMatte = 3, // fades from video to matte color (available with playlist section mix effects only) FadeThruMatte = 4, // fades from video to matte color to video (available with both flying and playlist mix effects) }; public enum AudioTransition { None = 0, // standard audio cut CrossFade = 1, // cross-fades between to audio tracks (available with both flying and playlist mix effects) FadeUp = 2, // audio fade up (available with playlist section mix effects only) FadeDown = 3, // audio fade down (available with playlist section mix effects only) FadeThruSilence = 4, // fade from audio to silence to audio (available with both flying and playlist mix effects) }; static int Main(string[] args) { // this example shows how to do insert edits and dual-context transitions. It uses three 10 second clips // in the V:\default bin called "test1", "test2", and "test3". try { // get the application's name & create a unique suite name string appName = Environment.GetCommandLineArgs()[0]; string suiteName = appName + "_" + System.Guid.NewGuid().ToString("N"); // fill in these values for your connection (i.e. hardcode them, pass in // cmdline arguments, read from file, read from console, etc.) string host = "localhost"; string username = ""; string password = ""; string domain = ""; // Connect to host & pass in credentials. The "using" block disposes connection when done. using ( Connection connection = new Connection(appName, suiteName, host, username, password, domain) ) { // do work only if we have a valid connection if ( connection.IsConnected ) { string channel = "C1"; // create a controller, player, and preview bool isNewController = false; ISimpleController controller = connection.AppServer.CreateController( appName, channel, out isNewController); ISimplePlayerRecorder player = (ISimplePlayerRecorder) controller; ITwoHeadPlayerRecorder preview = (ITwoHeadPlayerRecorder) controller; // load player, cue to start and start playing it player.Load("edl/cmf//local/V:/default/Clip_1"); player.CueStart(); player.Play(); // load another clip on the background preview context preview.LoadPreview("edl/cmf//local/V:/default/Clip_2"); // preview.ActivateMode = "replace"; // when context switching occurs, inactive context is ejected preview.ActivateMode = "swap"; // when context switching occurs, clip remains on inactive context // EXAMPLE 1: immediate dissolve // wait a few seconds... just so we can see the // transition from foreground to background context Thread.Sleep(3000); // cue the preview context and start it playing in the // background. Note: that the "manual" context change // performsthe cueing & starts playing, but it does not // switch the context from foreground to background preview.BeginPreviewContextChange (); preview.CueStart(); preview.Play(); preview.CommitContextChange("manual"); // setup a video dissolve & audio crossfade for 2 seconds Object[] transParams = new Object[4]; transParams[0] = 120; // fields of transition transParams[1] = (int) VideoTransition.Dissolve; // video dissolve transParams[2] = (int) AudioTransition.CrossFade; // audio crossfade transParams[3] = (int) MatteColor.Black; // black matte // now switch the context and do the transition. // note that the "transition" context changes performs // the "commit" so no CommitContextChange is needed // afterwards. preview.BeginPreviewContextChange(); preview.ScheduleContextChange ("transition", transParams ); // wait some time just to see the transition and the background clip Thread.Sleep(3000); /* // comment out example 1 and uncomment example 2 to see the next example // EXAMPLE 2: immediate fade thru matte // wait a few seconds... just so we can see the // transition from foreground to background context Thread.Sleep(3000); // cue the preview context and start it playing in the // background. Note: that the "manual" context change // performsthe cueing & starts playing, but it does not // switch the context from foreground to background preview.BeginPreviewContextChange (); preview.CueStart(); preview.Play(); preview.CommitContextChange("manual"); // setup a video fade thru matte for 3 seconds Object[] transParams = new Object[4]; transParams[0] = 180; // fields of transition transParams[1] = (int) VideoTransition.FadeThruMatte; // video transition fade thru matte transParams[2] = (int) AudioTransition.None; // audio crossfade transParams[3] = (int) MatteColor.White; // white // now switch the context and do the transition. // note that the "transition" context changes performs // the "commit" so no CommitContextChange is needed // afterwards. preview.BeginPreviewContextChange(); preview.ScheduleContextChange ("transition", transParams ); // wait some time just to see the transition and the background clip Thread.Sleep(5000); */ // eject the clip player.Stop(); player.Eject(); // close the channel controller.CloseChannel(); } } } catch (Exception e) { Console.WriteLine(e); } return 0; } } // Connection helper class: sets up credentials & hostname, connects to K2 public class Connection: IDisposable { private bool _connected = false; private AppServerMgrProxy _appServerMgrProxy = null; private IAppServer _appServer = null; /// ; /// Object that connects to the specified K2 credentials /// ; /// ;The application's name.; /// ;The suite's name.; /// ;The K2's host name.; /// ;The username.; /// ;The password.; /// ;The domain.; public Connection(string appname, string suitename, string host, string username, string password, string domain) { try { ////////////////////////// // SETUP ////////////////////////// if ( null == host || host.Length == 0) { Console.WriteLine("Empty host name passed to Connection object."); return; } ////////////////////////// // CONNECT TO K2 ////////////////////////// // create an AppServerMgr proxy object _appServerMgrProxy = new AppServerMgrProxy(); // tell it which K2 we're connecting to _appServerMgrProxy.SetHost(host); // give it the user credentials we want to use if ( username.Length > 0 ) _appServerMgrProxy.SetUserCredentials(username, password, domain, false); // connect to the K2's AppServerMgr if ( !_appServerMgrProxy.Connect() ) { // if the connection failed, report an error and exit Console.WriteLine("ERROR: Could not connect to AppService on host '" + host + "'. Check the host name."); _appServerMgrProxy = null; return; } // if we got here we're connected to K2 AppService ////////////////////////// // CREATE AN APPSERVER ////////////////////////// // now create an AppServer bool newConnection = false; _appServer = _appServerMgrProxy.CreateAppServer(suitename, appname, out newConnection); _connected = true; } catch (Exception e) { Console.WriteLine(e); } } /// ; /// Gets a value indicating whether this instance is connected. /// ; /// ; /// ;true; if this instance is connected; otherwise, ;false;. /// ; public bool IsConnected { get { return _connected; } } /// ; /// Gets the AppServerMgr. /// ; /// ;The AppServerMgr; public AppServerMgrProxy AppServerMgr { get { if ( _appServerMgrProxy == null ) Console.WriteLine("WARNING: AppServerMgrProxy object == null!"); return _appServerMgrProxy; } } /// ; /// Gets the AppServer /// ; /// ;The AppServer; public IAppServer AppServer { get { if ( _appServerMgrProxy == null ) Console.WriteLine("WARNING: AppServerProxy object == null!"); return _appServer; } } /// ; /// Disposes this instance. /// ; public void Dispose() { if ( _appServer != null ) _appServer.CloseConnection(); } } }