Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[xestiaab/.git] / source / contacteditor / frmContactEditor-Sound.cpp
index 45305b5..369238c 100644 (file)
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
 
 #include "frmContactEditor.h"
-#include "frmContactEditorSound.h"
-#include "../common/base64.h"
-#include <SFML/Audio.hpp>
-#include <thread>
 
 void frmContactEditor::AddSound( wxCommandEvent& event )
 {
 
        // Bring up a form to add sound.
-       
-       int intResult = 0;
-    
+           
        frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
        frameCESound->SetEditorMode(FALSE);
-       intResult = GetLastInt(&ContactEditorData.SoundsList);
        frameCESound->SetupPointers(&ContactEditorData.SoundsList,
                &ContactEditorData.SoundsListAltID,
                 &ContactEditorData.SoundsListPID,
@@ -57,7 +50,7 @@ void frmContactEditor::ModifySound( wxCommandEvent& event )
        long longSelected = -1;
        int intSelectedData = 0;
     
-       if (!GetSelectedItem(lboSounds,
+       if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
                &longSelected,
                 &intSelectedData)){
                return;
@@ -90,7 +83,7 @@ void frmContactEditor::DeleteSound( wxCommandEvent& event )
        long longSelected = -1;
        int intSelectedData = 0;
     
-       if (!GetSelectedItem(lboSounds,
+       if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
                &longSelected,
                &intSelectedData)){
                return;
@@ -110,7 +103,7 @@ void frmContactEditor::PlaySoundDetach()
     
        // Play the sound and detach.
        
-       if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
+       if (!AudioStreamPlaybackPointer->openFromMemory(base64dec.c_str(), base64declen)){
         
                // Can't load file. We must flee...
                // Also show an error message too.
@@ -122,25 +115,19 @@ void frmContactEditor::PlaySoundDetach()
        }
     
        btnStop->Enable();
+
+       AudioStreamPlaybackPointer->play();
     
-       //AudioStreamPlayback.setbuffer(AudioBuffer);
-       AudioStreamPlayback.play();
-    
-       /*timespec n1, n2;
-     
-       n1.tv_sec = 0;
-       n1.tv_nsec = 100000000L;*/
-    
-       //while (TimeA != TimeB){
-       while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
+       while (AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){
         
                // We poll this every 100ms in order to conserve CPU usage.
         
-               SleepFor(100000000);
+               SleepFor(10000000);
         
        }
-    
+       
        btnStop->Disable();
+       btnPlay->Enable();
     
 }
 
@@ -148,42 +135,32 @@ void frmContactEditor::PlaySound( wxCommandEvent& event )
 {
     
        // Play the sound.
-       
-       //sf::Music *AudioPlayback = new sf::Music;
-       //AudioStream *AudioStreamPlayback = new AudioStream;
-       //sf::SoundBuffer *AudioBuffer = new sf::SoundBuffer;
-    
-       //sf::Sound *AudioPlayback = new sf::Sound;
-    
-       //delete(AudioPlayback);
-    
-       //delete(AudioPlayback);
-       //delete(AudioStreamPlayback);
-       //delete(AudioBuffer);
-    
-       //AudioPlayback = NULL;
-       //AudioStreamPlayback = NULL;
-       //AudioBuffer = NULL;
-    
-       //return;
     
        long longSelected = -1;
        int intSelectedData = 0;
     
+       if (AudioStreamPlaybackPointer == nullptr){
+               
+               AudioStreamPlaybackPointer = new AudioStream;
+               
+       }
+       
        // Check if sound is still being played and if it is, stop it.
     
-       if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
+       if (AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){
         
-               AudioStreamPlayback.stop();
+               AudioStreamPlaybackPointer->stop();
         
        }
     
-       if (!GetSelectedItem(lboSounds,
+       if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
                &longSelected,
                &intSelectedData)){
                return;
        }
-    
+
+       btnPlay->Disable();
+       
        std::map<int, std::string>::iterator initier;
     
        initier = ContactEditorData.SoundsList.find(intSelectedData);
@@ -202,14 +179,15 @@ void frmContactEditor::StopSound( wxCommandEvent& event )
 {
        
        // Stop the sound.
-    
-       if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
-        
-               AudioStreamPlayback.stop();
+       
+       if (AudioStreamPlaybackPointer != nullptr && AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){
         
+               AudioStreamPlaybackPointer->stop();
+               
        }
     
        btnStop->Disable();
+       btnPlay->Enable();
 
        return;
     
@@ -223,7 +201,7 @@ void frmContactEditor::SaveSound( wxCommandEvent &event )
        long longSelected = -1;
        int intSelectedData = 0;
     
-       if (!GetSelectedItem(lboSounds,
+       if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
                          &longSelected,
                          &intSelectedData)){
                
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy