From 28556c2acb42441b15e126653a752bad62883a07 Mon Sep 17 00:00:00 2001 From: doitux Date: Mon, 4 Jun 2007 23:34:49 +0000 Subject: [PATCH] sdl audio fix small gui fixes --- src/gui/qt/joinnetworkgamedialog.ui | 240 +++++++++++++++++----------- src/gui/qt/sound/sdlplayer.cpp | 69 ++++---- src/gui/qt/sound/sdlplayer.h | 2 + 3 files changed, 187 insertions(+), 124 deletions(-) diff --git a/src/gui/qt/joinnetworkgamedialog.ui b/src/gui/qt/joinnetworkgamedialog.ui index 83142a2d..fb476aeb 100644 --- a/src/gui/qt/joinnetworkgamedialog.ui +++ b/src/gui/qt/joinnetworkgamedialog.ui @@ -31,80 +31,6 @@ 6 - - - - myServerProfile1 - - - - - - - Profile Name: - - - - - - - IP Address / Domain Name: - - - - - - - Port: - - - - - - - 65535 - - - 80 - - - 7234 - - - - - - - Password (optional): - - - - - - - QLineEdit::Password - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 16 - 57 - - - - @@ -123,7 +49,7 @@ true - 3 + 15 false @@ -191,37 +117,163 @@ - - - - Use IPv6 + + + + 0 + + + 6 + + + + + Use SCTP + + + + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Nimbus Sans L'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> <a href="http://en.wikipedia.org/wiki/Stream_Control_Transmission_Protocol"><span style=" text-decoration: underline; color:#0000ff;">What is this?</span></a></p></body></html> + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + 6 + + + + + Use IPv6 + + + + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Nimbus Sans L'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> <a href="http://en.wikipedia.org/wiki/Ipv6"><span style=" text-decoration: underline; color:#0000ff;">What is this?</span></a></p></body></html> + + + true + + + + + + + Qt::Horizontal + + + + 131 + 20 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 16 + 57 + + + + + + + + + + + QLineEdit::Password - - + + - <a href="http://en.wikipedia.org/wiki/Ipv6">What is this?</a> - - - true + Password (optional): - - - - Use SCTP + + + + 65535 + + + 80 + + + 7234 - - + + - <a href="http://en.wikipedia.org/wiki/Stream_Control_Transmission_Protocol">What is this?</a> + Port: - - true + + + + + + IP Address / Domain Name: + + + + + + + Profile Name: + + + + + + + myServerProfile1 diff --git a/src/gui/qt/sound/sdlplayer.cpp b/src/gui/qt/sound/sdlplayer.cpp index 939115b9..c7fddc64 100644 --- a/src/gui/qt/sound/sdlplayer.cpp +++ b/src/gui/qt/sound/sdlplayer.cpp @@ -16,7 +16,7 @@ using namespace std; SDLPlayer::SDLPlayer() -: soundData(NULL), currentChannel(0) +: soundData(NULL), currentChannel(0) , audioEnabled(0) { initAudio(); } @@ -37,47 +37,56 @@ void SDLPlayer::initAudio() { SDL_Init(SDL_INIT_AUDIO); - if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) + if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) { Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); + audioEnabled = 1; + } } void SDLPlayer::playSound(string audioString) { - QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav"); - - if(myFile.open(QIODevice::ReadOnly)) { - - audioDone(); - - QDataStream in(&myFile); - soundData = new Uint8[(int)myFile.size()]; - in.readRawData( (char*)soundData, (int)myFile.size() ); - - sound = Mix_QuickLoad_WAV(soundData); + if(audioEnabled) { - currentChannel = Mix_PlayChannel(-1, sound,0); + QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav"); + + if(myFile.open(QIODevice::ReadOnly)) { + + audioDone(); + + QDataStream in(&myFile); + soundData = new Uint8[(int)myFile.size()]; + in.readRawData( (char*)soundData, (int)myFile.size() ); + + sound = Mix_QuickLoad_WAV(soundData); + + currentChannel = Mix_PlayChannel(-1, sound,0); + } + // else cout << "could not load " << audioString << ".wav" << endl; + + //test + // audioDone(); + // sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() ); + // currentChannel = Mix_PlayChannel(-1, sound,0); + } -// else cout << "could not load " << audioString << ".wav" << endl; - - //test -// audioDone(); -// sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() ); -// currentChannel = Mix_PlayChannel(-1, sound,0); - } void SDLPlayer::audioDone() { - Mix_HaltChannel(currentChannel); - Mix_FreeChunk(sound); - sound = NULL; - delete[] soundData; - soundData = NULL; + if(audioEnabled) { + Mix_HaltChannel(currentChannel); + Mix_FreeChunk(sound); + sound = NULL; + delete[] soundData; + soundData = NULL; + } } void SDLPlayer::closeAudio() { - - audioDone(); - Mix_CloseAudio(); - SDL_Quit(); + + if(audioEnabled) { + audioDone(); + Mix_CloseAudio(); + SDL_Quit(); + } } diff --git a/src/gui/qt/sound/sdlplayer.h b/src/gui/qt/sound/sdlplayer.h index c786bfb6..03267a9d 100644 --- a/src/gui/qt/sound/sdlplayer.h +++ b/src/gui/qt/sound/sdlplayer.h @@ -50,6 +50,8 @@ private: Uint8 *soundData; int currentChannel; + bool audioEnabled; + }; #endif