?? mmwave.pas
字號:
{========================================================================}
{= (c) 1995-98 SwiftSoft Ronald Dittrich =}
{========================================================================}
{= All Rights Reserved =}
{========================================================================}
{= D 01099 Dresden = Fax.: +49(0)351-8037944 =}
{= Loewenstr.7a = info@swiftsoft.de =}
{========================================================================}
{= Actual versions on http://www.swiftsoft.de/index.html =}
{========================================================================}
{= This code is for reference purposes only and may not be copied or =}
{= distributed in any format electronic or otherwise except one copy =}
{= for backup purposes. =}
{= =}
{= No Delphi Component Kit or Component individually or in a collection=}
{= subclassed or otherwise from the code in this unit, or associated =}
{= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
{= without express permission from SwiftSoft. =}
{= =}
{= For more licence informations please refer to the associated =}
{= HelpFile. =}
{========================================================================}
{= $Date: 05.11.98 - 23:05:51 $ =}
{========================================================================}
unit MMWave;
{$I COMPILER.INC}
interface
uses
{$IFDEF WIN32}
Windows,
{$ELSE}
WinTypes,
WinProcs,
{$ENDIF}
SysUtils,
Messages,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
MMSystem,
MMUtils,
MMObj,
MMString,
MMObsrv,
MMDSPObj,
MMRegs,
MMRIFF,
MMWaveIO,
MMPCMSup,
MMFade,
MMPanel,
MMDIB,
MMCutLst;
type
EMMWaveError = class(Exception);
TMMPlayMode = (pmSync, pmAsync, pmLoop);
TMMWaveProgress = procedure(Sender: TObject; CurByte, NumBytes: Longint;
Var Cancel: Boolean) of Object;
{-- TMMWave ------------------------------------------------------------}
TMMWave = class(TMMObject)
private
FMemoryWave : TMemoryStream;
FPWaveIOCB : PWAVEIOCB;
FFileName : TFileName;
FFileMustExist: Boolean; { create new file or not }
FIOBufSize : Longint; { file IO buffersize }
FTimeFormat : TMMTimeFormats; { the actual time format for Position }
FStartPos : Longint;
FEndPos : Longint;
FPosition : Longint;
FBytesLeft : Longint;
FTotalBytes : Longint;
FCutList : TMMCutList;
FRegions : TMMCutList;
FCurRegion : integer;
FRegionLeft : Longint;
FOpen : Boolean;
FNoChange : Boolean;
FNeedChange : Boolean;
FPlayFadeList : TMMFadeList;
FIgnoreFades : Boolean;
FObservable : TMMObservable;
FOnProgress : TMMWaveProgress;
procedure SetDummy(aValue: Longint);
function GetEmpty: Boolean;
function GetFileSize: LongInt;
function GetDataSize: LongInt;
function GetDataOffset: Longint;
procedure SetFormatTag(aValue: Word);
function GetFormatTag: Word;
procedure SetFormatString(aValue: String);
function GetFormatString: String;
procedure SetBits(aValue: Word);
function GetBits: Word;
procedure SetMode(aValue: TMMMode);
function GetMode: TMMMode;
function GetSampleRate: Longint;
procedure SetFileMustExist(aValue: Boolean);
procedure SetTimeFormat(aValue: TMMTimeFormats);
procedure SetIOBufSize(aValue: Longint);
procedure SetStartPos(aPosition: Longint);
function GetStartPos: Longint;
procedure SetEndPos(aPosition: Longint);
function GetEndPos: Longint;
function GetPosition: Longint;
function GetBytesLeft: Longint;
function GetLength: Longint;
function GetLengthBytes: Longint;
function GetLengthSamples: Longint;
procedure SetPWaveFormat(lpwfx: PWaveFormatEx);
procedure SetPWaveIOCB(lpWaveIO: PWaveIOCB);
procedure FreeWaveIOCB(Var lpwio: PWAVEIOCB);
procedure ClearWave;
function GetStreamWaveIOCB(Stream: TMemoryStream; Var lpwio: PWAVEIOCB): Word;
function GetPWaveData: Pointer;
procedure SetIgnoreFades(aValue: Boolean);
protected
function ReadInternal(Buffer: PChar; NumBytes: Longint): Longint; virtual;
function GetPWaveFormat: PWaveFormatEx; virtual;
procedure SetPosition(aPosition: Longint); virtual;
function SamplesToBytes(Samples: Longint): Longint; virtual;
function BytesToSamples(Bytes: Longint): Longint; virtual;
function RealSamplesToSamples(aValue: Longint): Longint; virtual;
function SamplesToRealSamples(aValue: Longint): Longint; virtual;
function SamplesToTimeFormat(Samples: Longint): Longint; virtual;
function TimeFormatToSamples(aValue: Longint): Longint; virtual;
procedure SetCutList(aValue: TMMCutList); virtual;
procedure SetFileName(aValue: TFileName); virtual;
procedure Changed; override;
procedure DefineProperties(Filer: TFiler); override;
procedure ReadData(Stream: TStream); virtual;
procedure WriteData(Stream: TStream); virtual;
procedure InitPlayFadeList(Playing: Boolean); virtual;
property PlayFadeList: TMMFadeList read FPlayFadeList write FPlayFadeList;
public
{ internal use but must be public, don't touch this }
procedure Progress(CurByte, NumBytes: Longint; Var Cancel: Boolean); dynamic;
procedure InitRegionList;
property Regions: TMMCutList read FRegions;
property CutList: TMMCutList read FCutList write SetCutList;
procedure AddObserver(O: TMMObserver);
procedure RemoveObserver(O: TMMObserver);
constructor Create; virtual;
destructor Destroy; override;
function IsMemWave: Boolean;
procedure Assign(Source: TPersistent); override;
procedure FreeWave;
function PlaySound(aValue: TMMPlayMode): Boolean;
procedure StopSound;
procedure LoadFromStream(Stream: TStream); virtual;
procedure SaveToStream(Stream: TStream); virtual;
procedure LoadFromFile(const FileName: TFileName);
procedure SaveToFile(const Filename: TFileName);
procedure ImportFromRaw(const FileName: TFileName; BitLength,
Channels, SampleRate: Cardinal);
property IsOpen: Boolean read FOpen;
procedure OpenFile; virtual;
procedure CloseFile; virtual;
procedure ResetFile; virtual;
procedure CreateFile(const FileName: TFileName; pwfx: PWaveFormatEx);
{$IFDEF BCB}
procedure CreateFileC(const FileName: TFileName; pwfx: PWaveFormatEx);
{$ENDIF}
procedure ConvertFile(const FileName: TFileName; pwfxDst: PWaveFormatEx);
function GetInfoChunk(fcc: String): String;
procedure SetInfoChunk(fcc, Text: String);
procedure SetDispChunk(Text: string; aBitmap: TBitmap);
function ReadDataBytes(Buffer: PChar; NumBytes: Longint): Longint;
function ReadDataSamples(Buffer: PChar; NumSamples: Longint): Longint;
function WriteDataBytes(Buffer: PChar; NumBytes: Longint): Longint;
function WriteDataSamples(Buffer: PChar; NumSamples: Longint): Longint;
property StartPos: Longint read GetStartPos write SetStartPos;
property EndPos: Longint read GetEndPos write SetEndPos;
property Position: Longint read GetPosition write SetPosition;
property Length: Longint read GetLength;
property LengthBytes: Longint read GetLengthBytes;
property LengthSamples: Longint read GetLengthSamples;
property Empty: Boolean read GetEmpty;
property PWaveFormat: PWaveFormatEx read GetPWaveFormat write SetPWaveFormat;
property PWaveIOInfo: PWaveIOCB read FPWAVEIOCB write SetPWaveIOCB;
property PWaveData: Pointer read GetPWaveData;
property BytesLeft: Longint read GetBytesLeft;
property DataOffset: Longint read GetDataOffset;
property IgnoreFades: Boolean read FIgnoreFades write SetIgnoreFades default False;
published
property OnProgress: TMMWaveProgress read FOnProgress write FOnProgress;
property TimeFormat: TMMTimeFormats read FTimeFormat write SetTimeFormat default tfSample;
property FileMustExist: Boolean read FFileMustExist write SetFileMustExist default True; { must come before FileName ! }
property FileName: TFileName read FFileName write SetFileName;
property BitLength: Word read GetBits write SetBits stored False;
property Mode: TMMMode read GetMode write SetMode stored False;
property FormatTag: Word read GetFormatTag write SetFormatTag stored False;
property FormatString: String read GetFormatString write SetFormatString stored False;
property SampleRate: Longint read GetSampleRate write SetDummy stored False;
property FileSize: LongInt read GetFileSize write SetDummy stored False;
property DataSize: Longint read GetDataSize write SetDummy stored False;
property IOBufferSize: Longint read FIOBufSize write SetIOBufSize default 32768;
end;
{-- TMMCustomWaveFile --------------------------------------------------}
TMMCustomWaveFile = class(TMMDSPComponent)
private
FWave : TMMWave;
FOldStart : Longint;
FSilence : SmallInt; { silence value 0 or 128 }
FEnabled : Boolean;
FOpen : Boolean;
FStarted : Boolean;
FOverwrite : Boolean;
FObserver : TMMObserver;
FOnOpen : TNotifyEvent; { wave succ openend }
FOnClose : TNotifyEvent; { wave succ closed (disk full ?) }
FOnChange : TNotifyEvent;
FOnChanged : TNotifyEvent;
FOnLooping : TNotifyEvent; { Wave was at end and is looped }
procedure SetWave(aValue: TMMWave);
procedure WaveChanged(Sender, Data: TObject);
protected
procedure SetWaveEx(aValue: TMMWave);
procedure DoChanged; dynamic;
procedure DoOpen; dynamic;
procedure DoClose; dynamic;
procedure SetPWaveFormat(aValue: PWaveFormatEx); override;
public
procedure Opened; override;
procedure Closed; override;
procedure Reseting; override;
procedure Started; override;
procedure Stopped; override;
procedure BufferReady(lpwh: PWaveHdr); override;
procedure BufferLoad(lpwh: PWaveHdr; var MoreBuffers: Boolean); override;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure LoadFromFile(const FileName: String);
procedure SaveToFile(const FileName: String);
function PlaySound(aValue: TMMPlayMode): Boolean;
procedure StopSound;
protected
property OnOpen: TNotifyEvent read FOnOpen write FOnOpen;
property OnClose: TNotifyEvent read FOnClose write FOnClose;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanged: TNotifyEvent read FonChanged write FOnChanged;
property OnLooping: TNotifyEvent read FOnLooping write FOnLooping;
property Enabled: Boolean read FEnabled write FEnabled default True;
property OverwriteExisting: Boolean read FOverwrite write FOverwrite default True;
published
property Wave: TMMWave read FWave write SetWave;
end;
{-- TMMWaveFile --------------------------------------------------------}
TMMWaveFile = class(TMMCustomWaveFile)
published
property OnOpen;
property OnClose;
property OnChange;
property OnChanged;
property OnLooping;
property Input;
property Output;
property Enabled;
property OverwriteExisting;
end;
{-- TMMCustomMemoryWave ------------------------------------------------}
TMMCustomMemoryWave = class(TMMCustomWaveFile)
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
{-- TMMMemoryWave ------------------------------------------------------}
TMMMemoryWave = class(TMMCustomMemoryWave)
published
property OnOpen;
property OnClose;
property OnChange;
property OnChanged;
property OnLooping;
property Output;
property Enabled;
end;
{ TODO: ableiten von TMMCustomMarkerPanel und verschiedene Eigenschaften ver鰂fentlichen }
{-- TMMCustomWaveEditor ------------------------------------------------}
TMMCustomWaveEditor = class(TMMMarkerPanel)
protected
function GetWave: TMMWave; virtual; abstract;
public
property Wave: TMMWave read GetWave;
end;
implementation
{== TMMWave ==============================================================}
constructor TMMWave.Create;
begin
inherited Create;
FMemoryWave := nil;
FPWaveIOCB := nil;
FFileName := '';
FFileMustExist:= True;
FTimeFormat := tfSample;
FIOBufSize := 32768;
FStartPos := 0;
FEndPos := 0;
FPosition := 0;
FBytesLeft := 0;
FTotalBytes := 0;
FOpen := False;
FNoChange := False;
FNeedChange := False;
FCutList := nil;
FPlayFadeList:= nil;
FIgnoreFades := False;
FRegions := TMMCutList.Create;
FObservable := TMMObservable.Create;
end;
{-- TMMWave --------------------------------------------------------------}
Destructor TMMWave.Destroy;
begin
{ free the wave }
ClearWave;
FRegions.Free;
if (FPlayFadeList <> nil) then FPlayFadeList.Free;
FObservable.Free;
FObservable:= nil;
inherited Destroy;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.AddObserver(O: TMMObserver);
begin
FObservable.AddObserver(O);
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.RemoveObserver(O: TMMObserver);
begin
if (FObservable <> nil) then
FObservable.RemoveObserver(O);
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetCutList(aValue: TMMCutList);
begin
FCutList := aValue;
InitRegionList;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.InitRegionList;
var
Region: TMMCutRegion;
i: integer;
SPos,EPos,Start, Length: Longint;
begin
FRegions.Clear;
if (PWaveFormat = nil) then exit;
SPos := RealSamplesToSamples(FStartPos);
EPos := RealSamplesToSamples(FEndPos);
Region.dwLoops := 0;
if (FCutList <> nil) and (FCutList.Count > 0) then
begin
i := 0;
while (i < FCutList.Count) and
(FCutList[i].dwStartPos+FCutList[i].dwLength < SPos) do inc(i);
if (i >= FCutList.Count) or (SPos < FCutList[i].dwStartPos) then
Start := SPos
else
Start := Max(SPos, FCutList[i].dwStartPos+FCutList[i].dwLength);
while i <= FCutList.Count do
begin
if (i < FCutList.Count) and (EPos > FCutList[i].dwStartPos) then
Length := FCutList[i].dwStartPos-Start
else
begin
if (i >= FCutList.Count) or (EPos < FCutList[i].dwStartPos) then
Length := EPos-Start
else
Length := FCutList[i].dwStartPos-Start;
i := FCutList.Count;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -