Beispiel #1
0
 public void Unload()
 {
     this.useLoop = false;
     this.Midi    = "";
     this.times   = -1;
     if (this.CAPathPerformance != null)
     {
         this.CAPathPerformance.StopAll();
     }
     this.CSegment1.ReleaseSegment();
     this.CSegment1.UnloadAllPerformances();
     this.CSegment1.Dispose();
     this.CLoader.Dispose();
     this.COutPort.ReleasePort();
     this.CSegment1 = (CSegment)null;
     this.CLoader   = (CDLSLoader)null;
     this.CSegment1 = new CSegment();
     this.CLoader   = new CDLSLoader();
     this.CLoader.Initialize();
     this.UseDLS = false;
 }
Beispiel #2
0
        public void Play(string pt, bool loop = true)
        {
            if (cdm == null)
            {
                cdm = new CDirectMusic();
                cdm.Initialize();
                loader = new CDLSLoader();
                loader.Initialize();
                loader.LoadSegment(pt, out segment);
                ccollection = new CCollection();
                string pathDLS = Path.Combine(Memory.FF8DIRdata, "Music/dmusic_backup/FF8.dls");
                if (!File.Exists(pathDLS))
                {
                    pathDLS = Path.Combine(Memory.FF8DIRdata, "Music/dmusic/FF8.dls");
                }

                loader.LoadDLS(pathDLS, out ccollection);
                uint dwInstrumentIndex = 0;
                while (ccollection.EnumInstrument(++dwInstrumentIndex, out INSTRUMENTINFO iInfo) == S_OK)
                {
                    Debug.WriteLine(iInfo.szInstName);
                }
                instruments = new CInstrument[dwInstrumentIndex];

                path = new CAPathPerformance();
                path.Initialize(cdm, null, null, DMUS_APATH.DYNAMIC_3D, 128);
                cport = new CPortPerformance();
                cport.Initialize(cdm, null, null);
                outport = new COutputPort();
                outport.Initialize(cdm);

                uint     dwPortCount = 0;
                INFOPORT infoport;
                do
                {
                    outport.GetPortInfo(++dwPortCount, out infoport);
                }while ((infoport.dwFlags & DMUS_PC.SOFTWARESYNTH) == 0);

                outport.SetPortParams(0, 0, 0, DirectMidi.SET.REVERB | DirectMidi.SET.CHORUS, 44100);
                outport.ActivatePort(infoport);

                cport.AddPort(outport, 0, 1);

                for (int i = 0; i < dwInstrumentIndex; i++)
                {
                    ccollection.GetInstrument(out instruments[i], i);
                    outport.DownloadInstrument(instruments[i]);
                }
                segment.Download(cport);
                if (!loop)
                {
                    segment.SetRepeats(0);
                }

                cport.PlaySegment(segment);
            }
            else
            {
                cport.Stop(segment);
                segment.Dispose();
                //segment.ConnectToDLS
                loader.LoadSegment(pt, out segment);
                segment.Download(cport);
                if (!loop)
                {
                    segment.SetRepeats(0);
                }
                cport.PlaySegment(segment);
                cdm.Dispose();
            }

            //GCHandle.Alloc(cdm, GCHandleType.Pinned);
            //GCHandle.Alloc(loader, GCHandleType.Pinned);
            //GCHandle.Alloc(segment, GCHandleType.Pinned);
            //GCHandle.Alloc(path, GCHandleType.Pinned);
            //GCHandle.Alloc(cport, GCHandleType.Pinned);
            //GCHandle.Alloc(outport, GCHandleType.Pinned);
            //GCHandle.Alloc(infoport, GCHandleType.Pinned);
        }