X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_addresource_sound.pas;h=eaba574aa61e2d71e0f8621e5f3b0842d3442301;hb=4cd27745126226e5e57a02f4c2a44ccbab16bbac;hp=4efa9878cc1be4d8c082dd6f64beb944b94a6131;hpb=b72e164f0fb64e3301ae8ca217449daf6a9d301d;p=d2df-editor.git diff --git a/src/editor/f_addresource_sound.pas b/src/editor/f_addresource_sound.pas index 4efa987..eaba574 100644 --- a/src/editor/f_addresource_sound.pas +++ b/src/editor/f_addresource_sound.pas @@ -1,13 +1,13 @@ unit f_addresource_sound; -{$MODE Delphi} +{$INCLUDE ../shared/a_modes.inc} interface uses LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, f_addresource, - ExtCtrls, StdCtrls, spectrum, Buttons, ComCtrls; + ExtCtrls, StdCtrls, spectrum, Buttons, ComCtrls, utils; type TAddSoundForm = class (TAddResourceForm) @@ -30,8 +30,10 @@ type private FSpectrum: TMiniSpectrum; FSetResource: String; + FSoundEnabled: Boolean; procedure ShowSpectrum(); + function CreateSoundWAD(Resource: String): Boolean; public property SetResource: String read FSetResource write FSetResource; @@ -43,11 +45,24 @@ var implementation uses - BinEditor, fmod, fmodtypes, fmoderrors, WADEDITOR, e_log, f_main, - g_language; + BinEditor, WADEDITOR, e_log, f_main, g_language +{$IFNDEF NOSOUND}, fmod, fmodtypes, fmoderrors;{$ELSE};{$ENDIF} {$R *.lfm} +{$IFDEF NOSOUND} +// fuck my life +const + FMOD_OK = 0; + +type + FMOD_SYSTEM = Pointer; + FMOD_CHANNEL = Pointer; + FMOD_SOUND = Pointer; + FMOD_CREATESOUNDEXINFO = Pointer; + FMOD_RESULT = Integer; +{$ENDIF} + var F_System: FMOD_SYSTEM; SoundData: Pointer = nil; @@ -64,7 +79,9 @@ begin Inherited; res := FMOD_OK; + FSoundEnabled := False; +{$IFNDEF NOSOUND} try res := FMOD_System_Create(F_System); if res <> FMOD_OK then @@ -90,10 +107,11 @@ begin if res <> FMOD_OK then raise Exception.Create('FMOD_System_Init failed!'); + FSoundEnabled := True; except - Application.MessageBox(FMOD_ErrorString(res), 'Initialization', MB_OK or MB_ICONHAND); - raise; + Application.MessageBox(PChar('Sound was disabled. Reason: ' + FMOD_ErrorString(res)), 'FMOD Error', MB_OK or MB_ICONWARNING); end; +{$ENDIF} FSpectrum := TMiniSpectrum.Create(pSpectrum); FSpectrum.Align := alClient; @@ -101,35 +119,39 @@ begin FSpectrum.Style := ssBlock; end; -function CreateSoundWAD(Resource: String): Boolean; +function TAddSoundForm.CreateSoundWAD(Resource: String): Boolean; var WAD: TWADEditor_1; FileName, SectionName, ResourceName: String; - ResLength, sz: Integer; + ResLength: Integer; + sz: LongWord; soundExInfo: FMOD_CREATESOUNDEXINFO; res: FMOD_RESULT; begin Result := False; - SoundData := nil; Sound := nil; Channel := nil; - + + if FSoundEnabled = False then + Exit; + +{$IFNDEF NOSOUND} g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName); WAD := TWADEditor_1.Create; WAD.ReadFile(FileName); - if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then + if WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), SoundData, ResLength) then begin sz := SizeOf(FMOD_CREATESOUNDEXINFO); FillMemory(@soundExInfo, sz, 0); soundExInfo.cbsize := sz; - soundExInfo.length := ResLength; + soundExInfo.length := LongWord(ResLength); res := FMOD_System_CreateStream(F_System, SoundData, - FMOD_LOOP_OFF + FMOD_2D + FMOD_SOFTWARE + FMOD_OPENMEMORY, + FMOD_LOOP_OFF or FMOD_2D or FMOD_OPENMEMORY, @soundExInfo, Sound); if res <> FMOD_OK then @@ -150,6 +172,7 @@ begin WAD.Free(); Result := True; +{$ENDIF} end; procedure TAddSoundForm.bbPlayClick(Sender: TObject); @@ -164,15 +187,19 @@ begin if Playing then bbStop.Click(); + if FSoundEnabled = False then + Exit; + if not CreateSoundWAD(FFullResourceName) then Exit; +{$IFNDEF NOSOUND} res := FMOD_System_PlaySound(F_System, FMOD_CHANNEL_FREE, Sound, False, Channel); if res <> FMOD_OK then begin Application.MessageBox(FMOD_ErrorString(res), - PChar(_lc[I_MSG_SOUND_ERROR]), + PChar(MsgMsgSoundError), MB_OK or MB_ICONHAND); Exit; end; @@ -182,6 +209,7 @@ begin FMOD_Channel_SetVolume(Channel, 1.0); FSpectrum.SetChannel(Channel); +{$ENDIF} end; end; @@ -199,6 +227,10 @@ var begin Inherited; + if FSoundEnabled = False then + Exit; + +{$IFNDEF NOSOUND} FMOD_System_Update(F_System); ShowSpectrum(); @@ -206,6 +238,7 @@ begin res := FMOD_Channel_IsPlaying(Channel, b); if (res <> FMOD_OK) or (not b) then bbStop.Click(); +{$ENDIF} end; procedure TAddSoundForm.FormDestroy(Sender: TObject); @@ -217,6 +250,10 @@ begin FSpectrum.Free; + if FSoundEnabled = False then + Exit; + +{$IFNDEF NOSOUND} res := FMOD_System_Close(F_System); if res <> FMOD_OK then begin @@ -231,18 +268,19 @@ begin e_WriteLog('Error releasing FMOD system!', MSG_FATALERROR); e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR); end; +{$ENDIF} end; procedure Sound_StopRelease(); begin Playing := False; - +{$IFNDEF NOSOUND} if Channel <> nil then FMOD_Channel_Stop(Channel); if Sound <> nil then FMOD_Sound_Release(Sound); - +{$ENDIF} if SoundData <> nil then FreeMem(SoundData); @@ -286,7 +324,7 @@ begin g_ProcessResourceStr(FSetResource, FileName, SectionName, ResourceName); if FileName = '' then - FileName := _lc[I_WAD_SPECIAL_MAP]; + FileName := MsgWadSpecialMap; if SectionName = '' then SectionName := '..';