Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code from contacteditor/frmContactEditor-Sound.cpp
[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"
20 #include "frmContactEditorSound.h"
21 #include "../common/base64.h"
22 #include <SFML/Audio.hpp>
23 #include <thread>
25 void frmContactEditor::AddSound( wxCommandEvent& event )
26 {
28         // Bring up a form to add sound.
29         
30         int intResult = 0;
31     
32         frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
33         frameCESound->SetEditorMode(FALSE);
34         intResult = GetLastInt(&ContactEditorData.SoundsList);
35         frameCESound->SetupPointers(&ContactEditorData.SoundsList,
36                 &ContactEditorData.SoundsListAltID,
37                 &ContactEditorData.SoundsListPID,
38                 &ContactEditorData.SoundsListType,
39                 &ContactEditorData.SoundsListAudioType,
40                 &ContactEditorData.SoundsListAudioEncType,
41                 &ContactEditorData.SoundsListTokens,
42                 &ContactEditorData.SoundsListMediatype,
43                 &ContactEditorData.SoundsListPref,
44                 lboSounds,
45                 (intValueSeek));
46         frameCESound->ShowModal();
47         delete frameCESound;
48         frameCESound = NULL;
49         
50 }
52 void frmContactEditor::ModifySound( wxCommandEvent& event )
53 {
54         
55         // Bring up a form to modify sound.
56         
57         long longSelected = -1;
58         int intSelectedData = 0;
59     
60         if (!GetSelectedItem(lboSounds,
61                 &longSelected,
62                 &intSelectedData)){
63                 return;
64         }
65     
66         frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
67         frameCESound->SetupPointers(&ContactEditorData.SoundsList,
68                 &ContactEditorData.SoundsListAltID,
69                 &ContactEditorData.SoundsListPID,
70                 &ContactEditorData.SoundsListType,
71                 &ContactEditorData.SoundsListAudioType,
72                 &ContactEditorData.SoundsListAudioEncType,
73                 &ContactEditorData.SoundsListTokens,
74                 &ContactEditorData.SoundsListMediatype,
75                 &ContactEditorData.SoundsListPref,
76                 lboSounds,
77                 intSelectedData);
78         frameCESound->SetEditorMode(TRUE);
79         frameCESound->ShowModal();
80         delete frameCESound;
81         frameCESound = NULL;
82         
83 }
85 void frmContactEditor::DeleteSound( wxCommandEvent& event )
86 {
87         
88         // Bring up a form to delete sound.
89         
90         long longSelected = -1;
91         int intSelectedData = 0;
92     
93         if (!GetSelectedItem(lboSounds,
94                 &longSelected,
95                 &intSelectedData)){
96                 return;
97         }
98     
99         lboSounds->DeleteItem(longSelected);
100     
101         DeleteMapData(intSelectedData, &ContactEditorData.SoundsList, &ContactEditorData.SoundsListAltID,
102                 &ContactEditorData.SoundsListPID, &ContactEditorData.SoundsListType, &ContactEditorData.SoundsListAudioType,
103                 &ContactEditorData.SoundsListAudioEncType, &ContactEditorData.SoundsListTokens, &ContactEditorData.SoundsListMediatype,
104                 &ContactEditorData.SoundsListPref);
108 void frmContactEditor::PlaySoundDetach()
110     
111         // Play the sound and detach.
112         
113         if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
114         
115                 // Can't load file. We must flee...
116                 // Also show an error message too.
117         
118                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
119         
120                 return;
121         
122         }
123     
124         btnStop->Enable();
126         AudioStreamPlayback.play();
127     
128         while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
129         
130                 // We poll this every 100ms in order to conserve CPU usage.
131         
132                 SleepFor(100000000);
133         
134         }
135     
136         btnStop->Disable();
137     
140 void frmContactEditor::PlaySound( wxCommandEvent& event )
142     
143         // Play the sound.
144     
145         long longSelected = -1;
146         int intSelectedData = 0;
147     
148         // Check if sound is still being played and if it is, stop it.
149     
150         if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
151         
152                 AudioStreamPlayback.stop();
153         
154         }
155     
156         if (!GetSelectedItem(lboSounds,
157                 &longSelected,
158                 &intSelectedData)){
159                 return;
160         }
161     
162         std::map<int, std::string>::iterator initier;
163     
164         initier = ContactEditorData.SoundsList.find(intSelectedData);
165     
166         base64dec = base64_decode(initier->second);
167         base64declen = base64dec.size();
168     
169         std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
170         AudioPlaybackThread.detach();
171     
172         return;
173     
176 void frmContactEditor::StopSound( wxCommandEvent& event )
178         
179         // Stop the sound.
180     
181         if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
182         
183                 AudioStreamPlayback.stop();
184         
185         }
186     
187         btnStop->Disable();
189         return;
190     
193 void frmContactEditor::SaveSound( wxCommandEvent &event )
196         // Save the sound.
197         
198         long longSelected = -1;
199         int intSelectedData = 0;
200     
201         if (!GetSelectedItem(lboSounds,
202                          &longSelected,
203                          &intSelectedData)){
204                 
205                 return;
206                 
207         }
208         
209         wxString FileTypes;
210         
211         wxString FinalFilename;
212         
213         std::map<int,std::string>::iterator initier;
214         std::map<int,wxString>::iterator soundtypeiter;
215     
216         initier = ContactEditorData.SoundsList.find(intSelectedData);
217         soundtypeiter = ContactEditorData.SoundsListAudioType.find(intSelectedData);
218         
219         // Open up the dialog to save the picture.
220         
221         wxFileDialog ExportDlg(this, wxT("Save Sound"), wxT(""), wxT(""),
222                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
223         
224         if (ExportDlg.ShowModal() == wxID_CANCEL){
225         
226                 return;
227         
228         }
229         
230         // Write out the picture to the file.
231         
232         wxFile SoundFile;
233         
234         if (SoundFile.Open(ExportDlg.GetPath(), wxFile::write)){
235         
236                 std::string base64dec;
237                 
238                 initier = ContactEditorData.SoundsList.find(intSelectedData);
239                 base64dec = base64_decode(initier->second);
240                 
241                 SoundFile.Write(base64dec.c_str(), (size_t)base64dec.size());
243                 SoundFile.Close();
244         
245         } else {
246         
247                 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);
248                 return;
249         
250         }
251         
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