Beispiel #1
0
        public Pack ToPack()
        {
            var now  = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
            var pack = new Pack();

            foreach (var wave in WavePool.List.Values)
            {
                var waveInfo = new Wave();
                waveInfo.Header.SampleRate = wave.Format.SampleRate;
                if (0 < wave.Sampler.LoopCount)
                {
                    waveInfo.Header.LoopEnable = 1;
                    waveInfo.Header.LoopBegin  = wave.Loops[0].Start;
                    waveInfo.Header.LoopLength = wave.Loops[0].Length;
                }
                else
                {
                    waveInfo.Header.LoopEnable = 0;
                    waveInfo.Header.LoopBegin  = 0;
                    waveInfo.Header.LoopLength = (uint)(wave.Data.Length / wave.Format.BlockAlign);
                }
                waveInfo.Header.UnityNote = (byte)wave.Sampler.UnityNote;
                waveInfo.Header.Gain      = wave.Sampler.Gain;
                waveInfo.Header.Pitch     = Math.Pow(2.0, wave.Sampler.FineTune / 1200.0);

                var ptr = Marshal.AllocHGlobal(wave.Data.Length);
                Marshal.Copy(wave.Data, 0, ptr, wave.Data.Length);
                waveInfo.Data = new short[wave.Data.Length / 2];
                Marshal.Copy(ptr, waveInfo.Data, 0, waveInfo.Data.Length);
                Marshal.FreeHGlobal(ptr);

                waveInfo.Info.Name         = wave.Info.Name;
                waveInfo.Info.Category     = wave.Info.Category;
                waveInfo.Info.CreationDate = now;
                waveInfo.Info.SourceForm   = Path.GetFileName(mFilePath);

                pack.Wave.Add(waveInfo);
            }

            foreach (var dlsInst in Instruments.List)
            {
                var pres = new Preset();
                pres.Header.IsDrum  = 0 < (dlsInst.Key.BankFlg & 0x80);
                pres.Header.BankMSB = dlsInst.Key.BankMSB;
                pres.Header.BankLSB = dlsInst.Key.BankLSB;
                pres.Header.ProgNum = dlsInst.Key.ProgNum;

                var lyr = new Layer();
                lyr.Header.KeyLo = 0;
                lyr.Header.KeyHi = 127;
                lyr.Header.VelLo = 0;
                lyr.Header.VelHi = 127;
                lyr.InstIndex    = pack.Inst.Count;

                pres.Layer.Add(lyr);
                pres.Info.Name         = dlsInst.Value.Info.Name;
                pres.Info.Category     = dlsInst.Value.Info.Category;
                pres.Info.CreationDate = now;
                pres.Info.SourceForm   = Path.GetFileName(mFilePath);
                pack.Preset.Add(pres.Header, pres);

                var inst = new Inst();
                inst.Info.Name         = dlsInst.Value.Info.Name;
                inst.Info.Category     = dlsInst.Value.Info.Category;
                inst.Info.CreationDate = now;
                inst.Info.SourceForm   = Path.GetFileName(mFilePath);

                if (null != dlsInst.Value.Articulations && null != dlsInst.Value.Articulations.ART)
                {
                    foreach (var instArt in dlsInst.Value.Articulations.ART.List.Values)
                    {
                        if (instArt.Source != SRC_TYPE.NONE || instArt.Control != SRC_TYPE.NONE)
                        {
                            continue;
                        }

                        var art = new InstPack.ART {
                            Value = instArt.Value
                        };

                        switch (instArt.Destination)
                        {
                        case DST_TYPE.EG1_ATTACK_TIME:
                            art.Type = ART_TYPE.EG_AMP_ATTACK;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG1_HOLD_TIME:
                            art.Type = ART_TYPE.EG_AMP_HOLD;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG1_DECAY_TIME:
                            art.Type = ART_TYPE.EG_AMP_DECAY;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG1_SUSTAIN_LEVEL:
                            art.Type = ART_TYPE.EG_AMP_SUSTAIN;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG1_RELEASE_TIME:
                            art.Type = ART_TYPE.EG_AMP_RELEASE;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG2_ATTACK_TIME:
                            art.Type = ART_TYPE.EG_CUTOFF_ATTACK;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG2_HOLD_TIME:
                            art.Type = ART_TYPE.EG_CUTOFF_HOLD;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG2_DECAY_TIME:
                            art.Type = ART_TYPE.EG_CUTOFF_DECAY;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG2_SUSTAIN_LEVEL:
                            art.Type = ART_TYPE.EG_CUTOFF_SUSTAIN;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.EG2_RELEASE_TIME:
                            art.Type = ART_TYPE.EG_CUTOFF_RELEASE;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.GAIN:
                            art.Type = ART_TYPE.GAIN;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.PAN:
                            art.Type = ART_TYPE.PAN;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.PITCH:
                            art.Type = ART_TYPE.FINE_TUNE;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.FILTER_Q:
                            art.Type = ART_TYPE.LPF_RESONANCE;
                            inst.Art.Add(art);
                            break;

                        case DST_TYPE.FILTER_CUTOFF:
                            art.Type = ART_TYPE.LPF_CUTOFF;
                            inst.Art.Add(art);
                            break;
                        }
                    }
                }

                foreach (var dlsRegion in dlsInst.Value.Regions.List)
                {
                    var rgn = new Region();
                    rgn.Header.KeyLo = (byte)dlsRegion.Key.Key.Lo;
                    rgn.Header.KeyHi = (byte)dlsRegion.Key.Key.Hi;
                    rgn.Header.VelLo = (byte)dlsRegion.Key.Vel.Lo;
                    rgn.Header.VelHi = (byte)dlsRegion.Key.Vel.Hi;

                    rgn.Art.Add(new InstPack.ART {
                        Type  = ART_TYPE.WAVE_INDEX,
                        Value = dlsRegion.Value.WaveLink.TableIndex
                    });
                    rgn.Art.Add(new InstPack.ART {
                        Type  = ART_TYPE.UNITY_KEY,
                        Value = dlsRegion.Value.Sampler.UnityNote
                    });
                    rgn.Art.Add(new InstPack.ART {
                        Type  = ART_TYPE.FINE_TUNE,
                        Value = Math.Pow(2.0, dlsRegion.Value.Sampler.FineTune / 1200.0)
                    });
                    rgn.Art.Add(new InstPack.ART {
                        Type  = ART_TYPE.GAIN,
                        Value = dlsRegion.Value.Sampler.Gain
                    });

                    if (null != dlsRegion.Value.Articulations && null != dlsRegion.Value.Articulations.ART)
                    {
                        foreach (var regionArt in dlsRegion.Value.Articulations.ART.List.Values)
                        {
                            if (regionArt.Source != SRC_TYPE.NONE || regionArt.Control != SRC_TYPE.NONE)
                            {
                                continue;
                            }

                            var art = new InstPack.ART {
                                Value = regionArt.Value
                            };

                            switch (regionArt.Destination)
                            {
                            case DST_TYPE.EG1_ATTACK_TIME:
                                art.Type = ART_TYPE.EG_AMP_ATTACK;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG1_HOLD_TIME:
                                art.Type = ART_TYPE.EG_AMP_HOLD;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG1_DECAY_TIME:
                                art.Type = ART_TYPE.EG_AMP_DECAY;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG1_SUSTAIN_LEVEL:
                                art.Type = ART_TYPE.EG_AMP_SUSTAIN;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG1_RELEASE_TIME:
                                art.Type = ART_TYPE.EG_AMP_RELEASE;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG2_ATTACK_TIME:
                                art.Type = ART_TYPE.EG_CUTOFF_ATTACK;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG2_HOLD_TIME:
                                art.Type = ART_TYPE.EG_CUTOFF_HOLD;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG2_DECAY_TIME:
                                art.Type = ART_TYPE.EG_CUTOFF_DECAY;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG2_SUSTAIN_LEVEL:
                                art.Type = ART_TYPE.EG_CUTOFF_SUSTAIN;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.EG2_RELEASE_TIME:
                                art.Type = ART_TYPE.EG_CUTOFF_RELEASE;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.GAIN:
                                art.Type = ART_TYPE.GAIN;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.PAN:
                                art.Type = ART_TYPE.PAN;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.PITCH:
                                art.Type = ART_TYPE.FINE_TUNE;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.FILTER_Q:
                                art.Type = ART_TYPE.LPF_RESONANCE;
                                rgn.Art.Add(art);
                                break;

                            case DST_TYPE.FILTER_CUTOFF:
                                art.Type = ART_TYPE.LPF_CUTOFF;
                                rgn.Art.Add(art);
                                break;
                            }
                        }
                    }
                    inst.Region.Add(rgn);
                }
                pack.Inst.Add(inst);
            }

            return(pack);
        }
Beispiel #2
0
 public void Add(ART art)
 {
     List.Add(art);
 }