Exemplo n.º 1
0
        public SinglePatchGenerator(SinglePatchDescriptor descriptor)
        {
            this.harmonicLevelTemplates    = new Dictionary <string, HarmonicLevels>();
            this.harmonicEnvelopeTemplates = new Dictionary <string, HarmonicEnvelope>();
            this.formantFilterTemplates    = new Dictionary <string, List <int> >();

            this.Descriptor = descriptor;

            this.templates = JsonConvert.DeserializeObject <Templates>(File.ReadAllText(@"templates.json"));
            Console.WriteLine($"Templates: {this.templates.HarmonicLevels.Count} harmonic level templates, {this.templates.HarmonicEnvelopes.Count} harmonic envelopes, {this.templates.FormantFilters.Count} formant filters");

            foreach (HarmonicLevelTemplate hlt in this.templates.HarmonicLevels)
            {
                this.harmonicLevelTemplates.Add(hlt.Name, hlt.Levels);
            }

            foreach (HarmonicEnvelopeTemplate het in this.templates.HarmonicEnvelopes)
            {
                this.harmonicEnvelopeTemplates.Add(het.Name, het.Envelope);
            }

            foreach (FormantFilterTemplate fft in this.templates.FormantFilters)
            {
                this.formantFilterTemplates.Add(fft.Name, fft.Levels);
            }
        }
Exemplo n.º 2
0
        public static int RunCreateAndReturnExitCode(CreateOptions opts)
        {
            var header = new SystemExclusiveHeader(0x00);

            header.Function   = (byte)SystemExclusiveFunction.OneBlockDump;
            header.Group      = 0x00;
            header.MachineID  = 0x0A;
            header.Substatus1 = 0x00;  // single

            // Get the right bank. Since it is a required parameter, I suppose we can trust that it exists.
            string bankName = opts.BankName.ToLower();
            char   ch       = bankName[0];

            switch (ch)
            {
            case 'a':
                header.Substatus2 = 0x00;
                break;

            case 'd':
                header.Substatus2 = 0x02;
                break;

            case 'e':
                header.Substatus2 = 0x03;
                break;

            case 'f':
                header.Substatus2 = 0x04;
                break;

            default:
                Console.WriteLine(string.Format("Unknown bank: '{0}'", opts.BankName));
                return(-1);
            }

            var allData = new List <byte>();

            // SysEx initiator and basic header data
            allData.Add(SystemExclusiveHeader.Initiator);
            allData.AddRange(header.ToData());

            // Additional header data as required
            var patchNumber = opts.PatchNumber - 1;

            if (patchNumber < 0 || patchNumber > 127)
            {
                Console.WriteLine("Patch number must be 1...128");
                return(-1);
            }
            allData.Add((byte)patchNumber);

            SinglePatchGenerator  generator;
            SinglePatchDescriptor descriptor;

            if (opts.PatchType.Equals("single"))
            {
                if (!string.IsNullOrEmpty(opts.Descriptor))  // we have a JSON descriptor file, parse it
                {
                    var jsonText = File.ReadAllText(opts.Descriptor);
                    descriptor = JsonConvert.DeserializeObject <SinglePatchDescriptor>(jsonText);
                    generator  = new SinglePatchGenerator(descriptor);
                }
                else
                {
                    descriptor = new SinglePatchDescriptor();
                    generator  = new SinglePatchGenerator(descriptor);
                }

                SinglePatch single     = generator.Generate();
                byte[]      singleData = single.ToData();
                Console.Error.WriteLine(string.Format("Generated single data size: {0} bytes", singleData.Length));
                Console.Error.WriteLine(single.ToString());
                allData.AddRange(singleData);

                allData.Add(SystemExclusiveHeader.Terminator);

                File.WriteAllBytes(opts.OutputFileName, allData.ToArray());
            }
            else if (opts.PatchType.Equals("multi"))
            {
                Console.WriteLine("Don't know how to make a multi patch yet");
                return(1);
            }

            return(0);
        }