FS2_Open
Open source remastering of the Freespace 2 engine
soundenvironmentdlg.cpp
Go to the documentation of this file.
1 // soundenvironmentdlg.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "fred.h"
6 #include "soundenvironmentdlg.h"
7 #include "sound/audiostr.h"
8 #include "sound/sound.h"
9 #include "sound/ds.h"
10 #include "cfile/cfile.h"
11 
12 #ifdef _DEBUG
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
16 
18 // SoundEnvironment dialog
19 
20 
21 SoundEnvironment::SoundEnvironment(CWnd* pParent /*=NULL*/)
22  : CDialog(SoundEnvironment::IDD, pParent)
23 {
24  //{{AFX_DATA_INIT(SoundEnvironment)
25  m_environment = -1;
26  m_damping = 0.0f;
27  m_decay_time = 0.0f;
28  m_volume = 0.0f;
29  m_wave_filename = _T("");
30  m_wave_id = -1;
31  //}}AFX_DATA_INIT
32 }
33 
34 
35 void SoundEnvironment::DoDataExchange(CDataExchange* pDX)
36 {
37  CDialog::DoDataExchange(pDX);
38  //{{AFX_DATA_MAP(SoundEnvironment)
39  DDX_CBIndex(pDX, IDC_SOUND_ENVIRONMENT, m_environment);
41  DDV_MinMaxFloat(pDX, m_damping, 0.1f, 2.0f);
43  DDV_MinMaxFloat(pDX, m_decay_time, 0.1f, 20.0f);
44  DDX_Text(pDX, IDC_SOUND_ENVIRONMENT_VOLUME, m_volume);
45  DDV_MinMaxFloat(pDX, m_volume, 0.0f, 1.0f);
46  //}}AFX_DATA_MAP
47 }
48 
49 
50 BEGIN_MESSAGE_MAP(SoundEnvironment, CDialog)
51  //{{AFX_MSG_MAP(SoundEnvironment)
52  ON_CBN_SELCHANGE(IDC_SOUND_ENVIRONMENT, OnSelChangeSoundEnvironment)
53  ON_BN_CLICKED(IDC_BROWSE_WAVE, OnBrowseWave)
54  ON_BN_CLICKED(IDC_PLAY, OnPlay)
55  //}}AFX_MSG_MAP
56 END_MESSAGE_MAP()
57 
59 // SoundEnvironment message handlers
60 
61 BOOL SoundEnvironment::OnInitDialog()
62 {
63  m_play_bm.LoadBitmap(IDB_PLAY);
64  ((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
65 
66  // fill environment list ...
67 
68  CComboBox *box = (CComboBox *) GetDlgItem(IDC_SOUND_ENVIRONMENT);
69 
70  // add empty default string (for no environment set)
71  box->AddString("");
72 
73  for (size_t i = 0; i < EFX_presets.size(); i++) {
74  box->AddString(EFX_presets[i].name.c_str());
75  }
76 
77  // set values ...
78 
80 
81  // make sure we are set by default to mission values
82  if (m_env->id >= 0) {
83  m_environment = m_env->id + 1;
84 
85  m_volume = m_env->volume;
86  m_damping = m_env->damping;
87  m_decay_time = m_env->decay;
88 
89  // make it active
90  sound_env_set(m_env);
91  } else {
92  m_environment = 0;
93 
94  m_volume = 0.0f;
95  m_damping = 0.1f;
96  m_decay_time = 0.1f;
97 
99  }
100 
101  CDialog::OnInitDialog();
102  UpdateData(FALSE);
103  return TRUE;
104 }
105 
107 {
108  UpdateData(TRUE);
109 
111 
112  int env_id = m_environment - 1;
113 
114  // save anything if we need to
115  if (env_id >= 0) {
116  m_env->id = env_id;
117  m_env->volume = m_volume;
118  m_env->damping = m_damping;
119  m_env->decay = m_decay_time;
120  } else {
121  m_env->id = -1;
122  }
123 
124  CDialog::OnOK();
125 }
126 
128 {
129  CDialog::OnCancel();
130 }
131 
133 {
134  int z;
135 
136  UpdateData(TRUE);
137 
138  if (query_modified()) {
139  z = MessageBox("Do you want to keep your changes?", "Close", MB_ICONQUESTION | MB_YESNOCANCEL);
140  if (z == IDCANCEL) {
141  return;
142  }
143 
144  if (z == IDYES) {
145  OnOK();
146  return;
147  }
148  }
149 
150  CDialog::OnClose();
151 }
152 
154 {
155  int env_id = m_environment - 1;
157 
158  return ( (env_id != m_env->id) || (m_volume != m_env->volume) || (m_damping != m_env->damping)
159  || (m_decay_time != m_env->decay) );
160 }
161 
163 {
164  UpdateData(TRUE);
165 
166  int index = m_environment - 1;
167 
168  if (index >= 0) {
169  m_volume = EFX_presets[index].flGain;
170  m_damping = EFX_presets[index].flDecayHFRatio;
171  m_decay_time = EFX_presets[index].flDecayTime;
172  } else {
173  m_volume = 0.0f;
174  m_damping = 0.1f;
175  m_decay_time = 0.1f;
176  }
177 
178  UpdateData(FALSE);
179 }
180 
182 {
184 
185  audiostream_close_file(m_wave_id, 0);
186  m_wave_id = -1;
187 
188  m_play_bm.DeleteObject();
189  return CDialog::DestroyWindow();
190 }
191 
193 {
194  sound_env m_env;
195 
196  if ( !sound_env_supported() ) {
197  MessageBox("Sound environment effects are not available! Unable to preview!", "Error", MB_OK | MB_ICONEXCLAMATION);
198  return;
199  }
200 
201  if (m_wave_id < 0) {
202  OnBrowseWave();
203  return;
204  }
205 
206  UpdateData(TRUE);
207 
208  if (m_environment > 0) {
209  m_env.id = m_environment - 1;
210  m_env.volume = m_volume;
211  m_env.damping = m_damping;
212  m_env.decay = m_decay_time;
213 
214  sound_env_set(&m_env);
215  }
216 
217  audiostream_play(m_wave_id, 1.0f, 0);
218 }
219 
221 {
222  int z;
223 
224  if (m_wave_id >= 0) {
225  audiostream_close_file(m_wave_id, 0);
226  m_wave_id = -1;
227  }
228 
229  UpdateData(TRUE);
230 
231  m_wave_filename = _T("");
232 
234 
235  CFileDialog dlg(TRUE, "wav", m_wave_filename, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,
236  "Voice Files (*.ogg, *.wav)|*.ogg;*.wav|Ogg Vorbis Files (*.ogg)|*.ogg|Wave Files (*.wav)|*.wav||");
237 
238  if (dlg.DoModal() == IDOK) {
239  m_wave_filename = dlg.GetFileName();
240  m_wave_id = audiostream_open((char *)(LPCSTR) m_wave_filename, ASF_SOUNDFX);
241  }
242 
243  if ( !z ) {
244  cfile_pop_dir();
245  }
246 }
int i
Definition: multi_pxo.cpp:466
#define ASF_SOUNDFX
Definition: audiostr.h:18
int sound_env_set(sound_env *se)
Definition: sound.cpp:1357
GLuint index
Definition: Glext.h:5608
SoundEnvironment(CWnd *pParent=NULL)
#define IDC_SOUND_ENVIRONMENT_DAMPING
Definition: resource.h:783
#define MB_ICONQUESTION
Definition: config.h:188
int cfile_pop_dir()
Definition: cfile.cpp:381
int sound_env_supported()
Definition: sound.cpp:1402
virtual void DoDataExchange(CDataExchange *pDX)
GLclampf f
Definition: Glext.h:7097
#define IDC_SOUND_ENVIRONMENT_DECAY
Definition: resource.h:1162
#define TRUE
Definition: pstypes.h:399
#define MB_YESNOCANCEL
Definition: config.h:183
#define IDC_SOUND_ENVIRONMENT
Definition: resource.h:535
float volume
Definition: sound.h:93
#define IDC_BROWSE_WAVE
Definition: resource.h:859
afx_msg void OnBrowseWave()
sound_env sound_environment
Definition: missionparse.h:155
int cfile_push_chdir(int type)
Push current directory onto a 'stack' and change to a new directory.
Definition: cfile.cpp:342
GLdouble GLdouble z
Definition: Glext.h:5451
#define MB_OK
Definition: config.h:179
virtual BOOL DestroyWindow()
#define IDC_SOUND_ENVIRONMENT_VOLUME
Definition: resource.h:797
float decay
Definition: sound.h:95
GLuint const GLchar * name
Definition: Glext.h:5608
int BOOL
Definition: config.h:80
#define CF_TYPE_DATA
Definition: cfile.h:46
void audiostream_close_file(int i, int fade)
Definition: audiostr.cpp:1772
#define IDC_PLAY
Definition: resource.h:333
#define MB_ICONEXCLAMATION
Definition: config.h:184
float damping
Definition: sound.h:94
afx_msg void OnSelChangeSoundEnvironment()
SCP_vector< EFXREVERBPROPERTIES > EFX_presets
Definition: ds.cpp:128
int MessageBox(HWND h, const char *s1, const char *s2, int i)
void audiostream_play(int i, float volume, int looping)
Definition: audiostr.cpp:1803
#define IDB_PLAY
Definition: resource.h:87
int audiostream_open(const char *filename, int type)
Definition: audiostr.cpp:1713
mission The_mission
#define FALSE
Definition: pstypes.h:400
int sound_env_disable()
Definition: sound.cpp:1389
int id
Definition: sound.h:92