Example #1
0
        private static void ProcessMessage(byte[] message)
        {
            SystemExclusiveHeader header = new SystemExclusiveHeader(message);

            Console.WriteLine(header);

            Dictionary <SystemExclusiveFunction, string> functionNames = new Dictionary <SystemExclusiveFunction, string>()
            {
                { SystemExclusiveFunction.AllPatchDataDump, "All Patch Data Dump" },
                { SystemExclusiveFunction.AllPatchDumpRequest, "All Patch Data Dump Request" },
                { SystemExclusiveFunction.BlockPatchDataDump, "Block Patch Data Dump" },
                { SystemExclusiveFunction.BlockPatchDumpRequest, "Block Patch Data Dump Request" },
                { SystemExclusiveFunction.EditBufferDump, "Edit Buffer Dump" },
                { SystemExclusiveFunction.OnePatchDataDump, "One Patch Data Dump" },
                { SystemExclusiveFunction.OnePatchDumpRequest, "One Patch Data Dump Request" },
                { SystemExclusiveFunction.ParameterSend, "Parameter Send" },
                { SystemExclusiveFunction.ProgramChange, "Program Change" },
                { SystemExclusiveFunction.WriteComplete, "Write Complete" },
                { SystemExclusiveFunction.WriteError, "Write Error" },
                { SystemExclusiveFunction.WriteErrorNoCard, "Write Error (No Card)" },
                { SystemExclusiveFunction.WriteErrorProtect, "Write Error (Protect)" }
            };

            SystemExclusiveFunction function = (SystemExclusiveFunction)header.Function;
            string functionName = "";

            if (functionNames.TryGetValue(function, out functionName))
            {
                Console.WriteLine($"Function = {functionName}");
            }
            else
            {
                Console.WriteLine($"Unknown function: {function}");
            }
        }
Example #2
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                System.Console.WriteLine("Usage: K5KTool cmd filename.syx");
                return(1);
            }

            string command   = args[0];
            string fileName  = args[1];
            string patchName = "";

            if (args.Length > 2)
            {
                patchName = args[2];
            }

            byte[] fileData = File.ReadAllBytes(fileName);
            System.Console.WriteLine($"SysEx file: '{fileName}' ({fileData.Length} bytes)");

            List <byte[]> messages = Util.SplitBytesByDelimiter(fileData, Constants.SystemExclusiveTerminator);

            System.Console.WriteLine($"Got {messages.Count} messages");

            foreach (byte[] message in messages)
            {
                SystemExclusiveHeader header = new SystemExclusiveHeader(message);
                //System.Console.WriteLine(Util.HexDump(header.Data));
                System.Console.WriteLine(header.ToString());
                int headerLength = header.Data.Length;

                // Examine the header to see what kind of message this is:
                SystemExclusiveFunction function = (SystemExclusiveFunction)header.Function;
                if (function == SystemExclusiveFunction.AllPatchDataDump)
                {
                    // sub2: 0=I or E, 20H=i or e singles
                    if (header.Substatus2 == 0x00 || header.Substatus2 == 0x20)
                    {
                        int offset = headerLength;
                        for (int i = 0; i < NumSingles; i++)
                        {
                            byte[] singleData = new byte[SinglePatch.DataSize];
                            Buffer.BlockCopy(message, offset, singleData, 0, SinglePatch.DataSize);
                            System.Console.WriteLine("INGOING SINGLE DATA = \n" + Util.HexDump(singleData));
                            SinglePatch single = new SinglePatch(singleData);
                            System.Console.WriteLine(single.ToString());

                            byte[] sysExData = single.ToData();
                            System.Console.WriteLine("OUTCOMING SINGLE DATA = \n" + Util.HexDump(sysExData));

                            (bool result, int diffIndex) = Util.ByteArrayCompare(singleData, sysExData);
                            System.Console.WriteLine(String.Format("match = {0}, diff index = {1}", result ? "YES :-)" : "NO :-(", diffIndex));

                            offset += SinglePatch.DataSize;
                        }
                    }
                    else if (header.Substatus2 == 0x40)
                    {
                        System.Console.WriteLine("Multis not handled yet");
                        return(1);
                    }
                }
                else if (function == SystemExclusiveFunction.OnePatchDataDump)
                {
                    System.Console.WriteLine("One patch dumps not handled yet");
                    return(1);
                }
            }

            return(0);
        }