Esempio n. 1
0
        private static Dictionary <string, AMidiDefinition> getDefinitionsFromTsi(MappingType type, string tsiFile)
        {
            Dictionary <string, AMidiDefinition> result = new Dictionary <string, AMidiDefinition>();

            try
            {
                TsiFile file = TsiFile.Load(String.Empty, tsiFile);
                if (type == MappingType.In)
                {
                    result = file.Devices.SelectMany(dev =>
                                                     dev.RawDevice.Data.MidiDefinitions.In.Definitions.Select(def =>
                                                                                                              AMidiDefinition.Parse(dev.TypeStr, MappingType.In, def))
                                                     ).DistinctBy(m => m.Note).ToDictionary(k => k.Note, k => k);
                }
                else
                {
                    result
                        = file.Devices.SelectMany(dev =>
                                                  dev.RawDevice.Data.MidiDefinitions.Out.Definitions.Select(def =>
                                                                                                            AMidiDefinition.Parse(dev.TypeStr, MappingType.Out, def))
                                                  ).DistinctBy(m => m.Note).ToDictionary(k => k.Note, k => k);
                }
            }
            catch (Exception)
            {
            }

            return(result);
        }
Esempio n. 2
0
        private TsiFileViewModel(TsiFile tsiFile)
        {
            _tsiFile = tsiFile;

            // Is new file?
            if (tsiFile.Path == null)
            {
                IsChanged = true;
            }
            else
            {
                foreach (var device in _tsiFile.Devices)
                {
                    var dvm = new DeviceViewModel(device, this);
                    Devices.Add(dvm);
                    dvm.DirtyStateChanged += (s, a) => onDeviceChanged();
                }

                // Set selection if possible
                SelectedDevice = Devices.FirstOrDefault();

                AcceptChanges();
            }

            Devices.CollectionChanged += Devices_CollectionChanged;
        }
        private async void OpenMenuItemClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "TSI|*.tsi"
            };

            if (dialog.ShowDialog() == true)
            {
                var currentCursor = Cursor;
                Cursor = Cursors.Wait;
                var tsi = new TsiFile(dialog.FileName);

                var createModel = Task <List <MappingModel> > .Factory.StartNew(() => MainWindowController.CreateModel(tsi.Devices.First()));

                await createModel;
                model.Filter             = "";
                model.Mappings           = new ObservableCollection <MappingModel>(createModel.Result);
                model.MappingView        = CollectionViewSource.GetDefaultView(model.Mappings);
                model.MappingView.Filter = Filter;

                model.FileName = dialog.FileName;

                Cursor = currentCursor;
            }
        }
Esempio n. 4
0
        public MainWindow()
        {
            InitializeComponent();

            var tsi = new TsiFile(@"C:\Users\Ivan\Desktop\test.tsi");


            DataContext = new MappingsObservableCollection(tsi.Devices.First());
        }
Esempio n. 5
0
 private static async Task <TsiFile> loadTsiAsync(string filePath)
 {
     try {
         return(await Task <TsiFile> .Factory.StartNew(() => TsiFile.Load(
                                                           CmdrSettings.Instance.TraktorVersion,
                                                           filePath,
                                                           CmdrSettings.Instance.RemoveUnusedMIDIDefinitions,
                                                           false
                                                           )));
     }
     catch (Exception e) {
         if (CmdrSettings.Instance.VerboseExceptions)
         {
             MessageBoxHelper.ShowException("Error loading " + filePath, e);
         }
         return(null);
     }
 }
        private void ok()
        {
            switch (CurrentOption)
            {
            case EffectIdentificationViewModel.Options.Option1:
                _request.FxSettings = TraktorSettings.Instance.FxSettings;
                break;

            case EffectIdentificationViewModel.Options.Option2:
                if (String.IsNullOrEmpty(PathToTsi))
                {
                    MessageBoxHelper.ShowError("Please specify a path.");
                    return;
                }
                else
                {
                    try
                    {
                        _request.FxSettings = TsiFile.Load(CmdrSettings.Instance.TraktorVersion, PathToTsi, false).FxSettings;
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        MessageBoxHelper.ShowError("Could not load " + PathToTsi);
                        return;
                    }
                }
                break;

            case EffectIdentificationViewModel.Options.Option3:
                break;

            default:
                break;
            }

            if (CloseAction != null)
            {
                CloseAction();
            }
        }
