Exemple #1
0
        private void addMapping(MenuItemViewModel item)
        {
            int index = _mappings.Count;

            if (_selectedMappings.Count > 0)
            {
                index = _mappings.IndexOf(_selectedMappings.Last()) + 1;
            }

            var proxy = item.Tag as CommandProxy;
            var m     = _device.CreateMapping(proxy);

            _device.InsertMapping(index, m);

            var mvm = new MappingViewModel(_device, m);
            var row = new RowItemViewModel(mvm);

            _mappings.Insert(index, row);

            selectExclusive(row);
            row.BringIntoView();
        }
Exemple #2
0
        private void addMapping(MenuItemViewModel item)
        {
            int index = _mappings.Count;       //add on the last row by default

            if (_selectedMappings.Count > 0)   //if something is selected, add it at the end of the selection
            {
                index = _mappings.IndexOf(_selectedMappings.Last()) + 1;
            }

            var proxy = item.Tag as CommandProxy;
            var m     = _device.CreateMapping(proxy);

            _device.InsertMapping(index, m);      // this is to add the mapping itelf

            var mvm = new MappingViewModel(_device, m);
            var row = new RowItemViewModel(mvm);

            _mappings.Insert(index, row);         //this is to add the row to the grid

            selectExclusive(row);
            row.BringIntoView();

            row.ClearFiltering();   // HACK: investigate why there is a duplication on the very first paste or "add-in". Clearing grid filters avoids this bug
        }
Exemple #3
0
// Constructor
        public DeviceViewModel(Device device, TsiFileViewModel parent)
        {
            // link to parent, used for the filtering operations
            this.ParentSelector = parent;

            _device         = device;
            _traktorVersion = _device.TraktorVersion;

            updatePorts(device);

            generateAddMappingContextMenus();

            loadDefaultMidiDefinitionsAsync();

            foreach (var mapping in _device.Mappings)
            {
                var mvm = new MappingViewModel(_device, mapping);
                Mappings.Add(new RowItemViewModel(mvm));
                mvm.DirtyStateChanged += (s, e) => updateMapsChanged();
            }

            loadMetadata();

            AcceptChanges();

            Mappings.CollectionChanged += Mappings_CollectionChanged;

            // set selection if possible
            if (Mappings.Any())
            {
                SelectedMappings.Add(Mappings.First());
                updateAddMappingContextMenus();

                this.ParentSelector.ClearFiltering();
            }
        }
