1
// RCS-ID: $Id: Constrains.cpp,v 1.9 2006/03/03 15:01:14 cecilios Exp $
2
//--------------------------------------------------------------------------------------
3
// LenMus Phonascus: The teacher of music
4
// Copyright (c) 2002-2006 Cecilio Salmeron
6
// This program is free software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the Free Software Foundation;
8
// either version 2 of the License, or (at your option) any later version.
10
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License along with this
15
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
16
// Fifth Floor, Boston, MA 02110-1301, USA.
18
// For any comment, suggestion or feature request, please contact the manager of
19
// the project at cecilios@users.sourceforge.net
21
//-------------------------------------------------------------------------------------
22
/*! @file Constrains.cpp
23
@brief Implementation file for Constrain derived class lmClefConstrain
26
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
27
#pragma implementation "Constrains.h"
30
// For compilers that support precompilation, includes "wx.h".
31
#include "wx/wxprec.h"
37
#include "Constrains.h"
40
extern wxConfigBase *g_pPrefs;
44
//-------------------------------------------------------------------------------------------
46
//-------------------------------------------------------------------------------------------
48
lmClefConstrain::lmClefConstrain()
50
for (int i = lmMIN_CLEF; i <= lmMAX_CLEF; i++) {
51
m_fValidClefs[i-lmMIN_CLEF] = false;
52
m_aLowerPitch[i-lmMIN_CLEF] = _T("c0");
53
m_aUpperPitch[i-lmMIN_CLEF] = _T("c9");
58
//-------------------------------------------------------------------------------------------
60
//-------------------------------------------------------------------------------------------
62
lmKeyConstrains::lmKeyConstrains()
64
for (int i = lmMIN_KEY; i <= lmMAX_KEY; i++) {
65
m_fValidKeys[i-lmMIN_KEY] = false;
70
//-------------------------------------------------------------------------------------------
71
// lmTimeSignConstrains
72
//-------------------------------------------------------------------------------------------
74
lmTimeSignConstrains::lmTimeSignConstrains()
76
for (int i = lmMIN_TIME_SIGN; i <= lmMAX_TIME_SIGN; i++) {
77
m_fValidTimes[i-lmMIN_TIME_SIGN] = false;
81
/*! Initialize constrains from a comma separated list of values.
82
i.e.: '24,34,44' (no spaces allowed)
85
bool lmTimeSignConstrains::SetConstrains(wxString sTimeSign)
88
for (i = lmMIN_TIME_SIGN; i <= lmMAX_TIME_SIGN; i++) {
89
m_fValidTimes[i-lmMIN_TIME_SIGN] = false;
95
//split the list into values
96
i = sTimeSign.First(_T(","));
97
sData = ((i > 0) ? sTimeSign.Left(i) : sTimeSign);
98
while (sData != _T("")) {
99
// 24,34,44,68,98,128,28,38,22,32
100
if (sData == _T("24")) nTimeSign = (int)emtr24;
101
else if (sData == _T("34")) nTimeSign = (int)emtr34;
102
else if (sData == _T("44")) nTimeSign = (int)emtr44;
103
else if (sData == _T("68")) nTimeSign = (int)emtr68;
104
else if (sData == _T("98")) nTimeSign = (int)emtr98;
105
else if (sData == _T("128")) nTimeSign = (int)emtr128;
106
else if (sData == _T("28")) nTimeSign = (int)emtr28;
107
else if (sData == _T("38")) nTimeSign = (int)emtr38;
108
else if (sData == _T("22")) nTimeSign = (int)emtr22;
109
else if (sData == _T("32")) nTimeSign = (int)emtr32;
113
m_fValidTimes[nTimeSign-lmMIN_TIME_SIGN] = true;
114
sTimeSign = ((i > 0) ? sTimeSign.Mid(i+1) : _T(""));
115
i = sTimeSign.First(_T(","));
116
sData = ((i > 0) ? sTimeSign.Left(i) : sTimeSign);
124
//-------------------------------------------------------------------------------------------
125
// lmTheoIntervalsConstrains
126
//-------------------------------------------------------------------------------------------
128
lmTheoIntervalsConstrains::lmTheoIntervalsConstrains()
133
void lmTheoIntervalsConstrains::SaveSettings()
136
save settings in user configuration data file
142
for (i = lmMIN_CLEF; i <= lmMAX_CLEF; i++) {
143
sKey = wxString::Format(_T("/Constrains/TheoIntval/TheoIntervals/Clef%d"), i);
144
g_pPrefs->Write(sKey, IsValidClef((EClefType)i) );
147
// allowed accidentals
148
g_pPrefs->Write(_T("/Constrains/TheoIntval/TheoIntervals/Accidentals"),
150
g_pPrefs->Write(_T("/Constrains/TheoIntval/TheoIntervals/DoubleAccidentals"),
151
m_fDoubleAccidentals);
154
g_pPrefs->Write(_T("/Constrains/TheoIntval/TheoIntervals/ProblemType"),
155
(long) m_nProblemType );
159
void lmTheoIntervalsConstrains::LoadSettings()
162
load settings form user configuration data or default values
165
// allowed clefs. Default G clef
169
for (i = lmMIN_CLEF; i <= lmMAX_CLEF; i++) {
170
sKey = wxString::Format(_T("/Constrains/TheoIntval/TheoIntervals/Clef%d"), i);
171
g_pPrefs->Read(sKey, &fValid, (i == eclvSol) );
172
SetClef((EClefType)i, fValid);
175
// allowed accidentals. Defaul: none
176
g_pPrefs->Read(_T("/Constrains/TheoIntval/TheoIntervals/Accidentals"),
177
&m_fAccidentals, false);
178
g_pPrefs->Read(_T("/Constrains/TheoIntval/TheoIntervals/DoubleAccidentals"),
179
&m_fDoubleAccidentals, false);
182
m_nProblemType = (EProblemTheoIntervals) g_pPrefs->Read(
183
_T("/Constrains/TheoIntval/TheoIntervals/ProblemType"),
191
//-------------------------------------------------------------------------------------------
192
// lmSideReadingCtrolOptions
193
//-------------------------------------------------------------------------------------------
195
void lmSideReadingCtrolOptions::SetLabels(wxString& sLabel, wxString* pStart, wxString* pStop)
198
int i = sLabel.Find(_T("|"));
200
if (i > 1) *pStart = sLabel.Mid(0, i-1);
201
if (i < (int)sLabel.Length()-1) *pStop = sLabel.Mid(i+1);
211
//-------------------------------------------------------------------------------------------
212
// lmScoreCtrolOptions
213
//-------------------------------------------------------------------------------------------
215
void lmScoreCtrolOptions::SetLabels(wxString& sLabel, wxString* pStart, wxString* pStop)
218
int i = sLabel.Find(_T("|"));
220
if (i > 1) *pStart = sLabel.Mid(0, i-1);
221
if (i < (int)sLabel.Length()-1) *pStop = sLabel.Mid(i+1);