1
//--------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2007 Cecilio Salmeron
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation;
7
// either version 2 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
15
// Fifth Floor, Boston, MA 02110-1301, USA.
17
// for (any comment, suggestion or feature request, please contact the manager of
18
// the project at cecilios@users.sourceforge.net
20
//-------------------------------------------------------------------------------------
21
/*! @file DlgCfgIdfyChord.cpp
22
@brief Implementation file for class lmDlgCfgIdfyChord
28
#pragma implementation "DlgCfgIdfyChord.h"
31
// for (compilers that support precompilation, includes "wx/wx.h".
32
#include "wx/wxprec.h"
42
#include <wx/dialog.h>
43
#include <wx/button.h>
45
#include "wx/xrc/xmlres.h"
48
#include "../globals/Paths.h"
49
extern lmPaths* g_pPaths;
53
#include "DlgCfgIdfyChord.h"
54
#include "../ldp_parser/AuxString.h"
55
#include "../auxmusic/Conversion.h"
59
//-----------------------------------------------------------------------------
60
// Event table: connect the events to the handler functions to process them
61
//-----------------------------------------------------------------------------
63
BEGIN_EVENT_TABLE(lmDlgCfgIdfyChord, wxDialog)
64
EVT_BUTTON( XRCID( "buttonAccept" ), lmDlgCfgIdfyChord::OnAcceptClicked )
65
EVT_BUTTON( XRCID( "buttonCancel" ), lmDlgCfgIdfyChord::OnCancelClicked )
67
// Type of interval check boxes
68
EVT_CHECKBOX( XRCID( "chkModeHarmonic" ), lmDlgCfgIdfyChord::OnDataChanged )
69
EVT_CHECKBOX( XRCID( "chkModeMelodicAsc" ), lmDlgCfgIdfyChord::OnDataChanged )
70
EVT_CHECKBOX( XRCID( "chkModeMelodicDesc" ), lmDlgCfgIdfyChord::OnDataChanged )
72
// Key signature check boxes
73
EVT_CHECKBOX( XRCID( "chkKeyC" ), lmDlgCfgIdfyChord::OnDataChanged )
74
EVT_CHECKBOX( XRCID( "chkKeyG" ), lmDlgCfgIdfyChord::OnDataChanged )
75
EVT_CHECKBOX( XRCID( "chkKeyD" ), lmDlgCfgIdfyChord::OnDataChanged )
76
EVT_CHECKBOX( XRCID( "chkKeyA" ), lmDlgCfgIdfyChord::OnDataChanged )
77
EVT_CHECKBOX( XRCID( "chkKeyE" ), lmDlgCfgIdfyChord::OnDataChanged )
78
EVT_CHECKBOX( XRCID( "chkKeyB" ), lmDlgCfgIdfyChord::OnDataChanged )
79
EVT_CHECKBOX( XRCID( "chkKeyFSharp" ), lmDlgCfgIdfyChord::OnDataChanged )
80
EVT_CHECKBOX( XRCID( "chkKeyCSharp" ), lmDlgCfgIdfyChord::OnDataChanged )
81
EVT_CHECKBOX( XRCID( "chkKeyCFlat" ), lmDlgCfgIdfyChord::OnDataChanged )
82
EVT_CHECKBOX( XRCID( "chkKeyGFlat" ), lmDlgCfgIdfyChord::OnDataChanged )
83
EVT_CHECKBOX( XRCID( "chkKeyDFlat" ), lmDlgCfgIdfyChord::OnDataChanged )
84
EVT_CHECKBOX( XRCID( "chkKeyAFlat" ), lmDlgCfgIdfyChord::OnDataChanged )
85
EVT_CHECKBOX( XRCID( "chkKeyEFlat" ), lmDlgCfgIdfyChord::OnDataChanged )
86
EVT_CHECKBOX( XRCID( "chkKeyBFlat" ), lmDlgCfgIdfyChord::OnDataChanged )
87
EVT_CHECKBOX( XRCID( "chkKeyF" ), lmDlgCfgIdfyChord::OnDataChanged )
89
// Allowed chords check boxes
90
EVT_CHECKBOX( XRCID( "chkChordMajorTriad" ), lmDlgCfgIdfyChord::OnDataChanged )
91
EVT_CHECKBOX( XRCID( "chkChordMinorTriad" ), lmDlgCfgIdfyChord::OnDataChanged )
92
EVT_CHECKBOX( XRCID( "chkChordAugTriad" ), lmDlgCfgIdfyChord::OnDataChanged )
93
EVT_CHECKBOX( XRCID( "chkChordDimTriad" ), lmDlgCfgIdfyChord::OnDataChanged )
94
EVT_CHECKBOX( XRCID( "chkChordSus4th" ), lmDlgCfgIdfyChord::OnDataChanged )
95
EVT_CHECKBOX( XRCID( "chkChordSus2nd" ), lmDlgCfgIdfyChord::OnDataChanged )
96
EVT_CHECKBOX( XRCID( "chkChordMajor7" ), lmDlgCfgIdfyChord::OnDataChanged )
97
EVT_CHECKBOX( XRCID( "chkChordDominant7" ), lmDlgCfgIdfyChord::OnDataChanged )
98
EVT_CHECKBOX( XRCID( "chkChordMinor7" ), lmDlgCfgIdfyChord::OnDataChanged )
99
EVT_CHECKBOX( XRCID( "chkChordDim7" ), lmDlgCfgIdfyChord::OnDataChanged )
100
EVT_CHECKBOX( XRCID( "chkChordHalfDim7" ), lmDlgCfgIdfyChord::OnDataChanged )
101
EVT_CHECKBOX( XRCID( "chkChordAugMajor7" ), lmDlgCfgIdfyChord::OnDataChanged )
102
EVT_CHECKBOX( XRCID( "chkChordAug7" ), lmDlgCfgIdfyChord::OnDataChanged )
103
EVT_CHECKBOX( XRCID( "chkChordMinorMajor7" ), lmDlgCfgIdfyChord::OnDataChanged )
104
EVT_CHECKBOX( XRCID( "chkChordMajor6" ), lmDlgCfgIdfyChord::OnDataChanged )
105
EVT_CHECKBOX( XRCID( "chkChordMinor6" ), lmDlgCfgIdfyChord::OnDataChanged )
106
EVT_CHECKBOX( XRCID( "chkChordAug6" ), lmDlgCfgIdfyChord::OnDataChanged )
112
lmDlgCfgIdfyChord::lmDlgCfgIdfyChord(wxWindow* parent,
113
lmChordConstrains* pConstrains,
116
// save received data
117
m_pConstrains = pConstrains;
118
m_fTheoryMode = fTheoryMode;
120
// create the dialog controls
121
wxXmlResource::Get()->LoadDialog(this, parent, _T("DlgCfgIdfyChord"));
124
//get pointers to all controls
127
// error messages and bitmaps
128
m_pBmpPlayModeError = XRCCTRL(*this, "bmpPlayModeError", wxStaticBitmap);
129
m_pLblPlayModeError = XRCCTRL(*this, "lblPlayModeError", wxStaticText);
130
m_pBmpKeySignError = XRCCTRL(*this, "bmpKeySignError", wxStaticBitmap);
131
m_pLblKeySignError = XRCCTRL(*this, "lblKeySignError", wxStaticText);
132
m_pBmpAllowedChordsError = XRCCTRL(*this, "bmpAllowedChordsError", wxStaticBitmap);
133
m_pLblAllowedChordsError = XRCCTRL(*this, "lblAllowedChordsError", wxStaticText);
135
// allowed chords checkboxes
136
// correspondence with EChordTypes
137
m_pChkChord[ect_MajorTriad] = XRCCTRL(*this, "chkChordMajorTriad", wxCheckBox);
138
m_pChkChord[ect_MinorTriad] = XRCCTRL(*this, "chkChordMinorTriad", wxCheckBox);
139
m_pChkChord[ect_AugTriad] = XRCCTRL(*this, "chkChordAugTriad", wxCheckBox);
140
m_pChkChord[ect_DimTriad] = XRCCTRL(*this, "chkChordDimTriad", wxCheckBox);
141
m_pChkChord[ect_Suspended_4th] = XRCCTRL(*this, "chkChordSus4th", wxCheckBox);
142
m_pChkChord[ect_Suspended_2nd] = XRCCTRL(*this, "chkChordSus2nd", wxCheckBox);
143
m_pChkChord[ect_MajorSeventh] = XRCCTRL(*this, "chkChordMajor7", wxCheckBox);
144
m_pChkChord[ect_DominantSeventh] = XRCCTRL(*this, "chkChordDominant7", wxCheckBox);
145
m_pChkChord[ect_MinorSeventh] = XRCCTRL(*this, "chkChordMinor7", wxCheckBox);
146
m_pChkChord[ect_DimSeventh] = XRCCTRL(*this, "chkChordDim7", wxCheckBox);
147
m_pChkChord[ect_HalfDimSeventh] = XRCCTRL(*this, "chkChordHalfDim7", wxCheckBox);
148
m_pChkChord[ect_AugMajorSeventh] = XRCCTRL(*this, "chkChordAugMajor7", wxCheckBox);
149
m_pChkChord[ect_AugSeventh] = XRCCTRL(*this, "chkChordAug7", wxCheckBox);
150
m_pChkChord[ect_MinorMajorSeventh] = XRCCTRL(*this, "chkChordMinorMajor7", wxCheckBox);
151
m_pChkChord[ect_MajorSixth] = XRCCTRL(*this, "chkChordMajor6", wxCheckBox);
152
m_pChkChord[ect_MinorSixth] = XRCCTRL(*this, "chkChordMinor6", wxCheckBox);
153
m_pChkChord[ect_AugSixth] = XRCCTRL(*this, "chkChordAug6", wxCheckBox);
155
// Allowed key signatures
156
m_pChkKeySign[earmDo] = XRCCTRL(*this, "chkKeyC", wxCheckBox);
157
m_pChkKeySign[earmSol] = XRCCTRL(*this, "chkKeyG", wxCheckBox);
158
m_pChkKeySign[earmRe] = XRCCTRL(*this, "chkKeyD", wxCheckBox);
159
m_pChkKeySign[earmLa] = XRCCTRL(*this, "chkKeyA", wxCheckBox);
160
m_pChkKeySign[earmMi] = XRCCTRL(*this, "chkKeyE", wxCheckBox);
161
m_pChkKeySign[earmSi] = XRCCTRL(*this, "chkKeyB", wxCheckBox);
162
m_pChkKeySign[earmFas] = XRCCTRL(*this, "chkKeyFSharp", wxCheckBox);
163
m_pChkKeySign[earmDos] = XRCCTRL(*this, "chkKeyCSharp", wxCheckBox);
164
m_pChkKeySign[earmDob] = XRCCTRL(*this, "chkKeyCFlat", wxCheckBox);
165
m_pChkKeySign[earmSolb] = XRCCTRL(*this, "chkKeyGFlat", wxCheckBox);
166
m_pChkKeySign[earmReb] = XRCCTRL(*this, "chkKeyDFlat", wxCheckBox);
167
m_pChkKeySign[earmLab] = XRCCTRL(*this, "chkKeyAFlat", wxCheckBox);
168
m_pChkKeySign[earmMib] = XRCCTRL(*this, "chkKeyEFlat", wxCheckBox);
169
m_pChkKeySign[earmSib] = XRCCTRL(*this, "chkKeyBFlat", wxCheckBox);
170
m_pChkKeySign[earmFa] = XRCCTRL(*this, "chkKeyF", wxCheckBox);
172
// allowed types of intervals
173
m_pChkPlayMode[0] = XRCCTRL(*this, "chkModeHarmonic", wxCheckBox);
174
m_pChkPlayMode[1] = XRCCTRL(*this, "chkModeMelodicAsc", wxCheckBox);
175
m_pChkPlayMode[2] = XRCCTRL(*this, "chkModeMelodicDesc", wxCheckBox);
178
m_pChkAllowInversions = XRCCTRL(*this, "chkAllowInversions", wxCheckBox);
179
m_pChkDisplayKey = XRCCTRL(*this, "chkDisplayKey", wxCheckBox);
180
m_pBoxPlayModes = XRCCTRL(*this, "boxPlayModes", wxStaticBox);
184
wxArtProvider::GetBitmap(_T("msg_error"), wxART_TOOLBAR, wxSize(16,16));
185
m_pBmpPlayModeError->SetBitmap(bmpError);
186
m_pBmpKeySignError->SetBitmap(bmpError);
187
m_pBmpAllowedChordsError->SetBitmap(bmpError);
189
//hide all error messages and their associated icons
190
m_pLblPlayModeError->Show(false);
191
m_pBmpPlayModeError->Show(false);
192
m_pLblKeySignError->Show(false);
193
m_pBmpKeySignError->Show(false);
194
m_pLblAllowedChordsError->Show(false);
195
m_pBmpAllowedChordsError->Show(false);
198
// initialize all controls with current constraints data
201
//initialize check boxes for allowed chords with current settings
203
for (i=0; i < ect_Max; i++) {
204
m_pChkChord[i]->SetValue( m_pConstrains->IsChordValid((EChordType)i) );
208
for (i=0; i < 3; i++) {
209
m_pChkPlayMode[i]->SetValue( m_pConstrains->IsModeAllowed(i) );
212
// allowed key signatures
213
lmKeyConstrains* pKeyConstrains = m_pConstrains->GetKeyConstrains();
214
for (i=0; i < earmFa+1; i++) {
215
m_pChkKeySign[i]->SetValue( pKeyConstrains->IsValid((EKeySignatures)i) );
219
m_pChkAllowInversions->SetValue( m_pConstrains->AreInversionsAllowed() );
220
m_pChkDisplayKey->SetValue( m_pConstrains->DisplayKey() );
222
// As this dialog is shared by EarTraining and Theory.
223
// Flag m_fTheoryMode controls whether to show/hide
224
// specific controls used only in one of the exercises
226
// This dialog is being used for Theory so, hide play modes
227
m_pBoxPlayModes->Show(false);
231
//center dialog on screen
236
lmDlgCfgIdfyChord::~lmDlgCfgIdfyChord()
240
void lmDlgCfgIdfyChord::OnDataChanged(wxCommandEvent& WXUNUSED(event))
245
void lmDlgCfgIdfyChord::OnAcceptClicked(wxCommandEvent& WXUNUSED(event))
247
// Accept button will be enabled only if all data have been validated and is Ok. So
248
// when accept button is clicked we can proceed to save data.
250
//save allowed chords
252
for (i=0; i < ect_Max; i++) {
253
m_pConstrains->SetChordValid((EChordType)i, m_pChkChord[i]->GetValue());
256
// save selected key signatures
257
lmKeyConstrains* pKeyConstrains = m_pConstrains->GetKeyConstrains();
258
for (i=0; i < earmFa+1; i++) {
259
pKeyConstrains->SetValid((EKeySignatures)i, m_pChkKeySign[i]->GetValue());
263
m_pConstrains->SetDisplayKey( m_pChkDisplayKey->GetValue() );
264
m_pConstrains->SetInversionsAllowed( m_pChkAllowInversions->GetValue() );
266
// save options depending on mode: theory/ear training
267
if (!m_fTheoryMode) {
268
//ear training. Save play modes
269
for (i=0; i < 3; i++) {
270
m_pConstrains->SetModeAllowed(i, m_pChkPlayMode[i]->GetValue());
274
//terminate the dialog
278
bool lmDlgCfgIdfyChord::VerifyData()
280
// Returns a boolean to enable or not a tab change. That is: returns true if there are
281
// local errors (errors affecting only to the data in a tab) so not to enable a tab
282
// change. If there are no tab local errors then returns false (althought it there might
283
// be global errors -- coherence between data in different tabs --).
285
// Anyway, global errors al also checked. If there are no global neither local
286
// errors the Accept button is enabled. Otherwise it is disabled.
293
bool fLocalError = false;
294
bool fGlobalError = false;
296
m_pLblPlayModeError->Show(false);
297
m_pBmpPlayModeError->Show(false);
298
m_pLblKeySignError->Show(false);
299
m_pBmpKeySignError->Show(false);
300
m_pLblAllowedChordsError->Show(false);
301
m_pBmpAllowedChordsError->Show(false);
303
// check that at least one chord type is selected
306
for (i=0; i < ect_Max; i++) {
307
if (m_pChkChord[i]->GetValue()) {
312
fError = !fAtLeastOne;
314
m_pLblAllowedChordsError->Show(true);
315
m_pBmpAllowedChordsError->Show(true);
317
fLocalError |= fError;
319
// check that at least one key signature has been choosen
321
for (i=0; i < earmFa+1; i++) {
322
fAtLeastOne |= m_pChkKeySign[i]->GetValue();
324
fError = !fAtLeastOne;
326
m_pLblKeySignError->Show(true);
327
m_pBmpKeySignError->Show(true);
329
fLocalError |= fError;
331
//check that at least one play mode is choosen
334
for (i=0; i < 3; i++) {
335
fAtLeastOne |= m_pChkPlayMode[i]->GetValue();
337
fError = !fAtLeastOne;
339
m_pLblPlayModeError->Show(true);
340
m_pBmpPlayModeError->Show(true);
342
fLocalError |= fError;
346
// Check for global errors
349
fGlobalError = false; //no global checkings in this dlg
352
//enable / disable accept button
353
wxButton* pButtonAccept = XRCCTRL(*this, "buttonAccept", wxButton);
354
pButtonAccept->Enable(!fLocalError && !fGlobalError);