Esempio n. 7
0
        private async void addDevice(MenuItemViewModel item)
        {
            ControllerDefaultMappings.ControllerDefaultMappingFile defFile = item.Tag as ControllerDefaultMappings.ControllerDefaultMappingFile;

            App.SetStatus("Loading defaults for " + item.Text + " ...");

            if (item.Text.Equals(Device.TYPE_STRING_GENERIC_MIDI))
            {
                addDevice(_tsiFile.CreateDevice(Device.TYPE_STRING_GENERIC_MIDI));
            }
            else if (defFile != null)
            {
                TsiFile tsi = defFile.TsiFile;
                if (tsi == null)
                {
                    tsi = await defFile.LoadAsync();
                }
                if (tsi != null)
                {
                    bool includeMappings = MessageBoxHelper.ShowQuestion("Do you want to load the default mappings too?");
                    foreach (var d in tsi.Devices)
                    {
                        var copy = d.Copy(includeMappings);
                        if (copy.TypeStr.Equals(Device.TYPE_STRING_GENERIC_MIDI) && String.IsNullOrEmpty(copy.Comment))
                        {
                            copy.Comment = item.Text;
                        }
                        addDevice(copy);
                    }
                }
            }

            App.ResetStatus();
            if (Devices.Any())
            {
                SelectedDevice = Devices.LastOrDefault();
            }
        }
        private async void SaveTsi(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(model.FileName))
            {
                var currentCursor = Cursor;
                Cursor = Cursors.Wait;

                var saveFile = Task.Factory.StartNew(() =>
                {
                    var tsi = new TsiFile(model.FileName);
                    if (MainWindowController.SaveModel(model.Mappings, tsi.Devices.First()) == SaveModelResult.SuccessWithNonSavedUnknownMappings)
                    {
                        MessageBox.Show("You have made changes to mappings associated with unknown traktor functions. " +
                                        "Please note that these changes will not be saved. All other changes will be saved as normal.");
                    }
                    tsi.Save();
                });

                await saveFile;

                Cursor = currentCursor;
            }
        }
        private async Task addDefaultMappings(int count, string pathToDefaultFile)
        {
            FileInfo fi           = new FileInfo(pathToDefaultFile);
            string   manufacturer = fi.Directory.Name;
            string   controller   = Path.GetFileNameWithoutExtension(fi.Name)
                                    .Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries)
                                    .Last();

            TsiFile tsi = await loadTsiAsync(pathToDefaultFile);

            if (tsi == null)
            {
                Debug.WriteLine("Could not load " + pathToDefaultFile);
                return;
            }

            var file = new ControllerDefaultMappingFile(manufacturer, controller, pathToDefaultFile);

            file.DefaultMappings.AddRange(tsi.Devices.Select(pd => new ControllerDefaultMapping(file, pd.TypeStr)));
            this.Add(file);

            Interlocked.Increment(ref _progressCounter);
            App.SetStatus("Loading defaults for proprietary devices ... " + ((double)_progressCounter / count * 100) + "%");
        }
Esempio n. 10
0
 public static TsiFileViewModel Create()
 {
     return(new TsiFileViewModel(TsiFile.Create(CmdrSettings.Instance.TraktorVersion)));
 }
 private static async Task <TsiFile> loadTsiAsync(string filePath)
 {
     return(await Task <TsiFile> .Factory.StartNew(() => TsiFile.Load(CmdrSettings.Instance.TraktorVersion, filePath)));
 }
            public async Task <TsiFile> LoadAsync()
            {
                TsiFile = await Task <TsiFile> .Factory.StartNew(() => TsiFile.Load(CmdrSettings.Instance.TraktorVersion, Path));

                return(TsiFile);
            }