コード例 #1
0
ファイル: FxSnapshot.cs プロジェクト: whiteschool/cmdr
        internal void Save(TsiXmlDocument xml)
        {
            var defBtn = new DefaultButtonFx(_effect)
            {
                Value = new List <int>
                {
                    Buttons.ButtonGroupMode,
                    Buttons.Button3,
                    Buttons.Button2,
                    Buttons.Button1,
                    Buttons.OnOff,
                }
            };

            xml.SaveEntry(defBtn);

            var defParam = new DefaultParamFx(_effect)
            {
                Value = new List <float>
                {
                    Knobs.KnobGroupMode,
                    Knobs.Knob3,
                    Knobs.Knob2,
                    Knobs.Knob1,
                    Knobs.DryWet,
                }
            };

            xml.SaveEntry(defParam);
        }
コード例 #2
0
ファイル: TsiFile.cs プロジェクト: pestrela/cmdr
        /// <summary>
        /// Loads a TSI File.
        /// </summary>
        /// <exception cref="System.Exception">Thrown when file cannot be loaded or parsed.</exception>
        /// <param name="traktorVersion">The targeted Traktor Version. The version of the file is checked against it.</param>
        /// <param name="filePath">Path of the file.</param>
        public static TsiFile Load(string traktorVersion, string filePath, bool RemoveUnusedMIDIDefinitions, bool ignoreExceptions = true)
        {
            TsiFile file = new TsiFile(traktorVersion);

            file.Path = filePath;
            try {
                TsiXmlDocument xml = new TsiXmlDocument(filePath);
                file.load(xml, RemoveUnusedMIDIDefinitions);
                return(file);
            }
            catch (AggregateException ex) {
                if (ignoreExceptions)
                {
                    return(null);
                }
                else
                {
                    // Preserves the stack trace
                    // https://stackoverflow.com/questions/57383/how-to-rethrow-innerexception-without-losing-stack-trace-in-c
                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();

                    // This is just to please the compiler
                    throw ex;
                }
            }
        }
