Audacity 3.2.0
ScoreAlignDialog.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4 Audacity(R) is copyright (c) 1999-2008 Audacity Team.
5 License: GPL v2 or later. See License.txt.
6
7 ScoreAlignDialog.cpp
8 <TODO: authors>
9
10******************************************************************//*******************************************************************/
18
19
20#include "ScoreAlignDialog.h"
21
22#ifdef EXPERIMENTAL_SCOREALIGN
23
24// For compilers that support precompilation, includes "wx/wx.h".
25#include <wx/wxprec.h>
26
27#ifdef __BORLANDC__
28#pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32#include <wx/brush.h>
33#include <wx/choice.h>
34#include <wx/file.h>
35#include <wx/stattext.h>
36#include <wx/statusbr.h>
37#endif
38
39#include <fstream>
40#include "Prefs.h"
41#include "ShuttleGui.h"
42#include "WrapAllegro.h"
43#include "audioreader.h"
44#include "scorealign.h"
45#include "scorealign-glue.h"
46
47static std::unique_ptr<ScoreAlignDialog> gScoreAlignDialog{};
48
49//IMPLEMENT_CLASS(ScoreAlignDialog, wxDialogWrapper)
50
51ScoreAlignDialog::ScoreAlignDialog(ScoreAlignParams &params)
52 : wxDialogWrapper(NULL, -1, XO("Align MIDI to Audio"),
53 wxDefaultPosition, wxDefaultSize,
54 wxDEFAULT_DIALOG_STYLE)
55{
56 gScoreAlignDialog.reset(this); // Allows anyone to close dialog by calling
57 // CloseScoreAlignDialog()
58 gPrefs->Read(wxT("/Tracks/Synchronize/FramePeriod"), &p.mFramePeriod,
59 float(SA_DFT_FRAME_PERIOD));
60 gPrefs->Read(wxT("/Tracks/Synchronize/WindowSize"), &p.mWindowSize,
61 float(SA_DFT_WINDOW_SIZE));
62 gPrefs->Read(wxT("/Tracks/Synchronize/SilenceThreshold"),
63 &p.mSilenceThreshold, float(SA_DFT_SILENCE_THRESHOLD));
64 gPrefs->Read(wxT("/Tracks/Synchronize/ForceFinalAlignment"),
65 &p.mForceFinalAlignment, float(SA_DFT_FORCE_FINAL_ALIGNMENT));
66 gPrefs->Read(wxT("/Tracks/Synchronize/IgnoreSilence"),
67 &p.mIgnoreSilence, float(SA_DFT_IGNORE_SILENCE));
68 gPrefs->Read(wxT("/Tracks/Synchronize/PresmoothTime"), &p.mPresmoothTime,
69 float(SA_DFT_PRESMOOTH_TIME));
70 gPrefs->Read(wxT("/Tracks/Synchronize/LineTime"), &p.mLineTime,
71 float(SA_DFT_LINE_TIME));
72 gPrefs->Read(wxT("/Tracks/Synchronize/SmoothTime"), &p.mSmoothTime,
73 float(SA_DFT_SMOOTH_TIME));
74
75 //wxButton *ok = safenew wxButton(this, wxID_OK, _("OK"));
76 //wxButton *cancel = safenew wxButton(this, wxID_CANCEL, _("Cancel"));
77 //wxSlider *sl = safenew wxSliderWrapper(this, ID_SLIDER, 0, 0, 100,
78 // wxDefaultPosition, wxSize(20, 124),
79 // wxSL_HORIZONTAL);
80
82 //ok->SetDefault();
83
84 S.SetBorder(5);
85 S.StartVerticalLay(true);
86 S.StartStatic(XO("Align MIDI to Audio"));
87 S.StartMultiColumn(3, wxEXPAND | wxALIGN_CENTER_VERTICAL);
88 S.SetStretchyCol(1);
89
90 mFramePeriodLabel = S.AddVariableText(
91 XO("Frame Period:"), true, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
92 mFramePeriodSlider = S.Id(ID_FRAMEPERIOD)
93 .Name(XO("Frame Period"))
94 .Style(wxSL_HORIZONTAL)
95 .MinSize( { 300, -1 } )
96 .AddSlider( {},
97 /*pos*/ (int) (p.mFramePeriod * 100 + 0.5), /*max*/ 50, /*min*/ 5);
98 mFramePeriodText = S.AddVariableText(
99 SA_DFT_FRAME_PERIOD_TEXT, true, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
100
101 mWindowSizeLabel = S.AddVariableText(
102 XO("Window Size:"), true, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
103 mWindowSizeSlider = S.Id(ID_WINDOWSIZE)
104 .Name(XO("Window Size"))
105 .Style(wxSL_HORIZONTAL)
106 .AddSlider( {},
107 /*pos*/ (int) (p.mWindowSize * 100 + 0.5), /*max*/ 100, /*min*/ 5);
108 mWindowSizeText = S.AddVariableText(
109 SA_DFT_WINDOW_SIZE_TEXT, true, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
110
111 mForceFinalAlignmentCheckBox = S.Id(ID_FORCEFINALALIGNMENT)
112 .Name(XO("Force Final Alignment"))
113 .AddCheckBox(
114 XO("Force Final Alignment"),
115 p.mForceFinalAlignment);
116 mIgnoreSilenceCheckBox = S.Id(ID_IGNORESILENCE)
117 .Name(XO("Ignore Silence at Beginnings and Endings"))
118 .AddCheckBox(
119 XO("Ignore Silence at Beginnings and Endings"),
120 p.mIgnoreSilence );
121 // need a third column after checkboxes:
122 S.AddVariableText({}, true, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
123
124 mSilenceThresholdLabel = S.AddVariableText(XO("Silence Threshold:"),
125 true, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
126 mSilenceThresholdSlider = S.Id(ID_SILENCETHRESHOLD)
127 .Name(XO("Silence Threshold"))
128 .Style(wxSL_HORIZONTAL)
129 .AddSlider( {},
130 /*pos*/ (int) (p.mSilenceThreshold * 1000 + 0.5), /*max*/ 500);
131 mSilenceThresholdText = S.AddVariableText(
132 SA_DFT_SILENCE_THRESHOLD_TEXT,
133 true, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
134
135 mPresmoothLabel = S.AddVariableText(
136 /* i18n-hint: The English would be clearer if it had 'Duration' rather than 'Time'
137 This is a NEW experimental effect, and until we have it documented in the user
138 manual we don't have a clear description of what this parameter does.
139 It is OK to leave it in English. */
140 XO("Presmooth Time:"), true, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
141 mPresmoothSlider = S.Id(ID_PRESMOOTH)
142 /* i18n-hint: The English would be clearer if it had 'Duration' rather than 'Time'
143 This is a NEW experimental effect, and until we have it documented in the user
144 manual we don't have a clear description of what this parameter does.
145 It is OK to leave it in English. */
146 .Name(XO("Presmooth Time"))
147 .Style(wxSL_HORIZONTAL)
148 .AddSlider( {},
149 /*pos*/ (int) (p.mPresmoothTime * 100 + 0.5), /*max*/ 500);
150 mPresmoothText = S.AddVariableText(
151 SA_DFT_PRESMOOTH_TIME_TEXT, true, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
152
153 /* i18n-hint: The English would be clearer if it had 'Duration' rather than 'Time'
154 This is a NEW experimental effect, and until we have it documented in the user
155 manual we don't have a clear description of what this parameter does.
156 It is OK to leave it in English. */
157 mLineTimeLabel = S.AddVariableText(XO("Line Time:"), true,
158 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
159 mLineTimeSlider = S.Id(ID_LINETIME)
160 /* i18n-hint: The English would be clearer if it had 'Duration' rather than 'Time'
161 This is a NEW experimental effect, and until we have it documented in the user
162 manual we don't have a clear description of what this parameter does.
163 It is OK to leave it in English. */
164 .Name(XO("Line Time"))
165 .Style(wxSL_HORIZONTAL)
166 .AddSlider( {},
167 /*pos*/ (int) (p.mLineTime * 100 + 0.5), /*max*/ 500);
168 mLineTimeText = S.AddVariableText(
169 SA_DFT_LINE_TIME_TEXT, true, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
170
171 /* i18n-hint: The English would be clearer if it had 'Duration' rather than 'Time'
172 This is a NEW experimental effect, and until we have it documented in the user
173 manual we don't have a clear description of what this parameter does.
174 It is OK to leave it in English. */
175 mSmoothTimeLabel = S.AddVariableText(
176 XO("Smooth Time:"), true, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
177 mSmoothTimeSlider = S.Id(ID_SMOOTHTIME)
178 /* i18n-hint: The English would be clearer if it had 'Duration' rather than 'Time'
179 This is a NEW experimental effect, and until we have it documented in the user
180 manual we don't have a clear description of what this parameter does.
181 It is OK to leave it in English. */
182 .Name(XO("Smooth Time"))
183 .Style(wxSL_HORIZONTAL)
184 .AddSlider( {},
185 /*pos*/ (int) (p.mSmoothTime * 100 + 0.5), /*max*/ 500);
186 mSmoothTimeText = S.AddVariableText(
187 SA_DFT_SMOOTH_TIME_TEXT, true, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
188
189 S.EndMultiColumn();
190 S.EndStatic();
191
192 mDefaultButton = safenew wxButton(this, ID_DEFAULT, _("Use Defaults"));
193 mDefaultButton->SetName(_("Restore Defaults"));
194
195 S.AddStandardButtons(eOkButton | eCancelButton, mDefaultButton);
196 S.EndVerticalLay();
197 Layout();
198 Fit();
199 Center();
200
201 TransferDataFromWindow(); // set labels according to actual initial values
202
203 params.mStatus = p.mStatus = ShowModal();
204
205 if (p.mStatus == wxID_OK) {
206 // Retain the settings
207 gPrefs->Write(wxT("/Tracks/Synchronize/FramePeriod"), p.mFramePeriod);
208 gPrefs->Write(wxT("/Tracks/Synchronize/WindowSize"), p.mWindowSize);
209 gPrefs->Write(wxT("/Tracks/Synchronize/SilenceThreshold"),
210 p.mSilenceThreshold);
211 gPrefs->Write(wxT("/Tracks/Synchronize/ForceFinalAlignment"),
212 p.mForceFinalAlignment);
213 gPrefs->Write(wxT("/Tracks/Synchronize/IgnoreSilence"),
214 p.mIgnoreSilence);
215 gPrefs->Write(wxT("/Tracks/Synchronize/PresmoothTime"),
216 p.mPresmoothTime);
217 gPrefs->Write(wxT("/Tracks/Synchronize/LineTime"), p.mLineTime);
218 gPrefs->Write(wxT("/Tracks/Synchronize/SmoothTime"), p.mSmoothTime);
219 gPrefs->Flush();
220
221 params = p; // return all parameters through params
222 }
223}
224
225ScoreAlignDialog::~ScoreAlignDialog()
226{
227}
228
229
230//void ScoreAlignDialog::OnOK(wxCommandEvent & event)
231//{
232// EndModal(wxID_OK);
233//}
234
235//void ScoreAlignDialog::OnCancel(wxCommandEvent & event)
236//{
237// EndModal(wxID_CANCEL);
238//}
239
240void ScoreAlignDialog::OnSlider(wxCommandEvent & event)
241{
242 TransferDataFromWindow();
243}
244
245
246void ScoreAlignDialog::OnDefault(wxCommandEvent & event)
247{
248 mFramePeriodSlider->SetValue((int) (SA_DFT_FRAME_PERIOD * 100 + 0.5));
249 mWindowSizeSlider->SetValue((int) (SA_DFT_WINDOW_SIZE * 100 + 0.5));
250 mSilenceThresholdSlider->SetValue(
251 (int) (SA_DFT_SILENCE_THRESHOLD * 1000 + 0.5));
252 mForceFinalAlignmentCheckBox->SetValue(SA_DFT_FORCE_FINAL_ALIGNMENT);
253 mIgnoreSilenceCheckBox->SetValue(SA_DFT_IGNORE_SILENCE);
254 mPresmoothSlider->SetValue((int) (SA_DFT_PRESMOOTH_TIME * 100 + 0.5));
255 mLineTimeSlider->SetValue((int) (SA_DFT_LINE_TIME * 100 + 0.5));
256 mSmoothTimeSlider->SetValue((int) (SA_DFT_SMOOTH_TIME * 100 + 0.5));
257
258 TransferDataFromWindow();
259}
260
261
262bool ScoreAlignDialog::TransferDataFromWindow()
263{
264 p.mFramePeriod = (double) mFramePeriodSlider->GetValue() / 100.0;
265 p.mWindowSize = (double) mWindowSizeSlider->GetValue() / 100.0;
266 p.mSilenceThreshold = (double) mSilenceThresholdSlider->GetValue() / 1000.0;
267 p.mForceFinalAlignment = (double) mForceFinalAlignmentCheckBox->GetValue();
268 p.mIgnoreSilence = (double) mIgnoreSilenceCheckBox->GetValue();
269 p.mPresmoothTime = (double) mPresmoothSlider->GetValue() / 100.0;
270 p.mLineTime = (double) mLineTimeSlider->GetValue() / 100.0;
271 p.mSmoothTime = (double) mSmoothTimeSlider->GetValue() / 100.0;
272
273 mFramePeriodText->SetLabel(wxString::Format(_("%.2f secs"),
274 p.mFramePeriod));
275 mWindowSizeText->SetLabel(wxString::Format(_("%.2f secs"), p.mWindowSize));
276 mSilenceThresholdText->SetLabel(wxString::Format(_("%.3f"),
277 p.mSilenceThreshold));
278 mPresmoothText->SetLabel(p.mPresmoothTime > 0 ?
279 wxString::Format(_("%.2f secs"),
280 p.mPresmoothTime) : wxT("(off)"));
281 mLineTimeText->SetLabel(p.mLineTime > 0 ?
282 wxString::Format(_("%.2f secs"), p.mLineTime) :
283 wxT("(off)"));
284 mSmoothTimeText->SetLabel(wxString::Format(_("%.2f secs"), p.mSmoothTime));
285 return true;
286}
287
288
289void CloseScoreAlignDialog()
290{
291 gScoreAlignDialog.reset();
292}
293
294
295BEGIN_EVENT_TABLE(ScoreAlignDialog, wxDialogWrapper)
296// EVT_BUTTON(wxID_OK, ScoreAlignDialog::OnOK)
297// EVT_BUTTON(wxID_CANCEL, ScoreAlignDialog::OnCancel)
298 EVT_BUTTON(ID_DEFAULT, ScoreAlignDialog::OnDefault)
299 EVT_SLIDER(ID_FRAMEPERIOD, ScoreAlignDialog::OnSlider)
300 EVT_SLIDER(ID_WINDOWSIZE, ScoreAlignDialog::OnSlider)
301 EVT_SLIDER(ID_SILENCETHRESHOLD, ScoreAlignDialog::OnSlider)
302 EVT_CHECKBOX(ID_FORCEFINALALIGNMENT, ScoreAlignDialog::OnSlider)
303 EVT_CHECKBOX(ID_IGNORESILENCE, ScoreAlignDialog::OnSlider)
304 EVT_SLIDER(ID_PRESMOOTH, ScoreAlignDialog::OnSlider)
305 EVT_SLIDER(ID_LINETIME, ScoreAlignDialog::OnSlider)
306 EVT_SLIDER(ID_SMOOTHTIME, ScoreAlignDialog::OnSlider)
308
309#endif
wxT("CloseDown"))
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
EffectDistortionSettings params
Definition: Distortion.cpp:77
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
#define safenew
Definition: MemoryX.h:9
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:609
@ eCancelButton
Definition: ShuttleGui.h:610
#define S(N)
Definition: ToChars.cpp:64
ScoreAlignDialog is \TODO.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0