Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / pick_sound.cpp
blob01261cdecdd4c50998ebfc3f75c72bf23ae3e0dc
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "std_afx.h"
22 #include "object_viewer.h"
23 #include "pick_sound.h"
24 #include "sound_system.h"
26 #include "nel/sound/u_audio_mixer.h"
27 #include "nel/sound/u_listener.h"
28 #include "nel/sound/u_source.h"
30 using namespace std;
33 /////////////////////////////////////////////////////////////////////////////
34 // CPickSound dialog
37 //========================================================================================
38 CPickSound::CPickSound(const CPickSound::TNameVect &names, CWnd* pParent /*=NULL*/)
39 : CDialog(CPickSound::IDD, pParent), _Names(names), _CurrSource(NULL)
42 //{{AFX_DATA_INIT(CPickSound)
43 //}}AFX_DATA_INIT
47 //========================================================================================
48 void CPickSound::DoDataExchange(CDataExchange* pDX)
50 CDialog::DoDataExchange(pDX);
51 //{{AFX_DATA_MAP(CPickSound)
52 DDX_Control(pDX, IDC_LIST1, m_NameList);
53 //}}AFX_DATA_MAP
57 BEGIN_MESSAGE_MAP(CPickSound, CDialog)
58 //{{AFX_MSG_MAP(CPickSound)
59 ON_LBN_SELCHANGE(IDC_LIST1, OnSelchange)
60 ON_BN_CLICKED(IDC_BUTTON1, OnPlaySound)
61 ON_WM_TIMER()
62 ON_WM_DESTROY()
63 ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList)
64 ON_BN_CLICKED(IDC_PLAY_SOUND, OnPlaySound)
65 ON_WM_CLOSE()
66 //}}AFX_MSG_MAP
67 END_MESSAGE_MAP()
69 /////////////////////////////////////////////////////////////////////////////
70 // CPickSound message handlers
72 //========================================================================================
73 BOOL CPickSound::OnInitDialog()
75 CDialog::OnInitDialog();
76 UpdateData();
78 for (TNameVect::iterator it = _Names.begin(); it != _Names.end(); ++it)
80 m_NameList.AddString(nlUtf8ToTStr(NLMISC::CStringMapper::unmap(*it).c_str()));
83 _Timer = SetTimer (1, 100, NULL);
85 // store value
86 if (CSoundSystem::getAudioMixer())
88 _BackupGain = CSoundSystem::getAudioMixer()->getListener ()->getGain();
89 CSoundSystem::getAudioMixer()->getListener ()->getVelocity(_BackupVel);
91 CSoundSystem::getAudioMixer()->getListener ()->setGain(1.0f);
92 CSoundSystem::getAudioMixer()->getListener ()->setVelocity(NLMISC::CVector(0,0,0));
94 else
95 _BackupGain = 1.0f;
97 // set new value
99 if(!_Timer)
101 nlwarning ("Can't create the timer to update the sound system");
104 UpdateData(FALSE);
105 return TRUE; // return TRUE unless you set the focus to a control
106 // EXCEPTION: OCX Property Pages should return FALSE
109 //========================================================================================
110 void CPickSound::OnSelchange()
112 UpdateData();
113 TCHAR str[1024];
114 nlassert(m_NameList.GetTextLen(m_NameList.GetCurSel()) < 1024);
116 m_NameList.GetText(m_NameList.GetCurSel(), str);
117 _CurrName = NLMISC::CStringMapper::map(NLMISC::tStrToUtf8(str));
121 //========================================================================================
122 void CPickSound::OnPlaySound()
124 int curSel = m_NameList.GetCurSel();
125 if (curSel == LB_ERR) return;
126 stopCurrSource();
127 CString sName;
128 m_NameList.GetText(curSel, sName);
129 CSoundSystem::create(NLMISC::tStrToUtf8(sName));
132 //========================================================================================
133 void CPickSound::OnTimer(UINT_PTR nIDEvent)
135 CSoundSystem::poll();
137 CDialog::OnTimer(nIDEvent);
140 //========================================================================================
141 void CPickSound::OnDestroy()
143 stopCurrSource();
144 CDialog::OnDestroy();
146 if(_Timer != 0)
147 KillTimer (_Timer);
149 // restore old value
150 if (CSoundSystem::getAudioMixer())
152 CSoundSystem::getAudioMixer()->getListener ()->setGain(_BackupGain);
153 CSoundSystem::getAudioMixer()->getListener ()->setVelocity(_BackupVel);
157 //========================================================================================
158 void CPickSound::OnDblclkList()
160 int curSel = m_NameList.GetCurSel();
161 if (curSel == LB_ERR) return;
162 stopCurrSource();
163 CString sName;
164 m_NameList.GetText(curSel, sName);
165 _CurrSource = CSoundSystem::create(NLMISC::tStrToUtf8(sName));
168 //========================================================================================
169 void CPickSound::OnClose()
171 // TODO: Add your message handler code here and/or call default
172 stopCurrSource();
173 CDialog::OnClose();
176 //========================================================================================
177 void CPickSound::stopCurrSource()
179 delete _CurrSource;
180 _CurrSource = NULL;