1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
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"
33 /////////////////////////////////////////////////////////////////////////////
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)
47 //========================================================================================
48 void CPickSound::DoDataExchange(CDataExchange
* pDX
)
50 CDialog::DoDataExchange(pDX
);
51 //{{AFX_DATA_MAP(CPickSound)
52 DDX_Control(pDX
, IDC_LIST1
, m_NameList
);
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
)
63 ON_LBN_DBLCLK(IDC_LIST1
, OnDblclkList
)
64 ON_BN_CLICKED(IDC_PLAY_SOUND
, OnPlaySound
)
69 /////////////////////////////////////////////////////////////////////////////
70 // CPickSound message handlers
72 //========================================================================================
73 BOOL
CPickSound::OnInitDialog()
75 CDialog::OnInitDialog();
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
);
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));
101 nlwarning ("Can't create the timer to update the sound system");
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()
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;
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()
144 CDialog::OnDestroy();
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;
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
176 //========================================================================================
177 void CPickSound::stopCurrSource()