コード例 #3
0
ファイル: TsiFile.cs プロジェクト: whiteschool/cmdr
        public bool Save(string filePath)
        {
            // workaround to save indices instead of ids
            var effectSelectorInCommands  = getCriticalEffectSelectorInCommands();
            var effectSelectorOutCommands = getCriticalEffectSelectorOutCommands();

            bool prepared = false;

            if (!_ignoreFx && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
            {
                if (FxSettings == null)
                {
                    FxSettings = (TraktorSettings.Initialized) ? TraktorSettings.Instance.FxSettings : createDefaultFxSettings();
                }

                prepareFxForSave(effectSelectorInCommands, effectSelectorOutCommands);
                prepared = true;
            }

            // build controller config (binary)
            DeviceIoConfigController controllerConfig = null;

            try
            {
                string tsiData = getDataAsBase64String();
                controllerConfig       = new DeviceIoConfigController();
                controllerConfig.Value = tsiData;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error building controller config. Reason: " + ex.Message);
                return(false);
            }

            if (prepared)
            {
                restoreEffectSelectorCommands(effectSelectorInCommands, effectSelectorOutCommands);
            }

            // build xml document
            try
            {
                TsiXmlDocument xml = (Path != null) ? new TsiXmlDocument(Path) : new TsiXmlDocument();
                if (FxSettings != null && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
                {
                    FxSettings.Save(xml);
                }
                xml.SaveEntry(controllerConfig);
                xml.Save(filePath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error building xml document. Reason: " + ex.Message);
                return(false);
            }

            Path = filePath;
            return(true);
        }
コード例 #4
0
ファイル: FxSettings.cs プロジェクト: whiteschool/cmdr
        internal void Save(TsiXmlDocument xml)
        {
            var fxSelection = new AudioFxSelection {
                Value = _effects
            };

            xml.SaveEntry(fxSelection);

            foreach (var effDef in _snapshots.Values)
            {
                effDef.Save(xml);
            }
        }
コード例 #5
0
ファイル: TsiFile.cs プロジェクト: whiteschool/cmdr
        /// <summary>
        /// Loads a TSI File.
        /// </summary>
        /// <exception cref="System.Exception">Thrown when file cannot be loaded or parsed.</exception>
        /// <param name="traktorVersion">The targeted Traktor Version. The version of the file is checked against it.</param>
        /// <param name="filePath">Path of the file.</param>
        public static TsiFile Load(string traktorVersion, string filePath)
        {
            TsiFile file = new TsiFile(traktorVersion);

            file.Path = filePath;
            try
            {
                TsiXmlDocument xml = new TsiXmlDocument(filePath);
                file.load(xml);
                return(file);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: TsiFile.cs プロジェクト: pestrela/cmdr
        private void load(TsiXmlDocument xml, bool RemoveUnusedMIDIDefinitions)
        {
            // Traktor version, optional (only for "Traktor Settings.tsi")
            var browserDirRoot = xml.GetEntry <BrowserDirRoot>();

            if (browserDirRoot != null)
            {
                Match m = REGEX_TRAKTOR_FOLDER.Match(browserDirRoot.Value);
                if (m.Success) // Overwrite version if possible
                {
                    TraktorVersion = m.Groups[1].Value;
                }
            }

            // Effects, optional (FxSettings.Load may return null)
            // can this move below ?
            FxSettings = FxSettings.Load(xml);

            // Devices
            StringXmlEntry controllerConfigController = xml.GetEntry <DeviceIoConfigController>();

            if (controllerConfigController != null)
            {
                byte[] decoded = Convert.FromBase64String(controllerConfigController.Value);
                _devicesContainerControllers = new DeviceMappingsContainer(new MemoryStream(decoded));
                var _devices_tmp = _devicesContainerControllers.Devices.List.Select(d => new Device(max_id++, d, RemoveUnusedMIDIDefinitions, false)).ToList();

                // append to whole list
                _devices.AddRange(_devices_tmp);
            }

            StringXmlEntry controllerConfigKeyboard = xml.GetEntry <DeviceIoConfigKeyboard>();

            if (controllerConfigKeyboard != null)
            {
                byte[] decoded = Convert.FromBase64String(controllerConfigKeyboard.Value);
                _devicesContainerKeyboard = new DeviceMappingsContainer(new MemoryStream(decoded));
                var _devices_tmp = _devicesContainerKeyboard.Devices.List.Select(d => new Device(max_id++, d, RemoveUnusedMIDIDefinitions, true)).ToList();

                // append to whole list
                _devices.AddRange(_devices_tmp);
            }

            load_FX();
        }
コード例 #7
0
        /// <summary>
        /// Loads a TSI File.
        /// </summary>
        /// <exception cref="System.Exception">Thrown when file cannot be loaded or parsed.</exception>
        /// <param name="traktorVersion">The targeted Traktor Version. The version of the file is checked against it.</param>
        /// <param name="filePath">Path of the file.</param>
        public static TsiFile Load(string traktorVersion, string filePath, bool RemoveUnusedMIDIDefinitions)
        {
            TsiFile file = new TsiFile(traktorVersion);

            file.Path = filePath;
            try
            {
                TsiXmlDocument xml = new TsiXmlDocument(filePath);
                file.load(xml, RemoveUnusedMIDIDefinitions);
                return(file);
            }
            catch (Exception e)
            {
                String ret = e.ToString();
                //System.Windows.Forms.MessageBox.ShowError("Cannot open file."+ret);   // How to pass an exception string to the message box to the user?
                return(null);
            }
        }
コード例 #8
0
ファイル: FxSnapshot.cs プロジェクト: whiteschool/cmdr
        internal static FxSnapshot Load(Effect effect, TsiXmlDocument xml)
        {
            var fxDefault = new FxSnapshot(effect);

            DefaultButtonFx defBtn = xml.GetEntry(new DefaultButtonFx(effect));

            if (defBtn != null)
            {
                fxDefault._buttons = new FxButtonsSnapshot
                {
                    ButtonGroupMode = defBtn.Value[0],
                    Button3         = defBtn.Value[1],
                    Button2         = defBtn.Value[2],
                    Button1         = defBtn.Value[3],
                    OnOff           = defBtn.Value[4]
                };
            }

            DefaultParamFx defParam = xml.GetEntry(new DefaultParamFx(effect));

            if (defParam != null)
            {
                fxDefault._knobs = new FxKnobsSnapshot
                {
                    KnobGroupMode = defParam.Value[0],
                    Knob3         = defParam.Value[1],
                    Knob2         = defParam.Value[2],
                    Knob1         = defParam.Value[3],
                    DryWet        = defParam.Value[4]
                };
            }

            // reason for logical OR: usually, there is both entries, but preservation goes over completeness
            // TODO: try if Traktor accepts "half" snapshots
            if (defBtn != null || defParam != null)
            {
                return(fxDefault);
            }

            return(null);
        }
コード例 #9
0
ファイル: FxSettings.cs プロジェクト: whiteschool/cmdr
        internal static FxSettings Load(TsiXmlDocument xml)
        {
            var fxSelection = xml.GetEntry <AudioFxSelection>();

            if (fxSelection == null)
            {
                return(null);
            }

            Dictionary <Effect, FxSnapshot> defaults = new Dictionary <Effect, FxSnapshot>();
            var allEffects = Enum.GetValues(typeof(Effect)).Cast <Effect>().Except(new[] { Effect.NoEffect }).ToList();

            foreach (var effect in allEffects)
            {
                var effDef = FxSnapshot.Load(effect, xml);
                if (effDef != null)
                {
                    defaults.Add(effect, effDef);
                }
            }

            return(new FxSettings(fxSelection.Value, defaults));
        }
コード例 #10
0
ファイル: TsiFile.cs プロジェクト: pestrela/cmdr
        public bool Save(string filePath, bool optimizeFXList, bool backup = false)
        {
            // workaround to save indices (position on a list) instead of ids (actual command)
            var effectSelectorInCommands  = getCriticalEffectSelectorInCommands();
            var effectSelectorOutCommands = getCriticalEffectSelectorOutCommands();

            OptimizeFXList = optimizeFXList;

            bool prepared = false;

            if (!_ignoreFx && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
            {
                if (FxSettings == null)
                {
                    FxSettings = (TraktorSettings.Initialized) ? TraktorSettings.Instance.FxSettings : createDefaultFxSettings();
                }

                prepareFxForSave(effectSelectorInCommands, effectSelectorOutCommands);
                prepared = true;
            }

            // build controller config (binary)
            DeviceIoConfigController controllerConfigController = null;
            DeviceIoConfigKeyboard   controllerConfigKeyboard   = null;

            var all_devices      = _devices.Select(d => d).ToList();
            var only_keyboard    = _devices.Where(d => (d.IsKeyboard == true)).ToList();
            var only_controllers = _devices.Where(d => (d.IsKeyboard == false)).ToList();

            try {
                if (only_controllers.Any())
                {
                    string tsiDataController = getDataAsBase64String(false);
                    controllerConfigController       = new DeviceIoConfigController();
                    controllerConfigController.Value = tsiDataController;
                }

                if (only_keyboard.Any())
                {
                    string tsiDataKeyboard = getDataAsBase64String(true);
                    controllerConfigKeyboard       = new DeviceIoConfigKeyboard();
                    controllerConfigKeyboard.Value = tsiDataKeyboard;
                }
            }
            catch (Exception ex)
            {
                // FIXME: show this to the user somehow
                //   at least a show console option

                // Exception thrown: 'System.OutOfMemoryException' in mscorlib.dll
                // Error building controller config. Reason: Exception of type 'System.OutOfMemoryException' was thrown.

                Debug.WriteLine("Error building controller config. Reason: " + ex.Message);
                return(false);
            }

            if (prepared)
            {
                restoreEffectSelectorCommands(effectSelectorInCommands, effectSelectorOutCommands);
            }

            // build xml document
            try
            {
                TsiXmlDocument xml = (Path != null) ? new TsiXmlDocument(Path) : new TsiXmlDocument();
                if (FxSettings != null && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
                {
                    FxSettings.Save(xml);
                }

                if (only_controllers.Any())
                {
                    xml.SaveEntry(controllerConfigController);
                }
                if (only_keyboard.Any())
                {
                    xml.SaveEntry(controllerConfigKeyboard);
                }

                xml.Save(filePath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error building xml document. Reason: " + ex.Message);
                return(false);
            }

            if (!backup)
            {
                Path = filePath;
            }
            return(true);
        }
コード例 #11
0
ファイル: TsiFile.cs プロジェクト: whiteschool/cmdr
        private void load(TsiXmlDocument xml)
        {
            // Traktor version, optional (only for "Traktor Settings.tsi")
            var browserDirRoot = xml.GetEntry <BrowserDirRoot>();

            if (browserDirRoot != null)
            {
                Match m = REGEX_TRAKTOR_FOLDER.Match(browserDirRoot.Value);
                if (m.Success) // Overwrite version if possible
                {
                    TraktorVersion = m.Groups[1].Value;
                }
            }

            // effects, optional (FxSettings.Load may return null)
            FxSettings = FxSettings.Load(xml);

            // devices
            var controllerConfig = xml.GetEntry <DeviceIoConfigController>();

            if (controllerConfig != null)
            {
                byte[] decoded = Convert.FromBase64String(controllerConfig.Value);
                _devicesContainer = new DeviceMappingsContainer(new MemoryStream(decoded));
                int id = 0;
                _devices = _devicesContainer.Devices.List.Select(d => new Device(id++, d)).ToList();

                var effectSelectorInCommands  = getCriticalEffectSelectorInCommands();
                var effectSelectorOutCommands = getCriticalEffectSelectorOutCommands();
                if (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any())
                {
                    // need FxSettings for interpretation but not provided by file itself?
                    if (FxSettings == null)
                    {
                        // call for help
                        string rId     = new FileInfo(Path).Name;
                        var    request = new EffectIdentificationRequest(rId);
                        var    handler = EffectIdentificationRequest;
                        if (handler != null)
                        {
                            handler(this, request);

                            // wait for help
                            while (!request.Handled)
                            {
                                Thread.Sleep(100);
                            }

                            if (request.FxSettings != null)
                            {
                                FxSettings = request.FxSettings;
                            }
                        }
                    }

                    // if possible, replace effect indices with ids
                    if (FxSettings != null)
                    {
                        restoreEffectSelectorCommands(effectSelectorInCommands, effectSelectorOutCommands);
                    }
                    else
                    {
                        _ignoreFx = true;
                    }
                }
            }
        }