Exemplo n.º 1
0
        public SFZRegion(SFZGroup Group)
        {
            SetDefault();
            this.Group = Group;

            /*lokey = Group.lokey;
            hikey = Group.hikey;
            lovel = Group.lovel;
            hivel = Group.hivel;
            lorand = Group.lorand;
            hirand = Group.hirand;*/

            seq_length = Group.seq_length;
            seq_position = Group.seq_position;
        }
Exemplo n.º 2
0
        private void SetDefault()
        {
            Group = null;

            ID = -1;

            lokey = 0;
            hikey = 127;
            lovel = 0;
            hivel = 127;
            lorand = 0.0f;
            hirand = 1.0f;

            seq_length = 1;
            seq_position = 1;
            //seq_counter = 1;

            for (int i = 0; i < 127; i++)
            {
                locc[i] = 0;
                hicc[i] = 127;
            }

            cc = true;
        }
Exemplo n.º 3
0
        public int Load(string FilePath)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(FilePath));

            int LastOpcode = 0;//0=Null,1=Group,2=Region
            SFZGroup Group = null;
            SFZRegion Region = null;

            string[] Lines = File.ReadAllLines(FilePath);
            foreach (string line in Lines)
            {
                string[] Opcodes = line.Split(new string[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < Opcodes.Length; i++)
                {
                    if (Opcodes[i].Trim().StartsWith("//")) break;
                    else if (Opcodes[i].Trim() == "<group>")
                    {
                        if (Region != null)
                        {
                            if (Region.GenerateStream() == 0)
                            {
                                if (Group != null) Group.Regions.Add(Region);
                                else Regions.Add(Region);
                            }

                            Region = null;
                        }
                        if (Group != null) Groups.Add(Group);
                        Group = new SFZGroup();
                        LastOpcode = 1;
                    }
                    else if (Opcodes[i].Trim() == "<region>")
                    {
                        if (Region != null)
                        {
                            if (Region.GenerateStream() == 0)
                            {
                                if (Group != null) Group.Regions.Add(Region);
                                else Regions.Add(Region);
                            }
                        }
                        Region = new SFZRegion(Group);
                        LastOpcode = 2;
                    }
                    else
                    {
                        string tmp = Opcodes[i];
                        while (Opcodes.Length > (i + 1) && !Opcodes[i + 1].Contains("=")) tmp += (" " + Opcodes[++i]);
                        Opcodes[i] = tmp;

                        if (Opcodes[i].Trim().StartsWith("sample="))
                        {
                            if (LastOpcode == 1) Group.SamplePath = GetOpcodeValue(Opcodes[i]);
                            else if (LastOpcode == 2) Region.SamplePath = GetOpcodeValue(Opcodes[i]);
                        }
                        else if (Opcodes[i].Trim().StartsWith("key="))
                        {
                            byte key = 0;
                            if (!Byte.TryParse(GetOpcodeValue(Opcodes[i]), out key))
                                key = (byte)Note.getNoteFromString(GetOpcodeValue(Opcodes[i]));

                            /*try
                        {
                            key = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                        }
                        catch (Exception)
                        {
                            key = (byte)Note.getNoteFromString(GetOpcodeValue(Opcodes[i]));
                        }*/

                            if (LastOpcode == 1) { Group.lokey = Group.hikey = key; }
                            else if (LastOpcode == 2) { Region.lokey = Region.hikey = key; }

                        }
                        else if (Opcodes[i].Trim().StartsWith("lokey="))
                        {
                            byte lokey = 0;
                            if (!Byte.TryParse(GetOpcodeValue(Opcodes[i]), out lokey))
                                lokey = (byte)Note.getNoteFromString(GetOpcodeValue(Opcodes[i]));

                            /*try
                        {
                            lokey = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                        }
                        catch (Exception)
                        {
                            lokey = (byte)Note.getNoteFromString(GetOpcodeValue(Opcodes[i]));
                        }*/
                            if (LastOpcode == 1) { Group.lokey = lokey; }
                            else if (LastOpcode == 2) { Region.lokey = lokey; }

                        }
                        else if (Opcodes[i].Trim().StartsWith("hikey="))
                        {
                            byte hikey = 0;
                            if (!Byte.TryParse(GetOpcodeValue(Opcodes[i]), out hikey))
                                hikey = (byte)Note.getNoteFromString(GetOpcodeValue(Opcodes[i]));

                            /*try
                            {
                                hikey = Byte.TryParse(Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            }
                            catch (Exception)
                            {
                                hikey = (byte)Note.getNoteFromString(GetOpcodeValue(Opcodes[i]));
                            }*/
                            if (LastOpcode == 1) { Group.hikey = hikey; }
                            else if (LastOpcode == 2) { Region.hikey = hikey; }

                        }
                        else if (Opcodes[i].Trim().StartsWith("lovel="))
                        {
                            byte lovel = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            if (LastOpcode == 1) { Group.lovel = lovel; }
                            else if (LastOpcode == 2) { Region.lovel = lovel; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("hivel="))
                        {
                            byte hivel = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            if (LastOpcode == 1) { Group.hivel = hivel; }
                            else if (LastOpcode == 2) { Region.hivel = hivel; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("lorand="))
                        {
                            float lorand = (float)Convert.ToDouble(GetOpcodeValue(Opcodes[i]), System.Globalization.CultureInfo.InvariantCulture);
                            if (LastOpcode == 1) { Group.lorand = lorand; }
                            else if (LastOpcode == 2) { Region.lorand = lorand; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("hirand="))
                        {
                            float hirand = (float)Convert.ToDouble(GetOpcodeValue(Opcodes[i]), System.Globalization.CultureInfo.InvariantCulture);
                            if (LastOpcode == 1) { Group.hirand = hirand; }
                            else if (LastOpcode == 2) { Region.hirand = hirand; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("seq_length="))
                        {
                            byte seq_length = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            if (LastOpcode == 1) { Group.seq_length = seq_length; }
                            else if (LastOpcode == 2) { Region.seq_length = seq_length; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("seq_position="))
                        {
                            byte seq_position = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            if (LastOpcode == 1) { Group.seq_position = seq_position; }
                            else if (LastOpcode == 2) { Region.seq_position = seq_position; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("locc"))
                        {
                            byte locc = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            if (LastOpcode == 1) { Group.locc[Convert.ToByte(GetOpcodeCC(Opcodes[i]))] = locc; }
                            else if (LastOpcode == 2) { Region.locc[Convert.ToByte(GetOpcodeCC(Opcodes[i]))] = locc; }
                        }
                        else if (Opcodes[i].Trim().StartsWith("hicc"))
                        {
                            byte hicc = Convert.ToByte(GetOpcodeValue(Opcodes[i]));
                            if (LastOpcode == 1) { Group.hicc[Convert.ToByte(GetOpcodeCC(Opcodes[i]))] = hicc; }
                            else if (LastOpcode == 2) { Region.hicc[Convert.ToByte(GetOpcodeCC(Opcodes[i]))] = hicc; }
                        }
                        //else Console.WriteLine(Opcodes[i].Trim());
                    }
                }
            }
            if (Region != null)
            {
                if (Region.GenerateStream() == 0)
                {
                    if (Group != null) { Group.Regions.Add(Region); Groups.Add(Group); }
                    else Regions.Add(Region);

                }
            }

            return (0);
        }