Example #1
0
            public bool Play()
            {
                error = null;

                try {
                    if (!File.Exists(path))
                    {
                        error = string.Format("File '{0}' does not exist.", path);
                        return(false);
                    }

                    var           fileIOHandler = FileIOHelper.GetByExtension(path);
                    EventSequence sequence      = fileIOHandler.OpenSequence(path);
                    numberOfChannels = sequence.FullChannelCount;

                    object executionIfaceObj;
                    if (!Interfaces.Available.TryGetValue("IExecution", out executionIfaceObj))
                    {
                        error = "IExecution interface not available.";
                        return(false);
                    }

                    executionInterface = (IExecution)executionIfaceObj;
                    contextHandle      = executionInterface.RequestContext(true, false, null);
                    executionInterface.SetSynchronousContext(contextHandle, sequence);

                    executionInterface.ExecutePlay(contextHandle, 0, 0);

                    return(true);
                }
                catch (Exception e) {
                    error = e.Message;
                    return(false);
                }
            }
Example #2
0
        private void OpenSequence(string fileName)
        {
            var fileIOHandler = FileIOHelper.GetByExtension(fileName);

            if (fileIOHandler == null)
            {
                MessageBox.Show(Resources.VixenPlusForm_NoKnowEditor, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            if (!fileIOHandler.CanOpen())
            {
                MessageBox.Show(string.Format("Sorry, we can only export {0} files.", fileIOHandler.Name()), Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            AddToFileHistory(fileName);

            var plugInInterface = (IUIPlugIn)Activator.CreateInstance(_registeredFileTypes[".vix"].GetType());

            plugInInterface.Sequence = fileIOHandler.OpenSequence(fileName);

            ((Form)plugInInterface).Text = plugInInterface.Sequence.Name + " - " + plugInInterface.Sequence.FileIOHandler.Name();
            var uiBase = plugInInterface as UIBase;

            if (uiBase != null)
            {
                uiBase.DirtyChanged += plugin_DirtyChanged;
            }

            plugInInterface.MdiParent = this;
            plugInInterface.Show();
        }
Example #3
0
        private void VixenPlusForm_DragEnter(object sender, DragEventArgs e)
        {
            var isValidData = (e.Data.GetDataPresent(DataFormats.FileDrop));

            if (isValidData)
            {
                var files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
                isValidData = files.Aggregate(true, (current, file) => current & FileIOHelper.GetValidOpeningExtensions().Contains(file.Substring(file.Length - 4, 4)));
            }

            e.Effect = isValidData ? DragDropEffects.Copy : DragDropEffects.None;
        }
Example #4
0
 private void openALightingProgramToolStripMenuItem_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter           = FileIOHelper.GetOpenFilters();
     openFileDialog1.InitialDirectory = Paths.SequencePath;
     openFileDialog1.FileName         = string.Empty;
     if (openFileDialog1.ShowDialog() != DialogResult.OK)
     {
         return;
     }
     Cursor = Cursors.WaitCursor;
     try {
         OpenSequence(openFileDialog1.FileName);
     }
     finally {
         Cursor = Cursors.Default;
     }
 }
Example #5
0
        private void AttachToProfile(string profileName)
        {
            var path = Path.Combine(Paths.ProfilePath, profileName + Vendor.ProfileExtension);

            if (File.Exists(path))
            {
                if (null == FileIOHandler)
                {
                    FileIOHandler = FileIOHelper.GetProfileVersion(path);
                }
                // todo this could have the same issue with mismatch as another issue
                AttachToProfile(FileIOHandler.OpenProfile(path));
                Groups = _profile.Groups;
            }
            else
            {
                FileIOHandler.LoadEmbeddedData(FileName, this);
            }
        }
Example #6
0
        /// <summary>
        /// Save the file, routed to the appropriate plugin
        /// </summary>
        /// <param name="pluginInstance"></param>
        /// <returns>If a save action was performed</returns>
        private bool Save(IUIPlugIn pluginInstance)
        {
            if (pluginInstance == null)
            {
                return(false);
            }

            var plugInInterface = pluginInstance;

            if ((plugInInterface.IsDirty && string.IsNullOrEmpty(plugInInterface.Sequence.Name)) && !GetNewSequenceInfo(pluginInstance))
            {
                return(false);
            }

            UpdateHistoryImages(plugInInterface.Sequence.FileName);

            // If the sequenceType is not set, set it to Vixen Plus
            if (plugInInterface.Sequence.FileIOHandler == null)
            {
                // this should never be true, if it is we don't want to blow up, but notify and continue.
                MessageBox.Show("Interesting!",
                                "You should never see this, but if you do, I didn't want to blow up on you\n" + "Let Macebobo on Diychristmas.org know, please.\n" +
                                "I'm going to set your sequence file handler type to Vixen Plus - he'll know what that means\n" + "And I can continue gracefully.\n" +
                                "Sorry about that! Carry on.");
                plugInInterface.Sequence.FileIOHandler = FileIOHelper.GetNativeHelper();
            }

            plugInInterface.SaveTo();

            if (plugInInterface.Sequence.FileIOHandler.CanOpen())
            {
                AddToFileHistory(plugInInterface.Sequence.FileName);
            }

            if (_preferences.GetBoolean("ShowSaveConfirmation"))
            {
                MessageBox.Show(Resources.VixenPlusForm_SequenceSaved, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }

            return(true);
        }
Example #7
0
        public override void handleGETRequest(HttpProcessor p)
        {
            string[] args = p.http_url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            p.writeSuccess();

            if (args == null || args.Length == 0)
            {
                showHelp(p);
                return;
            }

            if (args[0] == "files")
            {
                string path = string.Join("\\", args.Skip(1).ToArray());
                p.serveFile(path);
                return;
            }
            else if (args[0] == "sequence")
            {
                string fullPath = Path.Combine(VixenPlusCommon.Paths.SequencePath, Uri.UnescapeDataString(args[1]));
                object obj2;
                if (sequences.Contains(fullPath))
                {
                    //Sequence exists
                    if (Interfaces.Available.TryGetValue("IExecution", out obj2))
                    {
                        var fileIOHandler = FileIOHelper.GetByExtension(fullPath);
                        sequence = fileIOHandler.OpenSequence(fullPath);

                        _executionInterface     = (IExecution)obj2;
                        _executionContextHandle = _executionInterface.RequestContext(false, true, null);
                        _executionInterface.SetAsynchronousContext(_executionContextHandle, sequence);

                        try {
                            if (_channelLevels == null)
                            {
                                _channelLevels = new byte[sequence.FullChannelCount];
                            }


                            if (args.Length == 2)
                            {
                                p.writeLine("Successfully selected sequence!");
                                p.writeLine("<br>");
                                p.writeLine("Commands: <br>");
                                p.writeLine("   /play/ <br>");
                                p.writeLine("   /play/ms/ <br>");
                                p.writeLine("   /pause/ <br>");
                                p.writeLine("   /stop/ <br>");
                                p.writeLine("   /channels/ <br>");
                                return;
                            }

                            if (args[2] == "channels")
                            {
                                int maxChannels = sequence.FullChannelCount;
                                if (args.Length == 3)
                                {
                                    p.writeLine("/set/channelnum/0-255");
                                    p.writeLine("<br>");
                                    p.writeLine("/get/channelnum/");
                                    p.writeLine("<br>");
                                    p.writeLine("Max channels: " + maxChannels);
                                    return;
                                }

                                if (args[3] == "set")
                                {
                                    int  channel = int.Parse(args[4]);
                                    byte value   = byte.Parse(args[5]);
                                    _channelLevels[channel] = value;
                                    updateChannels();
                                    p.writeLine("Executed command: " + args[2]);
                                }

                                if (args[3] == "get")
                                {
                                    int channel = int.Parse(args[4]);
                                    p.writeLine("" + _channelLevels[channel]);
                                }
                            }
                        } finally {
                            _executionInterface.ReleaseContext(_executionContextHandle);
                        }
                    }
                }
                else
                {
                    //Error and say that their sequence they selected doesnt exist.
                    p.writeLine(args[1] + " Does not exist.");
                    p.writeLine("<br>");
                    p.writeLine("Selectable sequences: ");
                    p.writeLine("<br>");
                    printoutVixenSequences(p, "<br>");
                }
            }
            else if (args[0] == "listseq")
            {
                printoutVixenSequences(p, null);
            }
            else
            {
                showHelp(p);
            }
        }
Example #8
0
        private bool GetNewSequenceInfo(IUIPlugIn pluginInstance)
        {
            var saveFilters        = FileIOHelper.GetSaveFilters();
            var filters            = saveFilters.Split('|');
            var currentFilter      = pluginInstance.Sequence.FileIOHandler.DialogFilterList();
            var currentFilterIndex = int.MinValue;

            for (var i = 0; i < filters.Count(); i += 2)
            {
                if (!currentFilter.StartsWith(filters[i]))
                {
                    continue;
                }
                currentFilterIndex = i / 2;
                break;
            }

            saveFileDialog1.Filter           = saveFilters;
            saveFileDialog1.FilterIndex      = currentFilterIndex == int.MinValue ? 0 : currentFilterIndex;
            saveFileDialog1.InitialDirectory = Paths.SequencePath;
            saveFileDialog1.FileName         = String.IsNullOrEmpty(pluginInstance.Sequence.FileName) ? string.Empty : Path.GetFileNameWithoutExtension(pluginInstance.Sequence.FileName);
            saveFileDialog1.AddExtension     = true;
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            var newFilterIndex = saveFileDialog1.FilterIndex - 1;

            // Okay format changed...
            if (currentFilterIndex != newFilterIndex)
            {
                var newFileIOHandler = FileIOHelper.GetHelperByName(filters[newFilterIndex * 2]);

                // Since Vixen+ is native, it has the lowest filter index of any of the list
                // Other file formats will be higher and thus may lose data or functionality when down versioning
                // or cross sequence formatting.  In some cases it won't matter, in other it will be very important.
                if (newFilterIndex > currentFilterIndex)
                {
                    if (
                        MessageBox.Show(
                            string.Format("{0}\n\nOld Format: {1}\nNewFormat: {2}\n\n{3}\n\n{4}\n\n{5}",
                                          "WARNING! A possible loss of data may occur from this change!",
                                          pluginInstance.Sequence.FileIOHandler.Name(),
                                          newFileIOHandler.Name(),
                                          "This will impact your sequence and " + ((pluginInstance.Sequence.Profile == null ? "embedded" : "attached") + " profile"),
                                          "Proceed with saving in this format?",
                                          "In other words, press OK if you have a backup.")
                            , "Possible loss of data!",
                            MessageBoxButtons.OKCancel,
                            MessageBoxIcon.Warning,
                            MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }

                //Okay they want the change, get the new handler and make it so

                pluginInstance.Sequence.FileIOHandler = newFileIOHandler; // this automatically handles embedded data

                // he we handle profiles.
                if (pluginInstance.Sequence.Profile != null)
                {
                    pluginInstance.Sequence.Profile.FileIOHandler = newFileIOHandler;
                    if (newFileIOHandler.SupportsProfiles)
                    {
                        newFileIOHandler.SaveProfile(pluginInstance.Sequence.Profile);
                    }
                }
            }

            ChangeSequenceName(pluginInstance, saveFileDialog1.FileName);

            return(true);
        }
Example #9
0
        public void SetSynchronousContext(int contextHandle, IExecutable executableObject)
        {
            if (contextHandle == 0)
            {
                return;
            }

            var context = _registeredContexts[contextHandle];

            if (context.SuppressSynchronousContext)
            {
                return;
            }

            try {
                var mask         = executableObject.Mask;
                var plugInData   = executableObject.PlugInData;
                var nativeHelper = FileIOHelper.GetNativeHelper();

                if (!context.LocalRequestor && !executableObject.TreatAsLocal)
                {
                    Profile profile;
                    var     str = _preferences.GetString("SynchronousData");
                    if (str == "Default")
                    {
                        var str2 = _preferences.GetString("DefaultProfile");

                        if (str2 == string.Empty)
                        {
                            LogError("SetSynchronousContext",
                                     "Preference set to use default profile for synchronous execution, but no default profile set.");
                            mask       = null;
                            plugInData = null;
                        }
                        else
                        {
                            profile = nativeHelper.OpenProfile(Path.Combine(Paths.ProfilePath, str2 + ".pro"));
                            profile.Freeze();
                            mask       = profile.Mask;
                            plugInData = profile.PlugInData;
                        }
                    }
                    else if (str != "Embedded")
                    {
                        profile = nativeHelper.OpenProfile(Path.Combine(Paths.ProfilePath, str + ".pro"));
                        profile.Freeze();
                        mask       = profile.Mask;
                        plugInData = profile.PlugInData;
                    }
                }
                context.Object      = executableObject;
                context.Object.Mask = mask;
                if (plugInData != null)
                {
                    context.Object.PlugInData.ReplaceRoot(plugInData.RootNode);
                }
                if (!(context.SuppressAsynchronousContext || _preferences.GetString("AsynchronousData") != "Sync"))
                {
                    AsyncInit(context);
                }
                if (executableObject.AudioDeviceIndex != -1)
                {
                    context.SynchronousEngineInstance.SetAudioDevice(executableObject.AudioDeviceIndex);
                }
                if (executableObject.AudioDeviceVolume != 0)
                {
                    context.SynchronousEngineInstance.SetAudioDevice(executableObject.AudioDeviceIndex);
                }
            }
            catch (Exception exception) {
                LogError("SetSynchronousContext", exception);
            }
        }
Example #10
0
 public int RequestContext(bool suppressAsynchronousContext, bool suppressSynchronousContext, Form keyInterceptor)
 {
     try {
         var num     = ((int)DateTime.Now.ToBinary()) + _registeredContexts.Count;
         var context = new ExecutionContext
         {
             SuppressAsynchronousContext = suppressAsynchronousContext, SuppressSynchronousContext = suppressSynchronousContext
         };
         var integer = _preferences.GetInteger("SoundDevice");
         context.SynchronousEngineInstance  = context.SuppressSynchronousContext ? null : new Engine8(_host, integer);
         context.AsynchronousEngineInstance = context.SuppressAsynchronousContext
             ? null : new Engine8(Engine8.EngineMode.Asynchronous, _host, integer);
         context.LocalRequestor = RequestorIsLocal(new StackTrace().GetFrame(1));
         context.Object         = null;
         context.KeyInterceptor = keyInterceptor;
         if (!context.SuppressAsynchronousContext)
         {
             byte[][]  mask;
             SetupData plugInData;
             var       str     = _preferences.GetString("AsynchronousData");
             var       str2    = ((str != "Default") && (str != "Sync")) ? str : _preferences.GetString("DefaultProfile");
             Profile   profile = null;
             if (str2.Length > 0)
             {
                 try {
                     var nativeIO = FileIOHelper.GetNativeHelper();
                     profile = nativeIO.OpenProfile(Path.Combine(Paths.ProfilePath, str2 + ".pro"));
                     profile.Freeze();
                 }
                 catch {
                     LogError("RequestContext", "Error loading profile " + str2);
                 }
             }
             if (profile == null)
             {
                 if (str == "Default")
                 {
                     LogError("RequestContext",
                              "Preference set to use default profile for asynchronous execution, but no default profile exists.");
                 }
                 mask       = null;
                 plugInData = null;
             }
             else
             {
                 mask           = profile.Mask;
                 plugInData     = profile.PlugInData;
                 context.Object = profile;
             }
             if (context.Object != null)
             {
                 context.Object.Mask = mask;
                 if (plugInData != null)
                 {
                     context.Object.PlugInData.ReplaceRoot(plugInData.RootNode);
                 }
                 AsyncInit(context);
             }
         }
         _registeredContexts[num] = context;
         return(num);
     }
     catch (Exception exception) {
         LogError("RequestContext", exception);
         return(0);
     }
 }