1
//---------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2011 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 "lenmus_conversion.h"
25
//// For compilers that support precompilation, includes <wx.h>.
26
//#include <wx/wxprec.h>
32
//#include "../score/Score.h"
33
//#include "lenmus_conversion.h"
40
//lmConverter::lmConverter()
45
////---------------------------------------------------------------------------------------
47
////---------------------------------------------------------------------------------------
49
//bool lmConverter::NoteToBits(wxString sNote, NoteBits* pBits)
51
// //Returns true if error
52
// //- sNote must be letter followed by a number (i.e.: "c4" ) optionally precedeed by
53
// // accidentals (i.e.: "++c4")
54
// //- It is assumed that sNote is trimmed (no spaces before or after data)
57
// //split the string: accidentals and name
58
// wxString sAccidentals;
59
// switch (sNote.length()) {
61
// sAccidentals = _T("");
64
// sAccidentals = sNote.substr(0, 1);
65
// sNote = sNote.substr(1, 2);
68
// sAccidentals = sNote.substr(0, 2);
69
// sNote = sNote.substr(2, 2);
72
// return true; //error
76
// int nStep = StepToInt( sNote.Left(1) );
77
// if (nStep == -1) return true; //error
78
// pBits->nStep = nStep;
81
// wxString sOctave = sNote.substr(1, 1);
83
// if (!sOctave.ToLong(&nOctave)) return true; //error
84
// pBits->nOctave = (int)nOctave;
86
// //compute accidentals
87
// int nAccidentals = AccidentalsToInt(sAccidentals);
88
// if (nAccidentals == -999) return true; //error
89
// pBits->nAccidentals = nAccidentals;
91
// //compute step semitones
92
// pBits->nStepSemitones = StepToSemitones( pBits->nStep );
94
// return false; //no error
98
//bool lmConverter::DPitchToBits(DiatonicPitch nPitch, NoteBits* pBits)
100
// //Returns true if error
101
// //Accidentals are set to 'none' (zero)
104
// pBits->nStep = DPitch_Step(nPitch);
107
// pBits->nOctave = DPitch_Octave(nPitch);
109
// //compute accidentals
110
// pBits->nAccidentals = 0;
112
// //compute step semitones
113
// pBits->nStepSemitones = StepToSemitones( pBits->nStep );
115
// return false; //no error
120
//wxString lmConverter::NoteBitsToName(NoteBits& tBits, EKeySignature nKey)
122
// static wxString m_sSteps = _T("cdefgab");
124
// // Get the accidentals implied by the key signature.
125
// // Each element of the array refers to one note: 0=Do, 1=Re, 2=Mi, 3=Fa, ... , 6=Si
126
// // and its value can be one of: 0=no accidental, -1 = a flat, 1 = a sharp
127
// int nAccidentals[7];
128
// lmComputeAccidentals(nKey, nAccidentals);
130
// //compute accidentals note accidentals
131
// wxString sResult = _T("");
132
// if (tBits.nAccidentals == 1)
133
// sResult = _T("+");
134
// else if (tBits.nAccidentals == 2)
135
// sResult = _T("x");
136
// else if (tBits.nAccidentals == -1)
137
// sResult = _T("-");
138
// else if (tBits.nAccidentals == -2)
139
// sResult = _T("--");
141
// //change note accidentals to take key into account
142
// if (nAccidentals[tBits.nStep] != 0) {
143
// if (tBits.nAccidentals == nAccidentals[tBits.nStep])
144
// sResult = _T(""); //replace note accidental by key accidental
145
// else if (tBits.nAccidentals == 0)
146
// sResult = _T("="); //force a natural
148
// //leave note accidentals
151
// // compute step letter
152
// sResult += m_sSteps.substr(tBits.nStep, 1);
155
// sResult += wxString::Format(_T("%d"), tBits.nOctave);
161
//int lmConverter::StepToSemitones(int nStep)
163
// //Returns -1 if error
164
// // 'c'=0, 'd'=2, 'e'=4, 'f'=5, 'g'=7, 'a'=9, 'b'=11
165
// if (nStep == 0) return 0;
166
// if (nStep == 1) return 2;
167
// if (nStep == 2) return 4;
168
// if (nStep == 3) return 5;
169
// if (nStep == 4) return 7;
170
// if (nStep == 5) return 9;
171
// if (nStep == 6) return 11;
172
// return -1; //error
175
//int lmConverter::AccidentalsToInt(wxString sAccidentals)
177
// //Returns -999 if error
178
// // '--'=-1, '-'=-1, ''=0, '+'=+1, '++'=+2 'x'=2
179
// if (sAccidentals == _T("")) return 0;
180
// if (sAccidentals == _T("-")) return -1;
181
// if (sAccidentals == _T("--")) return -2;
182
// if (sAccidentals == _T("+")) return 1;
183
// if (sAccidentals == _T("++")) return 2;
184
// if (sAccidentals == _T("x")) return 2;
188
//int lmConverter::StepToInt(wxString sStep)
190
// //Returns -1 if error
191
// // 'c'=0, 'd'=1, 'e'=2, 'f'=3, 'g'=4, 'a'=5, 'b'=6
192
// if (sStep == _T("c")) return 0;
193
// if (sStep == _T("d")) return 1;
194
// if (sStep == _T("e")) return 2;
195
// if (sStep == _T("f")) return 3;
196
// if (sStep == _T("g")) return 4;
197
// if (sStep == _T("a")) return 5;
198
// if (sStep == _T("b")) return 6;
203
//} //namespace lenmus