Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Fix issue with intValueSeek not being incremented properly
[xestiaab/.git] / source / contacteditor / frmContactEditor-Sound.cpp
1 // frmContactEditor-Sound.cpp - frmContactEditor Sound tab subroutines.
2 //
3 // (c) 2012-2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
21 void frmContactEditor::AddSound( wxCommandEvent& event )
22 {
24         // Bring up a form to add sound.
25             
26         frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
27         frameCESound->SetEditorMode(FALSE);
28         frameCESound->SetupPointers(&ContactEditorData.SoundsList,
29                 &ContactEditorData.SoundsListAltID,
30                 &ContactEditorData.SoundsListPID,
31                 &ContactEditorData.SoundsListType,
32                 &ContactEditorData.SoundsListAudioType,
33                 &ContactEditorData.SoundsListAudioEncType,
34                 &ContactEditorData.SoundsListTokens,
35                 &ContactEditorData.SoundsListMediatype,
36                 &ContactEditorData.SoundsListPref,
37                 lboSounds,
38                 (intValueSeek));
39         frameCESound->ShowModal();
40         delete frameCESound;
41         frameCESound = NULL;
42     intValueSeek++;
44 }
46 void frmContactEditor::ModifySound( wxCommandEvent& event )
47 {
48         
49         // Bring up a form to modify sound.
50         
51         long longSelected = -1;
52         int intSelectedData = 0;
53     
54         if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
55                 &longSelected,
56                 &intSelectedData)){
57                 return;
58         }
59     
60         frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
61         frameCESound->SetupPointers(&ContactEditorData.SoundsList,
62                 &ContactEditorData.SoundsListAltID,
63                 &ContactEditorData.SoundsListPID,
64                 &ContactEditorData.SoundsListType,
65                 &ContactEditorData.SoundsListAudioType,
66                 &ContactEditorData.SoundsListAudioEncType,
67                 &ContactEditorData.SoundsListTokens,
68                 &ContactEditorData.SoundsListMediatype,
69                 &ContactEditorData.SoundsListPref,
70                 lboSounds,
71                 intSelectedData);
72         frameCESound->SetEditorMode(TRUE);
73         frameCESound->ShowModal();
74         delete frameCESound;
75         frameCESound = NULL;
76         
77 }
79 void frmContactEditor::DeleteSound( wxCommandEvent& event )
80 {
81         
82         // Bring up a form to delete sound.
83         
84         long longSelected = -1;
85         int intSelectedData = 0;
86     
87         if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
88                 &longSelected,
89                 &intSelectedData)){
90                 return;
91         }
92     
93         lboSounds->DeleteItem(longSelected);
94     
95         DeleteMapData(intSelectedData, &ContactEditorData.SoundsList, &ContactEditorData.SoundsListAltID,
96                 &ContactEditorData.SoundsListPID, &ContactEditorData.SoundsListType, &ContactEditorData.SoundsListAudioType,
97                 &ContactEditorData.SoundsListAudioEncType, &ContactEditorData.SoundsListTokens, &ContactEditorData.SoundsListMediatype,
98                 &ContactEditorData.SoundsListPref);
102 void frmContactEditor::PlaySoundDetach()
104     
105         // Play the sound and detach.
106         
107         if (!AudioStreamPlaybackPointer->openFromMemory(base64dec.c_str(), base64declen)){
108         
109                 // Can't load file. We must flee...
110                 // Also show an error message too.
111         
112                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
113         
114                 return;
115         
116         }
117     
118         btnStop->Enable();
120         AudioStreamPlaybackPointer->play();
121     
122         while (AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){
123         
124                 // We poll this every 100ms in order to conserve CPU usage.
125         
126                 SleepFor(10000000);
127         
128         }
129         
130         btnStop->Disable();
131         btnPlay->Enable();
132     
135 void frmContactEditor::PlaySound( wxCommandEvent& event )
137     
138         // Play the sound.
139     
140         long longSelected = -1;
141         int intSelectedData = 0;
142     
143         if (AudioStreamPlaybackPointer == nullptr){
144                 
145                 AudioStreamPlaybackPointer = new AudioStream;
146                 
147         }
148         
149         // Check if sound is still being played and if it is, stop it.
150     
151         if (AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){
152         
153                 AudioStreamPlaybackPointer->stop();
154         
155         }
156     
157         if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
158                 &longSelected,
159                 &intSelectedData)){
160                 return;
161         }
163         btnPlay->Disable();
164         
165         std::map<int, std::string>::iterator initier;
166     
167         initier = ContactEditorData.SoundsList.find(intSelectedData);
168     
169         base64dec = base64_decode(initier->second);
170         base64declen = base64dec.size();
171     
172         std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
173         AudioPlaybackThread.detach();
174     
175         return;
176     
179 void frmContactEditor::StopSound( wxCommandEvent& event )
181         
182         // Stop the sound.
183         
184         if (AudioStreamPlaybackPointer != nullptr && AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){
185         
186                 AudioStreamPlaybackPointer->stop();
187                 
188         }
189     
190         btnStop->Disable();
191         btnPlay->Enable();
193         return;
194     
197 void frmContactEditor::SaveSound( wxCommandEvent &event )
200         // Save the sound.
201         
202         long longSelected = -1;
203         int intSelectedData = 0;
204     
205         if (lboSounds->GetItemCount() == 0 || !GetSelectedItem(lboSounds,
206                          &longSelected,
207                          &intSelectedData)){
208                 
209                 return;
210                 
211         }
212         
213         wxString FileTypes;
214         
215         wxString FinalFilename;
216         
217         std::map<int,std::string>::iterator initier;
218         std::map<int,wxString>::iterator soundtypeiter;
219     
220         initier = ContactEditorData.SoundsList.find(intSelectedData);
221         soundtypeiter = ContactEditorData.SoundsListAudioType.find(intSelectedData);
222         
223         // Open up the dialog to save the picture.
224         
225         wxFileDialog ExportDlg(this, wxT("Save Sound"), wxT(""), wxT(""),
226                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
227         
228         if (ExportDlg.ShowModal() == wxID_CANCEL){
229         
230                 return;
231         
232         }
233         
234         // Write out the picture to the file.
235         
236         wxFile SoundFile;
237         
238         if (SoundFile.Open(ExportDlg.GetPath(), wxFile::write)){
239         
240                 std::string base64dec;
241                 
242                 initier = ContactEditorData.SoundsList.find(intSelectedData);
243                 base64dec = base64_decode(initier->second);
244                 
245                 SoundFile.Write(base64dec.c_str(), (size_t)base64dec.size());
247                 SoundFile.Close();
248         
249         } else {
250         
251                 wxMessageBox(_("An error occured whilst saving the sound. Check that you have free space and permissions to write the picture at this location."), _("Sound save error"), wxOK, this);
252                 return;
253         
254         }
255         
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