1
//--------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2010 LenMus project
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 3 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, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//-------------------------------------------------------------------------------------
21
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
22
#pragma implementation "KbdCmdParser.h"
25
// for (compilers that support precompilation, includes <wx/wx.h>.
26
#include <wx/wxprec.h>
36
#include "KbdCmdParser.h"
40
const wxChar nEOB = _T('\x00'); //End of buffer
43
//-------------------------------------------------------------------------------------------
44
// Implementation of class lmKbdCmdParser
45
//-------------------------------------------------------------------------------------------
47
lmKbdCmdParser::lmKbdCmdParser()
51
lmKbdCmdParser::~lmKbdCmdParser()
55
bool lmKbdCmdParser::ParserCommand(wxString sCmd)
57
//Return true if OK (no error)
59
//default values for answers
60
m_nAcc = lm_eNoAccidentals;
66
m_iMax = m_sBuff.Length();
70
wxChar lmKbdCmdParser::GetNextChar()
73
// when entering, m_iFirst points to the char to read
75
if (m_iFirst >= m_iMax)
78
return m_sBuff.GetChar(m_iFirst++);
81
bool lmKbdCmdParser::DoParse()
83
//Return true if OK (no error)
96
int nState = FT_Start;
97
wxChar curChar = _T('-');
102
curChar = GetNextChar();
117
m_nAcc = lm_eDoubleSharp;
128
return true; //End of buffer. Parsed without errors
135
curChar = GetNextChar();
136
if (curChar == _T('+')) {
137
m_nAcc = lm_eSharpSharp;
146
curChar = GetNextChar();
147
if (curChar == _T('-')) {
148
m_nAcc = lm_eFlatFlat;
157
curChar = GetNextChar();
158
if (curChar == _T('+')) {
159
m_nAcc = lm_eNaturalSharp;
161
} else if (curChar == _T('-')) {
162
m_nAcc = lm_eNaturalFlat;
165
m_nAcc = lm_eNatural;
171
curChar = GetNextChar();
172
if (curChar == _T('.')) {
180
return false; //parse error
183
wxASSERT(false); //not defined state
184
return false; //parse error
186
} // switch for states
188
return true; //parsed without errors