1 // frmContactEditor-Sound.cpp - frmContactEditor Sound tab subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditor.h"
20 #include "frmContactEditorSound.h"
21 #include "../common/base64.h"
22 #include <SFML/Audio.hpp>
25 void frmContactEditor::AddSound( wxCommandEvent& event )
29 frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
30 frameCESound->SetEditorMode(FALSE);
31 intResult = GetLastInt(&SoundsList);
32 frameCESound->SetupPointers(&SoundsList,
37 &SoundsListAudioEncType,
43 frameCESound->ShowModal();
48 void frmContactEditor::ModifySound( wxCommandEvent& event )
50 long longSelected = -1;
51 int intSelectedData = 0;
53 if (!GetSelectedItem(lboSounds,
59 frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
60 frameCESound->SetupPointers(&SoundsList,
65 &SoundsListAudioEncType,
71 frameCESound->SetEditorMode(TRUE);
72 frameCESound->ShowModal();
77 void frmContactEditor::DeleteSound( wxCommandEvent& event )
79 long longSelected = -1;
80 int intSelectedData = 0;
82 if (!GetSelectedItem(lboSounds,
88 lboSounds->DeleteItem(longSelected);
90 DeleteMapData(intSelectedData, &SoundsList, &SoundsListAltID,
91 &SoundsListPID, &SoundsListType, &SoundsListAudioType,
92 &SoundsListAudioEncType, &SoundsListTokens, &SoundsListMediatype,
97 void frmContactEditor::PlaySoundDetach()
100 if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
102 // Can't load file. We must flee...
103 // Also show an error message too.
105 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
113 //AudioStreamPlayback.setbuffer(AudioBuffer);
114 AudioStreamPlayback.play();
119 n1.tv_nsec = 100000000L;*/
121 //while (TimeA != TimeB){
122 while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
124 // We poll this every 100ms in order to conserve CPU usage.
134 void frmContactEditor::PlaySound( wxCommandEvent& event )
137 //sf::Music *AudioPlayback = new sf::Music;
138 //AudioStream *AudioStreamPlayback = new AudioStream;
139 //sf::SoundBuffer *AudioBuffer = new sf::SoundBuffer;
141 //sf::Sound *AudioPlayback = new sf::Sound;
143 //delete(AudioPlayback);
145 //delete(AudioPlayback);
146 //delete(AudioStreamPlayback);
147 //delete(AudioBuffer);
149 //AudioPlayback = NULL;
150 //AudioStreamPlayback = NULL;
151 //AudioBuffer = NULL;
155 long longSelected = -1;
156 int intSelectedData = 0;
158 // Check if sound is still being played and if it is, stop it.
160 if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
162 AudioStreamPlayback.stop();
166 if (!GetSelectedItem(lboSounds,
172 std::map<int, std::string>::iterator initier;
174 initier = SoundsList.find(intSelectedData);
176 base64dec = base64_decode(initier->second);
177 base64declen = base64dec.size();
179 std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
180 AudioPlaybackThread.detach();
186 void frmContactEditor::StopSound( wxCommandEvent& event )
189 if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
191 AudioStreamPlayback.stop();
201 void frmContactEditor::SaveSound( wxCommandEvent &event )