Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Indented code properly 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         int intResult = 0;
29     
30         frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
31         frameCESound->SetEditorMode(FALSE);
32         intResult = GetLastInt(&ContactEditorData.SoundsList);
33         frameCESound->SetupPointers(&ContactEditorData.SoundsList,
34                 &ContactEditorData.SoundsListAltID,
35                 &ContactEditorData.SoundsListPID,
36                 &ContactEditorData.SoundsListType,
37                 &ContactEditorData.SoundsListAudioType,
38                 &ContactEditorData.SoundsListAudioEncType,
39                 &ContactEditorData.SoundsListTokens,
40                 &ContactEditorData.SoundsListMediatype,
41                 &ContactEditorData.SoundsListPref,
42                 lboSounds,
43                 (intValueSeek));
44         frameCESound->ShowModal();
45         delete frameCESound;
46         frameCESound = NULL;
47         
48 }
50 void frmContactEditor::ModifySound( wxCommandEvent& event )
51 {
52         
53         long longSelected = -1;
54         int intSelectedData = 0;
55     
56         if (!GetSelectedItem(lboSounds,
57                 &longSelected,
58                 &intSelectedData)){
59                 return;
60         }
61     
62         frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
63         frameCESound->SetupPointers(&ContactEditorData.SoundsList,
64                 &ContactEditorData.SoundsListAltID,
65                 &ContactEditorData.SoundsListPID,
66                 &ContactEditorData.SoundsListType,
67                 &ContactEditorData.SoundsListAudioType,
68                 &ContactEditorData.SoundsListAudioEncType,
69                 &ContactEditorData.SoundsListTokens,
70                 &ContactEditorData.SoundsListMediatype,
71                 &ContactEditorData.SoundsListPref,
72                 lboSounds,
73                 intSelectedData);
74         frameCESound->SetEditorMode(TRUE);
75         frameCESound->ShowModal();
76         delete frameCESound;
77         frameCESound = NULL;
78         
79 }
81 void frmContactEditor::DeleteSound( wxCommandEvent& event )
82 {
83         
84         long longSelected = -1;
85         int intSelectedData = 0;
86     
87         if (!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         if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
106         
107                 // Can't load file. We must flee...
108                 // Also show an error message too.
109         
110                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
111         
112                 return;
113         
114         }
115     
116         btnStop->Enable();
117     
118         //AudioStreamPlayback.setbuffer(AudioBuffer);
119         AudioStreamPlayback.play();
120     
121         /*timespec n1, n2;
122      
123         n1.tv_sec = 0;
124         n1.tv_nsec = 100000000L;*/
125     
126         //while (TimeA != TimeB){
127         while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
128         
129                 // We poll this every 100ms in order to conserve CPU usage.
130         
131                 SleepFor(100000000);
132         
133         }
134     
135         btnStop->Disable();
136     
139 void frmContactEditor::PlaySound( wxCommandEvent& event )
141     
142         //sf::Music *AudioPlayback = new sf::Music;
143         //AudioStream *AudioStreamPlayback = new AudioStream;
144         //sf::SoundBuffer *AudioBuffer = new sf::SoundBuffer;
145     
146         //sf::Sound *AudioPlayback = new sf::Sound;
147     
148         //delete(AudioPlayback);
149     
150         //delete(AudioPlayback);
151         //delete(AudioStreamPlayback);
152         //delete(AudioBuffer);
153     
154         //AudioPlayback = NULL;
155         //AudioStreamPlayback = NULL;
156         //AudioBuffer = NULL;
157     
158         //return;
159     
160         long longSelected = -1;
161         int intSelectedData = 0;
162     
163         // Check if sound is still being played and if it is, stop it.
164     
165         if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
166         
167                 AudioStreamPlayback.stop();
168         
169         }
170     
171         if (!GetSelectedItem(lboSounds,
172                 &longSelected,
173                 &intSelectedData)){
174                 return;
175         }
176     
177         std::map<int, std::string>::iterator initier;
178     
179         initier = ContactEditorData.SoundsList.find(intSelectedData);
180     
181         base64dec = base64_decode(initier->second);
182         base64declen = base64dec.size();
183     
184         std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
185         AudioPlaybackThread.detach();
186     
187         return;
188     
191 void frmContactEditor::StopSound( wxCommandEvent& event )
193     
194         if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
195         
196                 AudioStreamPlayback.stop();
197         
198         }
199     
200         btnStop->Disable();
202         return;
203     
206 void frmContactEditor::SaveSound( wxCommandEvent &event )
209         long longSelected = -1;
210         int intSelectedData = 0;
211     
212         if (!GetSelectedItem(lboSounds,
213                          &longSelected,
214                          &intSelectedData)){
215                 
216                 return;
217                 
218         }
219         
220         wxString FileTypes;
221         
222         wxString FinalFilename;
223         
224         std::map<int,std::string>::iterator initier;
225         std::map<int,wxString>::iterator soundtypeiter;
226     
227         initier = ContactEditorData.SoundsList.find(intSelectedData);
228         soundtypeiter = ContactEditorData.SoundsListAudioType.find(intSelectedData);
229         
230         // Open up the dialog to save the picture.
231         
232         wxFileDialog ExportDlg(this, wxT("Save Sound"), wxT(""), wxT(""),
233                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
234         
235         if (ExportDlg.ShowModal() == wxID_CANCEL){
236         
237                 return;
238         
239         }
240         
241         // Write out the picture to the file.
242         
243         wxFile SoundFile;
244         
245         if (SoundFile.Open(ExportDlg.GetPath(), wxFile::write)){
246         
247                 std::string base64dec;
248                 
249                 initier = ContactEditorData.SoundsList.find(intSelectedData);
250                 base64dec = base64_decode(initier->second);
251                 
252                 SoundFile.Write(base64dec.c_str(), (size_t)base64dec.size());
254                 SoundFile.Close();
255         
256         } else {
257         
258                 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);
259                 return;
260         
261         }
262         
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