// frmContactEditor-Sound.cpp - frmContactEditor Sound tab subroutines.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "frmContactEditor.h"
#include "frmContactEditorSound.h"
#include "../common/base64.h"
#include
#include
void frmContactEditor::AddSound( wxCommandEvent& event )
{
int intResult = 0;
frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
frameCESound->SetEditorMode(FALSE);
intResult = GetLastInt(&SoundsList);
frameCESound->SetupPointers(&SoundsList,
&SoundsListAltID,
&SoundsListPID,
&SoundsListType,
&SoundsListAudioType,
&SoundsListAudioEncType,
&SoundsListTokens,
&SoundsListMediatype,
&SoundsListPref,
lboSounds,
(intValueSeek));
frameCESound->ShowModal();
delete frameCESound;
frameCESound = NULL;
}
void frmContactEditor::ModifySound( wxCommandEvent& event )
{
long longSelected = -1;
int intSelectedData = 0;
if (!GetSelectedItem(lboSounds,
&longSelected,
&intSelectedData)){
return;
}
frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
frameCESound->SetupPointers(&SoundsList,
&SoundsListAltID,
&SoundsListPID,
&SoundsListType,
&SoundsListAudioType,
&SoundsListAudioEncType,
&SoundsListTokens,
&SoundsListMediatype,
&SoundsListPref,
lboSounds,
intSelectedData);
frameCESound->SetEditorMode(TRUE);
frameCESound->ShowModal();
delete frameCESound;
frameCESound = NULL;
}
void frmContactEditor::DeleteSound( wxCommandEvent& event )
{
long longSelected = -1;
int intSelectedData = 0;
if (!GetSelectedItem(lboSounds,
&longSelected,
&intSelectedData)){
return;
}
lboSounds->DeleteItem(longSelected);
DeleteMapData(intSelectedData, &SoundsList, &SoundsListAltID,
&SoundsListPID, &SoundsListType, &SoundsListAudioType,
&SoundsListAudioEncType, &SoundsListTokens, &SoundsListMediatype,
&SoundsListPref);
}
void frmContactEditor::PlaySoundDetach()
{
if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
// Can't load file. We must flee...
// Also show an error message too.
wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
return;
}
btnStop->Enable();
//AudioStreamPlayback.setbuffer(AudioBuffer);
AudioStreamPlayback.play();
/*timespec n1, n2;
n1.tv_sec = 0;
n1.tv_nsec = 100000000L;*/
//while (TimeA != TimeB){
while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
// We poll this every 100ms in order to conserve CPU usage.
SleepFor(100000000);
}
btnStop->Disable();
}
void frmContactEditor::PlaySound( wxCommandEvent& event )
{
//sf::Music *AudioPlayback = new sf::Music;
//AudioStream *AudioStreamPlayback = new AudioStream;
//sf::SoundBuffer *AudioBuffer = new sf::SoundBuffer;
//sf::Sound *AudioPlayback = new sf::Sound;
//delete(AudioPlayback);
//delete(AudioPlayback);
//delete(AudioStreamPlayback);
//delete(AudioBuffer);
//AudioPlayback = NULL;
//AudioStreamPlayback = NULL;
//AudioBuffer = NULL;
//return;
long longSelected = -1;
int intSelectedData = 0;
// Check if sound is still being played and if it is, stop it.
if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
AudioStreamPlayback.stop();
}
if (!GetSelectedItem(lboSounds,
&longSelected,
&intSelectedData)){
return;
}
std::map::iterator initier;
initier = SoundsList.find(intSelectedData);
base64dec = base64_decode(initier->second);
base64declen = base64dec.size();
std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
AudioPlaybackThread.detach();
return;
}
void frmContactEditor::StopSound( wxCommandEvent& event )
{
if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
AudioStreamPlayback.stop();
}
btnStop->Disable();
return;
}
void frmContactEditor::SaveSound( wxCommandEvent &event )
{
return;
}