X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fcontacteditor%2FfrmContactEditor-Sound.cpp;h=369238c227882c8ea1973bae2151d21fd17255c9;hb=074e2db3331d35762f1d2dcf06d98f15200fc225;hp=f6b6643abc50c2844edd87d669d3e9327ee3a42d;hpb=afac9861ea075bd0c0bd0f5724c104466b96fb3d;p=xestiaab%2F.git diff --git a/source/contacteditor/frmContactEditor-Sound.cpp b/source/contacteditor/frmContactEditor-Sound.cpp index f6b6643..369238c 100644 --- a/source/contacteditor/frmContactEditor-Sound.cpp +++ b/source/contacteditor/frmContactEditor-Sound.cpp @@ -17,194 +17,191 @@ // with Xestia Address Book. If not, see #include "frmContactEditor.h" -#include "frmContactEditorSound.h" -#include "../common/base64.h" -#include -#include void frmContactEditor::AddSound( wxCommandEvent& event ) { - int intResult = 0; - - frmContactEditorSound *frameCESound = new frmContactEditorSound ( this ); - frameCESound->SetEditorMode(FALSE); - intResult = GetLastInt(&ContactEditorData.SoundsList); - frameCESound->SetupPointers(&ContactEditorData.SoundsList, - &ContactEditorData.SoundsListAltID, - &ContactEditorData.SoundsListPID, - &ContactEditorData.SoundsListType, - &ContactEditorData.SoundsListAudioType, - &ContactEditorData.SoundsListAudioEncType, - &ContactEditorData.SoundsListTokens, - &ContactEditorData.SoundsListMediatype, - &ContactEditorData.SoundsListPref, - lboSounds, - (intValueSeek)); - frameCESound->ShowModal(); - delete frameCESound; - frameCESound = NULL; + + // Bring up a form to add sound. + + frmContactEditorSound *frameCESound = new frmContactEditorSound ( this ); + frameCESound->SetEditorMode(FALSE); + frameCESound->SetupPointers(&ContactEditorData.SoundsList, + &ContactEditorData.SoundsListAltID, + &ContactEditorData.SoundsListPID, + &ContactEditorData.SoundsListType, + &ContactEditorData.SoundsListAudioType, + &ContactEditorData.SoundsListAudioEncType, + &ContactEditorData.SoundsListTokens, + &ContactEditorData.SoundsListMediatype, + &ContactEditorData.SoundsListPref, + lboSounds, + (intValueSeek)); + frameCESound->ShowModal(); + delete frameCESound; + frameCESound = NULL; + } void frmContactEditor::ModifySound( wxCommandEvent& event ) { - long longSelected = -1; - int intSelectedData = 0; + + // Bring up a form to modify sound. + + long longSelected = -1; + int intSelectedData = 0; - if (!GetSelectedItem(lboSounds, - &longSelected, - &intSelectedData)){ - return; - } + if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds, + &longSelected, + &intSelectedData)){ + return; + } - frmContactEditorSound *frameCESound = new frmContactEditorSound ( this ); - frameCESound->SetupPointers(&ContactEditorData.SoundsList, - &ContactEditorData.SoundsListAltID, - &ContactEditorData.SoundsListPID, - &ContactEditorData.SoundsListType, - &ContactEditorData.SoundsListAudioType, - &ContactEditorData.SoundsListAudioEncType, - &ContactEditorData.SoundsListTokens, - &ContactEditorData.SoundsListMediatype, - &ContactEditorData.SoundsListPref, - lboSounds, - intSelectedData); - frameCESound->SetEditorMode(TRUE); - frameCESound->ShowModal(); - delete frameCESound; - frameCESound = NULL; + frmContactEditorSound *frameCESound = new frmContactEditorSound ( this ); + frameCESound->SetupPointers(&ContactEditorData.SoundsList, + &ContactEditorData.SoundsListAltID, + &ContactEditorData.SoundsListPID, + &ContactEditorData.SoundsListType, + &ContactEditorData.SoundsListAudioType, + &ContactEditorData.SoundsListAudioEncType, + &ContactEditorData.SoundsListTokens, + &ContactEditorData.SoundsListMediatype, + &ContactEditorData.SoundsListPref, + lboSounds, + intSelectedData); + frameCESound->SetEditorMode(TRUE); + frameCESound->ShowModal(); + delete frameCESound; + frameCESound = NULL; + } void frmContactEditor::DeleteSound( wxCommandEvent& event ) { - long longSelected = -1; - int intSelectedData = 0; - - if (!GetSelectedItem(lboSounds, - &longSelected, - &intSelectedData)){ - return; - } + + // Bring up a form to delete sound. + + long longSelected = -1; + int intSelectedData = 0; - lboSounds->DeleteItem(longSelected); + if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds, + &longSelected, + &intSelectedData)){ + return; + } - DeleteMapData(intSelectedData, &ContactEditorData.SoundsList, &ContactEditorData.SoundsListAltID, - &ContactEditorData.SoundsListPID, &ContactEditorData.SoundsListType, &ContactEditorData.SoundsListAudioType, - &ContactEditorData.SoundsListAudioEncType, &ContactEditorData.SoundsListTokens, &ContactEditorData.SoundsListMediatype, - &ContactEditorData.SoundsListPref); + lboSounds->DeleteItem(longSelected); + DeleteMapData(intSelectedData, &ContactEditorData.SoundsList, &ContactEditorData.SoundsListAltID, + &ContactEditorData.SoundsListPID, &ContactEditorData.SoundsListType, &ContactEditorData.SoundsListAudioType, + &ContactEditorData.SoundsListAudioEncType, &ContactEditorData.SoundsListTokens, &ContactEditorData.SoundsListMediatype, + &ContactEditorData.SoundsListPref); + } void frmContactEditor::PlaySoundDetach() { - if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){ + // Play the sound and detach. + + if (!AudioStreamPlaybackPointer->openFromMemory(base64dec.c_str(), base64declen)){ - // Can't load file. We must flee... - // Also show an error message too. + // Can't load file. We must flee... + // Also show an error message too. - wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR); + wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR); - return; + return; - } - - btnStop->Enable(); - - //AudioStreamPlayback.setbuffer(AudioBuffer); - AudioStreamPlayback.play(); + } - /*timespec n1, n2; - - n1.tv_sec = 0; - n1.tv_nsec = 100000000L;*/ + btnStop->Enable(); + + AudioStreamPlaybackPointer->play(); - //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. + // We poll this every 100ms in order to conserve CPU usage. - SleepFor(100000000); + SleepFor(10000000); - } - - btnStop->Disable(); + } + + btnStop->Disable(); + btnPlay->Enable(); } void frmContactEditor::PlaySound( wxCommandEvent& event ) { - //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); + // Play the sound. - //AudioPlayback = NULL; - //AudioStreamPlayback = NULL; - //AudioBuffer = NULL; - - //return; - - long longSelected = -1; - int intSelectedData = 0; + long longSelected = -1; + int intSelectedData = 0; - // Check if sound is still being played and if it is, stop it. + 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, - &longSelected, - &intSelectedData)){ - return; - } + } - std::map::iterator initier; + if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds, + &longSelected, + &intSelectedData)){ + return; + } + + btnPlay->Disable(); + + std::map::iterator initier; - initier = ContactEditorData.SoundsList.find(intSelectedData); + initier = ContactEditorData.SoundsList.find(intSelectedData); - base64dec = base64_decode(initier->second); - base64declen = base64dec.size(); + base64dec = base64_decode(initier->second); + base64declen = base64dec.size(); - std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this); - AudioPlaybackThread.detach(); + std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this); + AudioPlaybackThread.detach(); - return; + return; } void frmContactEditor::StopSound( wxCommandEvent& event ) { - - if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){ - - AudioStreamPlayback.stop(); + + // Stop the sound. + + if (AudioStreamPlaybackPointer != nullptr && AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){ - } - - btnStop->Disable(); + AudioStreamPlaybackPointer->stop(); + + } - return; + btnStop->Disable(); + btnPlay->Enable(); + + return; } void frmContactEditor::SaveSound( wxCommandEvent &event ) { + // Save the sound. + long longSelected = -1; int intSelectedData = 0; - if (!GetSelectedItem(lboSounds, + if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds, &longSelected, &intSelectedData)){