示例#1
0
        private void SetInstList()
        {
            for (int i = 0; i < mINST.Count; i++)
            {
                var inst = mINST[i];
                int bagCount;
                if (i < mINST.Count - 1)
                {
                    bagCount = mINST[i + 1].bagIndex - inst.bagIndex;
                }
                else
                {
                    bagCount = mIBAG.Count - inst.bagIndex;
                }

                var global = new INSTRUMENT();
                global.Init();
                var list = new List <INSTRUMENT>();
                for (int ib = 0, bagIdx = inst.bagIndex; ib < bagCount; ib++, bagIdx++)
                {
                    var bag = mIBAG[bagIdx];
                    int genCount;
                    if (bagIdx < mIBAG.Count - 1)
                    {
                        genCount = mIBAG[bagIdx + 1].genIndex - bag.genIndex;
                    }
                    else
                    {
                        genCount = mIGEN.Count - bag.genIndex;
                    }
                    var v = GetInstGen(global, bag.genIndex, genCount);
                    if (v.sampleId < 0)
                    {
                        global = v;
                    }
                    else
                    {
                        list.Add(v);
                    }
                }

                var name = Encoding.ASCII.GetString(inst.name);
                if (0 <= name.IndexOf("\0"))
                {
                    name = name.Substring(0, name.IndexOf("\0"));
                }
                InstList.Add(new Tuple <string, INSTRUMENT[]>(name.TrimEnd(), list.ToArray()));
            }
            mINST.Clear();
            mIBAG.Clear();
            mIGEN.Clear();
            mIMOD.Clear();
        }
示例#2
0
        private INSTRUMENT GetInstGen(INSTRUMENT global, int begin, int count)
        {
            var v = new INSTRUMENT();

            v.Init();

            for (int i = 0, genIdx = begin; i < count; i++, genIdx++)
            {
                var g = mIGEN[genIdx];

                switch (g.genOper)
                {
                case E_OPER.KEY_RANGE:
                    v.keyLo = (byte)(g.genAmount & 0x7F);
                    v.keyHi = (byte)((g.genAmount >> 8) & 0x7F);
                    break;

                case E_OPER.VEL_RANGE:
                    v.velLo = (byte)(g.genAmount & 0x7F);
                    v.velHi = (byte)((g.genAmount >> 8) & 0x7F);
                    break;

                case E_OPER.INITIAL_ATTENUATION:
                    v.gain = Math.Pow(10.0, -g.genAmount / 200.0);
                    break;

                case E_OPER.PAN:
                    v.pan = g.genAmount / 500.0;
                    break;

                case E_OPER.COARSE_TUNE:
                    v.coarseTune = Math.Pow(2.0, g.genAmount / 120.0);
                    break;

                case E_OPER.FINETUNE:
                    v.fineTune = Math.Pow(2.0, g.genAmount / 1200.0);
                    break;

                case E_OPER.OVERRIDING_ROOTKEY:
                    v.rootKey = g.genAmount;
                    break;

                case E_OPER.SAMPLE_MODES:
                    v.loopEnable = 0 < (g.genAmount & 1);
                    break;

                case E_OPER.SAMPLE_ID:
                    v.sampleId = g.genAmount;
                    break;

                case E_OPER.OFFSET_ADDRS__START_LSB:
                    v.waveBegin |= (ushort)g.genAmount;
                    break;

                case E_OPER.OFFSET_ADDRS__START_MSB:
                    v.waveBegin |= (uint)((ushort)g.genAmount << 16);
                    break;

                case E_OPER.OFFSET_ADDRS__END_LSB:
                    v.waveEnd |= (ushort)g.genAmount;
                    break;

                case E_OPER.OFFSET_ADDRS__END_MSB:
                    v.waveEnd |= (uint)((ushort)g.genAmount << 16);
                    break;

                case E_OPER.ENV_VOL__ATTACK:
                    v.env.deltaA = Sender.AttackSpeed * Sender.DeltaTime
                                   / Math.Pow(2.0, g.genAmount / 1200.0);
                    break;

                case E_OPER.ENV_VOL__HOLD:
                    v.env.hold = Math.Pow(2.0, g.genAmount / 1200.0);
                    break;

                case E_OPER.ENV_VOL__DECAY:
                    v.env.deltaD = Sender.AttackSpeed * Sender.DeltaTime
                                   / Math.Pow(2.0, g.genAmount / 1200.0);
                    break;

                case E_OPER.ENV_VOL__SUSTAIN:
                    v.env.levelS = Math.Pow(10.0, -(ushort)g.genAmount / 200.0);
                    break;

                case E_OPER.ENV_VOL__RELEASE:
                    v.env.deltaR = Sender.AttackSpeed * Sender.DeltaTime
                                   / Math.Pow(2.0, g.genAmount / 1200.0);
                    break;

                default:
                    break;
                }
            }

            /**** set global value ****/
            if (0 <= v.sampleId)
            {
                if (v.rootKey < 0)
                {
                    v.rootKey = global.rootKey;
                }
                if (v.coarseTune == 0.0)
                {
                    v.coarseTune = global.coarseTune;
                }
                if (v.fineTune == 0.0)
                {
                    v.fineTune = global.fineTune;
                }
                if (v.env.deltaA <= 0.0)
                {
                    v.env.deltaA = global.env.deltaA;
                }
                if (v.env.deltaD <= 0.0)
                {
                    v.env.deltaD = global.env.deltaD;
                }
                if (v.env.deltaR <= 0.0)
                {
                    v.env.deltaR = global.env.deltaR;
                }
                if (v.env.hold < 0.0)
                {
                    v.env.hold = global.env.hold;
                }
                if (v.env.levelS < 0.0)
                {
                    v.env.levelS = global.env.levelS;
                }
            }

            /**** set default value ****/
            {
                if (v.coarseTune == 0.0)
                {
                    v.coarseTune = 1.0;
                }
                if (v.fineTune == 0.0)
                {
                    v.fineTune = 1.0;
                }
                if (v.env.deltaA <= 0.0)
                {
                    v.env.deltaA = 1000 * Sender.AttackSpeed * Sender.DeltaTime;
                }
                if (v.env.deltaD <= 0.0)
                {
                    v.env.deltaD = 1000 * Sender.AttackSpeed * Sender.DeltaTime;
                }
                if (v.env.deltaR <= 0.0)
                {
                    v.env.deltaR = 1000 * Sender.AttackSpeed * Sender.DeltaTime;
                }
                if (v.env.hold < 0.0)
                {
                    v.env.hold = 0.0;
                }
                if (v.env.levelS < 0.0)
                {
                    v.env.levelS = 1.0;
                }
                v.env.hold += Sender.AttackSpeed * Sender.DeltaTime / v.env.deltaA;
            }

            return(v);
        }