Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Splitting frmContactEditor.cpp into 15 files to make it more manageable.
[xestiaab/.git] / source / contacteditor / frmContactEditor-Sound.cpp
1 #include "frmContactEditor.h"
2 #include "frmContactEditorSound.h"
3 #include "../common/base64.h"
4 #include <SFML/Audio.hpp>
5 #include <thread>
7 void frmContactEditor::AddSound( wxCommandEvent& event )
8 {
9     int intResult = 0;
10     
11     frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
12     frameCESound->SetEditorMode(FALSE);
13     intResult = GetLastInt(&SoundsList);
14     frameCESound->SetupPointers(&SoundsList,
15                                 &SoundsListAltID,
16                                 &SoundsListPID,
17                                 &SoundsListType,
18                                 &SoundsListAudioType,
19                                 &SoundsListAudioEncType,
20                                 &SoundsListTokens,
21                                 &SoundsListMediatype,
22                                 &SoundsListPref,
23                                 lboSounds,
24                                 (intValueSeek));
25     frameCESound->ShowModal();
26     delete frameCESound;
27     frameCESound = NULL;
28 }
30 void frmContactEditor::ModifySound( wxCommandEvent& event )
31 {
32     long longSelected = -1;
33     int intSelectedData = 0;
34     
35     if (!GetSelectedItem(lboSounds,
36                          &longSelected,
37                          &intSelectedData)){
38         return;
39     }
40     
41     frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
42     frameCESound->SetupPointers(&SoundsList,
43                                 &SoundsListAltID,
44                                 &SoundsListPID,
45                                 &SoundsListType,
46                                 &SoundsListAudioType,
47                                 &SoundsListAudioEncType,
48                                 &SoundsListTokens,
49                                 &SoundsListMediatype,
50                                 &SoundsListPref,
51                                 lboSounds,
52                                 intSelectedData);
53     frameCESound->SetEditorMode(TRUE);
54     frameCESound->ShowModal();
55     delete frameCESound;
56     frameCESound = NULL;
57 }
59 void frmContactEditor::DeleteSound( wxCommandEvent& event )
60 {
61     long longSelected = -1;
62     int intSelectedData = 0;
63     
64     if (!GetSelectedItem(lboSounds,
65                          &longSelected,
66                          &intSelectedData)){
67         return;
68     }
69     
70     lboSounds->DeleteItem(longSelected);
71     
72     DeleteMapData(intSelectedData, &SoundsList, &SoundsListAltID,
73                   &SoundsListPID, &SoundsListType, &SoundsListAudioType,
74                   &SoundsListAudioEncType, &SoundsListTokens, &SoundsListMediatype,
75                   &SoundsListPref);
76     
77 }
79 void frmContactEditor::PlaySoundDetach()
80 {
81     
82     if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
83         
84         // Can't load file. We must flee...
85         // Also show an error message too.
86         
87         wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
88         
89         return;
90         
91     }
92     
93     btnStop->Enable();
94     
95     //AudioStreamPlayback.setbuffer(AudioBuffer);
96     AudioStreamPlayback.play();
97     
98     /*timespec n1, n2;
99      
100      n1.tv_sec = 0;
101      n1.tv_nsec = 100000000L;*/
102     
103     //while (TimeA != TimeB){
104     while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
105         
106         // We poll this every 100ms in order to conserve CPU usage.
107         
108         SleepFor(100000000);
109         
110     }
111     
112     btnStop->Disable();
113     
116 void frmContactEditor::PlaySound( wxCommandEvent& event )
118     
119     //sf::Music *AudioPlayback = new sf::Music;
120     //AudioStream *AudioStreamPlayback = new AudioStream;
121     //sf::SoundBuffer *AudioBuffer = new sf::SoundBuffer;
122     
123     //sf::Sound *AudioPlayback = new sf::Sound;
124     
125     //delete(AudioPlayback);
126     
127     //delete(AudioPlayback);
128     //delete(AudioStreamPlayback);
129     //delete(AudioBuffer);
130     
131     //AudioPlayback = NULL;
132     //AudioStreamPlayback = NULL;
133     //AudioBuffer = NULL;
134     
135     //return;
136     
137     long longSelected = -1;
138     int intSelectedData = 0;
139     
140     // Check if sound is still being played and if it is, stop it.
141     
142     if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
143         
144         AudioStreamPlayback.stop();
145         
146     }
147     
148     if (!GetSelectedItem(lboSounds,
149                          &longSelected,
150                          &intSelectedData)){
151         return;
152     }
153     
154     std::map<int, std::string>::iterator initier;
155     
156     initier = SoundsList.find(intSelectedData);
157     
158     base64dec = base64_decode(initier->second);
159     base64declen = base64dec.size();
160     
161     std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
162     AudioPlaybackThread.detach();
163     
164     return;
165     
168 void frmContactEditor::StopSound( wxCommandEvent& event )
170     
171     if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
172         
173         AudioStreamPlayback.stop();
174         
175     }
176     
177     btnStop->Disable();
178     
179     return;
180     
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