1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
//--------------------------------------------------------------------------------------
// LenMus Phonascus: The teacher of music
// Copyright (c) 2002-2007 Cecilio Salmeron
//
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software Foundation;
// either version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
// Fifth Floor, Boston, MA 02110-1301, USA.
//
// For any comment, suggestion or feature request, please contact the manager of
// the project at cecilios@users.sourceforge.net
//
//-------------------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "MetronomeMark.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "Score.h"
#include "MetronomeMark.h"
#include "../graphic/Shape.h"
// 'note_symbol = 80'
lmMetronomeMark::lmMetronomeMark(lmVStaff* pVStaff, ENoteType nNoteType, int nDots,
int nTicksPerMinute, bool fParentheses, bool fVisible)
: lmStaffObj(pVStaff, eSFOT_MetronomeMark, pVStaff, 1, fVisible, lmDRAGGABLE)
{
m_nMarkType = eMMT_Note_Value;
m_nLeftNoteType = nNoteType;
m_nLeftDots = nDots;
m_nTicksPerMinute = nTicksPerMinute;
m_fParentheses = fParentheses;
wxString sText = wxString::Format(_T(" = %d"), m_nTicksPerMinute);
m_pTextShape = new lmShapeText(this, sText, (wxFont*)NULL);
m_pRightNoteShape = (lmShapeGlyph*)NULL;
m_pLeftNoteShape = new lmShapeGlyph(this, SelectGlyph(nNoteType, nDots), m_pFont);
}
// 'm.m. = 80'
lmMetronomeMark::lmMetronomeMark(lmVStaff* pVStaff, int nTicksPerMinute,
bool fParentheses, bool fVisible)
: lmStaffObj(pVStaff, eSFOT_MetronomeMark, pVStaff, 1, fVisible, lmDRAGGABLE)
{
m_nMarkType = eMMT_MM_Value;
m_nTicksPerMinute = nTicksPerMinute;
m_fParentheses = fParentheses;
wxString sText = wxString::Format(_T("m.m. = %d"), m_nTicksPerMinute);
m_pTextShape = new lmShapeText(this, sText, (wxFont*)NULL);
m_pLeftNoteShape = (lmShapeGlyph*)NULL;
m_pRightNoteShape = (lmShapeGlyph*)NULL;
}
// 'note_symbol = note_symbol'
lmMetronomeMark::lmMetronomeMark(lmVStaff* pVStaff,
ENoteType nLeftNoteType, int nLeftDots,
ENoteType nRightNoteType, int nRightDots,
bool fParentheses, bool fVisible)
: lmStaffObj(pVStaff, eSFOT_MetronomeMark, pVStaff, 1, fVisible, lmDRAGGABLE)
{
m_nMarkType = eMMT_Note_Note;
m_nLeftNoteType = nLeftNoteType;
m_nLeftDots = nLeftDots;
m_nRightNoteType = nRightNoteType;
m_nRightDots = nRightDots;
m_nTicksPerMinute = 0;
m_fParentheses = fParentheses;
m_pTextShape = new lmShapeText(this, _T(" = "), (wxFont*)NULL);
m_pLeftNoteShape = new lmShapeGlyph(this, SelectGlyph(nLeftNoteType, nLeftDots), m_pFont);
m_pRightNoteShape = new lmShapeGlyph(this, SelectGlyph(nRightNoteType, nRightDots), m_pFont);
}
lmMetronomeMark::~lmMetronomeMark()
{
if (m_pLeftNoteShape) delete m_pLeftNoteShape;
if (m_pRightNoteShape) delete m_pRightNoteShape;
}
//-----------------------------------------------------------------------------------------
// implementation of virtual methods defined in base abstract class lmStaffObj
//-----------------------------------------------------------------------------------------
wxBitmap* lmMetronomeMark::GetBitmap(double rScale)
{
//todo
return (wxBitmap*)NULL; //PrepareBitMap(rScale, m_sText);
}
void lmMetronomeMark::DrawObject(bool fMeasuring, lmPaper* pPaper, wxColour colorC,
bool fHighlight)
{
lmLUnits yPos = pPaper->GetCursorY() - m_pVStaff->TenthsToLogical(50, m_nStaffNum);
lmLUnits xPos = pPaper->GetCursorX();
lmLUnits uWidth = DrawMetronomeMark(fMeasuring, pPaper, xPos, yPos, colorC);
if (fMeasuring) {
// store selection rectangle measures and position
m_selRect.width = uWidth;
m_selRect.height = m_pVStaff->TenthsToLogical(32, m_nStaffNum); //todo
m_selRect.x = xPos - m_paperPos.x; //relative to m_paperPos
m_selRect.y = yPos - m_paperPos.y;;
// set total width to zero: metronome marks does not consume staff space
m_nWidth = 0; // uWidth;
// store glyph position (relative to paper pos).
m_glyphPos.x = 0;
m_glyphPos.y = pPaper->GetCursorY() - yPos;
}
}
// returns the width of the metronome mark (in logical units)
lmLUnits lmMetronomeMark::DrawMetronomeMark(bool fMeasuring, lmPaper* pPaper,
lmLUnits xPos, lmLUnits yPos, wxColour colorC)
{
lmLUnits xStart = xPos;
switch(m_nMarkType)
{
case eMMT_MM_Value: // 'm.m. = 80'
return DrawText(fMeasuring, pPaper, xPos, yPos, colorC);
break;
case eMMT_Note_Note: // 'note_symbol = note_symbol'
xPos += DrawSymbol(fMeasuring, pPaper, m_pLeftNoteShape, xPos, yPos, colorC);
xPos += DrawText(fMeasuring, pPaper, xPos, yPos, colorC);
xPos += DrawSymbol(fMeasuring, pPaper, m_pRightNoteShape, xPos, yPos, colorC);
return xPos - xStart;
break;
case eMMT_Note_Value: // 'note_symbol = 80'
xPos += DrawSymbol(fMeasuring, pPaper, m_pLeftNoteShape, xPos, yPos, colorC);
xPos += DrawText(fMeasuring, pPaper, xPos, yPos, colorC);
return xPos - xStart;
break;
default:
wxASSERT(false);
return 0; // to keep compiler happy
}
}
lmLUnits lmMetronomeMark::DrawText(bool fMeasuring, lmPaper* pPaper,
lmLUnits xPos, lmLUnits yPos, wxColour colorC)
{
// returns the width of the text (in logical units)
if (fMeasuring) {
int nWeight = wxNORMAL;
int nStyle = wxNORMAL;
int nFontSize = PointsToLUnits(8);
wxFont* pFont = pPaper->GetFont(nFontSize, _T("Times New Roman"), wxDEFAULT, nStyle, nWeight, false);
if (!pFont) {
wxMessageBox(_("Sorry, an error has occurred while allocating the font."),
_T("lmScoreText::SetFont"), wxOK);
::wxExit();
}
m_pTextShape->SetFont(pFont);
lmUPoint offset(xPos - m_paperPos.x,
yPos - m_paperPos.y + m_pVStaff->TenthsToLogical(10, m_nStaffNum));
m_pTextShape->Measure(pPaper, m_pVStaff->GetStaff(m_nStaffNum), offset);
}
else {
m_pTextShape->Render(pPaper, m_paperPos, colorC);
}
return m_pTextShape->GetWidth();
}
lmLUnits lmMetronomeMark::DrawSymbol(bool fMeasuring, lmPaper* pPaper, lmShapeGlyph* pShape,
lmLUnits xPos, lmLUnits yPos, wxColour colorC)
{
// returns the width of the note (in logical units)
wxASSERT(pShape);
if (fMeasuring) {
lmUPoint offset(xPos - m_paperPos.x, yPos - m_paperPos.y - m_pVStaff->TenthsToLogical(35, m_nStaffNum));
pShape->SetFont(m_pFont);
pShape->Measure(pPaper, m_pVStaff->GetStaff(m_nStaffNum), offset);
}
else {
pShape->Render(pPaper, m_paperPos, colorC);
}
return pShape->GetWidth();
}
lmEGlyphIndex lmMetronomeMark::SelectGlyph(ENoteType nNoteType, int nDots)
{
lmEGlyphIndex nGlyph = GLYPH_SMALL_QUARTER_NOTE;
switch (nNoteType) {
case eQuarter:
if (nDots == 0)
nGlyph = GLYPH_SMALL_QUARTER_NOTE;
else
nGlyph = GLYPH_SMALL_QUARTER_NOTE_DOTTED;
break;
case eEighth:
if (nDots == 0)
nGlyph = GLYPH_SMALL_EIGHTH_NOTE;
else
nGlyph = GLYPH_SMALL_EIGHTH_NOTE_DOTTED;
break;
default:
wxASSERT(false);
}
return nGlyph;
}
wxString lmMetronomeMark::Dump()
{
wxString sDump = wxString::Format(
_T("%d\tMetronome %d\tTicksPerMinute=%d, fParentheses=%s,")
_T(" TimePos=%.2f, fixed=%s\n"),
m_nId, m_nMarkType, m_nTicksPerMinute, (m_fParentheses ? _T("yes") : _T("no")),
m_rTimePos, (m_fFixedPos ? _T("yes") : _T("no")) );
return sDump;
}
wxString lmMetronomeMark::SourceLDP()
{
wxString sSource = _T(" (metronome");
switch (m_nMarkType)
{
case eMMT_MM_Value:
sSource += wxString::Format(_T(" %d"), m_nTicksPerMinute);
break;
case eMMT_Note_Note:
sSource += GetLDPNote(m_nLeftNoteType, m_nLeftDots);
sSource += GetLDPNote(m_nRightNoteType, m_nRightDots);
break;
case eMMT_Note_Value:
sSource += GetLDPNote(m_nLeftNoteType, m_nLeftDots);
sSource += wxString::Format(_T(" %d"), m_nTicksPerMinute);
break;
default:
wxASSERT(false);
}
if (m_fParentheses) sSource += _T(" parentheses");
if (!m_fVisible) sSource += _T(" noVisible");
sSource += _T(")\n");
return sSource;
}
wxString lmMetronomeMark::SourceXML()
{
//! @todo all
wxString sSource = _T("TODO: lmMetronomeMark XML Source code generation methods");
return sSource;
}
wxString lmMetronomeMark::GetLDPNote(ENoteType nNoteType, int nDots)
{
// returns LDP data (English) starting with an space
wxString sNote = _T(" ");
switch (nNoteType)
{
case eWhole:
sNote += _T("w");
break;
case eHalf:
sNote += _T("h");
break;
case eQuarter:
sNote += _T("q");
break;
case eEighth:
sNote += _T("e");
break;
case e16th:
sNote += _T("s");
break;
case e32th:
sNote += _T("t");
break;
case e64th:
sNote += _T("i");
break;
case e128th:
sNote += _T("o");
break;
case e256th:
sNote += _T("f");
break;
}
for(int i=0; i < nDots; i++) sNote += _T(".");
return sNote;
}
|