-
Notifications
You must be signed in to change notification settings - Fork 14
/
EffEditWnd.cpp
314 lines (256 loc) · 10.8 KB
/
EffEditWnd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*****************************************************************************/
/* EffEditWnd.cpp : implementation file */
/*****************************************************************************/
/******************************************************************************
Copyright (C) 2006 Hermann Seib
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "stdafx.h"
#include "mainfrm.h"
#include "childfrm.h"
#include "EffEditWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/*===========================================================================*/
/* CEffEditDlg dialog */
/*===========================================================================*/
/*****************************************************************************/
/* CEffEditDlg : constructor */
/*****************************************************************************/
CEffEditDlg::CEffEditDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEffEditDlg::IDD, pParent)
{
nEffect = -1; /* initialize effect to nothing */
//{{AFX_DATA_INIT(CEffEditDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
/*****************************************************************************/
/* Create : creates the dialog */
/*****************************************************************************/
BOOL CEffEditDlg::Create(CWnd* pParentWnd)
{
return CDialog::Create(IDD, pParentWnd);
}
/*****************************************************************************/
/* DoDataExchange : data exchange between dialog and object */
/*****************************************************************************/
void CEffEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEffEditDlg)
DDX_Control(pDX, IDC_PARMVAL, slParmval);
DDX_Control(pDX, IDC_PARMTEXT, stParmtext);
DDX_Control(pDX, IDC_PARMLIST, lbParms);
//}}AFX_DATA_MAP
}
/*****************************************************************************/
/* CEffEditDlg message map */
/*****************************************************************************/
BEGIN_MESSAGE_MAP(CEffEditDlg, CDialog)
//{{AFX_MSG_MAP(CEffEditDlg)
ON_LBN_SELCHANGE(IDC_PARMLIST, OnSelchangeParmlist)
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/*****************************************************************************/
/* OnInitDialog : called upon WM_INITDIALOG */
/*****************************************************************************/
BOOL CEffEditDlg::OnInitDialog()
{
CDialog::OnInitDialog();
slParmval.SetRange(0, 65535);
SetDlgItemText(IDC_RVALUE, "");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/*****************************************************************************/
/* PreTranslateMessage : called before message translation */
/*****************************************************************************/
BOOL CEffEditDlg::PreTranslateMessage(MSG* pMsg)
{
// we need this for correct accelerator key handling
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
HACCEL hAccel = pFrame->GetAccelTable();
if (hAccel &&
::TranslateAccelerator(pFrame->m_hWnd, hAccel, pMsg))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
/*****************************************************************************/
/* SetEffect : initializes dialog to a specific effect */
/*****************************************************************************/
void CEffEditDlg::SetEffect(int nEffect)
{
this->nEffect = nEffect;
CEffect *pEffect = GetApp()->vstHost.GetAt(nEffect);
if (pEffect)
{
char szTxt[65];
for (int i = 0; i < pEffect->pEffect->numParams; i++)
{
CString sParm;
sParm.Format("%02d: ", i);
pEffect->EffGetParamName(i, szTxt);
sParm += szTxt;
int idx = lbParms.AddString(sParm);
lbParms.SetItemData(idx, i);
}
lbParms.SetCurSel(0);
}
OnSelchangeParmlist();
}
/*****************************************************************************/
/* OnSelchangeParmlist : called when the parameter list selection changes */
/*****************************************************************************/
void CEffEditDlg::OnSelchangeParmlist()
{
int i = (int)lbParms.GetItemData(lbParms.GetCurSel());
CEffect *pEffect = GetApp()->vstHost.GetAt(nEffect);
float fVal = 0.;
if (pEffect)
{
SetParmDisp(pEffect, i);
fVal = pEffect->EffGetParameter(i);
}
CString sVal;
sVal.Format("%8f", fVal);
SetDlgItemText(IDC_RVALUE, sVal);
slParmval.SetPos(65535 - (int)(fVal * 65535.));
}
/*****************************************************************************/
/* SetParmDisp : internal function for parameter display */
/*****************************************************************************/
void CEffEditDlg::SetParmDisp(CEffect *pEffect, int nParm)
{
char szData[30];
CString sDisp;
if (pEffect)
{
pEffect->EffGetParamDisplay(nParm, szData);
sDisp += szData;
pEffect->EffGetParamLabel(nParm, szData);
sDisp += CString(' ') + szData;
}
stParmtext.SetWindowText(sDisp);
}
/*****************************************************************************/
/* OnVScroll : called when a vertical sb / slider value changes */
/*****************************************************************************/
void CEffEditDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (pScrollBar->GetDlgCtrlID() == IDC_PARMVAL)
{
int i = (int)lbParms.GetItemData(lbParms.GetCurSel());
float fNewVal = float(65535 - slParmval.GetPos()) / 65535.f;
CEffect *pEffect = GetApp()->vstHost.GetAt(nEffect);
pEffect->EffSetParameter(i, fNewVal);
SetParmDisp(pEffect, i);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
if (nSBCode == SB_ENDSCROLL) /* if scroll terminated */
OnSelchangeParmlist(); /* reset to real current value */
}
/*****************************************************************************/
/* OnSetParameterAutomated : called when a parameter changes */
/*****************************************************************************/
bool CEffEditDlg::OnSetParameterAutomated(long index, float value)
{
if (index == lbParms.GetCurSel()) /* if it's the currently displayed */
OnSelchangeParmlist(); /* reget parameter settings */
return true;
}
/*===========================================================================*/
/* CEffEditWnd class members */
/*===========================================================================*/
IMPLEMENT_DYNCREATE(CEffEditWnd, CEffectWnd)
/*****************************************************************************/
/* CEffEditWnd : constructor */
/*****************************************************************************/
CEffEditWnd::CEffEditWnd()
{
}
/*****************************************************************************/
/* ~CEffEditWnd : destructor */
/*****************************************************************************/
CEffEditWnd::~CEffEditWnd()
{
}
/*****************************************************************************/
/* CEffEditWnd message map */
/*****************************************************************************/
BEGIN_MESSAGE_MAP(CEffEditWnd, CEffectWnd)
//{{AFX_MSG_MAP(CEffEditWnd)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/*****************************************************************************/
/* CreateView : creates a view for the window */
/*****************************************************************************/
CWnd * CEffEditWnd::CreateView()
{
CEffEditDlg *pWnd = new CEffEditDlg;
if (pWnd)
pWnd->Create(this);
return pWnd;
}
/*****************************************************************************/
/* SetEffect : sets new effect */
/*****************************************************************************/
void CEffEditWnd::SetEffect(int nEff)
{
CEffectWnd::SetEffect(nEff);
CEffEditDlg *pEffDlg = (CEffEditDlg *)pView;
if (pEffDlg)
{
pEffDlg->SetEffect(nEffect);
CRect rc;
pEffDlg->GetWindowRect(&rc);
SetEffSize(rc.Width(), rc.Height());
}
}
/*****************************************************************************/
/* OnClose : called when the parameter edit window is closed */
/*****************************************************************************/
void CEffEditWnd::OnClose()
{
// we need to skip CEffectWnd::OnClose() here since it would try to close an
// (eventually unopened) effect edit window... and would report the wrong
// window as closed to the main window.
pMain->ParmClosed();
CWnd::OnClose();
}
/*****************************************************************************/
/* OnSetParameterAutomated : called when one of the effect's parms changes */
/*****************************************************************************/
bool CEffEditWnd::OnSetParameterAutomated(long index, float value)
{
CEffEditDlg *pEffDlg = (CEffEditDlg *)pView;
if (pEffDlg)
return pEffDlg->OnSetParameterAutomated(index, value);
else
return CEffectWnd::OnSetParameterAutomated(index, value);
}
/*****************************************************************************/
/* Update : makes sure that the dialog is up to date */
/*****************************************************************************/
void CEffEditWnd::Update()
{
SetupTitle();
CEffEditDlg *pEffDlg = (CEffEditDlg *)pView;
if (pEffDlg)
pEffDlg->OnSelchangeParmlist();
}