public static WriteMultiValueMessage FromModule(Module module)
        {
            var props = module.GetParameterProperties(false)
                        .ToDictionary(
                p => p.GetNrpnAddress(module),
                p => p);

            if (!props.Any())
            {
                throw new Exception(""); // todo: implement specific exception
            }
            WriteMultiValueMessage msg = null;

            foreach (var kvp in props)
            {
                var prop    = kvp.Value;
                var address = kvp.Key;
                if (msg == null)
                {
                    msg = new WriteMultiValueMessage(address.Page, address.Address);
                }
                else
                {
                    msg.Values.Add((int)ConverterCache.Instance.ConvertToMidi(prop, prop.GetValue(module)));
                }
            }

            return(msg);
        }
        /// <summary>
        /// Creates a WriteMultiValueMessage from an inboud SysEx message byte[]
        /// </summary>
        /// <param name="dataBlock">The entire data block received from the MIDI SysEx message</param>
        /// <returns></returns>
        public static WriteMultiValueMessage FromInboundData(byte[] dataBlock)
        {
            var page    = dataBlock[8];
            var address = dataBlock[9];
            var values  = dataBlock.Skip(10).ToArray();

            var msg = new WriteMultiValueMessage(page, address);

            while (values.Length >= 2)
            {
                var ba = new[] { values[0], values[1] };
                msg.Values.Add(ba.ToInt());
                values = values.Skip(2).ToArray();
            }

            return(msg);
        }
Beispiel #3
0
        public static SysExMessage Parse(byte[] data)
        {
            var functioncode = data[6];

            if (functioncode == KemperFunctions.WriteSingleParameter)
            {
                return(WriteValueMessage.FromInboundData(data));
            }

            if (functioncode == KemperFunctions.WriteStringParameter)
            {
                return(WriteStringValueMessage.FromInboundData(data));
            }

            if (functioncode == KemperFunctions.WriteMultiParameter)
            {
                return(WriteMultiValueMessage.FromInboundData(data));
            }

            throw new NotSupportedException($"Function code {functioncode:X} is not supported.");
        }