DEADSOFTWARE

sound: fix build
[d2df-editor.git] / src / editor / f_addresource_sound.pas
index 55508f0b724985ba0f52b0527e7fe51a81685d1d..a3d3fe15c415323c647e899b4f695c81f443f369 100644 (file)
@@ -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,7 +45,7 @@ var
 implementation
 
 uses
-  BinEditor, WADEDITOR, e_log, f_main, g_language
+  BinEditor, WADEDITOR, e_log, f_main, g_language, g_resources
 {$IFNDEF NOSOUND}, fmod, fmodtypes, fmoderrors;{$ELSE};{$ENDIF}
 
 {$R *.lfm}
@@ -77,6 +79,7 @@ begin
   Inherited;
 
   res := FMOD_OK;
+  FSoundEnabled := False;
 
 {$IFNDEF NOSOUND}
   try
@@ -104,9 +107,9 @@ 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}
 
@@ -116,9 +119,8 @@ 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: Integer;
   sz: LongWord;
@@ -130,13 +132,15 @@ begin
   SoundData := nil;
   Sound := nil;
   Channel := nil;
+
+  if FSoundEnabled = False then
+    Exit;
+
 {$IFNDEF NOSOUND}
   g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
+  g_ReadResource(FileName, SectionName, ResourceName, SoundData, ResLength);
 
-  WAD := TWADEditor_1.Create;
-  WAD.ReadFile(FileName);
-
-  if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then
+  if SoundData <> nil then
     begin
       sz := SizeOf(FMOD_CREATESOUNDEXINFO);
       FillMemory(@soundExInfo, sz, 0);
@@ -151,19 +155,16 @@ begin
       begin
         e_WriteLog(Format('Error creating sound %s', [Resource]), MSG_WARNING);
         e_WriteLog(FMOD_ErrorString(res), MSG_WARNING);
-        WAD.Free();
         Exit;
       end;
     end
   else
     begin
       e_WriteLog(Format('Error loading sound %s', [Resource]), MSG_WARNING);
-      e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
-      WAD.Free();
+      //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
       Exit;
     end;
  
-  WAD.Free();
   Result := True;
 {$ENDIF}
 end;
@@ -180,15 +181,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;
@@ -215,6 +220,10 @@ var
 
 begin
   Inherited;
+
+  if FSoundEnabled = False then
+    Exit;
+
 {$IFNDEF NOSOUND}
   FMOD_System_Update(F_System);
   
@@ -234,6 +243,10 @@ begin
   Inherited;
 
   FSpectrum.Free;
+
+  if FSoundEnabled = False then
+    Exit;
+
 {$IFNDEF NOSOUND}
   res := FMOD_System_Close(F_System);
   if res <> FMOD_OK then
@@ -305,13 +318,13 @@ begin
     g_ProcessResourceStr(FSetResource, FileName, SectionName, ResourceName);
 
     if FileName = '' then
-      FileName := _lc[I_WAD_SPECIAL_MAP];
+      FileName := MsgWadSpecialMap;
 
     if SectionName = '' then
       SectionName := '..';
 
   // WAD файл:
-    a := cbWADList.Items.IndexOf(win2utf(FileName));
+    a := cbWADList.Items.IndexOf(FileName);
     if a <> -1 then
     begin
       cbWADList.ItemIndex := a;
@@ -319,7 +332,7 @@ begin
     end;
 
   // Секция:
-    a := cbSectionsList.Items.IndexOf(win2utf(SectionName));
+    a := cbSectionsList.Items.IndexOf(SectionName);
     if a <> -1 then
     begin
       cbSectionsList.ItemIndex := a;
@@ -327,7 +340,7 @@ begin
     end;
 
   // Ресурс:
-    a := lbResourcesList.Items.IndexOf(win2utf(ResourceName));
+    a := lbResourcesList.Items.IndexOf(ResourceName);
     if a <> -1 then
     begin
       lbResourcesList.ItemIndex := a;