Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private void prepareFxSettings(IEnumerable <EffectSelectorInCommand> effectSelectorInCommands, IEnumerable <EffectSelectorOutCommand> effectSelectorOutCommands)
        {
            List <Effect> usedFxIn  = effectSelectorInCommands.Select(e => e.Value).Distinct().ToList();
            List <Effect> usedFxOut = effectSelectorOutCommands.Select(e => e.ControllerRangeMin).Distinct().ToList();
            List <Effect> usedFx    = usedFxIn.Union(usedFxOut).Distinct().Except(new[] { Effect.NoEffect }).OrderBy(e => e).ToList();

            // Keep effects from Traktor settings as they are. Append new effects if necessary.
            if (IsTraktorSettings)
            {
                usedFx = FxSettings.Effects.Union(usedFx).Distinct().ToList();
            }

            Dictionary <Effect, FxSnapshot> usedSnapshots = new Dictionary <Effect, FxSnapshot>();

            foreach (var fx in usedFx)
            {
                FxSnapshot snapshot = null;
                if (FxSettings.Snapshots.ContainsKey(fx))
                {
                    snapshot = FxSettings.Snapshots[fx];
                }
                else
                {
                    if (TraktorSettings.Initialized && TraktorSettings.Instance.FxSettings.Snapshots.ContainsKey(fx))
                    {
                        snapshot = TraktorSettings.Instance.FxSettings.Snapshots[fx];
                    }
                    else
                    {
                        snapshot = new FxSnapshot(fx);
                    }
                }
                usedSnapshots.Add(fx, snapshot);
            }

            // Keep snapshots from Traktor settings as they are. Add new snapshots if necessary.
            if (IsTraktorSettings)
            {
                usedSnapshots = FxSettings.Snapshots.Union(usedSnapshots).Distinct().ToDictionary(s => s.Key, s => s.Value);
            }


            bool optimizeFXList = OptimizeFXList; // how to use  CmdrSettings.Instance.OptimizeFXList ?;

            if (optimizeFXList)
            {
                FxSettings = new FxSettings(usedFx, usedSnapshots);
            }
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        private void load_FX()
        {
            // Effects
            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 (position on a list) with ids (actual command)
                if (FxSettings != null)
                {
                    restoreEffectSelectorCommands(effectSelectorInCommands, effectSelectorOutCommands);
                }
                else
                {
                    _ignoreFx = true;
                }
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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;
                    }
                }
            }
        }