Rev 1 | Rev 57 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 4 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | {$INCLUDE DelphiXcfg.inc} |
5 | {$INCLUDE DelphiXcfg.inc} |
6 | 6 | ||
7 | uses |
7 | uses |
8 | Windows, Messages, SysUtils, Classes, Controls, Forms, ExtCtrls, MMSystem, |
8 | Windows, Messages, SysUtils, Classes, Controls, Forms, ExtCtrls, MMSystem, ActiveX, |
- | 9 | DXClass, DXWave, D3DUtils, {$IFDEF VER17UP} Types, {$ENDIF} |
|
- | 10 | {$IFDEF StandardDX} |
|
9 | DirectX, DXClass, Wave; |
11 | DirectSound, DirectMusic; |
- | 12 | {$ELSE} |
|
- | 13 | DirectX; |
|
- | 14 | {$ENDIF} |
|
10 | 15 | ||
11 | type |
16 | type |
12 | 17 | ||
13 | { EDirectSoundError } |
18 | { EDirectSoundError } |
14 | 19 | ||
Line 41... | Line 46... | ||
41 | property Buffers[Index: Integer]: TDirectSoundBuffer read GetBuffer; |
46 | property Buffers[Index: Integer]: TDirectSoundBuffer read GetBuffer; |
42 | property IDSound: IDirectSound read GetIDSound; |
47 | property IDSound: IDirectSound read GetIDSound; |
43 | property ISound: IDirectSound read GetISound; |
48 | property ISound: IDirectSound read GetISound; |
44 | end; |
49 | end; |
45 | 50 | ||
- | 51 | { TD3DSParams } |
|
- | 52 | ||
- | 53 | TConeAngle = record |
|
- | 54 | Inside,Outside:DWord; |
|
- | 55 | end; |
|
- | 56 | TD3DSParams = class |
|
- | 57 | private |
|
- | 58 | FOwner: TDirectSoundBuffer; |
|
- | 59 | ||
- | 60 | FDsb: TDS3DBUFFER; |
|
- | 61 | ||
- | 62 | function GetPosition: TD3DVector; |
|
- | 63 | function GetVelocity: TD3DVector; |
|
- | 64 | function GetConeOrientation: TD3DVector; |
|
- | 65 | function GetConeAngle: TConeAngle; |
|
- | 66 | function GetConeOutsideVolume: Integer; |
|
- | 67 | function GetMinDistance: TD3DValue; |
|
- | 68 | function GetMaxDistance: TD3DValue; |
|
- | 69 | function GetRaw: TDS3DBuffer; |
|
- | 70 | ||
- | 71 | procedure SetPosition(const v: TD3DVector); |
|
- | 72 | procedure SetVelocity(const v: TD3DVector); |
|
- | 73 | procedure SetConeOrientation(const v: TD3DVector); |
|
- | 74 | procedure SetConeAngle(const v: TConeAngle); |
|
- | 75 | procedure SetConeOutsideVolume(const v: Integer); |
|
- | 76 | procedure SetMinDistance(const v: TD3DValue); |
|
- | 77 | procedure SetMaxDistance(const v: TD3DValue); |
|
- | 78 | procedure SetRaw(const v: TDS3DBuffer); |
|
- | 79 | ||
- | 80 | function CheckValidity: Boolean; |
|
- | 81 | public |
|
- | 82 | constructor Create(Owner: TDirectSoundBuffer); |
|
- | 83 | destructor Destroy; override; |
|
- | 84 | property Position: TD3DVector read getPosition write setPosition; |
|
- | 85 | property Velocity: TD3DVector read getVelocity write setVelocity; |
|
- | 86 | property ConeOrientation: TD3DVector read getConeOrientation write setConeOrientation; |
|
- | 87 | property ConeAngle: TConeAngle read getConeAngle write setConeAngle; |
|
- | 88 | property ConeOutsideVolume: Integer read getConeOutsideVolume write setConeOutsideVolume; |
|
- | 89 | property MinDistance: TD3DValue read getMinDistance write setMinDistance; |
|
- | 90 | property MaxDistance: TD3DValue read getMaxDistance write setMaxDistance; |
|
- | 91 | property RawParams: TDS3DBuffer read getRaw write setRaw; |
|
- | 92 | procedure Assign(Prms: TD3DSParams); |
|
- | 93 | end; |
|
- | 94 | ||
46 | { TDirectSoundBuffer } |
95 | { TDirectSoundBuffer } |
47 | 96 | ||
48 | TDirectSoundBuffer = class(TDirectX) |
97 | TDirectSoundBuffer = class(TDirectX) |
49 | private |
98 | private |
50 | FDSound: TDirectSound; |
99 | FDSound: TDirectSound; |
51 | FIDSBuffer: IDirectSoundBuffer; |
100 | FIDSBuffer: IDirectSoundBuffer; |
- | 101 | FIDS3DBuffer:IDirectSound3DBuffer; |
|
- | 102 | FD3DSParams: TD3DSParams; |
|
52 | FCaps: TDSBCaps; |
103 | FCaps: TDSBCaps; |
53 | FFormat: PWaveFormatEx; |
104 | FFormat: PWaveFormatEx; |
54 | FFormatSize: Integer; |
105 | FFormatSize: Integer; |
55 | FLockAudioPtr1, FLockAudioPtr2: array[0..0] of Pointer; |
106 | FLockAudioPtr1, FLockAudioPtr2: array[0..0] of Pointer; |
56 | FLockAudioSize1, FLockAudioSize2: array[0..0] of DWORD; |
107 | FLockAudioSize1, FLockAudioSize2: array[0..0] of DWORD; |
57 | FLockCount: Integer; |
108 | FLockCount: Integer; |
- | 109 | FIsD3D: Boolean; |
|
58 | function GetBitCount: Longint; |
110 | function GetBitCount: Longint; |
59 | function GetFormat: PWaveFormatEx; |
111 | function GetFormat: PWaveFormatEx; |
60 | function GetFrequency: Integer; |
112 | function GetFrequency: Integer; |
61 | function GetIDSBuffer: IDirectSoundBuffer; |
113 | function GetIDSBuffer: IDirectSoundBuffer; |
62 | function GetIBuffer: IDirectSoundBuffer; |
114 | function GetIBuffer: IDirectSoundBuffer; |
Line 69... | Line 121... | ||
69 | procedure SetFrequency(Value: Integer); |
121 | procedure SetFrequency(Value: Integer); |
70 | procedure SetIDSBuffer(Value: IDirectSoundBuffer); |
122 | procedure SetIDSBuffer(Value: IDirectSoundBuffer); |
71 | procedure SetPan(Value: Integer); |
123 | procedure SetPan(Value: Integer); |
72 | procedure SetPosition(Value: Longint); |
124 | procedure SetPosition(Value: Longint); |
73 | procedure SetVolume(Value: Integer); |
125 | procedure SetVolume(Value: Integer); |
- | 126 | function GetIDS3DBuffer: IDirectSound3DBuffer; |
|
- | 127 | procedure SetIDS3DBuffer(const Value: IDirectSound3DBuffer); |
|
- | 128 | procedure SetD3DSParams(const Value: TD3DSParams); |
|
74 | protected |
129 | protected |
75 | procedure Check; override; |
130 | procedure Check; override; |
76 | public |
131 | public |
77 | constructor Create(ADirectSound: TDirectSound); |
132 | constructor Create(ADirectSound: TDirectSound); |
78 | destructor Destroy; override; |
133 | destructor Destroy; override; |
Line 87... | Line 142... | ||
87 | var AudioPtr1: Pointer; var AudioSize1: Longint; |
142 | var AudioPtr1: Pointer; var AudioSize1: Longint; |
88 | var AudioPtr2: Pointer; var AudioSize2: Longint): Boolean; |
143 | var AudioPtr2: Pointer; var AudioSize2: Longint): Boolean; |
89 | function Play(Loop: Boolean{$IFNDEF VER100}=False{$ENDIF}): Boolean; |
144 | function Play(Loop: Boolean{$IFNDEF VER100} = False{$ENDIF}): Boolean; |
90 | function Restore: Boolean; |
145 | function Restore: Boolean; |
91 | function SetFormat(const Format: TWaveFormatEx): Boolean; |
146 | function SetFormat(const Format: TWaveFormatEx): Boolean; |
92 | procedure SetSize(const Format: TWaveFormatEx; Size: Integer); |
147 | procedure SetSize(const Format: TWaveFormatEx; Size: Integer; D3D: Boolean {$IFNDEF VER100}= False{$ENDIF}); |
93 | procedure Stop; |
148 | procedure Stop; |
94 | procedure UnLock; |
149 | procedure UnLock; |
95 | property BitCount: Longint read GetBitCount; |
150 | property BitCount: Longint read GetBitCount; |
96 | property DSound: TDirectSound read FDSound; |
151 | property DSound: TDirectSound read FDSound; |
97 | property Format: PWaveFormatEx read GetFormat; |
152 | property Format: PWaveFormatEx read GetFormat; |
98 | property FormatSize: Integer read FFormatSize; |
153 | property FormatSize: Integer read FFormatSize; |
99 | property Frequency: Integer read GetFrequency write SetFrequency; |
154 | property Frequency: Integer read GetFrequency write SetFrequency; |
100 | property IBuffer: IDirectSoundBuffer read GetIBuffer; |
155 | property IBuffer: IDirectSoundBuffer read GetIBuffer; |
101 | property IDSBuffer: IDirectSoundBuffer read GetIDSBuffer write SetIDSBuffer; |
156 | property IDSBuffer: IDirectSoundBuffer read GetIDSBuffer write SetIDSBuffer; |
- | 157 | property IDS3DBuffer: IDirectSound3DBuffer read GetIDS3DBuffer write SetIDS3DBuffer; |
|
102 | property Playing: Boolean read GetPlaying; |
158 | property Playing: Boolean read GetPlaying; |
103 | property Pan: Integer read GetPan write SetPan; |
159 | property Pan: Integer read GetPan write SetPan; |
- | 160 | property D3DSParams: TD3DSParams read FD3DSParams write SetD3DSParams; |
|
- | 161 | property IsD3D: Boolean read FIsD3D write FIsD3D default False; |
|
104 | property Position: Longint read GetPosition write SetPosition; |
162 | property Position: Longint read GetPosition write SetPosition; |
105 | property Size: Integer read GetSize; |
163 | property Size: Integer read GetSize; |
106 | property Volume: Integer read GetVolume write SetVolume; |
164 | property Volume: Integer read GetVolume write SetVolume; |
107 | end; |
165 | end; |
108 | 166 | ||
Line 375... | Line 433... | ||
375 | procedure SetLooped(Value: Boolean); |
433 | procedure SetLooped(Value: Boolean); |
376 | procedure SetMaxPlayingCount(Value: Integer); |
434 | procedure SetMaxPlayingCount(Value: Integer); |
377 | procedure SetPan(Value: Integer); |
435 | procedure SetPan(Value: Integer); |
378 | procedure SetVolume(Value: Integer); |
436 | procedure SetVolume(Value: Integer); |
379 | procedure SetWave(Value: TWave); |
437 | procedure SetWave(Value: TWave); |
- | 438 | protected |
|
- | 439 | function GetPlaying: boolean; |
|
380 | public |
440 | public |
381 | constructor Create(Collection: TCollection); override; |
441 | constructor Create(Collection: TCollection); override; |
382 | destructor Destroy; override; |
442 | destructor Destroy; override; |
383 | procedure Assign(Source: TPersistent); override; |
443 | procedure Assign(Source: TPersistent); override; |
384 | procedure Play(Wait: Boolean); |
444 | procedure Play(Wait: Boolean); |
Line 387... | Line 447... | ||
387 | property Frequency: Integer read FFrequency write SetFrequency; |
447 | property Frequency: Integer read FFrequency write SetFrequency; |
388 | property Initialized: Boolean read FInitialized; |
448 | property Initialized: Boolean read FInitialized; |
389 | property Pan: Integer read FPan write SetPan; |
449 | property Pan: Integer read FPan write SetPan; |
390 | property Volume: Integer read FVolume write SetVolume; |
450 | property Volume: Integer read FVolume write SetVolume; |
391 | property WaveCollection: TWaveCollection read GetWaveCollection; |
451 | property WaveCollection: TWaveCollection read GetWaveCollection; |
- | 452 | ||
- | 453 | property Playing: boolean read GetPlaying; |
|
392 | published |
454 | published |
393 | property Looped: Boolean read FLooped write SetLooped; |
455 | property Looped: Boolean read FLooped write SetLooped; |
394 | property MaxPlayingCount: Integer read FMaxPlayingCount write SetMaxPlayingCount; |
456 | property MaxPlayingCount: Integer read FMaxPlayingCount write SetMaxPlayingCount; |
395 | property Wave: TWave read FWave write SetWave; |
457 | property Wave: TWave read FWave write SetWave; |
396 | end; |
458 | end; |
Line 443... | Line 505... | ||
443 | published |
505 | published |
444 | property DXSound; |
506 | property DXSound; |
445 | property Items; |
507 | property Items; |
446 | end; |
508 | end; |
447 | 509 | ||
- | 510 | { EDXMusicError } |
|
- | 511 | ||
- | 512 | EDXMusicError = class(Exception); |
|
- | 513 | ||
- | 514 | TMusicListCollection = class; |
|
- | 515 | ||
- | 516 | { TMusicListCollectionItem } |
|
- | 517 | ||
- | 518 | TMusicDataProp = class(TPersistent) |
|
- | 519 | private |
|
- | 520 | FMusicData: string; |
|
- | 521 | FMidiname: string; |
|
- | 522 | function GetMusicData: string; |
|
- | 523 | procedure SetMusicData(const Value: string); |
|
- | 524 | protected |
|
- | 525 | procedure DefineProperties(Filer: TFiler); override; |
|
- | 526 | procedure ReadMidiData(Stream: TStream); |
|
- | 527 | procedure WriteMidiData(Stream: TStream); |
|
- | 528 | public |
|
- | 529 | property MusicData: string read GetMusicData write SetMusicData; |
|
- | 530 | published |
|
- | 531 | property MidiName: string read FMidiname write FMidiname; |
|
- | 532 | end; |
|
- | 533 | ||
- | 534 | TMusicListCollectionItem = class(THashCollectionItem) |
|
- | 535 | private |
|
- | 536 | { Private declarations } |
|
- | 537 | FDirectMusicPerformance: IDirectMusicPerformance; |
|
- | 538 | FDirectSound: IDirectSound; |
|
- | 539 | FDirectMusic: IDirectMusic; |
|
- | 540 | FDirectMusicLoader: IDirectMusicLoader; |
|
- | 541 | FDirectMusicSegment: IDirectMusicSegment; |
|
- | 542 | FMusicObjDesc: TDMus_ObjectDesc; |
|
- | 543 | FDirectMusicSegmentState: IDirectMusicSegmentState; |
|
- | 544 | FRepeats: Cardinal; |
|
- | 545 | FStartpoint: Integer; |
|
- | 546 | FDuration: Integer; |
|
- | 547 | // startpoint props in seconds these used to hold millisecond value |
|
- | 548 | FActualDuration: Integer; |
|
- | 549 | FActualStartPoint: Integer; |
|
- | 550 | FIsInitialized: Boolean; |
|
- | 551 | FMusicDataProp: TMusicDataProp; |
|
- | 552 | procedure SetDuration(const Value: integer); |
|
- | 553 | procedure SetRepeats(const Value: Cardinal); |
|
- | 554 | procedure SetStartPoint(const Value: integer); |
|
- | 555 | function GetMusicListCollection: TMusicListCollection; |
|
- | 556 | protected |
|
- | 557 | function GetDisplayName: string; override; |
|
- | 558 | public |
|
- | 559 | constructor Create(Collection: TCollection); override; |
|
- | 560 | destructor Destroy; override; |
|
- | 561 | function Size: Integer; |
|
- | 562 | procedure Play; |
|
- | 563 | function IsPlaying: Boolean; |
|
- | 564 | procedure Stop; |
|
- | 565 | procedure Load; |
|
- | 566 | procedure Init; |
|
- | 567 | procedure LoadFromFile(const MidiFileName: string); |
|
- | 568 | procedure SaveToFile(const MidiFileName: string); |
|
- | 569 | property MusicCollection: TMusicListCollection read GetMusicListCollection; |
|
- | 570 | property IsInitialized: Boolean read FIsInitialized write FIsInitialized; |
|
- | 571 | published |
|
- | 572 | property Name; |
|
- | 573 | property Repeats: Cardinal read Frepeats write SetRepeats; |
|
- | 574 | property Duration: integer read FDuration write SetDuration; |
|
- | 575 | property StartPoint: integer read FStartPoint write SetStartPoint; |
|
- | 576 | property Midi: TMusicDataProp read FMusicDataProp write FMusicDataProp; |
|
- | 577 | end; |
|
- | 578 | ||
- | 579 | { TMusicListCollection } |
|
- | 580 | ||
- | 581 | TMusicListCollection = class(THashCollection) |
|
- | 582 | private |
|
- | 583 | FOwner: TPersistent; |
|
- | 584 | FDirectSound: IDirectSound; |
|
- | 585 | protected |
|
- | 586 | function GetItem(Index: Integer): TMusicListCollectionItem; |
|
- | 587 | procedure SetItem(Index: Integer; Value: TMusicListCollectionItem); |
|
- | 588 | procedure Update(Item: TCollectionItem); override; |
|
- | 589 | function GetOwner: TPersistent; override; |
|
- | 590 | public |
|
- | 591 | constructor Create(AOwner: TComponent); |
|
- | 592 | function Add: TMusicListCollectionItem; |
|
- | 593 | function Find(const Name: string): TMusicListCollectionItem; |
|
- | 594 | procedure Restore; |
|
- | 595 | procedure LoadFromFile(const FileName: string); |
|
- | 596 | procedure LoadFromStream(Stream: TStream); |
|
- | 597 | procedure SaveToFile(const FileName: string); |
|
- | 598 | procedure SaveToStream(Stream: TStream); |
|
- | 599 | {$IFDEF VER4UP} |
|
- | 600 | function Insert(Index: Integer): TMusicListCollectionItem; |
|
- | 601 | {$ENDIF} |
|
- | 602 | property Items[Index: Integer]: TMusicListCollectionItem read GetItem write SetItem; |
|
- | 603 | published |
|
- | 604 | end; |
|
- | 605 | ||
- | 606 | { TDXMusic } |
|
- | 607 | ||
- | 608 | TDXMusic = class(TComponent) |
|
- | 609 | private |
|
- | 610 | FDXSound: TDXSound; |
|
- | 611 | FMidis: TMusicListCollection; |
|
- | 612 | procedure SetMidis(const value: TMusicListCollection); |
|
- | 613 | procedure SetDXSound(const Value: TDXSound); |
|
- | 614 | public |
|
- | 615 | constructor Create(AOwner: TComponent); override; |
|
- | 616 | destructor Destroy; override; |
|
- | 617 | published |
|
- | 618 | property DXSound: TDXSound read FDXSound write SetDXSound; |
|
- | 619 | property Midis: TMusicListCollection read FMidis write SetMidis; |
|
- | 620 | end; |
|
- | 621 | ||
448 | implementation |
622 | implementation |
449 | 623 | ||
450 | uses DXConsts; |
624 | uses DXConsts; |
451 | 625 | ||
- | 626 | const |
|
- | 627 | dm_OK = 0; |
|
- | 628 | ||
452 | function DXDirectSoundCreate(lpGUID: PGUID; out lpDS: IDirectSound; |
629 | function DXDirectSoundCreate(lpGUID: PGUID; out lpDS: IDirectSound; |
453 | pUnkOuter: IUnknown): HRESULT; |
630 | pUnkOuter: IUnknown): HRESULT; |
454 | type |
631 | type |
455 | TDirectSoundCreate = function(lpGUID: PGUID; out lplpDD: IDirectSound; |
632 | TDirectSoundCreate = function(lpGUID: PGUID; out lplpDD: IDirectSound; |
456 | pUnkOuter: IUnknown): HRESULT; stdcall; |
633 | pUnkOuter: IUnknown): HRESULT; stdcall; |
Line 499... | Line 676... | ||
499 | 676 | ||
500 | var |
677 | var |
501 | DirectSoundDrivers: TDirectXDrivers; |
678 | DirectSoundDrivers: TDirectXDrivers; |
502 | DirectSoundCaptureDrivers: TDirectXDrivers; |
679 | DirectSoundCaptureDrivers: TDirectXDrivers; |
503 | 680 | ||
504 | function EnumDirectSoundDrivers_DSENUMCALLBACK(lpGuid: PGUID; lpstrDescription: LPCSTR; |
681 | function EnumDirectSoundDrivers_DSENUMCALLBACK(lpGuid: PGUID; lpstrDescription: {$IFDEF UNICODE}LPCTSTR{$ELSE}LPCSTR{$ENDIF}; |
505 | lpstrModule: LPCSTR; lpContext: Pointer): BOOL; stdcall; |
682 | lpstrModule: {$IFDEF UNICODE}LPCTSTR{$ELSE}LPCSTR{$ENDIF}; lpContext: Pointer): BOOL; stdcall; |
506 | begin |
683 | begin |
507 | Result := True; |
684 | Result := True; |
508 | with TDirectXDriver.Create(TDirectXDrivers(lpContext)) do |
685 | with TDirectXDriver.Create(TDirectXDrivers(lpContext)) do |
509 | begin |
686 | begin |
510 | Guid := lpGuid; |
687 | Guid := lpGuid; |
Line 621... | Line 798... | ||
621 | { TDirectSoundBuffer } |
798 | { TDirectSoundBuffer } |
622 | 799 | ||
623 | constructor TDirectSoundBuffer.Create(ADirectSound: TDirectSound); |
800 | constructor TDirectSoundBuffer.Create(ADirectSound: TDirectSound); |
624 | begin |
801 | begin |
625 | inherited Create; |
802 | inherited Create; |
- | 803 | FIsD3D := False; |
|
626 | FDSound := ADirectSound; |
804 | FDSound := ADirectSound; |
- | 805 | FIDS3DBuffer := nil; |
|
627 | FDSound.FBufferList.Add(Self); |
806 | FDSound.FBufferList.Add(Self); |
628 | end; |
807 | end; |
629 | 808 | ||
630 | destructor TDirectSoundBuffer.Destroy; |
809 | destructor TDirectSoundBuffer.Destroy; |
631 | begin |
810 | begin |
632 | IDSBuffer := nil; |
811 | IDSBuffer := nil; |
- | 812 | IDS3DBuffer := nil; |
|
633 | FDSound.FBufferList.Remove(Self); |
813 | FDSound.FBufferList.Remove(Self); |
634 | inherited Destroy; |
814 | inherited Destroy; |
635 | end; |
815 | end; |
636 | 816 | ||
637 | procedure TDirectSoundBuffer.Assign(Source: TPersistent); |
817 | procedure TDirectSoundBuffer.Assign(Source: TPersistent); |
638 | var |
818 | var |
639 | TempBuffer: IDirectSoundBuffer; |
819 | TempBuffer: IDirectSoundBuffer; |
640 | begin |
820 | begin |
641 | if Source=nil then |
821 | if Source = nil then |
642 | IDSBuffer := nil |
822 | IDSBuffer := nil |
- | 823 | else |
|
643 | else if Source is TWave then |
824 | if Source is TWave then |
644 | LoadFromWave(TWave(Source)) |
825 | LoadFromWave(TWave(Source)) |
- | 826 | else |
|
645 | else if Source is TDirectSoundBuffer then |
827 | if Source is TDirectSoundBuffer then |
646 | begin |
828 | begin |
647 | if TDirectSoundBuffer(Source).IDSBuffer=nil then |
829 | if TDirectSoundBuffer(Source).IDSBuffer = nil then |
648 | IDSBuffer := nil |
830 | IDSBuffer := nil |
- | 831 | else |
|
649 | else begin |
832 | begin |
650 | FDSound.DXResult := FDSound.ISound.DuplicateSoundBuffer(TDirectSoundBuffer(Source).IDSBuffer, |
833 | FDSound.DXResult := FDSound.ISound.DuplicateSoundBuffer(TDirectSoundBuffer(Source).IDSBuffer, TempBuffer); |
651 | TempBuffer); |
- | |
652 | if FDSound.DXResult=0 then |
834 | if FDSound.DXResult = DS_OK then |
653 | begin |
835 | begin |
654 | IDSBuffer := TempBuffer; |
836 | IDSBuffer := TempBuffer; |
655 | end; |
837 | end; |
656 | end; |
838 | end; |
- | 839 | ||
- | 840 | if FIsD3D then |
|
- | 841 | if TDirectSoundBuffer(Source).IDS3DBuffer = nil then |
|
- | 842 | IDS3DBuffer := nil |
|
657 | end else |
843 | else |
- | 844 | begin |
|
- | 845 | FDSound.DXResult := FDSound.ISound.QueryInterface(IID_IDirectSound3DBuffer, FIDS3DBuffer); |
|
- | 846 | if FDSound.DXResult = DS_OK then |
|
- | 847 | FD3DSParams := TDirectSoundBuffer(Source).FD3DSParams; |
|
- | 848 | end; |
|
- | 849 | ||
- | 850 | end |
|
- | 851 | else |
|
658 | inherited Assign(Source); |
852 | inherited Assign(Source); |
659 | end; |
853 | end; |
660 | 854 | ||
661 | procedure TDirectSoundBuffer.Check; |
855 | procedure TDirectSoundBuffer.Check; |
662 | begin |
856 | begin |
Line 690... | Line 884... | ||
690 | function TDirectSoundBuffer.GetFrequency: Integer; |
884 | function TDirectSoundBuffer.GetFrequency: Integer; |
691 | begin |
885 | begin |
692 | DXResult := IBuffer.GetFrequency(DWORD(Result)); |
886 | DXResult := IBuffer.GetFrequency(DWORD(Result)); |
693 | end; |
887 | end; |
694 | 888 | ||
- | 889 | function TDirectSoundBuffer.GetIDS3DBuffer: IDirectSound3DBuffer; |
|
- | 890 | begin |
|
- | 891 | if Self <> nil then |
|
- | 892 | Result := FIDS3DBuffer |
|
- | 893 | else |
|
- | 894 | Result := nil; |
|
- | 895 | end; |
|
- | 896 | ||
695 | function TDirectSoundBuffer.GetIDSBuffer: IDirectSoundBuffer; |
897 | function TDirectSoundBuffer.GetIDSBuffer: IDirectSoundBuffer; |
696 | begin |
898 | begin |
697 | if Self<>nil then |
899 | if Self <> nil then |
698 | Result := FIDSBuffer |
900 | Result := FIDSBuffer |
699 | else |
901 | else |
Line 719... | Line 921... | ||
719 | 921 | ||
720 | function TDirectSoundBuffer.GetPosition: Longint; |
922 | function TDirectSoundBuffer.GetPosition: Longint; |
721 | var |
923 | var |
722 | dwCurrentWriteCursor: Longint; |
924 | dwCurrentWriteCursor: Longint; |
723 | begin |
925 | begin |
724 | IBuffer.GetCurrentPosition(DWORD(Result), DWORD(dwCurrentWriteCursor)); |
926 | IBuffer.GetCurrentPosition(@DWORD(Result), @DWORD(dwCurrentWriteCursor)); |
725 | end; |
927 | end; |
726 | 928 | ||
727 | function TDirectSoundBuffer.GetSize: Integer; |
929 | function TDirectSoundBuffer.GetSize: Integer; |
728 | begin |
930 | begin |
729 | Result := FCaps.dwBufferBytes; |
931 | Result := FCaps.dwBufferBytes; |
Line 755... | Line 957... | ||
755 | Data: Pointer; Size: Integer); |
957 | Data: Pointer; Size: Integer); |
756 | var |
958 | var |
757 | Data1, Data2: Pointer; |
959 | Data1, Data2: Pointer; |
758 | Data1Size, Data2Size: Longint; |
960 | Data1Size, Data2Size: Longint; |
759 | begin |
961 | begin |
760 | SetSize(Format, Size); |
962 | SetSize(Format, Size, FIsD3D); |
761 | 963 | ||
762 | if Data<>nil then |
964 | if Data <> nil then |
763 | begin |
965 | begin |
764 | if Lock(0, Size, Data1, Data1Size, Data2, Data2Size) then |
966 | if Lock(0, Size, Data1, Data1Size, Data2, Data2Size) then |
765 | begin |
967 | begin |
Line 768... | Line 970... | ||
768 | if Data2<>nil then |
970 | if Data2 <> nil then |
769 | Move(Pointer(Longint(Data)+Data1Size)^, Data2^, Data2Size); |
971 | Move(Pointer(Longint(Data) + Data1Size)^, Data2^, Data2Size); |
770 | finally |
972 | finally |
771 | UnLock; |
973 | UnLock; |
772 | end; |
974 | end; |
- | 975 | end |
|
773 | end else |
976 | else |
774 | begin |
977 | begin |
775 | FIDSBuffer := nil; |
978 | FIDSBuffer := nil; |
- | 979 | FIDS3DBuffer := nil; |
|
776 | raise EDirectSoundBufferError.CreateFmt(SCannotLock, [SDirectSoundBuffer]); |
980 | raise EDirectSoundBufferError.CreateFmt(SCannotLock, [SDirectSoundBuffer]); |
777 | end; |
981 | end; |
778 | end; |
982 | end; |
779 | end; |
983 | end; |
780 | 984 | ||
Line 802... | Line 1006... | ||
802 | begin |
1006 | begin |
803 | Result := False; |
1007 | Result := False; |
804 | if IDSBuffer=nil then Exit; |
1008 | if IDSBuffer = nil then Exit; |
805 | 1009 | ||
806 | if FLockCount>High(FLockAudioPtr1) then Exit; |
1010 | if FLockCount > High(FLockAudioPtr1) then Exit; |
807 | - | ||
808 | DXResult := IBuffer.Lock(LockPosition, LockSize, |
1011 | DXResult := IBuffer.Lock(LockPosition, LockSize, |
809 | FLockAudioPtr1[FLockCount], FLockAudioSize1[FLockCount], |
1012 | {$IFNDEF DX7}@{$ENDIF}FLockAudioPtr1[FLockCount], {$IFNDEF DX7}@{$ENDIF}FLockAudioSize1[FLockCount], |
810 | FLockAudioPtr2[FLockCount], FLockAudioSize2[FLockCount], 0); |
1013 | {$IFNDEF DX7}@{$ENDIF}FLockAudioPtr2[FLockCount], {$IFNDEF DX7}@{$ENDIF}FLockAudioSize2[FLockCount], 0); |
811 | Result := DXResult=DS_OK; |
1014 | Result := DXResult = DS_OK; |
812 | 1015 | ||
813 | if Result then |
1016 | if Result then |
814 | begin |
1017 | begin |
815 | AudioPtr1 := FLockAudioPtr1[FLockCount]; |
1018 | AudioPtr1 := FLockAudioPtr1[FLockCount]; |
Line 833... | Line 1036... | ||
833 | begin |
1036 | begin |
834 | DXResult := IBuffer.Restore; |
1037 | DXResult := IBuffer.Restore; |
835 | Result := DXResult=DS_OK; |
1038 | Result := DXResult = DS_OK; |
836 | end; |
1039 | end; |
837 | 1040 | ||
- | 1041 | procedure TDirectSoundBuffer.SetD3DSParams(const Value: TD3DSParams); |
|
- | 1042 | begin |
|
- | 1043 | FD3DSParams.Assign(Value); |
|
- | 1044 | end; |
|
- | 1045 | ||
838 | function TDirectSoundBuffer.SetFormat(const Format: TWaveFormatEx): Boolean; |
1046 | function TDirectSoundBuffer.SetFormat(const Format: TWaveFormatEx): Boolean; |
839 | begin |
1047 | begin |
840 | DXResult := IBuffer.SetFormat(Format); |
1048 | DXResult := IBuffer.SetFormat(FFormat{$IFDEF DX7}^{$ENDIF}); |
841 | Result := DXResult=DS_OK; |
1049 | Result := DXResult = DS_OK; |
842 | 1050 | ||
843 | if Result then |
1051 | if Result then |
844 | begin |
1052 | begin |
845 | FreeMem(FFormat); |
1053 | FreeMem(FFormat); |
846 | FFormat := nil; |
1054 | FFormat := nil; |
847 | FFormatSize := 0; |
1055 | FFormatSize := 0; |
848 | if IBuffer.GetFormat(PWaveFormatEx(nil)^, 0, DWORD(FFormatSize))=DS_OK then |
1056 | if IBuffer.GetFormat(PWaveFormatEx(nil), 0, @DWORD(FFormatSize)) = DS_OK then |
849 | begin |
1057 | begin |
850 | GetMem(FFormat, FFormatSize); |
1058 | GetMem(FFormat, FFormatSize); |
851 | IBuffer.GetFormat(FFormat^, FFormatSize, PDWORD(nil)^); |
1059 | IBuffer.GetFormat(FFormat, FFormatSize, nil); |
852 | end; |
1060 | end; |
853 | end; |
1061 | end; |
854 | end; |
1062 | end; |
855 | 1063 | ||
856 | procedure TDirectSoundBuffer.SetFrequency(Value: Integer); |
1064 | procedure TDirectSoundBuffer.SetFrequency(Value: Integer); |
857 | begin |
1065 | begin |
858 | DXResult := IBuffer.SetFrequency(Value); |
1066 | DXResult := IBuffer.SetFrequency(Value); |
859 | end; |
1067 | end; |
860 | 1068 | ||
- | 1069 | procedure TDirectSoundBuffer.SetIDS3DBuffer(const Value: IDirectSound3DBuffer); |
|
- | 1070 | begin |
|
- | 1071 | if FIDS3DBuffer = Value then Exit; |
|
- | 1072 | ||
- | 1073 | FIDS3DBuffer := Value; |
|
- | 1074 | FillChar(FCaps, SizeOf(FCaps), 0); |
|
- | 1075 | FreeMem(FFormat); |
|
- | 1076 | FFormat := nil; |
|
- | 1077 | FFormatSize := 0; |
|
- | 1078 | FLockCount := 0; |
|
- | 1079 | ||
- | 1080 | if FIDS3DBuffer <> nil then |
|
- | 1081 | begin |
|
- | 1082 | FCaps.dwSize := SizeOf(FCaps); |
|
- | 1083 | IBuffer.GetCaps(FCaps); |
|
- | 1084 | ||
- | 1085 | if IBuffer.GetFormat(PWaveFormatEx(nil), 0, @DWORD(FFormatSize)) = DS_OK then |
|
- | 1086 | begin |
|
- | 1087 | GetMem(FFormat, FFormatSize); |
|
- | 1088 | IBuffer.GetFormat(FFormat, FFormatSize, nil); |
|
- | 1089 | end; |
|
- | 1090 | end; |
|
- | 1091 | end; |
|
- | 1092 | ||
861 | procedure TDirectSoundBuffer.SetIDSBuffer(Value: IDirectSoundBuffer); |
1093 | procedure TDirectSoundBuffer.SetIDSBuffer(Value: IDirectSoundBuffer); |
862 | begin |
1094 | begin |
863 | if FIDSBuffer=Value then Exit; |
1095 | if FIDSBuffer = Value then Exit; |
864 | 1096 | ||
865 | FIDSBuffer := Value; |
1097 | FIDSBuffer := Value; |
Line 872... | Line 1104... | ||
872 | if FIDSBuffer<>nil then |
1104 | if FIDSBuffer <> nil then |
873 | begin |
1105 | begin |
874 | FCaps.dwSize := SizeOf(FCaps); |
1106 | FCaps.dwSize := SizeOf(FCaps); |
875 | IBuffer.GetCaps(FCaps); |
1107 | IBuffer.GetCaps(FCaps); |
876 | 1108 | ||
877 | if IBuffer.GetFormat(PWaveFormatEx(nil)^, 0, DWORD(FFormatSize))=DS_OK then |
1109 | if IBuffer.GetFormat(PWaveFormatEx(nil), 0, @DWORD(FFormatSize)) = DS_OK then |
878 | begin |
1110 | begin |
879 | GetMem(FFormat, FFormatSize); |
1111 | GetMem(FFormat, FFormatSize); |
880 | IBuffer.GetFormat(FFormat^, FFormatSize, PDWORD(nil)^); |
1112 | IBuffer.GetFormat(FFormat, FFormatSize, nil); |
881 | end; |
1113 | end; |
882 | end; |
1114 | end; |
883 | end; |
1115 | end; |
884 | 1116 | ||
885 | procedure TDirectSoundBuffer.SetPan(Value: Integer); |
1117 | procedure TDirectSoundBuffer.SetPan(Value: Integer); |
Line 889... | Line 1121... | ||
889 | 1121 | ||
890 | procedure TDirectSoundBuffer.SetPosition(Value: Longint); |
1122 | procedure TDirectSoundBuffer.SetPosition(Value: Longint); |
891 | begin |
1123 | begin |
892 | DXResult := IBuffer.SetCurrentPosition(Value); |
1124 | DXResult := IBuffer.SetCurrentPosition(Value); |
893 | end; |
1125 | end; |
- | 1126 | {$IFNDEF DX7} |
|
- | 1127 | const |
|
- | 1128 | DSBCAPS_CTRLDEFAULT = DSBCAPS_CTRLFREQUENCY or DSBCAPS_CTRLPAN or DSBCAPS_CTRLVOLUME; |
|
- | 1129 | {$ENDIF} |
|
894 | 1130 | ||
895 | procedure TDirectSoundBuffer.SetSize(const Format: TWaveFormatEx; Size: Integer); |
1131 | procedure TDirectSoundBuffer.SetSize(const Format: TWaveFormatEx; Size: Integer; D3D: Boolean {$IFNDEF VER100}= False{$ENDIF}); |
896 | var |
1132 | var |
897 | BufferDesc: TDSBufferDesc; |
1133 | BufferDesc: TDSBufferDesc; |
898 | begin |
1134 | begin |
899 | { IDirectSoundBuffer made. } |
1135 | { IDirectSoundBuffer made. } |
900 | FillChar(BufferDesc, SizeOf(BufferDesc), 0); |
1136 | FillChar(BufferDesc, SizeOf(BufferDesc), 0); |
Line 905... | Line 1141... | ||
905 | dwFlags := DSBCAPS_CTRLDEFAULT; |
1141 | dwFlags := DSBCAPS_CTRLDEFAULT; |
906 | if DSound.FStickyFocus then |
1142 | if DSound.FStickyFocus then |
907 | dwFlags := dwFlags or DSBCAPS_STICKYFOCUS |
1143 | dwFlags := dwFlags or DSBCAPS_STICKYFOCUS |
908 | else if DSound.FGlobalFocus then |
1144 | else if DSound.FGlobalFocus then |
909 | dwFlags := dwFlags or DSBCAPS_GLOBALFOCUS; |
1145 | dwFlags := dwFlags or DSBCAPS_GLOBALFOCUS; |
- | 1146 | if D3D then |
|
- | 1147 | dwFlags := DSBCAPS_STATIC + DSBCAPS_CTRLDEFAULT + DSBCAPS_CTRL3D - DSBCAPS_CTRLPAN; |
|
910 | dwBufferBytes := Size; |
1148 | dwBufferBytes := Size; |
911 | lpwfxFormat := @Format; |
1149 | lpwfxFormat := @Format; |
912 | end; |
1150 | end; |
913 | 1151 | ||
914 | if not CreateBuffer(BufferDesc) then |
1152 | if not CreateBuffer(BufferDesc) then |
Line 933... | Line 1171... | ||
933 | Dec(FLockCount); |
1171 | Dec(FLockCount); |
934 | DXResult := IBuffer.UnLock(FLockAudioPtr1[FLockCount], FLockAudioSize1[FLockCount], |
1172 | DXResult := IBuffer.UnLock(FLockAudioPtr1[FLockCount], FLockAudioSize1[FLockCount], |
935 | FLockAudioPtr2[FLockCount], FLockAudioSize2[FLockCount]); |
1173 | FLockAudioPtr2[FLockCount], FLockAudioSize2[FLockCount]); |
936 | end; |
1174 | end; |
937 | 1175 | ||
- | 1176 | { TD3DSParams } |
|
- | 1177 | ||
- | 1178 | function TD3DSParams.CheckValidity: Boolean; |
|
- | 1179 | begin |
|
- | 1180 | Result := (FOwner <> nil) and (TDirectSoundBuffer(FOwner).IDS3DBuffer <> nil) |
|
- | 1181 | end; |
|
- | 1182 | ||
- | 1183 | constructor TD3DSParams.Create(Owner: TDirectSoundBuffer); |
|
- | 1184 | {$IFDEF VER14UP} |
|
- | 1185 | function MakeD3DVector(x, y, z: TD3DValue): TD3DVector; {$IFDEF VER9UP}inline; {$ENDIF} |
|
- | 1186 | begin |
|
- | 1187 | Result.x := x; |
|
- | 1188 | Result.y := y; |
|
- | 1189 | Result.z := z; |
|
- | 1190 | end; |
|
- | 1191 | {$ENDIF} |
|
- | 1192 | begin |
|
- | 1193 | inherited Create; |
|
- | 1194 | FOwner := Owner; |
|
- | 1195 | with FDsb do |
|
- | 1196 | begin |
|
- | 1197 | dwSize := SizeOf(TDS3DBuffer); |
|
- | 1198 | vPosition := MakeD3DVector(0, 0, 0); |
|
- | 1199 | vVelocity := MakeD3DVector(0, 0, 0); |
|
- | 1200 | dwInsideConeAngle := DS3D_DEFAULTCONEANGLE; |
|
- | 1201 | dwOutsideConeAngle := DS3D_DEFAULTCONEANGLE; |
|
- | 1202 | vConeOrientation := MakeD3DVector(0, 0, 0); |
|
- | 1203 | lConeoutsideVolume := DS3D_DEFAULTCONEOUTSIDEVOLUME; |
|
- | 1204 | flMinDistance := 5; |
|
- | 1205 | flMaxDistance := 100.0; |
|
- | 1206 | dwMode := DS3DMODE_NORMAL; |
|
- | 1207 | end; |
|
- | 1208 | end; |
|
- | 1209 | ||
- | 1210 | destructor TD3DSParams.destroy; |
|
- | 1211 | begin |
|
- | 1212 | inherited destroy; |
|
- | 1213 | end; |
|
- | 1214 | ||
- | 1215 | function TD3DSParams.getPosition: TD3DVector; |
|
- | 1216 | begin |
|
- | 1217 | if CheckValidity then |
|
- | 1218 | begin |
|
- | 1219 | FOwner.IDS3DBuffer.GetPosition(FDsb.vPosition); |
|
- | 1220 | end; |
|
- | 1221 | result := FDsb.vPosition; |
|
- | 1222 | end; |
|
- | 1223 | ||
- | 1224 | function TD3DSParams.getVelocity: TD3DVector; |
|
- | 1225 | begin |
|
- | 1226 | if CheckValidity then |
|
- | 1227 | begin |
|
- | 1228 | FOwner.IDS3DBuffer.GetVelocity(FDsb.vVelocity); |
|
- | 1229 | end; |
|
- | 1230 | result := FDsb.vVelocity; |
|
- | 1231 | end; |
|
- | 1232 | ||
- | 1233 | function TD3DSParams.getConeOrientation: TD3DVector; |
|
- | 1234 | begin |
|
- | 1235 | if CheckValidity then |
|
- | 1236 | begin |
|
- | 1237 | FOwner.IDS3DBuffer.GetConeOrientation(FDsb.vConeOrientation); |
|
- | 1238 | end; |
|
- | 1239 | result := FDsb.vConeOrientation; |
|
- | 1240 | end; |
|
- | 1241 | ||
- | 1242 | function TD3DSParams.getConeAngle: TConeAngle; |
|
- | 1243 | begin |
|
- | 1244 | if CheckValidity then |
|
- | 1245 | begin |
|
- | 1246 | FOwner.IDS3DBuffer.GetConeAngles(FDsb.dwInsideConeAngle, FDsb.dwOutsideConeAngle); |
|
- | 1247 | end; |
|
- | 1248 | with result do |
|
- | 1249 | begin |
|
- | 1250 | Inside := FDsb.dwInsideConeAngle; |
|
- | 1251 | OutSide := FDsb.dwOutsideConeAngle; |
|
- | 1252 | end; |
|
- | 1253 | end; |
|
- | 1254 | ||
- | 1255 | function TD3DSParams.getConeOutsideVolume: Integer; |
|
- | 1256 | begin |
|
- | 1257 | if CheckValidity then |
|
- | 1258 | begin |
|
- | 1259 | FOwner.IDS3DBuffer.GetConeOutsideVolume(FDsb.lConeOutsideVolume); |
|
- | 1260 | end; |
|
- | 1261 | result := FDsb.lConeOutsideVolume; |
|
- | 1262 | end; |
|
- | 1263 | ||
- | 1264 | function TD3DSParams.getMinDistance: TD3DValue; |
|
- | 1265 | begin |
|
- | 1266 | if CheckValidity then |
|
- | 1267 | begin |
|
- | 1268 | FOwner.IDS3DBuffer.GetMinDistance(FDsb.flMinDistance); |
|
- | 1269 | end; |
|
- | 1270 | result := FDsb.flMinDistance; |
|
- | 1271 | end; |
|
- | 1272 | ||
- | 1273 | function TD3DSParams.getMaxDistance: TD3DValue; |
|
- | 1274 | begin |
|
- | 1275 | if CheckValidity then |
|
- | 1276 | begin |
|
- | 1277 | FOwner.IDS3DBuffer.GetMaxDistance(FDsb.flMaxDistance); |
|
- | 1278 | end; |
|
- | 1279 | result := FDsb.flMaxDistance; |
|
- | 1280 | end; |
|
- | 1281 | ||
- | 1282 | function TD3DSParams.getRaw: TDS3DBuffer; |
|
- | 1283 | begin |
|
- | 1284 | if CheckValidity then |
|
- | 1285 | begin |
|
- | 1286 | FOwner.IDS3DBuffer.GetAllParameters(FDsb); |
|
- | 1287 | end; |
|
- | 1288 | result := FDsb; |
|
- | 1289 | end; |
|
- | 1290 | ||
- | 1291 | ||
- | 1292 | procedure TD3DSParams.setPosition(const v: TD3DVector); |
|
- | 1293 | begin |
|
- | 1294 | if CheckValidity then |
|
- | 1295 | begin |
|
- | 1296 | FOwner.IDS3DBuffer.SetPosition(v.x, v.y, v.z, DS3D_IMMEDIATE); |
|
- | 1297 | end; |
|
- | 1298 | FDsb.vPosition := v; |
|
- | 1299 | end; |
|
- | 1300 | ||
- | 1301 | procedure TD3DSParams.setVelocity(const v: TD3DVector); |
|
- | 1302 | begin |
|
- | 1303 | if CheckValidity then |
|
- | 1304 | begin |
|
- | 1305 | FOwner.IDS3DBuffer.SetVelocity(v.x, v.y, v.z, DS3D_IMMEDIATE); |
|
- | 1306 | end; |
|
- | 1307 | FDsb.vVelocity := v; |
|
- | 1308 | end; |
|
- | 1309 | ||
- | 1310 | procedure TD3DSParams.setConeOrientation(const v: TD3DVector); |
|
- | 1311 | begin |
|
- | 1312 | if CheckValidity then |
|
- | 1313 | begin |
|
- | 1314 | FOwner.IDS3DBuffer.SetConeOrientation(v.x, v.y, v.z, DS3D_IMMEDIATE); |
|
- | 1315 | end; |
|
- | 1316 | FDsb.vConeOrientation := v; |
|
- | 1317 | end; |
|
- | 1318 | ||
- | 1319 | procedure TD3DSParams.setConeAngle(const v: TConeAngle); |
|
- | 1320 | begin |
|
- | 1321 | if CheckValidity then |
|
- | 1322 | begin |
|
- | 1323 | FOwner.IDS3DBuffer.SetConeAngles(v.Inside, v.Outside, DS3D_IMMEDIATE); |
|
- | 1324 | end; |
|
- | 1325 | FDsb.dwInsideConeAngle := v.Inside; |
|
- | 1326 | FDsb.dwInsideConeAngle := v.Outside; |
|
- | 1327 | end; |
|
- | 1328 | ||
- | 1329 | procedure TD3DSParams.setConeOutsideVolume(const v: Integer); |
|
- | 1330 | begin |
|
- | 1331 | if CheckValidity then |
|
- | 1332 | begin |
|
- | 1333 | FOwner.IDS3DBuffer.SetConeOutsideVolume(v, DS3D_IMMEDIATE); |
|
- | 1334 | end; |
|
- | 1335 | FDsb.lConeOutsideVolume := v; |
|
- | 1336 | end; |
|
- | 1337 | ||
- | 1338 | procedure TD3DSParams.setMinDistance(const v: TD3DValue); |
|
- | 1339 | begin |
|
- | 1340 | if CheckValidity then |
|
- | 1341 | begin |
|
- | 1342 | FOwner.IDS3DBuffer.SetMinDistance(v, DS3D_IMMEDIATE); |
|
- | 1343 | end; |
|
- | 1344 | FDsb.flMinDistance := v; |
|
- | 1345 | end; |
|
- | 1346 | ||
- | 1347 | procedure TD3DSParams.setMaxDistance(const v: TD3DValue); |
|
- | 1348 | begin |
|
- | 1349 | if CheckValidity then |
|
- | 1350 | begin |
|
- | 1351 | FOwner.IDS3DBuffer.SetMaxDistance(v, DS3D_IMMEDIATE); |
|
- | 1352 | end; |
|
- | 1353 | FDsb.flMaxDistance := v; |
|
- | 1354 | end; |
|
- | 1355 | ||
- | 1356 | procedure TD3DSParams.setRaw(const v: TDS3DBuffer); |
|
- | 1357 | begin |
|
- | 1358 | if CheckValidity then |
|
- | 1359 | begin |
|
- | 1360 | if FOwner.IDS3DBuffer.SetAllParameters(v, DS3D_IMMEDIATE) <> DS_OK then |
|
- | 1361 | {'Parameter is invalid for Params3D'}; |
|
- | 1362 | end; |
|
- | 1363 | FDsb := v; |
|
- | 1364 | end; |
|
- | 1365 | ||
- | 1366 | procedure TD3DSParams.Assign(Prms: TD3DSParams); |
|
- | 1367 | begin |
|
- | 1368 | FDsb := Prms.RawParams; |
|
- | 1369 | ||
- | 1370 | if CheckValidity then |
|
- | 1371 | begin |
|
- | 1372 | if FOwner.IDS3DBuffer.SetAllParameters(FDsb, DS3D_IMMEDIATE) <> DS_OK then |
|
- | 1373 | {'Parameter is invalid for Params3D'}; |
|
- | 1374 | end; |
|
- | 1375 | end; |
|
- | 1376 | ||
938 | { TAudioStream } |
1377 | { TAudioStream } |
939 | 1378 | ||
940 | type |
1379 | type |
941 | TAudioStreamNotify = class(TThread) |
1380 | TAudioStreamNotify = class(TThread) |
942 | private |
1381 | private |
Line 1660... | Line 2099... | ||
1660 | 2099 | ||
1661 | function TSoundCaptureStream.GetReadSize: Integer; |
2100 | function TSoundCaptureStream.GetReadSize: Integer; |
1662 | var |
2101 | var |
1663 | CapturePosition, ReadPosition: DWORD; |
2102 | CapturePosition, ReadPosition: DWORD; |
1664 | begin |
2103 | begin |
1665 | if FBuffer.GetCurrentPosition(CapturePosition, ReadPosition)=DS_OK then |
2104 | if FBuffer.GetCurrentPosition(@DWORD(CapturePosition), @DWORD(ReadPosition)) = DS_OK then |
1666 | begin |
2105 | begin |
1667 | if FBufferPos<=ReadPosition then |
2106 | if FBufferPos <= ReadPosition then |
1668 | Result := ReadPosition - FBufferPos |
2107 | Result := ReadPosition - FBufferPos |
1669 | else |
2108 | else |
1670 | Result := FBufferSize - FBufferPos + ReadPosition; |
2109 | Result := FBufferSize - FBufferPos + ReadPosition; |
Line 1679... | Line 2118... | ||
1679 | Data1Size, Data2Size: DWORD; |
2118 | Data1Size, Data2Size: DWORD; |
1680 | C: Byte; |
2119 | C: Byte; |
1681 | begin |
2120 | begin |
1682 | if not FCapturing then |
2121 | if not FCapturing then |
1683 | Start; |
2122 | Start; |
- | 2123 | Data1 := nil; |
|
1684 | 2124 | Data2 := nil; |
|
1685 | Result := 0; |
2125 | Result := 0; |
1686 | while Result<Count do |
2126 | while Result < Count do |
1687 | begin |
2127 | begin |
1688 | Size := Min(Count-Result, GetReadSize); |
2128 | Size := Min(Count - Result, GetReadSize); |
1689 | if Size>0 then |
2129 | if Size > 0 then |
1690 | begin |
2130 | begin |
1691 | if FBuffer.Lock(FBufferPos, Size, Data1, Data1Size, Data2, Data2Size, 0)=DS_OK then |
2131 | if FBuffer.Lock(FBufferPos, Size, Data1, {$IFNDEF DX7}@{$ENDIF}Data1Size, |
- | 2132 | Data2, {$IFNDEF DX7}@{$ENDIF}Data2Size, 0) = DS_OK then |
|
1692 | begin |
2133 | begin |
1693 | Move(Data1^, Pointer(Integer(@Buffer)+Result)^, Data1Size); |
2134 | Move(Data1^, Pointer(Integer(@Buffer) + Result)^, Data1Size); |
1694 | Result := Result + Integer(Data1Size); |
2135 | Result := Result + Integer(Data1Size); |
1695 | 2136 | ||
1696 | if Data2<>nil then |
2137 | if Data2 <> nil then |
Line 1798... | Line 2239... | ||
1798 | begin |
2239 | begin |
1799 | inherited Create; |
2240 | inherited Create; |
1800 | FDSound := ADSound; |
2241 | FDSound := ADSound; |
1801 | FEnabled := True; |
2242 | FEnabled := True; |
1802 | 2243 | ||
1803 | - | ||
1804 | FEffectList := TList.Create; |
2244 | FEffectList := TList.Create; |
1805 | FTimer := TTimer.Create(nil); |
2245 | FTimer := TTimer.Create(nil); |
1806 | FTimer.Interval := 500; |
2246 | FTimer.Interval := 500; |
1807 | FTimer.OnTimer := TimerEvent; |
2247 | FTimer.OnTimer := TimerEvent; |
1808 | end; |
2248 | end; |
Line 2221... | Line 2661... | ||
2221 | 2661 | ||
2222 | FWave.Assign(TWaveCollectionItem(Source).FWave); |
2662 | FWave.Assign(TWaveCollectionItem(Source).FWave); |
2223 | 2663 | ||
2224 | if PrevInitialized then |
2664 | if PrevInitialized then |
2225 | Restore; |
2665 | Restore; |
- | 2666 | end |
|
2226 | end else |
2667 | else |
2227 | inherited Assign(Source); |
2668 | inherited Assign(Source); |
2228 | end; |
2669 | end; |
2229 | 2670 | ||
- | 2671 | function TWaveCollectionItem.GetPlaying: boolean; |
|
- | 2672 | var |
|
- | 2673 | Buffer: TDirectSoundBuffer; |
|
- | 2674 | index: integer; |
|
- | 2675 | begin |
|
- | 2676 | Result := False; |
|
- | 2677 | if not FInitialized then Exit; |
|
- | 2678 | Assert(GetBuffer <> nil); |
|
- | 2679 | Assert(FBufferList <> nil); |
|
- | 2680 | if FLooped then |
|
- | 2681 | begin |
|
- | 2682 | Buffer := GetBuffer; |
|
- | 2683 | Assert(Buffer <> nil); |
|
- | 2684 | Result := Buffer.Playing; |
|
- | 2685 | end |
|
- | 2686 | else |
|
- | 2687 | begin |
|
- | 2688 | for index := 0 to FBufferList.Count - 1 do |
|
- | 2689 | begin |
|
- | 2690 | Result := TDirectSoundBuffer(FBufferList[index]).Playing; |
|
- | 2691 | if Result then |
|
- | 2692 | Break; |
|
- | 2693 | end; |
|
- | 2694 | end; |
|
- | 2695 | end; {GetPlaying} |
|
- | 2696 | ||
2230 | function TWaveCollectionItem.GetBuffer: TDirectSoundBuffer; |
2697 | function TWaveCollectionItem.GetBuffer: TDirectSoundBuffer; |
2231 | begin |
2698 | begin |
2232 | if FInitialized and (FBuffer=nil) then |
2699 | if FInitialized and (FBuffer = nil) then |
2233 | Restore; |
2700 | Restore; |
2234 | Result := FBuffer; |
2701 | Result := FBuffer; |
Line 2282... | Line 2749... | ||
2282 | if FLooped then |
2749 | if FLooped then |
2283 | begin |
2750 | begin |
2284 | GetBuffer.Stop; |
2751 | GetBuffer.Stop; |
2285 | GetBuffer.Position := 0; |
2752 | GetBuffer.Position := 0; |
2286 | GetBuffer.Play(True); |
2753 | GetBuffer.Play(True); |
- | 2754 | end |
|
2287 | end else |
2755 | else |
2288 | begin |
2756 | begin |
2289 | NewBuffer := nil; |
2757 | NewBuffer := nil; |
2290 | for i:=0 to FBufferList.Count-1 do |
2758 | for i := 0 to FBufferList.Count - 1 do |
2291 | if not TDirectSoundBuffer(FBufferList[i]).Playing then |
2759 | if not TDirectSoundBuffer(FBufferList[i]).Playing then |
2292 | begin |
2760 | begin |
Line 2300... | Line 2768... | ||
2300 | begin |
2768 | begin |
2301 | NewBuffer := CreateBuffer; |
2769 | NewBuffer := CreateBuffer; |
2302 | if NewBuffer=nil then Exit; |
2770 | if NewBuffer = nil then Exit; |
2303 | 2771 | ||
2304 | FBufferList.Add(NewBuffer); |
2772 | FBufferList.Add(NewBuffer); |
- | 2773 | end |
|
2305 | end else |
2774 | else |
2306 | begin |
2775 | begin |
2307 | if FBufferList.Count<FMaxPlayingCount then |
2776 | if FBufferList.Count < FMaxPlayingCount then |
2308 | begin |
2777 | begin |
2309 | NewBuffer := CreateBuffer; |
2778 | NewBuffer := CreateBuffer; |
2310 | if NewBuffer=nil then Exit; |
2779 | if NewBuffer = nil then Exit; |
2311 | 2780 | ||
2312 | FBufferList.Add(NewBuffer); |
2781 | FBufferList.Add(NewBuffer); |
- | 2782 | end |
|
2313 | end else |
2783 | else |
2314 | begin |
2784 | begin |
2315 | NewBuffer := FBufferList[0]; |
2785 | NewBuffer := FBufferList[0]; |
2316 | FBufferList.Move(0, FBufferList.Count-1); |
2786 | FBufferList.Move(0, FBufferList.Count - 1); |
2317 | end; |
2787 | end; |
2318 | end; |
2788 | end; |
Line 2590... | Line 3060... | ||
2590 | procedure TCustomDXWaveList.SetItems(Value: TWaveCollection); |
3060 | procedure TCustomDXWaveList.SetItems(Value: TWaveCollection); |
2591 | begin |
3061 | begin |
2592 | FItems.Assign(Value); |
3062 | FItems.Assign(Value); |
2593 | end; |
3063 | end; |
2594 | 3064 | ||
- | 3065 | {(c) 2006 Jaro Benes, Play midi from memory module} |
|
- | 3066 | ||
- | 3067 | { TMusicDataProp } |
|
- | 3068 | ||
- | 3069 | type |
|
- | 3070 | TMidiDataHeader = packed record |
|
- | 3071 | Size: Integer; |
|
- | 3072 | end; |
|
- | 3073 | ||
- | 3074 | procedure TMusicDataProp.DefineProperties(Filer: TFiler); |
|
- | 3075 | begin |
|
- | 3076 | inherited DefineProperties(Filer); |
|
- | 3077 | Filer.DefineBinaryProperty('Midi', ReadMidiData, WriteMidiData, Length(Self.FMusicData) <> 0); |
|
- | 3078 | end; |
|
- | 3079 | ||
- | 3080 | function TMusicDataProp.GetMusicData: string; |
|
- | 3081 | begin |
|
- | 3082 | SetLength(Result, Length(FMusicData)); |
|
- | 3083 | if Length(FMusicData) <> 0 then |
|
- | 3084 | Move(FMusicData[1], Result[1], Length(FMusicData)); |
|
- | 3085 | end; |
|
- | 3086 | ||
- | 3087 | procedure TMusicDataProp.ReadMidiData(Stream: TStream); |
|
- | 3088 | var |
|
- | 3089 | Header: TMidiDataHeader; |
|
- | 3090 | begin |
|
- | 3091 | Stream.ReadBuffer(Header, SizeOf(Header)); |
|
- | 3092 | SetLength(FMusicData, Header.Size); |
|
- | 3093 | Stream.ReadBuffer(FMusicData[1], Header.Size); |
|
- | 3094 | end; |
|
- | 3095 | ||
- | 3096 | procedure TMusicDataProp.SetMusicData(const Value: string); |
|
- | 3097 | begin |
|
- | 3098 | SetLength(FMusicData, Length(Value)); |
|
- | 3099 | if Length(Value) <> 0 then |
|
- | 3100 | Move(Value[1], FMusicData[1], Length(Value)); |
|
- | 3101 | end; |
|
- | 3102 | ||
- | 3103 | procedure TMusicDataProp.WriteMidiData(Stream: TStream); |
|
- | 3104 | var |
|
- | 3105 | Header: TMidiDataHeader; |
|
- | 3106 | begin |
|
- | 3107 | Header.Size := Length(FMusicData); |
|
- | 3108 | Stream.WriteBuffer(Header, SizeOf(Header)); |
|
- | 3109 | Stream.WriteBuffer(FMusicData[1], Header.Size); |
|
- | 3110 | end; |
|
- | 3111 | ||
- | 3112 | { TMusicListCollectionItem } |
|
- | 3113 | ||
- | 3114 | procedure TMusicListCollectionItem.Load; |
|
- | 3115 | var |
|
- | 3116 | MidiFilelength: Integer; |
|
- | 3117 | begin |
|
- | 3118 | // kdyby nahodou uz nejaky existoval tak ho znic |
|
- | 3119 | if FDirectMusicSegment <> nil then |
|
- | 3120 | FDirectMusicSegment := nil; |
|
- | 3121 | ZeroMemory(@FMusicObjDesc, SizeOf(TDMUS_OBJECTDESC)); |
|
- | 3122 | // tohle je popisek parametru - chceme hrat z pameti |
|
- | 3123 | with FMusicObjDesc do |
|
- | 3124 | begin |
|
- | 3125 | dwsize := SizeOf(TDMUS_OBJECTDESC); |
|
- | 3126 | guidclass := CLSID_DirectMusicSegment; |
|
- | 3127 | //tohle jen pokud je to ze souboru |
|
- | 3128 | //dwvaliddata := DMUS_OBJ_CLASS or DMUS_OBJ_FULLPATH or DMUS_OBJ_FILENAME; |
|
- | 3129 | dwvaliddata := DMUS_OBJ_CLASS or DMUS_OBJ_MEMORY or DMUS_OBJ_LOADED; |
|
- | 3130 | pbMemData := @FMusicDataProp.FMusicData[1]; |
|
- | 3131 | llMemLength := Length(FMusicDataProp.FMusicData); |
|
- | 3132 | end; |
|
- | 3133 | if FDirectMusicLoader.GetObject(FMusicObjDesc, IID_IDirectMusicSegment, FDirectMusicSegment) <> dm_ok then |
|
- | 3134 | raise EDXMusicError.Create('Failed to Get object for Direct music'); ; |
|
- | 3135 | if FDirectMusicSegment.setParam(GUID_StandardMidiFile, $FFFFFFFF, 0, 0, Pointer(FDirectMusicPerformance)) <> dm_ok then |
|
- | 3136 | raise EDXMusicError.Create('Failed to Set param for Direct music'); ; |
|
- | 3137 | if FDirectMusicSegment.setParam(GUID_Download, $FFFFFFFF, 0, 0, Pointer(FDirectMusicPerformance)) <> dm_ok then |
|
- | 3138 | raise EDXMusicError.Create('Failed to Set param for Direct music'); ; |
|
- | 3139 | FDirectMusicSegment.GetLength(MidiFilelength); |
|
- | 3140 | if (FActualDuration < MidiFilelength) and (FActualDuration > 0) then |
|
- | 3141 | FDirectMusicSegment.SetLength(FActualDuration); |
|
- | 3142 | if FActualStartPoint < MidiFilelength - FActualDuration then |
|
- | 3143 | FDirectMusicSegment.SetStartpoint(FActualStartPoint); |
|
- | 3144 | // jak opakovat |
|
- | 3145 | FDirectMusicSegment.Setrepeats(repeats - 1); |
|
- | 3146 | end; |
|
- | 3147 | ||
- | 3148 | constructor TMusicListCollectionItem.Create(Collection: TCollection); |
|
- | 3149 | begin |
|
- | 3150 | inherited Create(Collection); |
|
- | 3151 | CoInitialize(nil); |
|
- | 3152 | FMusicDataProp := TMusicDataProp.Create; |
|
- | 3153 | SetLength(FMusicDataProp.FMusicData, 0); |
|
- | 3154 | FDirectMusicPerformance := nil; |
|
- | 3155 | FDirectMusic := nil; |
|
- | 3156 | FDirectSound := nil; |
|
- | 3157 | FDirectMusicSegment := nil; |
|
- | 3158 | FDirectMusicLoader := nil; |
|
- | 3159 | FIsInitialized := False; |
|
- | 3160 | end; |
|
- | 3161 | ||
- | 3162 | procedure TMusicListCollectionItem.Stop; |
|
- | 3163 | begin |
|
- | 3164 | if FDirectMusicPerformance <> nil then |
|
- | 3165 | FDirectMusicPerformance.Stop(nil, nil, 0, 0); |
|
- | 3166 | end; |
|
- | 3167 | ||
- | 3168 | function TMusicListCollectionItem.GetDisplayName: string; |
|
- | 3169 | begin |
|
- | 3170 | Result := inherited GetDisplayName |
|
- | 3171 | end; |
|
- | 3172 | ||
- | 3173 | procedure TMusicListCollectionItem.Play; |
|
- | 3174 | begin |
|
- | 3175 | if not FIsInitialized then |
|
- | 3176 | Init; |
|
- | 3177 | Load; |
|
- | 3178 | if FDirectMusicPerformance <> nil then |
|
- | 3179 | FDirectMusicPerformance.PlaySegment(FDirectMusicSegment, 0, 0, @FDirectMusicSegmentState); |
|
- | 3180 | end; |
|
- | 3181 | ||
- | 3182 | function TMusicListCollectionItem.IsPlaying: Boolean; |
|
- | 3183 | begin |
|
- | 3184 | Result := False; |
|
- | 3185 | if FDirectMusicPerformance <> nil then |
|
- | 3186 | Result := FDirectMusicPerformance.IsPlaying(FDirectMusicSegment, FDirectMusicSegmentState) = DM_OK; |
|
- | 3187 | end; |
|
- | 3188 | ||
- | 3189 | destructor TMusicListCollectionItem.Destroy; |
|
- | 3190 | begin |
|
- | 3191 | FDirectMusicPerformance := nil; |
|
- | 3192 | FDirectMusic := nil; |
|
- | 3193 | FDirectSound := nil; |
|
- | 3194 | FDirectMusicSegment := nil; |
|
- | 3195 | FDirectMusicLoader := nil; |
|
- | 3196 | FMusicDataProp.Free; |
|
- | 3197 | CoUninitialize; |
|
- | 3198 | inherited Destroy; |
|
- | 3199 | end; |
|
- | 3200 | ||
- | 3201 | procedure TMusicListCollectionItem.SetRepeats(const Value: Cardinal); |
|
- | 3202 | begin |
|
- | 3203 | Frepeats := Value; |
|
- | 3204 | end; |
|
- | 3205 | ||
- | 3206 | procedure TMusicListCollectionItem.SetStartPoint(const Value: integer); |
|
- | 3207 | begin |
|
- | 3208 | FStartPoint := Value; |
|
- | 3209 | end; |
|
- | 3210 | ||
- | 3211 | procedure TMusicListCollectionItem.SetDuration(const Value: integer); |
|
- | 3212 | begin |
|
- | 3213 | FDuration := Value; |
|
- | 3214 | end; |
|
- | 3215 | ||
- | 3216 | procedure TMusicListCollectionItem.Init; |
|
- | 3217 | var OK: Boolean; |
|
- | 3218 | begin |
|
- | 3219 | FIsInitialized := False; |
|
- | 3220 | OK := False; |
|
- | 3221 | // vytvor FDirectMusicPerformance pokud uz neni vytvoreno |
|
- | 3222 | if FDirectMusicPerformance = nil then |
|
- | 3223 | OK := CoCreateInstance(CLSID_DirectMusicPerformance, nil, CLSCTX_INPROC, |
|
- | 3224 | IID_IDirectMusicperformance, FDirectMusicPerformance) = DM_OK; |
|
- | 3225 | if not OK then Exit; |
|
- | 3226 | if FDirectSound <> nil then |
|
- | 3227 | OK := FDirectMusicPerformance.Init({$IFDEF DX7}@{$ENDIF}FDirectMusic, FDirectSound, 0) = DM_OK |
|
- | 3228 | else |
|
- | 3229 | OK := FDirectMusicPerformance.Init({$IFDEF DX7}@{$ENDIF}FDirectMusic, nil, 0) = dm_OK; |
|
- | 3230 | if not OK then Exit; |
|
- | 3231 | // vychozi midi port |
|
- | 3232 | // pridej pokud neni nastaven |
|
- | 3233 | if FDirectMusicPerformance.Addport(nil) <> DM_OK then Exit; |
|
- | 3234 | // zkus vytvorit loader |
|
- | 3235 | OK := CoCreateInstance(CLSID_DirectMusicLoader, nil, CLSCTX_Inproc, |
|
- | 3236 | IID_IDirectMusicLoader, FDirectMusicLoader) = DM_OK; |
|
- | 3237 | FIsInitialized := OK; |
|
- | 3238 | end; |
|
- | 3239 | ||
- | 3240 | function TMusicListCollectionItem.GetMusicListCollection: TMusicListCollection; |
|
- | 3241 | begin |
|
- | 3242 | Result := Collection as TMusicListCollection; |
|
- | 3243 | end; |
|
- | 3244 | ||
- | 3245 | procedure TMusicListCollectionItem.SaveToFile(const MidiFileName: string); |
|
- | 3246 | var F: file; |
|
- | 3247 | begin |
|
- | 3248 | AssignFile(F, MidiFileName); |
|
- | 3249 | Rewrite(F, 1); |
|
- | 3250 | try |
|
- | 3251 | BlockWrite(F, FMusicDataProp.FMusicData[1], Length(FMusicDataProp.FMusicData)); |
|
- | 3252 | finally |
|
- | 3253 | CloseFile(F); |
|
- | 3254 | end; |
|
- | 3255 | end; |
|
- | 3256 | ||
- | 3257 | procedure TMusicListCollectionItem.LoadFromFile(const MidiFileName: string); |
|
- | 3258 | var F: file; S: string; I: Integer; |
|
- | 3259 | begin |
|
- | 3260 | AssignFile(F, MidiFileName); |
|
- | 3261 | Reset(F, 1); |
|
- | 3262 | try |
|
- | 3263 | SetLength(FMusicDataProp.FMusicData, FileSize(F)); |
|
- | 3264 | BlockRead(F, FMusicDataProp.FMusicData[1], FileSize(F)); |
|
- | 3265 | S := ExtractFileName(MidiFileName); |
|
- | 3266 | I := Pos(ExtractFileExt(S), S); |
|
- | 3267 | if I > 0 then S := Copy(S, 1, I - 1); |
|
- | 3268 | FMusicDataProp.Midiname := S; |
|
- | 3269 | finally |
|
- | 3270 | CloseFile(F); |
|
- | 3271 | end; |
|
- | 3272 | Name := ExtractFileName(MidiFileName); |
|
- | 3273 | end; |
|
- | 3274 | ||
- | 3275 | function TMusicListCollectionItem.Size: Integer; |
|
- | 3276 | begin |
|
- | 3277 | Result := Length(FMusicDataProp.FMusicData); |
|
- | 3278 | end; |
|
- | 3279 | ||
- | 3280 | { TMusicListCollection } |
|
- | 3281 | ||
- | 3282 | constructor TMusicListCollection.Create(AOwner: TComponent); |
|
- | 3283 | begin |
|
- | 3284 | inherited Create(TMusicListCollectionItem); |
|
- | 3285 | FOwner := AOwner; |
|
- | 3286 | end; |
|
- | 3287 | ||
- | 3288 | function TMusicListCollection.Add: TMusicListCollectionItem; |
|
- | 3289 | begin |
|
- | 3290 | Result := TMusicListCollectionItem(inherited Add); |
|
- | 3291 | Result.FDirectSound := Self.FDirectSound; |
|
- | 3292 | end; |
|
- | 3293 | ||
- | 3294 | function TMusicListCollection.GetItem(Index: Integer): TMusicListCollectionItem; |
|
- | 3295 | begin |
|
- | 3296 | Result := TMusicListCollectionItem(inherited GetItem(Index)); |
|
- | 3297 | end; |
|
- | 3298 | ||
- | 3299 | procedure TMusicListCollection.SetItem(Index: Integer; |
|
- | 3300 | Value: TMusicListCollectionItem); |
|
- | 3301 | begin |
|
- | 3302 | inherited SetItem(Index, Value); |
|
- | 3303 | end; |
|
- | 3304 | ||
- | 3305 | procedure TMusicListCollection.Update(Item: TCollectionItem); |
|
- | 3306 | begin |
|
- | 3307 | inherited Update(Item); |
|
- | 3308 | end; |
|
- | 3309 | ||
- | 3310 | function TMusicListCollection.Find( |
|
- | 3311 | const Name: string): TMusicListCollectionItem; |
|
- | 3312 | var |
|
- | 3313 | i: Integer; |
|
- | 3314 | begin |
|
- | 3315 | i := IndexOf(Name); |
|
- | 3316 | if i = -1 then |
|
- | 3317 | raise EDXMusicError.CreateFmt('The midi document does not exist: %s.', [Name]); |
|
- | 3318 | Result := Items[i]; |
|
- | 3319 | end; |
|
- | 3320 | ||
- | 3321 | {$IFDEF VER4UP} |
|
- | 3322 | function TMusicListCollection.Insert(Index: Integer): TMusicListCollectionItem; |
|
- | 3323 | begin |
|
- | 3324 | Result := TMusicListCollectionItem(inherited Insert(Index)); |
|
- | 3325 | end; |
|
- | 3326 | {$ENDIF} |
|
- | 3327 | ||
- | 3328 | function TMusicListCollection.GetOwner: TPersistent; |
|
- | 3329 | begin |
|
- | 3330 | Result := FOwner; |
|
- | 3331 | end; |
|
- | 3332 | ||
- | 3333 | procedure TMusicListCollection.Restore; |
|
- | 3334 | begin |
|
- | 3335 | ||
- | 3336 | end; |
|
- | 3337 | ||
- | 3338 | procedure TMusicListCollection.SaveToFile(const FileName: string); |
|
- | 3339 | var |
|
- | 3340 | Stream: TFileStream; |
|
- | 3341 | begin |
|
- | 3342 | Stream := TFileStream.Create(FileName, fmCreate); |
|
- | 3343 | try |
|
- | 3344 | SaveToStream(Stream); |
|
- | 3345 | finally |
|
- | 3346 | Stream.Free; |
|
- | 3347 | end; |
|
- | 3348 | end; |
|
- | 3349 | ||
- | 3350 | procedure TMusicListCollection.LoadFromFile(const FileName: string); |
|
- | 3351 | var |
|
- | 3352 | Stream: TFileStream; |
|
- | 3353 | begin |
|
- | 3354 | Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); |
|
- | 3355 | try |
|
- | 3356 | LoadFromStream(Stream); |
|
- | 3357 | finally |
|
- | 3358 | Stream.Free; |
|
- | 3359 | end; |
|
- | 3360 | end; |
|
- | 3361 | ||
- | 3362 | type |
|
- | 3363 | TMidiCollectionComponent = class(TComponent) |
|
- | 3364 | private |
|
- | 3365 | FList: TMusicListCollection; |
|
- | 3366 | published |
|
- | 3367 | property List: TMusicListCollection read FList write FList; |
|
- | 3368 | end; |
|
- | 3369 | ||
- | 3370 | procedure TMusicListCollection.SaveToStream(Stream: TStream); |
|
- | 3371 | var |
|
- | 3372 | Component: TMidiCollectionComponent; |
|
- | 3373 | begin |
|
- | 3374 | Component := TMidiCollectionComponent.Create(nil); |
|
- | 3375 | try |
|
- | 3376 | Component.FList := Self; |
|
- | 3377 | Stream.WriteComponentRes('DelphiXMidiCollection', Component); |
|
- | 3378 | finally |
|
- | 3379 | Component.Free; |
|
- | 3380 | end; |
|
- | 3381 | end; |
|
- | 3382 | ||
- | 3383 | procedure TMusicListCollection.LoadFromStream(Stream: TStream); |
|
- | 3384 | var |
|
- | 3385 | Component: TMidiCollectionComponent; |
|
- | 3386 | begin |
|
- | 3387 | Clear; |
|
- | 3388 | Component := TMidiCollectionComponent.Create(nil); |
|
- | 3389 | try |
|
- | 3390 | Component.FList := Self; |
|
- | 3391 | Stream.ReadComponentRes(Component); |
|
- | 3392 | Restore; |
|
- | 3393 | finally |
|
- | 3394 | Component.Free; |
|
- | 3395 | end; |
|
- | 3396 | end; |
|
- | 3397 | ||
- | 3398 | { TDXMusic } |
|
- | 3399 | ||
- | 3400 | constructor TDXMusic.Create(AOwner: TComponent); |
|
- | 3401 | begin |
|
- | 3402 | inherited Create(AOwner); |
|
- | 3403 | FMidis := TMusicListCollection.Create(Self); |
|
- | 3404 | if Assigned(FDXSound) then |
|
- | 3405 | FMidis.FDirectSound := FDXSound.DSound.IDSound; |
|
- | 3406 | end; |
|
- | 3407 | ||
- | 3408 | procedure TDXMusic.SetMidis(const value: TMusicListCollection); |
|
- | 3409 | begin |
|
- | 3410 | FMidis.Assign(Value); |
|
- | 3411 | end; |
|
- | 3412 | ||
- | 3413 | destructor TDXMusic.Destroy; |
|
- | 3414 | begin |
|
- | 3415 | FMidis.Free; |
|
- | 3416 | inherited Destroy; |
|
- | 3417 | end; |
|
- | 3418 | ||
- | 3419 | procedure TDXMusic.SetDXSound(const Value: TDXSound); |
|
- | 3420 | begin |
|
- | 3421 | FDXSound := Value; |
|
- | 3422 | if Assigned(FDXSound) then |
|
- | 3423 | FMidis.FDirectSound := FDXSound.DSound.IDSound; |
|
- | 3424 | end; |
|
- | 3425 | ||
2595 | initialization |
3426 | initialization |
2596 | finalization |
3427 | finalization |
2597 | DirectSoundDrivers.Free; |
3428 | DirectSoundDrivers.Free; |
2598 | DirectSoundCaptureDrivers.Free; |
3429 | DirectSoundCaptureDrivers.Free; |
2599 | end. |
3430 | end. |