示例#1
0
        public InstPack.Pack ToIns()
        {
            var now      = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
            var instFile = new InstPack.Pack();

            for (var idx = 0; idx < mPdta.SampleList.Count - 1; idx++)
            {
                var smpl = mPdta.SampleList[idx];
                var wi   = new Wave();
                wi.Header.SampleRate = smpl.sampleRate;
                wi.Header.UnityNote  = smpl.originalKey;

                if (1 == (byte)(smpl.type & 1))
                {
                    wi.Header.LoopBegin  = smpl.loopstart - smpl.start;
                    wi.Header.LoopLength = smpl.loopend - smpl.loopstart;
                    wi.Header.LoopEnable = 1;
                }
                else
                {
                    wi.Header.LoopBegin  = smpl.start;
                    wi.Header.LoopLength = smpl.end - smpl.start;
                    wi.Header.LoopEnable = 0;
                }

                wi.Header.Gain  = 1.0;
                wi.Header.Pitch = 1.0;

                var wavePos = (int)(smpl.start * 2);
                var waveLen = (int)(smpl.end - smpl.start + 1) * 2;
                var wavePtr = Marshal.AllocHGlobal(waveLen);
                wi.Data = new short[waveLen / 2];
                Marshal.Copy(mSdta.Data, wavePos, wavePtr, waveLen);
                Marshal.Copy(wavePtr, wi.Data, 0, waveLen / 2);
                Marshal.FreeHGlobal(wavePtr);

                wi.Info.Name         = Encoding.ASCII.GetString(smpl.name).Replace("\0", "");
                wi.Info.CreationDate = now;
                wi.Info.SourceForm   = Path.GetFileName(mPath);

                instFile.Wave.Add(wi);
            }

            foreach (var sf2Inst in mPdta.InstList)
            {
                var inst = new InstPack.Inst();

                inst.Info.Name         = sf2Inst.Name.Replace("\0", "");
                inst.Info.CreationDate = now;
                inst.Info.SourceForm   = Path.GetFileName(mPath);

                foreach (var art in sf2Inst.GlobalArt)
                {
                    var globalArt = new ART {
                        Value = art.Value
                    };
                    switch (art.Key)
                    {
                    case E_OPER.INITIAL_ATTENUATION:
                        globalArt.Type = ART_TYPE.GAIN;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.PAN:
                        globalArt.Type = ART_TYPE.PAN;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.COARSE_TUNE:
                        globalArt.Type = ART_TYPE.COASE_TUNE;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.FINETUNE:
                        globalArt.Type = ART_TYPE.FINE_TUNE;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.OVERRIDING_ROOTKEY:
                        globalArt.Type = ART_TYPE.UNITY_KEY;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.ENV_VOL_ATTACK:
                        globalArt.Type = ART_TYPE.EG_AMP_ATTACK;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.ENV_VOL_HOLD:
                        globalArt.Type = ART_TYPE.EG_AMP_HOLD;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.ENV_VOL_DECAY:
                        globalArt.Type = ART_TYPE.EG_AMP_DECAY;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.ENV_VOL_SUSTAIN:
                        globalArt.Type = ART_TYPE.EG_AMP_SUSTAIN;
                        inst.Art.Add(globalArt);
                        break;

                    case E_OPER.ENV_VOL_RELEASE:
                        globalArt.Type = ART_TYPE.EG_AMP_RELEASE;
                        inst.Art.Add(globalArt);
                        break;
                    }
                }

                foreach (var sf2InstRng in sf2Inst.Range)
                {
                    var rgn = new Region();
                    rgn.Header.KeyLo = sf2InstRng.keyLo;
                    rgn.Header.KeyHi = sf2InstRng.keyHi;
                    rgn.Header.VelLo = sf2InstRng.velLo;
                    rgn.Header.VelHi = sf2InstRng.velHi;

                    rgn.Art.Add(new ART {
                        Type  = ART_TYPE.WAVE_INDEX,
                        Value = sf2InstRng.sampleId
                    });

                    foreach (var art in sf2InstRng.Art)
                    {
                        var layerArt = new ART {
                            Value = art.Value
                        };
                        switch (art.Key)
                        {
                        case E_OPER.INITIAL_ATTENUATION:
                            layerArt.Type = ART_TYPE.GAIN;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.PAN:
                            layerArt.Type = ART_TYPE.PAN;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.COARSE_TUNE:
                            layerArt.Type = ART_TYPE.COASE_TUNE;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.FINETUNE:
                            layerArt.Type = ART_TYPE.FINE_TUNE;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.OVERRIDING_ROOTKEY:
                            layerArt.Type = ART_TYPE.UNITY_KEY;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.ENV_VOL_ATTACK:
                            layerArt.Type = ART_TYPE.EG_AMP_ATTACK;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.ENV_VOL_HOLD:
                            layerArt.Type = ART_TYPE.EG_AMP_HOLD;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.ENV_VOL_DECAY:
                            layerArt.Type = ART_TYPE.EG_AMP_DECAY;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.ENV_VOL_SUSTAIN:
                            layerArt.Type = ART_TYPE.EG_AMP_SUSTAIN;
                            rgn.Art.Add(layerArt);
                            break;

                        case E_OPER.ENV_VOL_RELEASE:
                            layerArt.Type = ART_TYPE.EG_AMP_RELEASE;
                            rgn.Art.Add(layerArt);
                            break;
                        }
                    }

                    inst.Region.Add(rgn);
                }

                instFile.Inst.Add(inst);
            }

            foreach (var sf2Pres in mPdta.PresetList)
            {
                var preset = new InstPack.Preset();
                preset.Header.IsDrum  = 0 < sf2Pres.Key.bankFlg;
                preset.Header.BankMSB = sf2Pres.Key.bankMSB;
                preset.Header.BankLSB = sf2Pres.Key.bankLSB;
                preset.Header.ProgNum = sf2Pres.Key.progNum;

                preset.Info.Name         = sf2Pres.Value.Name.Replace("\0", "");
                preset.Info.CreationDate = now;
                preset.Info.SourceForm   = Path.GetFileName(mPath);

                foreach (var art in sf2Pres.Value.GlobalArt)
                {
                    var globalArt = new ART {
                        Value = art.Value
                    };
                    switch (art.Key)
                    {
                    case E_OPER.INITIAL_ATTENUATION:
                        globalArt.Type = ART_TYPE.GAIN;
                        preset.Art.Add(globalArt);
                        break;

                    case E_OPER.PAN:
                        globalArt.Type = ART_TYPE.PAN;
                        preset.Art.Add(globalArt);
                        break;

                    case E_OPER.COARSE_TUNE:
                        globalArt.Type = ART_TYPE.COASE_TUNE;
                        preset.Art.Add(globalArt);
                        break;

                    case E_OPER.FINETUNE:
                        globalArt.Type = ART_TYPE.FINE_TUNE;
                        preset.Art.Add(globalArt);
                        break;

                    case E_OPER.INSTRUMENT:
                        break;
                    }
                }

                foreach (var sf2PresRng in sf2Pres.Value.Range)
                {
                    var layer = new Layer();
                    layer.Header.KeyLo = sf2PresRng.keyLo;
                    layer.Header.KeyHi = sf2PresRng.keyHi;
                    layer.Header.VelLo = sf2PresRng.velLo;
                    layer.Header.VelHi = sf2PresRng.velHi;

                    foreach (var art in sf2PresRng.Art)
                    {
                        var layerArt = new ART {
                            Value = art.Value
                        };
                        switch (art.Key)
                        {
                        case E_OPER.INITIAL_ATTENUATION:
                            layerArt.Type = ART_TYPE.GAIN;
                            layer.Art.Add(layerArt);
                            break;

                        case E_OPER.PAN:
                            layerArt.Type = ART_TYPE.PAN;
                            layer.Art.Add(layerArt);
                            break;

                        case E_OPER.COARSE_TUNE:
                            layerArt.Type = ART_TYPE.COASE_TUNE;
                            layer.Art.Add(layerArt);
                            break;

                        case E_OPER.FINETUNE:
                            layerArt.Type = ART_TYPE.FINE_TUNE;
                            layer.Art.Add(layerArt);
                            break;

                        case E_OPER.INSTRUMENT:
                            layer.InstIndex = (int)art.Value;
                            break;
                        }
                    }
                    preset.Layer.Add(layer);
                }
                instFile.Preset.Add(preset.Header, preset);
            }

            return(instFile);
        }
示例#2
0
 public void Add(Inst inst)
 {
     List.Add(inst);
 }