internal ComboMidiDefinition(MappingType type, int channel, Format.MidiDefinition definition)
            : base(type, channel, definition)
        {
            var defs = splitDefinition(definition);

            _midiDefinition1 = AGenericMidiDefinition.Parse(type, defs.Item1);
            _midiDefinition2 = AGenericMidiDefinition.Parse(type, defs.Item2);
        }
Exemple #2
0
        public void hack_encoder_mididefinition()
        {
            AGenericMidiDefinition midiBinding = (this._mapping.MidiBinding as AGenericMidiDefinition);

            if (midiBinding == null)
            {
                return;    //nothing todo. We are not linked to a midi modifier yet
            }

            MidiEncoderMode actual_encoder_mode = _mapping.Command.get_EncoderMode();

            midiBinding.MidiEncoderMode = actual_encoder_mode;
        }
        private void updateBinding(AMidiDefinition definition = null)
        {
            string          expression;
            AMidiDefinition tmpDefinition;

            foreach (var mapping in _mappings)
            {
                expression    = null;
                tmpDefinition = definition;

                if (IsGenericMidi)
                {
                    if (!String.IsNullOrEmpty(_channel))
                    {
                        if (!String.IsNullOrEmpty(_note))
                        {
                            expression = _channel + "." + _note.Replace("+", "+" + _channel + ".");
                        }
                        else if (mapping.MidiBinding != null)
                        {
                            expression = Regex.Replace(mapping.MidiBinding.Note, @"Ch\d+", _channel);
                        }
                    }
                    else if (!String.IsNullOrEmpty(_note))
                    {
                        if (mapping.MidiBinding != null)
                        {
                            var channel = mapping.MidiBinding.Note.Substring(0, 4);
                            expression = channel + "." + _note.Replace("+", "+" + channel + ".");
                        }
                    }

                    if (expression != null)
                    {
                        tmpDefinition = AGenericMidiDefinition.Parse(mapping.Command.MappingType, expression);
                    }
                }
                else
                {
                    if (tmpDefinition != null && mapping.Command.MappingType != tmpDefinition.Type)
                    {
                        tmpDefinition = _proprietaryDefinitions.First(p => p.Type == mapping.Command.MappingType && p.Note == tmpDefinition.Note);
                    }
                }

                mapping.SetBinding(tmpDefinition);
            }

            analyzeSelection();
            updateMenus();
        }
        /*
         * Note1:
         *   "Mapping.MidiBinding" comes without type by some reason.
         *   Workaound inspects the types explicitelly
         *   We could use AGenericMidiDefinition.Parse but then we had to generte the string by hand
         *
         * Note2:
         *   "Type" is not C#. Its about traktor "in"/"out"
         *
         */
        private AGenericMidiDefinition incDecGeneric(AGenericMidiDefinition old, int step, IncDecWhat what)
        {
            if (old is ComboMidiDefinition)
            {
                var specific = (ComboMidiDefinition)old;

                return(new ComboMidiDefinition(
                           incDecGeneric(specific.MidiDefinition1, step, what),
                           incDecGeneric(specific.MidiDefinition2, step, what)));
            }

            // at this stage we always have a channel
            int old_channel = old.Channel;
            int new_channel = incDec_channel(old_channel, step, what);

            if (old is NoteMidiDefinition)
            {
                var specific     = (NoteMidiDefinition)old;
                var keyConverter = new MidiLib.Utils.KeyConverter();

                int    old_value = keyConverter.ToKeyIPN(specific.KeyText);
                int    new_value = incDec_note(old_value, step, what);
                string new_note  = keyConverter.GetKeyTextIPN(new_value);

                return(new NoteMidiDefinition(old.Type, new_channel, new_note));
            }

            if (old is ControlChangeMidiDefinition)
            {
                var specific = (ControlChangeMidiDefinition)old;

                int new_value = incDec_note(specific.Cc, step, what);

                return(new ControlChangeMidiDefinition(old.Type, new_channel, new_value));
            }

            // this should never be reached!
            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Set binding.
        /// </summary>
        /// <param name="device">The device this mapping belongs to. </param>
        /// <param name="midi">AMidiDefinition or null to reset binding.</param>
        /// <returns>True if binding was changed.</returns>
        public bool SetBinding(Device device, AMidiDefinition midi) // if the Device paramater was left out, it would be possible to make an invalid binding.
        {
            // given device and definition do not match. binding cannot be kept.
            if (midi != null && device.TypeStr != midi.DeviceTypeStr)
            {
                MidiBinding = null;
                return(true);
            }

            // midi definitions and bindings
            var deviceData  = device.RawDevice.Data;
            var definitions = (Command.MappingType == MappingType.In) ? deviceData.MidiDefinitions.In.Definitions : deviceData.MidiDefinitions.Out.Definitions;
            var bindings    = deviceData.Mappings.MidiBindings.Bindings;

            // remove old binding and definition(s) if no longer in use
            if (MidiBinding != null)
            {
                // remove old binding and check if old definition can be removed too, because it is not used in another binding
                var oldBinding = bindings.SingleOrDefault(b => b.BindingId.Equals(Id));
                if (oldBinding != null)
                {
                    bindings.Remove(oldBinding);

                    var oldBindings = bindings.Where(b => b.MidiNote.Equals(MidiBinding.Note));
                    if (!oldBindings.Any())
                    {
                        int removedCount = definitions.RemoveAll(d => d.MidiNote.Equals(MidiBinding.Note));
                        if (removedCount > 1)
                        {
                            // TODO: Something for the consolidation function
                        }
                    }
                }
            }

            if (midi != null)
            {
                // add midi definition to device, if it doesn't already exist
                var matchingDefinitions = definitions.Where(d => d.MidiNote.Equals(midi.Note));
                if (matchingDefinitions.Any() == false)
                {
                    var definition = midi.RawDefinition;

                    // adapt encoder mode to device, if necessary
                    var genericDefinition = midi as AGenericMidiDefinition;
                    if (genericDefinition != null) //  && genericDefinition.MidiEncoderMode != device.EncoderMode)
                    {
                        genericDefinition = AGenericMidiDefinition.Parse(genericDefinition.Type, definition);
                        // genericDefinition.MidiEncoderMode = device.EncoderMode;
                        genericDefinition.MidiEncoderMode =
                            //this.MidiBinding.RawDefinition.MidiEncoderMode;
                            this.Command.RawSettings.EncoderMode2;

                        //genericDefinition.MidiEncoderMode = this.Command.Control.EncoderMode;

                        definition = genericDefinition.RawDefinition;  // pestrela: this was unchanged
                    }

                    definitions.Add(definition);
                }
                else
                {
                    // definition already exist. Update encoder
                    //matchingDefinitions.First().EncoderMode = this.MidiBinding.MidiEncoderMode;
                }

                // add midi binding to device
                bindings.Add(new Format.MidiNoteBinding(Id, midi.Note));
            }

            // set midi binding to mapping
            bool changed = (MidiBinding != null && !MidiBinding.Equals(midi)) || (midi != null && !midi.Equals(MidiBinding));

            if (changed)
            {
                MidiBinding = midi;
            }

            return(changed);
        }
        private List <Setting> getSettings()
        {
            _propertyDict = new Dictionary <Setting, System.Reflection.PropertyInfo>();

            string[] ignored = { "Type", "AllowedInteractionModes" };

            var detailsSettings = new List <Setting>();

            Type t     = _command.Control.GetType();
            var  props = t.GetProperties().Where(p => !ignored.Contains(p.Name));

            int     i = 0;
            Setting s = null;
            string  name;

            foreach (var p in props)
            {
                Type targetType = p.PropertyType;
                name = p.Name;

                switch (name)
                {
                case "Invert":
                case "Blend":
                    s = new BoolSetting(i++, name + ":");
                    break;

                case "SoftTakeOver":
                    s = new BoolSetting(i++, "Soft Takeover:");
                    break;

                case "AutoRepeat":
                    s = new BoolSetting(i++, "Auto Repeat:");
                    break;

                case "RotaryAcceleration":
                    s = new IntSetting(i++, "Rotary Acceleration:", 0, 100);
                    break;

                case "RotarySensitivity":
                    s = new IntSetting(i++, "Rotary Sensitivity:", 0, 300);
                    break;

                case "Mode":
                case "EncoderMode":
                    AGenericMidiDefinition midiBinding = (this._mappings.First().MidiBinding as AGenericMidiDefinition);
                    if (midiBinding != null)
                    {
                        MidiEncoderMode actual_encoder_mode = midiBinding.MidiEncoderMode;
                        _command.set_EncoderMode(actual_encoder_mode);
                    }
                    s = new EnumSetting <MidiEncoderMode>(i++, name + ":");
                    break;

                case "MidiRangeMin":
                    // pestrela 2020/04/11: there is no source code to "IntSetting", comes from "SettingControlLibrary.dll" that is pre-compiled.
                    //s = new IntSetting(i++, "MIDI Range Min:", 0, 127);

                    // pestrela: replaced this with a realy large enum.
                    s = new EnumSetting <MidiOutRange>(i++, "MIDI Range Min:");
                    break;

                case "MidiRangeMax":
                    // s = new IntSetting(i++, "MIDI Range Max:", 0, 127);
                    s = new EnumSetting <MidiOutRange>(i++, "MIDI Range Max:");
                    break;

                case "Resolution":
                    s = new EnumSetting <MappingResolution>(i++, name + ":");
                    break;

                default:
                    s = null;
                    break;
                }

                if (s != null)
                {
                    object rawValue = p.GetValue(_command.Control, null);

                    s.TryParse(rawValue.ToString());
                    s.AcceptChanges();
                    detailsSettings.Add(s);
                    _propertyDict.Add(s, p);
                    s.PropertyChanged += s_PropertyChanged;
                }
                else
                {
                    // Datatype not supported
                }
            }
            return(detailsSettings);
        }
        // This is when we select a new Channel or Note
        private void updateBinding(AMidiDefinition definition = null)
        {
            //if (_channel == "None")
            //    _channel = null;  // this is to simplify the processing a lot

            string          expression;
            AMidiDefinition tmpDefinition;
            bool            needs_cleanup = false;

            foreach (var mapping in _mappings)
            {
                expression    = null;
                tmpDefinition = definition;

                if (IsGenericMidi)
                {
                    // special HACK follows
                    if (!String.IsNullOrEmpty(_note) && _note[0] == '_')
                    {
                        // remove the initial '_', but keep it for further processing
                        // the expression is already complete - doesn't need manipulations
                        expression = _note.Substring(1);
                    }
                    else if (!String.IsNullOrEmpty(_channel))
                    {
                        if (!String.IsNullOrEmpty(_note))
                        {
                            expression = _channel + "." + _note.Replace("+", "+" + _channel + ".");
                        }
                        else if (mapping.MidiBinding != null)
                        {
                            expression = Regex.Replace(mapping.MidiBinding.Note, @"Ch\d+", _channel);
                        }
                    }
                    else if (!String.IsNullOrEmpty(_note))
                    {
                        if (mapping.MidiBinding != null)
                        {
                            var channel = mapping.MidiBinding.Note.Substring(0, 4);
                            expression = channel + "." + _note.Replace("+", "+" + channel + ".");
                        }
                    }

                    if (expression != null)
                    {
                        tmpDefinition = AGenericMidiDefinition.Parse(mapping.Command.MappingType, expression);
                    }
                }
                else
                {
                    if (tmpDefinition != null && mapping.Command.MappingType != tmpDefinition.Type)
                    {
                        tmpDefinition = _proprietaryDefinitions.First(p => p.Type == mapping.Command.MappingType && p.Note == tmpDefinition.Note);
                    }
                }

                mapping.SetBinding(tmpDefinition);
            }

            if (needs_cleanup)
            {
                _note = _note.Substring(6);   //this is just to display correctly in the textbox
            }
            ;

            analyzeSelection();
            updateMenus();
        }
 public ComboMidiDefinition(AGenericMidiDefinition def1, AGenericMidiDefinition def2)
     : base(def1.Type, def1.Channel, def1.Note + "+" + def2.Note, def1.MinValue, def1.MaxValue)
 {
     _midiDefinition1 = def1;
     _midiDefinition2 = def2;
 }