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 creates a playlist with one section and two events. It fades up at the /// start of the section, fades thru between events, and fades down at the end of the section. /// 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) { 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 ) { // setup default values string channel = "C1"; string volume = "V:"; string bin = "default"; string uriClip1 = String.Format("edl/cmf//localhost/{0}/{1}/{2}", volume, bin, "Clip_1"); string uriClip2 = String.Format("edl/cmf//localhost/{0}/{1}/{2}", volume, bin, "Clip_2"); // create a controller and player bool isNewController = false; ISimpleController controller = connection.AppServer.CreateController( appName, channel, out isNewController); ISimplePlayerRecorder player = (ISimplePlayerRecorder) controller; // turn off the player's loop play mode player.LoopPlayMode = false; // enable playlist pauses player.SetChannelProperty("listpauses", "true"); // enable playlist repeats player.SetChannelProperty("listrepeats", "true"); // set current bin player.SetCurrentBin(volume, bin); // generate a unique name for the playlist string playlist = player.GenerateUniqueName("playlist", "_"); // create the new playlist (which also loads it) player.New(playlist); // get an event editor IEventEditor editor = (IEventEditor) player.GetEditor(); // start the playlist at 1 hour editor.SetStartingTimecode("01:00:00,00"); // create a new section at the end of the clip (i.e. "") string section1 = editor.InsertSection(""); // setup section so that it starts by fading up from matte color editor.SetSectionProperty(section1, "StartTrans", true); editor.SetSectionProperty(section1, "StartTransDur", 120); // duration in fields editor.SetSectionProperty(section1, "StartVidTrans", (int)VideoTransition.FadeFromMatte); // video fade from matte editor.SetSectionProperty(section1, "StartAudTrans", (int)AudioTransition.FadeUp); // audio fade up editor.SetSectionProperty(section1, "StartTransMatte", (int)MatteColor.Black); // black matte color // setup section so that it ends by fading down to matte color editor.SetSectionProperty(section1, "EndTrans", true); editor.SetSectionProperty(section1, "EndTransDur", 120); // duration in fields editor.SetSectionProperty(section1, "EndVidTrans", (int)VideoTransition.FadeToMatte); // video fade to matte editor.SetSectionProperty(section1, "EndAudTrans", (int)AudioTransition.FadeDown); // audio fade down editor.SetSectionProperty(section1, "EndTransMatte", (int)MatteColor.Black); // black matte color // insert Clip 1 into section 1 string edit1 = editor.InsertPlayEvent(uriClip1, section1, 0, ""); // insert Clip 2 into section 1 string edit2 = editor.InsertPlayEvent(uriClip2, section1, 0, ""); // setup edit1 so that it fades thru matte color editor.SetEventProperty(edit1, "Trans", true); editor.SetEventProperty(edit1, "TransDur", 120); // duration in fields editor.SetEventProperty(edit1, "VidTrans", (int)VideoTransition.FadeThruMatte); // fade thru matte editor.SetEventProperty(edit1, "AudTrans", (int)AudioTransition.CrossFade); // audio crossfade editor.SetEventProperty(edit1, "TransMatte", (int)MatteColor.Black); // matte color // cue playlist to the start player.CueStart(); // start playing player.Play(); // wait for a keypress from the user before continuing Console.WriteLine(Environment.NewLine + "press ENTER key to exit"); Console.ReadLine(); // 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(); } } }