Exemple #4
0
        private void updateAddMappingContextMenus()
        {
            if (OutCommands.Contains(_separator))
            {
                OutCommands.Remove(_separator);
                OutCommands.RemoveAt(OutCommands.Count - 1);
            }

            MappingViewModel selectedMapping = null;

            if (_selectedMappings.Count != 1 || (selectedMapping = _selectedMappings.Single().Item as MappingViewModel).Command.MappingType != MappingType.In)
            {
                return;
            }

            if (All.KnownOutCommands.ContainsKey(selectedMapping.Command.Id))
            {
                var commandProxy = All.KnownOutCommands[selectedMapping.Command.Id];
                if (!OutCommands.Contains(_separator))
                {
                    OutCommands.Add(_separator);
                    OutCommands.Add(new MenuItemViewModel
                    {
                        Text    = commandProxy.Name + " (" + selectedMapping.AssignmentExpression + ")",
                        Tag     = commandProxy,
                        Command = new CommandHandler <MenuItemViewModel>(i =>
                        {
                            int index = _mappings.Count;
                            if (_selectedMappings.Count > 0)
                            {
                                index = _mappings.IndexOf(_selectedMappings.Last()) + 1;
                            }

                            var proxy = i.Tag as CommandProxy;
                            var m     = _device.CreateMapping(proxy);
                            _device.InsertMapping(index, m);

                            var mvm        = new MappingViewModel(_device, m);
                            mvm.Assignment = selectedMapping.Assignment;

                            if (selectedMapping.CanOverrideFactoryMap)
                            {
                                mvm.OverrideFactoryMap = selectedMapping.OverrideFactoryMap;
                            }

                            if (selectedMapping.MidiBinding != null && MidiOutDefinitions.ContainsKey(selectedMapping.MidiBinding.Note))
                            {
                                mvm.SetBinding(MidiOutDefinitions[selectedMapping.MidiBinding.Note]);
                            }

                            if (selectedMapping.Conditions.Condition1 != null)
                            {
                                mvm.SetCondition(TsiLib.Conditions.ConditionNumber.One, selectedMapping.Conditions.Condition1);
                            }

                            if (selectedMapping.Conditions.Condition2 != null)
                            {
                                mvm.SetCondition(TsiLib.Conditions.ConditionNumber.Two, selectedMapping.Conditions.Condition2);
                            }

                            var row = new RowItemViewModel(mvm);
                            _mappings.Insert(index, row);

                            selectExclusive(row);
                            row.BringIntoView();
                        })
                    });
                }
            }
        }
        public void try_rotate_command(MappingViewModel m, int step, KnownCommands start_c, KnownCommands end_c)
        {
            var           command = m.Command;
            KnownCommands cur_id  = (KnownCommands)m.Command.Id;

            if (!is_range_id(cur_id, start_c, end_c))
            {
                //return;
            }

            int cur_modifier = cur_id - start_c + 1;

            int start_i = 1;
            int end_i;

            switch (end_c)
            {
            case KnownCommands.FXUnit_Button3:
            case KnownCommands.FXUnit_Effect3Selector:
            case KnownCommands.FXUnit_Knob3:
                end_i = 3;
                break;

            case KnownCommands.Mixer_FXUnit4On:
                end_i = 4;
                break;

            case KnownCommands.Global_MidiControls_Buttons_MidiButton8:
            case KnownCommands.Global_MidiControls_Knobs_MidiFader8:
            case KnownCommands.Global_MidiControls_Knobs_MidiKnob8:
            case KnownCommands.Modifier_Modifier8:
            case KnownCommands.TrackDeck_Cue_Hotcue8Type:
                end_i = 8;
                break;

            case KnownCommands.RemixDeck_StepSequencer_EnableStep16:
            case KnownCommands.DeckCommon_FreezeMode_SliceTrigger16:
                // needs bugfix?
                //return;

                end_i = 16;
                break;

            default:
                MessageBoxHelper.ShowError(String.Format("Rotating command - unknown command: {0}", end_c));
                return;
            }

            int distance_id = end_c - start_c + 1;

            if (distance_id != end_i)
            {
                MessageBoxHelper.ShowError(String.Format("Rotating command {0} has id_diff of {1}, but expected {2}", end_c, distance_id, end_i));
                return;
            }

            if (!is_range_id(cur_id, start_c, end_c))
            {
                return;
            }

            int new_modifier = rotate_modifier_key_int(cur_modifier, step, start_i, end_i);

            string new_name = patch_command_name(command.Name, new_modifier);

            KnownCommands new_id = start_c + new_modifier - 1;

            // pestrela: this is a bit fragile, and should be improved
            m.Command.hack_modifier(new_id, new_name);
            m.hack_modifier(new_id);

            // would this be the proper way?
            //    var _rawMapping = m._mapping.RawMapping;
            //    ACommand Command = Commands.All.GetCommandProxy(_rawMapping.TraktorControlId, _rawMapping.Type).Create(_rawMapping.Settings);

            m.UpdateInteraction();
        }
        public bool try_rotate_command_exceptions(MappingViewModel m, int step)
        // returns: handled
        {
            var           command = m.Command;
            KnownCommands cur_id  = (KnownCommands)m.Command.Id;

            int cur_modifier;

            switch (cur_id)
            {
            case KnownCommands.Mixer_FXUnit1On:
                cur_modifier = 1;
                break;

            case KnownCommands.Mixer_FXUnit2On:
                cur_modifier = 2;
                break;

            case KnownCommands.Mixer_FXUnit3On:
                cur_modifier = 3;
                break;

            case KnownCommands.Mixer_FXUnit4On:
                cur_modifier = 4;
                break;

            default:
                return(false);
            }

            int start_i = 1;
            int end_i   = 4;

            int new_modifier = rotate_modifier_key_int(cur_modifier, step, start_i, end_i);

            string new_name = patch_command_name(command.Name, new_modifier);

            KnownCommands new_id;

            switch (new_modifier)
            {
            case 1:
                new_id = KnownCommands.Mixer_FXUnit1On;
                break;

            case 2:
                new_id = KnownCommands.Mixer_FXUnit2On;
                break;

            case 3:
                new_id = KnownCommands.Mixer_FXUnit3On;
                break;

            case 4:
                new_id = KnownCommands.Mixer_FXUnit4On;
                break;

            default:
                return(false);
            }
            ;

            // pestrela: this is a bit fragile, and should be improved
            m.Command.hack_modifier(new_id, new_name);
            m.hack_modifier(new_id);

            m.UpdateInteraction();

            return(true);
        }
        public void try_rotate(MappingViewModel m, int step, KnownCommands start_c, KnownCommands end_c)
        {
            var           command = m.Command;
            KnownCommands cur_id  = (KnownCommands)m.Command.Id;

            if (!is_range_id(cur_id, start_c, end_c))
            {
                return;
            }


            int cur_modifier = cur_id - start_c + 1;

            int start_i = 1;
            int end_i   = 8;

            switch (end_c)
            {
            case KnownCommands.FXUnit_Button3:
            case KnownCommands.FXUnit_Effect3Selector:
            case KnownCommands.FXUnit_Knob3:
                end_i = 3;
                break;


            case KnownCommands.Global_MidiControls_Buttons_MidiButton8:
            case KnownCommands.Global_MidiControls_Knobs_MidiFader8:
            case KnownCommands.Global_MidiControls_Knobs_MidiKnob8:
            case KnownCommands.Modifier_Modifier8:
            case KnownCommands.TrackDeck_Cue_Hotcue8Type:
                end_i = 8;
                break;

            case KnownCommands.Mixer_FXUnit4On:
                end_i = 4;
                break;

            case KnownCommands.RemixDeck_StepSequencer_EnableStep16:
                // needs bugfix
                return;

                end_i = 16;
                break;
            }

            int new_modifier = rotate_modifier_key_int(cur_modifier, step, start_i, end_i);

            string new_name = patch_command_name(command.Name, new_modifier);

            KnownCommands new_id = start_c + new_modifier - 1;

            // pestrela: this is a bit fragile, and should be improved
            m.Command.hack_modifier(new_id, new_name);
            m.hack_modifier(new_id);

            // would this be the proper way?
            //    var _rawMapping = m._mapping.RawMapping;
            //    ACommand Command = Commands.All.GetCommandProxy(_rawMapping.TraktorControlId, _rawMapping.Type).Create(_rawMapping.Settings);

            m.UpdateInteraction();
        }