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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <richard.bown@ferventsoftware.com>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
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. See the file
COPYING included with this distribution for more information.
*/
#include "NoteStyle.h"
#include "base/NotationTypes.h"
#include "base/PropertyName.h"
#include "NoteCharacterNames.h"
#include "NoteStyleFactory.h"
namespace Rosegarden
{
NoteStyle::~NoteStyle()
{
// nothing
}
const NoteStyle::NoteHeadShape NoteStyle::AngledOval = "angled oval";
const NoteStyle::NoteHeadShape NoteStyle::LevelOval = "level oval";
const NoteStyle::NoteHeadShape NoteStyle::Breve = "breve";
const NoteStyle::NoteHeadShape NoteStyle::Cross = "cross";
const NoteStyle::NoteHeadShape NoteStyle::TriangleUp = "triangle up";
const NoteStyle::NoteHeadShape NoteStyle::TriangleDown = "triangle down";
const NoteStyle::NoteHeadShape NoteStyle::Diamond = "diamond";
const NoteStyle::NoteHeadShape NoteStyle::Rectangle = "rectangle";
const NoteStyle::NoteHeadShape NoteStyle::Number = "number";
const NoteStyle::NoteHeadShape NoteStyle::CustomCharName = "custom character";
NoteStyle::NoteHeadShape
NoteStyle::getShape(Note::Type type)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle)
return m_baseStyle->getShape(type);
std::cerr
<< "WARNING: NoteStyle::getShape: No tqshape defined for note type "
<< type << ", defaulting to AngledOval" << std::endl;
return AngledOval;
}
return i->second.tqshape;
}
bool
NoteStyle::isFilled(Note::Type type)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle)
return m_baseStyle->isFilled(type);
std::cerr
<< "WARNING: NoteStyle::isFilled: No definition for note type "
<< type << ", defaulting to true" << std::endl;
return true;
}
return i->second.filled;
}
bool
NoteStyle::hasStem(Note::Type type)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle)
return m_baseStyle->hasStem(type);
std::cerr
<< "WARNING: NoteStyle::hasStem: No definition for note type "
<< type << ", defaulting to true" << std::endl;
return true;
}
return i->second.stem;
}
int
NoteStyle::getFlagCount(Note::Type type)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle)
return m_baseStyle->getFlagCount(type);
std::cerr
<< "WARNING: NoteStyle::getFlagCount: No definition for note type "
<< type << ", defaulting to 0" << std::endl;
return 0;
}
return i->second.flags;
}
int
NoteStyle::getSlashCount(Note::Type type)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle)
return m_baseStyle->getSlashCount(type);
std::cerr
<< "WARNING: NoteStyle::getSlashCount: No definition for note type "
<< type << ", defaulting to 0" << std::endl;
return 0;
}
return i->second.slashes;
}
void
NoteStyle::getStemFixPoints(Note::Type type,
HFixPoint &hfix, VFixPoint &vfix)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle) {
m_baseStyle->getStemFixPoints(type, hfix, vfix);
return ;
}
std::cerr
<< "WARNING: NoteStyle::getStemFixPoints: "
<< "No definition for note type " << type
<< ", defaulting to (Normal,Middle)" << std::endl;
hfix = Normal;
vfix = Middle;
return ;
}
hfix = i->second.hfix;
vfix = i->second.vfix;
}
NoteStyle::CharNameRec
NoteStyle::getNoteHeadCharName(Note::Type type)
{
NoteDescriptionMap::iterator i = m_notes.find(type);
if (i == m_notes.end()) {
if (m_baseStyle)
return m_baseStyle->getNoteHeadCharName(type);
std::cerr
<< "WARNING: NoteStyle::getNoteHeadCharName: No definition for note type "
<< type << ", defaulting to NOTEHEAD_BLACK" << std::endl;
return CharNameRec(NoteCharacterNames::NOTEHEAD_BLACK, false);
}
const NoteDescription &desc(i->second);
CharName name = NoteCharacterNames::UNKNOWN;
bool inverted = false;
if (desc.tqshape == AngledOval) {
name = desc.filled ? NoteCharacterNames::NOTEHEAD_BLACK
: NoteCharacterNames::VOID_NOTEHEAD;
} else if (desc.tqshape == LevelOval) {
if (desc.filled) {
std::cerr << "WARNING: NoteStyle::getNoteHeadCharName: No filled level oval head" << std::endl;
}
name = NoteCharacterNames::WHOLE_NOTE;
} else if (desc.tqshape == Breve) {
if (desc.filled) {
std::cerr << "WARNING: NoteStyle::getNoteHeadCharName: No filled breve head" << std::endl;
}
name = NoteCharacterNames::BREVE;
} else if (desc.tqshape == Cross) {
name = desc.filled ? NoteCharacterNames::X_NOTEHEAD
: NoteCharacterNames::CIRCLE_X_NOTEHEAD;
} else if (desc.tqshape == TriangleUp) {
name = desc.filled ? NoteCharacterNames::TRIANGLE_NOTEHEAD_UP_BLACK
: NoteCharacterNames::TRIANGLE_NOTEHEAD_UP_WHITE;
} else if (desc.tqshape == TriangleDown) {
name = desc.filled ? NoteCharacterNames::TRIANGLE_NOTEHEAD_UP_BLACK
: NoteCharacterNames::TRIANGLE_NOTEHEAD_UP_WHITE;
inverted = true;
} else if (desc.tqshape == Diamond) {
name = desc.filled ? NoteCharacterNames::SEMIBREVIS_BLACK
: NoteCharacterNames::SEMIBREVIS_WHITE;
} else if (desc.tqshape == Rectangle) {
name = desc.filled ? NoteCharacterNames::STQUARE_NOTEHEAD_BLACK
: NoteCharacterNames::STQUARE_NOTEHEAD_WHITE;
} else if (desc.tqshape == Number) {
std::cerr << "WARNING: NoteStyle::getNoteHeadCharName: Number not yet implemented" << std::endl;
name = NoteCharacterNames::UNKNOWN; //!!!
} else if (desc.tqshape == CustomCharName) {
name = desc.charName;
} else {
name = NoteCharacterNames::UNKNOWN;
}
return CharNameRec(name, inverted);
}
CharName
NoteStyle::getAccidentalCharName(const Accidental &a)
{
if (a == Accidentals::Sharp)
return NoteCharacterNames::SHARP;
else if (a == Accidentals::Flat)
return NoteCharacterNames::FLAT;
else if (a == Accidentals::Natural)
return NoteCharacterNames::NATURAL;
else if (a == Accidentals::DoubleSharp)
return NoteCharacterNames::DOUBLE_SHARP;
else if (a == Accidentals::DoubleFlat)
return NoteCharacterNames::DOUBLE_FLAT;
return NoteCharacterNames::UNKNOWN;
}
CharName
NoteStyle::getMarkCharName(const Mark &mark)
{
if (mark == Marks::Accent)
return NoteCharacterNames::ACCENT;
else if (mark == Marks::Tenuto)
return NoteCharacterNames::TENUTO;
else if (mark == Marks::Staccato)
return NoteCharacterNames::STACCATO;
else if (mark == Marks::Staccatissimo)
return NoteCharacterNames::STACCATISSIMO;
else if (mark == Marks::Marcato)
return NoteCharacterNames::MARCATO;
else if (mark == Marks::Trill)
return NoteCharacterNames::TRILL;
else if (mark == Marks::LongTrill)
return NoteCharacterNames::TRILL;
else if (mark == Marks::TrillLine)
return NoteCharacterNames::TRILL_LINE;
else if (mark == Marks::Turn)
return NoteCharacterNames::TURN;
else if (mark == Marks::Pause)
return NoteCharacterNames::FERMATA;
else if (mark == Marks::UpBow)
return NoteCharacterNames::UP_BOW;
else if (mark == Marks::DownBow)
return NoteCharacterNames::DOWN_BOW;
else if (mark == Marks::Mordent)
return NoteCharacterNames::MORDENT;
else if (mark == Marks::MordentInverted)
return NoteCharacterNames::MORDENT_INVERTED;
else if (mark == Marks::MordentLong)
return NoteCharacterNames::MORDENT_LONG;
else if (mark == Marks::MordentLongInverted)
return NoteCharacterNames::MORDENT_LONG_INVERTED;
// Things like "sf" and "rf" are generated from text fonts
return NoteCharacterNames::UNKNOWN;
}
CharName
NoteStyle::getClefCharName(const Clef &clef)
{
std::string clefType(clef.getClefType());
if (clefType == Clef::Bass || clefType == Clef::Varbaritone || clefType == Clef::Subbass) {
return NoteCharacterNames::F_CLEF;
} else if (clefType == Clef::Treble || clefType == Clef::French) {
return NoteCharacterNames::G_CLEF;
} else {
return NoteCharacterNames::C_CLEF;
}
}
CharName
NoteStyle::getRestCharName(Note::Type type, bool restOutsideStave)
{
switch (type) {
case Note::Hemidemisemiquaver:
return NoteCharacterNames::SIXTY_FOURTH_REST;
case Note::Demisemiquaver:
return NoteCharacterNames::THIRTY_SECOND_REST;
case Note::Semiquaver:
return NoteCharacterNames::SIXTEENTH_REST;
case Note::Quaver:
return NoteCharacterNames::EIGHTH_REST;
case Note::Crotchet:
return NoteCharacterNames::TQUARTER_REST;
case Note::Minim:
return restOutsideStave ?
NoteCharacterNames::HALF_REST
: NoteCharacterNames::HALF_REST_ON_STAFF;
case Note::Semibreve:
return restOutsideStave ?
NoteCharacterNames::WHOLE_REST
: NoteCharacterNames::WHOLE_REST_ON_STAFF;
case Note::Breve:
return restOutsideStave ?
NoteCharacterNames::MULTI_REST
: NoteCharacterNames::MULTI_REST_ON_STAFF;
default:
return NoteCharacterNames::UNKNOWN;
}
}
CharName
NoteStyle::getPartialFlagCharName(bool final)
{
if (final)
return NoteCharacterNames::FLAG_PARTIAL_FINAL;
else
return NoteCharacterNames::FLAG_PARTIAL;
}
CharName
NoteStyle::getFlagCharName(int flagCount)
{
switch (flagCount) {
case 1:
return NoteCharacterNames::FLAG_1;
case 2:
return NoteCharacterNames::FLAG_2;
case 3:
return NoteCharacterNames::FLAG_3;
case 4:
return NoteCharacterNames::FLAG_4;
default:
return NoteCharacterNames::UNKNOWN;
}
}
CharName
NoteStyle::getTimeSignatureDigitName(int digit)
{
switch (digit) {
case 0:
return NoteCharacterNames::DIGIT_ZERO;
case 1:
return NoteCharacterNames::DIGIT_ONE;
case 2:
return NoteCharacterNames::DIGIT_TWO;
case 3:
return NoteCharacterNames::DIGIT_THREE;
case 4:
return NoteCharacterNames::DIGIT_FOUR;
case 5:
return NoteCharacterNames::DIGIT_FIVE;
case 6:
return NoteCharacterNames::DIGIT_SIX;
case 7:
return NoteCharacterNames::DIGIT_SEVEN;
case 8:
return NoteCharacterNames::DIGIT_EIGHT;
case 9:
return NoteCharacterNames::DIGIT_NINE;
default:
return NoteCharacterNames::UNKNOWN;
}
}
void
NoteStyle::setBaseStyle(NoteStyleName name)
{
try {
m_baseStyle = NoteStyleFactory::getStyle(name);
if (m_baseStyle == this)
m_baseStyle = 0;
} catch (NoteStyleFactory::StyleUnavailable u) {
if (name != NoteStyleFactory::DefaultStyle) {
std::cerr
<< "NoteStyle::setBaseStyle: Base style "
<< name << " not available, defaulting to "
<< NoteStyleFactory::DefaultStyle << std::endl;
setBaseStyle(NoteStyleFactory::DefaultStyle);
} else {
std::cerr
<< "NoteStyle::setBaseStyle: Base style "
<< name << " not available" << std::endl;
m_baseStyle = 0;
}
}
}
void
NoteStyle::checkDescription(Note::Type note)
{
if (m_baseStyle && (m_notes.find(note) == m_notes.end())) {
m_baseStyle->checkDescription(note);
m_notes[note] = m_baseStyle->m_notes[note];
}
}
void
NoteStyle::setShape(Note::Type note, NoteHeadShape tqshape)
{
checkDescription(note);
m_notes[note].tqshape = tqshape;
}
void
NoteStyle::setCharName(Note::Type note, CharName charName)
{
checkDescription(note);
m_notes[note].charName = charName;
}
void
NoteStyle::setFilled(Note::Type note, bool filled)
{
checkDescription(note);
m_notes[note].filled = filled;
}
void
NoteStyle::setStem(Note::Type note, bool stem)
{
checkDescription(note);
m_notes[note].stem = stem;
}
void
NoteStyle::setFlagCount(Note::Type note, int flags)
{
checkDescription(note);
m_notes[note].flags = flags;
}
void
NoteStyle::setSlashCount(Note::Type note, int slashes)
{
checkDescription(note);
m_notes[note].slashes = slashes;
}
void
NoteStyle::setStemFixPoints(Note::Type note, HFixPoint hfix, VFixPoint vfix)
{
checkDescription(note);
m_notes[note].hfix = hfix;
m_notes[note].vfix = vfix;
}
}
|