2012-05-26 14:26:10 +02:00
|
|
|
|
//=============================================================================
|
|
|
|
|
// MuseScore
|
|
|
|
|
// Music Composition & Notation
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2002-2011 Werner Schweer
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
#include "figuredbass.h"
|
|
|
|
|
#include "score.h"
|
|
|
|
|
#include "note.h"
|
|
|
|
|
#include "measure.h"
|
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "segment.h"
|
|
|
|
|
|
|
|
|
|
// the array of configured fonts
|
|
|
|
|
static QList<FiguredBassFont> g_FBFonts;
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// F I G U R E D B A S S I T E M
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// used for indexed access to parenthesis chars
|
|
|
|
|
// (these is no normAccidToChar[], as accidentals may use mult. chars in normalized display):
|
2012-08-11 01:15:22 +02:00
|
|
|
|
const QChar FiguredBassItem::normParenthToChar[NumOfParentheses] =
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{ 0, '(', ')', '[', ']'};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FiguredBassItem::FiguredBassItem(Score* s, int l)
|
2012-08-01 19:06:20 +02:00
|
|
|
|
: Element(s), ord(l)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
_prefix = _suffix = ModifierNone;
|
2012-08-10 20:50:27 +02:00
|
|
|
|
_digit = FBIDigitNone;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
parenth[0] = parenth[1] = parenth[2] = parenth[3] = parenth[4] = ParenthesisNone;
|
2013-02-12 16:00:05 +01:00
|
|
|
|
_contLine = ContLineNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FiguredBassItem::FiguredBassItem(const FiguredBassItem& item)
|
2012-08-01 19:06:20 +02:00
|
|
|
|
: Element(item)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
|
|
|
|
ord = item.ord;
|
2012-08-10 20:50:27 +02:00
|
|
|
|
_prefix = item._prefix;
|
|
|
|
|
_digit = item._digit;
|
|
|
|
|
_suffix = item._suffix;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
parenth[0] = item.parenth[0];
|
|
|
|
|
parenth[1] = item.parenth[1];
|
|
|
|
|
parenth[2] = item.parenth[2];
|
|
|
|
|
parenth[3] = item.parenth[3];
|
|
|
|
|
parenth[4] = item.parenth[4];
|
2012-08-10 20:50:27 +02:00
|
|
|
|
_contLine = item._contLine;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
textWidth = item.textWidth;
|
2012-08-01 19:06:20 +02:00
|
|
|
|
_displayText= item._displayText;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FiguredBassItem::~FiguredBassItem()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem parse()
|
|
|
|
|
//
|
|
|
|
|
// converts a string into a property-based representation, if possible;
|
|
|
|
|
// return true on success | false if the string is non-conformant
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool FiguredBassItem::parse(QString& str)
|
|
|
|
|
{
|
|
|
|
|
int retVal;
|
|
|
|
|
|
|
|
|
|
parseParenthesis(str, 0);
|
|
|
|
|
retVal = parsePrefixSuffix(str, true); // prefix
|
|
|
|
|
if(retVal == -1)
|
|
|
|
|
return false;
|
|
|
|
|
parseParenthesis(str, 1);
|
|
|
|
|
retVal = parseDigit(str); // digit
|
|
|
|
|
if(retVal == -1)
|
|
|
|
|
return false;
|
|
|
|
|
parseParenthesis(str, 2);
|
|
|
|
|
retVal = parsePrefixSuffix(str, false); // suffix
|
|
|
|
|
if(retVal == -1)
|
|
|
|
|
return false;
|
|
|
|
|
parseParenthesis(str, 3);
|
|
|
|
|
// check for a possible cont. line symbol(s)
|
2013-02-12 16:00:05 +01:00
|
|
|
|
_contLine = ContLineNone; // contLine
|
|
|
|
|
if(str[0] == '-' || str[0] == '_') { // 1 symbol: simple continuation
|
|
|
|
|
_contLine = ContLineSimple;
|
|
|
|
|
str.remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
while(str[0] == '-' || str[0] == '_') { // more than 1 symbol: extended continuation
|
|
|
|
|
_contLine = ContLineExtended;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
parseParenthesis(str, 4);
|
|
|
|
|
|
2013-02-12 16:00:05 +01:00
|
|
|
|
// remove useless parentheses, moving external parentheses toward central digit element
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_prefix == ModifierNone && parenth[1] == ParenthesisNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
parenth[1] = parenth[0];
|
2012-08-11 01:15:22 +02:00
|
|
|
|
parenth[0] = ParenthesisNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_digit == FBIDigitNone && parenth[2] == ParenthesisNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
parenth[2] = parenth[1];
|
2012-08-11 01:15:22 +02:00
|
|
|
|
parenth[1] = ParenthesisNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if(_contLine == ContLineNone && parenth[3] == ParenthesisNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
parenth[3] = parenth[4];
|
2012-08-11 01:15:22 +02:00
|
|
|
|
parenth[4] = ParenthesisNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_suffix == ModifierNone && parenth[2] == ParenthesisNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
parenth[2] = parenth[3];
|
2012-08-11 01:15:22 +02:00
|
|
|
|
parenth[3] = ParenthesisNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// some checks:
|
|
|
|
|
// if some extra input, str is not conformant
|
|
|
|
|
if(str.size())
|
|
|
|
|
return false;
|
|
|
|
|
// can't have BOTH prefix and suffix
|
|
|
|
|
// prefix, digit, suffix and cont.line cannot be ALL empty
|
|
|
|
|
// suffix cannot combine with empty digit
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if( (_prefix != ModifierNone && _suffix != ModifierNone)
|
2013-02-12 16:00:05 +01:00
|
|
|
|
|| (_prefix == ModifierNone && _digit == FBIDigitNone && _suffix == ModifierNone && _contLine == ContLineNone)
|
2013-02-10 07:01:31 +01:00
|
|
|
|
|| ( (_suffix == ModifierCross || _suffix == ModifierBackslash || _suffix == ModifierSlash)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
&& _digit == FBIDigitNone) )
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem parsePrefixSuffix()
|
|
|
|
|
//
|
|
|
|
|
// scans str to extract prefix or suffix properties. Stops at the first char which cannot fit.
|
|
|
|
|
// Fitting chars are removed from str. DOES NOT generate any display text
|
|
|
|
|
//
|
|
|
|
|
// returns the number of QChar's read from str or -1 if prefix / suffix has an illegal format
|
|
|
|
|
// (no prefix / suffix at all IS legal)
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
int FiguredBassItem::parsePrefixSuffix(QString& str, bool bPrefix)
|
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
Modifier * dest = bPrefix ? &_prefix : &_suffix;
|
|
|
|
|
bool done = false;
|
|
|
|
|
int size = str.size();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str = str.trimmed();
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
*dest = ModifierNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
while(str.size()) {
|
|
|
|
|
switch(str.at(0).unicode())
|
|
|
|
|
{
|
|
|
|
|
case 'b':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(*dest != ModifierNone) {
|
|
|
|
|
if(*dest == ModifierFlat) // FLAT may double a previous FLAT
|
|
|
|
|
*dest = ModifierDoubleFlat;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else
|
|
|
|
|
return -1; // but no other combination is acceptable
|
|
|
|
|
}
|
2012-08-11 01:15:22 +02:00
|
|
|
|
*dest = ModifierFlat;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(*dest != ModifierNone) // cannot combine with any other accidental
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return -1;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
*dest = ModifierNatural;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case '#':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(*dest != ModifierNone) {
|
|
|
|
|
if(*dest == ModifierSharp) // SHARP may double a preivous SHARP
|
|
|
|
|
*dest = ModifierDoubleSharp;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else
|
|
|
|
|
return -1; // but no other combination is acceptable
|
|
|
|
|
}
|
2012-08-11 01:15:22 +02:00
|
|
|
|
*dest = ModifierSharp;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case '+':
|
2013-02-10 07:01:31 +01:00
|
|
|
|
// accept '+' as both a prefix and a suffix for harmony notation
|
|
|
|
|
if(*dest != ModifierNone) // cannot combine with any other accidental
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return -1;
|
2013-02-10 07:01:31 +01:00
|
|
|
|
*dest = ModifierCross;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
2013-02-10 07:01:31 +01:00
|
|
|
|
// '\\' and '/' go into the suffix
|
2012-05-26 14:26:10 +02:00
|
|
|
|
case '\\':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_suffix != ModifierNone) // cannot combine with any other accidental
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return -1;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
_suffix = ModifierBackslash;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case '/':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_suffix != ModifierNone) // cannot combine with any other accidental
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return -1;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
_suffix = ModifierSlash;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
2012-08-10 20:50:27 +02:00
|
|
|
|
default: // any other char: no longer in prefix/suffix
|
2012-05-26 14:26:10 +02:00
|
|
|
|
done = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(done)
|
|
|
|
|
break;
|
|
|
|
|
str.remove(0,1); // 'eat' the char and continue
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-10 20:50:27 +02:00
|
|
|
|
return size - str.size(); // return how many chars we had read into prefix/suffix
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem parseDigit()
|
|
|
|
|
//
|
|
|
|
|
// scans str to extract digit properties. Stops at the first char which cannot belong to digit part.
|
|
|
|
|
// Fitting chars are removed from str. DOES NOT generate any display text
|
|
|
|
|
//
|
|
|
|
|
// returns the number of QChar's read from str or -1 if no legal digit can be constructed
|
|
|
|
|
// (no digit at all IS legal)
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
int FiguredBassItem::parseDigit(QString& str)
|
|
|
|
|
{
|
|
|
|
|
int size = str.size();
|
|
|
|
|
str = str.trimmed();
|
|
|
|
|
|
2012-08-10 20:50:27 +02:00
|
|
|
|
_digit = FBIDigitNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
while(str.size()) {
|
|
|
|
|
// any digit acceptable, if no previous digit
|
|
|
|
|
if(str[0] >= '1' && str[0] <= '9') {
|
2012-08-10 20:50:27 +02:00
|
|
|
|
if(_digit == FBIDigitNone) {
|
|
|
|
|
_digit = str[0].unicode() - '0';
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// anything else: no longer in digit part
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return size - str.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem parseParenthesis()
|
|
|
|
|
//
|
|
|
|
|
// scans str to extract a (possible) parenthesis, stores its code into parenth[parenthIdx]
|
|
|
|
|
// and removes it from str. Only looks at first str char.
|
|
|
|
|
//
|
|
|
|
|
// returns the number of QChar's read from str (actually 0 or 1).
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
int FiguredBassItem::parseParenthesis(QString& str, int parenthIdx)
|
|
|
|
|
{
|
|
|
|
|
int c = str[0].unicode();
|
2012-08-11 01:15:22 +02:00
|
|
|
|
Parenthesis code = ParenthesisNone;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
switch(c)
|
|
|
|
|
{
|
|
|
|
|
case '(':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
code =ParenthesisRoundOpen;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case ')':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
code =ParenthesisRoundClosed;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case '[':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
code =ParenthesisSquaredOpen;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
case ']':
|
2012-08-11 01:15:22 +02:00
|
|
|
|
code =ParenthesisSquaredClosed;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
parenth[parenthIdx] = code;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(code != ParenthesisNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.remove(0, 1);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem normalizedText()
|
|
|
|
|
//
|
|
|
|
|
// returns a string with the normalized text, i.e. the text displayed while editing;
|
|
|
|
|
// this is a standard textual representation of the item properties
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QString FiguredBassItem::normalizedText() const
|
|
|
|
|
{
|
|
|
|
|
QString str = QString();
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[0] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(normParenthToChar[parenth[0]]);
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_prefix != ModifierNone) {
|
2012-08-10 20:50:27 +02:00
|
|
|
|
switch(_prefix)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierFlat:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('b');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierNatural:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('h');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierSharp:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('#');
|
|
|
|
|
break;
|
2013-02-10 07:01:31 +01:00
|
|
|
|
case ModifierCross:
|
|
|
|
|
str.append('+');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierDoubleFlat:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append("bb");
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierDoubleSharp:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append("##");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[1] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(normParenthToChar[parenth[1]]);
|
|
|
|
|
|
|
|
|
|
// digit
|
2012-08-10 20:50:27 +02:00
|
|
|
|
if(_digit != FBIDigitNone)
|
|
|
|
|
str.append(QChar('0' + _digit));
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[2] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(normParenthToChar[parenth[2]]);
|
|
|
|
|
|
|
|
|
|
// suffix
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_suffix != ModifierNone) {
|
2012-08-10 20:50:27 +02:00
|
|
|
|
switch(_suffix)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierFlat:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('b');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierNatural:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('h');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierSharp:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('#');
|
|
|
|
|
break;
|
2013-02-10 07:01:31 +01:00
|
|
|
|
case ModifierCross:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('+');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierBackslash:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('\\');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierSlash:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('/');
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierDoubleFlat:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append("bb");
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierDoubleSharp:
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append("##");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[3] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(normParenthToChar[parenth[3]]);
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if(_contLine > ContLineNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append('_');
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if (_contLine > ContLineSimple)
|
|
|
|
|
str.append('_');
|
|
|
|
|
}
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[4] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(normParenthToChar[parenth[4]]);
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem write()
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBassItem::write(Xml& xml) const
|
|
|
|
|
{
|
|
|
|
|
xml.stag("FiguredBassItem");
|
|
|
|
|
xml.tagE(QString("brackets b0=\"%1\" b1=\"%2\" b2=\"%3\" b3=\"%4\" b4=\"%5\"")
|
|
|
|
|
.arg(parenth[0]) .arg(parenth[1]) .arg(parenth[2]) .arg(parenth[3]) .arg(parenth[4]) );
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_prefix != ModifierNone)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
xml.tag(QString("prefix"), _prefix);
|
|
|
|
|
if(_digit != FBIDigitNone)
|
|
|
|
|
xml.tag(QString("digit"), _digit);
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_suffix != ModifierNone)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
xml.tag(QString("suffix"), _suffix);
|
|
|
|
|
if(_contLine)
|
|
|
|
|
xml.tag("continuationLine", _contLine);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
xml.etag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem read()
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
|
void FiguredBassItem::read(XmlReader& e)
|
|
|
|
|
{
|
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
const QStringRef& tag(e.name());
|
|
|
|
|
|
|
|
|
|
if (tag == "brackets") {
|
|
|
|
|
parenth[0] = (Parenthesis)e.intAttribute("b0");
|
|
|
|
|
parenth[1] = (Parenthesis)e.intAttribute("b1");
|
|
|
|
|
parenth[2] = (Parenthesis)e.intAttribute("b2");
|
|
|
|
|
parenth[3] = (Parenthesis)e.intAttribute("b3");
|
|
|
|
|
parenth[4] = (Parenthesis)e.intAttribute("b4");
|
2013-01-20 01:05:45 +01:00
|
|
|
|
e.readNext();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (tag == "prefix")
|
|
|
|
|
_prefix = (Modifier)(e.readInt());
|
|
|
|
|
else if (tag == "digit")
|
|
|
|
|
_digit = e.readInt();
|
|
|
|
|
else if (tag == "suffix")
|
|
|
|
|
_suffix = (Modifier)(e.readInt());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if(tag == "continuationLine")
|
2013-02-12 16:00:05 +01:00
|
|
|
|
_contLine = (ContLine)(e.readInt());
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (!Element::readProperties(e))
|
|
|
|
|
e.unknown();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-01-11 18:10:18 +01:00
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem layout()
|
|
|
|
|
// creates the display text (set as element text) and computes
|
|
|
|
|
// the horiz. offset needed to align the right part as well as the vert. offset
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBassItem::layout()
|
|
|
|
|
{
|
|
|
|
|
qreal h, w, x, x1, x2, y;
|
|
|
|
|
|
2012-08-01 19:06:20 +02:00
|
|
|
|
// contruct font metrics
|
|
|
|
|
int fontIdx = 0;
|
|
|
|
|
QFont f(g_FBFonts.at(fontIdx).family);
|
2012-08-02 18:41:29 +02:00
|
|
|
|
// font size in points, scaled according to spatium()
|
|
|
|
|
qreal m = score()->styleD(ST_figuredBassFontSize) * spatium() / ( SPATIUM20 * MScore::DPI);
|
2012-08-01 19:06:20 +02:00
|
|
|
|
f.setPointSizeF(m);
|
|
|
|
|
QFontMetrics fm(f);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
QString str = QString();
|
|
|
|
|
x = symbols[score()->symIdx()][quartheadSym].width(magS()) * .5;
|
|
|
|
|
x1 = x2 = 0.0;
|
|
|
|
|
|
|
|
|
|
// create display text
|
|
|
|
|
int font = 0;
|
|
|
|
|
int style = score()->styleI(ST_figuredBassStyle);
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[0] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayParenthesis[parenth[0]]);
|
|
|
|
|
|
|
|
|
|
// prefix
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(_prefix != ModifierNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// if no digit, the string created so far 'hangs' to the left of the note
|
2012-08-10 20:50:27 +02:00
|
|
|
|
if(_digit == FBIDigitNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
x1 = fm.width(str);
|
2012-08-10 20:50:27 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayAccidental[_prefix]);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// if no digit, the string from here onward 'hangs' to the right of the note
|
2012-08-10 20:50:27 +02:00
|
|
|
|
if(_digit == FBIDigitNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
x2 = fm.width(str);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[1] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayParenthesis[parenth[1]]);
|
|
|
|
|
|
|
|
|
|
// digit
|
2012-08-10 20:50:27 +02:00
|
|
|
|
if(_digit != FBIDigitNone) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// if some digit, the string created so far 'hangs' to the left of the note
|
|
|
|
|
x1 = fm.width(str);
|
|
|
|
|
// if suffix is a combining shape, combine it with digit
|
|
|
|
|
// unless there is a parenthesis in between
|
2013-02-10 07:01:31 +01:00
|
|
|
|
if( (_suffix == ModifierCross || _suffix == ModifierBackslash || _suffix == ModifierSlash)
|
2012-08-11 01:15:22 +02:00
|
|
|
|
&& parenth[2] == ParenthesisNone)
|
2013-02-10 07:01:31 +01:00
|
|
|
|
str.append(g_FBFonts.at(font).displayDigit[style][_digit][_suffix-(ModifierCross-1)]);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else
|
2012-08-10 20:50:27 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayDigit[style][_digit][0]);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// if some digit, the string from here onward 'hangs' to the right of the note
|
|
|
|
|
x2 = fm.width(str);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[2] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayParenthesis[parenth[2]]);
|
|
|
|
|
|
|
|
|
|
// suffix
|
|
|
|
|
// append only if non-combining shape or cannot combine (no digit or parenthesis in between)
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if( _suffix != ModifierNone
|
2013-02-10 07:01:31 +01:00
|
|
|
|
&& ( (_suffix != ModifierCross && _suffix != ModifierBackslash && _suffix != ModifierSlash)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
|| _digit == FBIDigitNone
|
2012-08-11 01:15:22 +02:00
|
|
|
|
|| parenth[2] != ParenthesisNone) )
|
2012-08-10 20:50:27 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayAccidental[_suffix]);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[3] != ParenthesisNone)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
str.append(g_FBFonts.at(font).displayParenthesis[parenth[3]]);
|
|
|
|
|
|
2012-08-01 19:06:20 +02:00
|
|
|
|
setDisplayText(str); // this text will be displayed
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if (str.size()) // if some text
|
|
|
|
|
x = x - (x1+x2) * 0.5; // position the text so that [x1<-->x2] is centered below the note
|
|
|
|
|
else // if no text (but possibly a line)
|
|
|
|
|
x = 0; // start at note left margin
|
2013-02-10 13:34:08 +01:00
|
|
|
|
// vertical position
|
2012-05-26 14:26:10 +02:00
|
|
|
|
h = fm.lineSpacing();
|
|
|
|
|
h *= score()->styleD(ST_figuredBassLineHeight);
|
2013-02-10 13:34:08 +01:00
|
|
|
|
if (score()->styleI(ST_figuredBassAlignment) == 0) // top alignment: stack down from first item
|
|
|
|
|
y = h * ord;
|
|
|
|
|
else // bottom alignment: stack up from last item
|
|
|
|
|
y = -h * (figuredBass()->numOfItems() - ord);
|
|
|
|
|
setPos(x, y);
|
2013-02-12 16:00:05 +01:00
|
|
|
|
// determine bbox from text width
|
|
|
|
|
// w = fm.width(str);
|
|
|
|
|
w = fm.boundingRect(str).width();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
textWidth = w;
|
2013-02-12 16:00:05 +01:00
|
|
|
|
// if there is a cont.line, extend width to cover the whole FB element duration line
|
2012-05-26 14:26:10 +02:00
|
|
|
|
int lineLen;
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if(_contLine != ContLineNone && (lineLen=figuredBass()->lineLength(0)) > w)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
w = lineLen;
|
2013-01-02 09:29:17 +01:00
|
|
|
|
bbox().setRect(0, 0, w, h);
|
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// FiguredBassItem draw()
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBassItem::draw(QPainter* painter) const
|
|
|
|
|
{
|
2012-07-24 01:46:12 +02:00
|
|
|
|
int font = 0;
|
|
|
|
|
// set font from general style
|
|
|
|
|
QFont f(g_FBFonts.at(font).family);
|
|
|
|
|
#ifdef USE_GLYPHS
|
|
|
|
|
f.setHintingPreference(QFont::PreferVerticalHinting);
|
|
|
|
|
#endif
|
2012-08-02 18:41:29 +02:00
|
|
|
|
// font size in pixels, scaled according to spatium()
|
2012-07-24 01:46:12 +02:00
|
|
|
|
qreal m = score()->styleD(ST_figuredBassFontSize) * MScore::DPI / PPI;
|
|
|
|
|
m *= spatium() / (SPATIUM20 * MScore::DPI); // make spatium dependent
|
|
|
|
|
f.setPixelSize(lrint(m));
|
|
|
|
|
|
|
|
|
|
painter->setFont(f);
|
|
|
|
|
painter->setBrush(Qt::NoBrush);
|
|
|
|
|
painter->setPen(figuredBass()->curColor());
|
2012-08-01 19:06:20 +02:00
|
|
|
|
painter->drawText(bbox(), Qt::TextDontClip | Qt::AlignLeft | Qt::AlignTop, displayText());
|
2012-07-24 01:46:12 +02:00
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// continuation line
|
2013-02-12 16:00:05 +01:00
|
|
|
|
qreal lineEndX = 0.0;
|
|
|
|
|
if (_contLine > ContLineNone) {
|
|
|
|
|
qreal _spatium = spatium();
|
2013-03-01 13:42:05 +01:00
|
|
|
|
qreal lineStartX = textWidth; // by default, line starts right after text
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if (lineStartX > 0.0)
|
2013-03-01 13:42:05 +01:00
|
|
|
|
lineStartX += _spatium * 0.1; // if some text, give some room after it
|
|
|
|
|
lineEndX = figuredBass()->printedLineLength(); // by default, line ends
|
|
|
|
|
if(lineEndX - lineStartX < 1.0) // if line length < 1 sp, ignore it
|
|
|
|
|
lineEndX = 0.0;
|
|
|
|
|
|
|
|
|
|
// if extended cont.line and no closing parenthesis: look at next FB element
|
2013-02-12 16:00:05 +01:00
|
|
|
|
if (_contLine > ContLineSimple && parenth[4] == ParenthesisNone) {
|
|
|
|
|
FiguredBass * nextFB;
|
|
|
|
|
// if there is a contiguous FB element
|
|
|
|
|
if ( (nextFB=figuredBass()->nextFiguredBass()) != 0) {
|
|
|
|
|
// retrieve the X position (in page coords) of a possible cont. line of nextFB
|
|
|
|
|
// on the same line of 'this'
|
|
|
|
|
QPointF pgPos = pagePos();
|
|
|
|
|
qreal nextContPageX = nextFB->additionalContLineX(pgPos.y());
|
|
|
|
|
// if an additional cont. line has been found, extend up to its initial X coord
|
|
|
|
|
if (nextContPageX > 0)
|
|
|
|
|
lineEndX = nextContPageX - pgPos.x() + _spatium*0.125; // with a little bit of overlap
|
2013-03-01 13:42:05 +01:00
|
|
|
|
else
|
|
|
|
|
lineEndX = figuredBass()->lineLength(0); // if none found, draw to the duration end
|
2013-02-12 16:00:05 +01:00
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-03-01 13:42:05 +01:00
|
|
|
|
// if some line, draw it
|
|
|
|
|
if (lineEndX > 0.0) {
|
|
|
|
|
qreal h = bbox().height() * 0.875;
|
|
|
|
|
painter->drawLine(lineStartX, h, lineEndX - ipos().x(), h);
|
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2012-07-24 01:46:12 +02:00
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// closing cont.line parenthesis
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if(parenth[4] != ParenthesisNone) {
|
2013-02-12 16:00:05 +01:00
|
|
|
|
int x = lineEndX > 0.0 ? lineEndX : textWidth;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
painter->drawText(QRectF(x, 0, bbox().width(), bbox().height()), Qt::AlignLeft | Qt::AlignTop,
|
|
|
|
|
g_FBFonts.at(font).displayParenthesis[parenth[4]]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-10 20:50:27 +02:00
|
|
|
|
//---------------------------------------------------------
|
2012-08-11 01:15:22 +02:00
|
|
|
|
// PROPERTY METHODS
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QVariant FiguredBassItem::getProperty(P_ID propertyId) const
|
|
|
|
|
{
|
|
|
|
|
switch(propertyId) {
|
|
|
|
|
case P_FBPREFIX:
|
|
|
|
|
return _prefix;
|
|
|
|
|
case P_FBDIGIT:
|
|
|
|
|
return _digit;
|
|
|
|
|
case P_FBSUFFIX:
|
|
|
|
|
return _suffix;
|
|
|
|
|
case P_FBCONTINUATIONLINE:
|
|
|
|
|
return _contLine;
|
2012-08-14 14:58:43 +02:00
|
|
|
|
case P_FBPARENTHESIS1:
|
|
|
|
|
return parenth[0];
|
|
|
|
|
case P_FBPARENTHESIS2:
|
|
|
|
|
return parenth[1];
|
|
|
|
|
case P_FBPARENTHESIS3:
|
|
|
|
|
return parenth[2];
|
|
|
|
|
case P_FBPARENTHESIS4:
|
|
|
|
|
return parenth[3];
|
|
|
|
|
case P_FBPARENTHESIS5:
|
|
|
|
|
return parenth[4];
|
2012-08-11 01:15:22 +02:00
|
|
|
|
default:
|
|
|
|
|
return Element::getProperty(propertyId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FiguredBassItem::setProperty(P_ID propertyId, const QVariant& v)
|
|
|
|
|
{
|
|
|
|
|
score()->addRefresh(canvasBoundingRect());
|
|
|
|
|
int val = v.toInt();
|
|
|
|
|
switch(propertyId) {
|
|
|
|
|
case P_FBPREFIX:
|
2013-02-10 07:01:31 +01:00
|
|
|
|
if(val < ModifierNone || val > ModifierCross)
|
2012-08-11 01:15:22 +02:00
|
|
|
|
return false;
|
|
|
|
|
_prefix = (Modifier)val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBDIGIT:
|
|
|
|
|
if(val < 1 || val > 9)
|
|
|
|
|
return false;
|
|
|
|
|
_digit = val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBSUFFIX:
|
|
|
|
|
if(val < ModifierNone || val >= NumOfModifiers)
|
|
|
|
|
return false;
|
|
|
|
|
_suffix = (Modifier)val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBCONTINUATIONLINE:
|
2013-02-12 16:00:05 +01:00
|
|
|
|
_contLine = (ContLine)val;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
break;
|
2012-08-14 14:58:43 +02:00
|
|
|
|
case P_FBPARENTHESIS1:
|
|
|
|
|
if(val < ParenthesisNone || val > ParenthesisSquaredClosed)
|
|
|
|
|
return false;
|
|
|
|
|
parenth[0] = (Parenthesis)val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBPARENTHESIS2:
|
|
|
|
|
if(val < ParenthesisNone || val > ParenthesisSquaredClosed)
|
|
|
|
|
return false;
|
|
|
|
|
parenth[1] = (Parenthesis)val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBPARENTHESIS3:
|
|
|
|
|
if(val < ParenthesisNone || val > ParenthesisSquaredClosed)
|
|
|
|
|
return false;
|
|
|
|
|
parenth[2] = (Parenthesis)val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBPARENTHESIS4:
|
|
|
|
|
if(val < ParenthesisNone || val > ParenthesisSquaredClosed)
|
|
|
|
|
return false;
|
|
|
|
|
parenth[3] = (Parenthesis)val;
|
|
|
|
|
break;
|
|
|
|
|
case P_FBPARENTHESIS5:
|
|
|
|
|
if(val < ParenthesisNone || val > ParenthesisSquaredClosed)
|
|
|
|
|
return false;
|
|
|
|
|
parenth[4] = (Parenthesis)val;
|
|
|
|
|
break;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
default:
|
|
|
|
|
return Element::setProperty(propertyId, v);
|
|
|
|
|
}
|
|
|
|
|
score()->setLayoutAll(true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant FiguredBassItem::propertyDefault(P_ID id) const
|
|
|
|
|
{
|
|
|
|
|
switch(id) {
|
|
|
|
|
case P_FBPREFIX:
|
|
|
|
|
case P_FBSUFFIX:
|
|
|
|
|
return ModifierNone;
|
|
|
|
|
case P_FBDIGIT:
|
|
|
|
|
return FBIDigitNone;
|
|
|
|
|
case P_FBCONTINUATIONLINE:
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return Element::propertyDefault(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// UNDOABLE PROPERTY SETTERS
|
2012-08-10 20:50:27 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
void FiguredBassItem::undoSetPrefix(Modifier pref)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
{
|
2013-02-10 07:01:31 +01:00
|
|
|
|
if(pref <= ModifierCross) {
|
2012-08-11 01:15:22 +02:00
|
|
|
|
score()->undoChangeProperty(this, P_FBPREFIX, (int)pref);
|
2012-08-12 13:39:25 +02:00
|
|
|
|
// if setting some prefix and there is a suffix already, clear suffix
|
|
|
|
|
if(pref != ModifierNone && _suffix != ModifierNone)
|
|
|
|
|
score()->undoChangeProperty(this, P_FBSUFFIX, ModifierNone);
|
2012-08-14 14:58:43 +02:00
|
|
|
|
layout(); // re-generate displayText
|
2012-08-12 13:39:25 +02:00
|
|
|
|
}
|
2012-08-10 20:50:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FiguredBassItem::undoSetDigit(int digit)
|
|
|
|
|
{
|
2012-08-14 14:58:43 +02:00
|
|
|
|
if(digit >= 0 && digit <= 9) {
|
2012-08-11 01:15:22 +02:00
|
|
|
|
score()->undoChangeProperty(this, P_FBDIGIT, digit);
|
2012-08-14 14:58:43 +02:00
|
|
|
|
layout(); // re-generate displayText
|
|
|
|
|
}
|
2012-08-10 20:50:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
void FiguredBassItem::undoSetSuffix(Modifier suff)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
score()->undoChangeProperty(this, P_FBSUFFIX, suff);
|
2012-08-12 13:39:25 +02:00
|
|
|
|
// if setting some suffix and there is a prefix already, clear prefix
|
|
|
|
|
if(suff != ModifierNone && _prefix != ModifierNone)
|
|
|
|
|
score()->undoChangeProperty(this, P_FBPREFIX, ModifierNone);
|
2012-08-14 14:58:43 +02:00
|
|
|
|
layout(); // re-generate displayText
|
2012-08-10 20:50:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
void FiguredBassItem::undoSetContLine(bool val)
|
2012-08-10 20:50:27 +02:00
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
score()->undoChangeProperty(this, P_FBCONTINUATIONLINE, val);
|
2012-08-14 14:58:43 +02:00
|
|
|
|
layout(); // re-generate displayText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FiguredBassItem::undoSetParenth1(Parenthesis par)
|
|
|
|
|
{
|
|
|
|
|
score()->undoChangeProperty(this, P_FBPARENTHESIS1, par);
|
|
|
|
|
layout(); // re-generate displayText
|
|
|
|
|
}
|
|
|
|
|
void FiguredBassItem::undoSetParenth2(Parenthesis par)
|
|
|
|
|
{
|
|
|
|
|
score()->undoChangeProperty(this, P_FBPARENTHESIS2, par);
|
|
|
|
|
layout(); // re-generate displayText
|
|
|
|
|
}
|
|
|
|
|
void FiguredBassItem::undoSetParenth3(Parenthesis par)
|
|
|
|
|
{
|
|
|
|
|
score()->undoChangeProperty(this, P_FBPARENTHESIS3, par);
|
|
|
|
|
layout(); // re-generate displayText
|
|
|
|
|
}
|
|
|
|
|
void FiguredBassItem::undoSetParenth4(Parenthesis par)
|
|
|
|
|
{
|
|
|
|
|
score()->undoChangeProperty(this, P_FBPARENTHESIS4, par);
|
|
|
|
|
layout(); // re-generate displayText
|
|
|
|
|
}
|
|
|
|
|
void FiguredBassItem::undoSetParenth5(Parenthesis par)
|
|
|
|
|
{
|
|
|
|
|
score()->undoChangeProperty(this, P_FBPARENTHESIS5, par);
|
|
|
|
|
layout(); // re-generate displayText
|
2012-08-10 20:50:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// MusicXML I/O
|
|
|
|
|
//
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Convert MusicXML prefix/suffix to Modifier
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// TODO add missing non-accidental types
|
|
|
|
|
|
|
|
|
|
FiguredBassItem::Modifier FiguredBassItem::MusicXML2Modifier(const QString prefix) const
|
2012-08-10 20:50:27 +02:00
|
|
|
|
{
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if (prefix == "sharp")
|
|
|
|
|
return ModifierSharp;
|
|
|
|
|
else if (prefix == "flat")
|
|
|
|
|
return ModifierFlat;
|
|
|
|
|
else if (prefix == "natural")
|
|
|
|
|
return ModifierNatural;
|
|
|
|
|
else if (prefix == "double-sharp")
|
|
|
|
|
return ModifierDoubleSharp;
|
|
|
|
|
else if (prefix == "flat-flat")
|
|
|
|
|
return ModifierDoubleFlat;
|
|
|
|
|
else if (prefix == "sharp-sharp")
|
|
|
|
|
return ModifierDoubleSharp;
|
|
|
|
|
else if (prefix == "slash")
|
|
|
|
|
return ModifierSlash;
|
|
|
|
|
else
|
|
|
|
|
return ModifierNone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Convert Modifier to MusicXML prefix/suffix
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// TODO add missing non-accidental types
|
|
|
|
|
|
|
|
|
|
QString FiguredBassItem::Modifier2MusicXML(FiguredBassItem::Modifier prefix) const
|
|
|
|
|
{
|
|
|
|
|
switch (prefix) {
|
|
|
|
|
case ModifierNone: return "";
|
|
|
|
|
case ModifierDoubleFlat: return "flat-flat";
|
|
|
|
|
case ModifierFlat: return "flat";
|
|
|
|
|
case ModifierNatural: return "natural";
|
|
|
|
|
case ModifierSharp: return "sharp";
|
|
|
|
|
case ModifierDoubleSharp: return "double-sharp";
|
2013-02-10 07:01:31 +01:00
|
|
|
|
case ModifierCross: return ""; // TODO TBD
|
2012-08-11 01:15:22 +02:00
|
|
|
|
case ModifierBackslash: return ""; // TODO TBD
|
|
|
|
|
case ModifierSlash: return "slash";
|
|
|
|
|
case NumOfModifiers: return ""; // prevent gcc "‘FBINumOfAccid’ not handled in switch" warning
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Read MusicXML
|
|
|
|
|
//
|
|
|
|
|
// Set the FiguredBassItem state based on the MusicXML <figure> node de.
|
|
|
|
|
// In MusicXML, parentheses is set to "yes" or "no" for the figured-bass
|
|
|
|
|
// node instead of for each individual <figure> node.
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-17 11:33:11 +01:00
|
|
|
|
#if 0
|
2013-01-11 18:10:18 +01:00
|
|
|
|
void FiguredBassItem::readMusicXML(XmlReader& e, bool paren, bool& extend)
|
2012-08-11 01:15:22 +02:00
|
|
|
|
{
|
|
|
|
|
// read the <figure> node de
|
2013-01-11 18:10:18 +01:00
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
const QStringRef& tag(e.name());
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if (tag == "extend")
|
2013-01-01 14:36:49 +01:00
|
|
|
|
extend = true;
|
2012-08-11 01:15:22 +02:00
|
|
|
|
else if (tag == "figure-number") {
|
|
|
|
|
// MusicXML spec states figure-number is a number
|
|
|
|
|
// MuseScore can only handle single digit
|
2013-01-11 18:10:18 +01:00
|
|
|
|
int iVal = e.readInt();
|
2012-08-11 01:15:22 +02:00
|
|
|
|
if (1 <= iVal && iVal <= 9)
|
|
|
|
|
_digit = iVal;
|
|
|
|
|
}
|
|
|
|
|
else if (tag == "prefix")
|
2013-01-11 18:10:18 +01:00
|
|
|
|
_prefix = MusicXML2Modifier(e.readElementText());
|
2012-08-11 01:15:22 +02:00
|
|
|
|
else if (tag == "suffix")
|
2013-01-11 18:10:18 +01:00
|
|
|
|
_suffix = MusicXML2Modifier(e.readElementText());
|
2012-08-11 01:15:22 +02:00
|
|
|
|
else
|
2013-01-11 18:10:18 +01:00
|
|
|
|
e.unknown();
|
2012-08-11 01:15:22 +02:00
|
|
|
|
}
|
|
|
|
|
// set parentheses
|
|
|
|
|
if (paren) {
|
|
|
|
|
// parenthesis open
|
|
|
|
|
if (_prefix != ModifierNone)
|
|
|
|
|
parenth[0] = ParenthesisRoundOpen; // before prefix
|
|
|
|
|
else if (_digit != FBIDigitNone)
|
|
|
|
|
parenth[1] = ParenthesisRoundOpen; // before digit
|
|
|
|
|
else if (_suffix != ModifierNone)
|
|
|
|
|
parenth[2] = ParenthesisRoundOpen; // before suffix
|
|
|
|
|
// parenthesis close
|
|
|
|
|
if (_suffix != ModifierNone)
|
|
|
|
|
parenth[3] = ParenthesisRoundClosed; // after suffix
|
|
|
|
|
else if (_digit != FBIDigitNone)
|
|
|
|
|
parenth[2] = ParenthesisRoundClosed; // after digit
|
|
|
|
|
else if (_prefix != ModifierNone)
|
|
|
|
|
parenth[1] = ParenthesisRoundClosed; // after prefix
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-17 11:33:11 +01:00
|
|
|
|
#endif
|
2012-08-11 01:15:22 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Write MusicXML
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-01 14:36:49 +01:00
|
|
|
|
void FiguredBassItem::writeMusicXML(Xml& xml, bool doFigure, bool doExtend) const
|
2012-08-11 01:15:22 +02:00
|
|
|
|
{
|
|
|
|
|
xml.stag("figure");
|
2013-01-01 14:36:49 +01:00
|
|
|
|
if (doFigure) {
|
|
|
|
|
QString strPrefix = Modifier2MusicXML(_prefix);
|
|
|
|
|
if (strPrefix != "")
|
|
|
|
|
xml.tag("prefix", strPrefix);
|
|
|
|
|
if (_digit != FBIDigitNone)
|
|
|
|
|
xml.tag("figure-number", _digit);
|
|
|
|
|
QString strSuffix = Modifier2MusicXML(_suffix);
|
|
|
|
|
if (strSuffix != "")
|
|
|
|
|
xml.tag("suffix", strSuffix);
|
|
|
|
|
}
|
|
|
|
|
if (doExtend) {
|
|
|
|
|
xml.tagE("extend");
|
|
|
|
|
}
|
2012-08-11 01:15:22 +02:00
|
|
|
|
xml.etag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// startsWithParenthesis
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool FiguredBassItem::startsWithParenthesis() const
|
|
|
|
|
{
|
|
|
|
|
if (_prefix != ModifierNone)
|
|
|
|
|
return (parenth[0] != ParenthesisNone);
|
|
|
|
|
if (_digit != FBIDigitNone)
|
|
|
|
|
return (parenth[1] != ParenthesisNone);
|
|
|
|
|
if (_suffix != ModifierNone)
|
|
|
|
|
return (parenth[2] != ParenthesisNone);
|
|
|
|
|
return false;
|
2012-08-10 20:50:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// F I G U R E D B A S S
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#include "chord.h"
|
|
|
|
|
#include "rest.h"
|
|
|
|
|
|
|
|
|
|
FiguredBass::FiguredBass(Score* s)
|
|
|
|
|
: Text(s)
|
|
|
|
|
{
|
|
|
|
|
setOnNote(true);
|
2013-02-22 19:59:52 +01:00
|
|
|
|
setTextStyleType(TEXT_STYLE_FIGURED_BASS);
|
|
|
|
|
TextStyle st("figBass", g_FBFonts[0].family, score()->styleD(ST_figuredBassFontSize),
|
|
|
|
|
false, false, false, ALIGN_LEFT | ALIGN_TOP, QPointF(0, score()->styleD(ST_figuredBassYOffset)), OFFSET_SPATIUM);
|
2012-08-10 01:24:19 +02:00
|
|
|
|
st.setSizeIsSpatiumDependent(true);
|
|
|
|
|
setTextStyle(st);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
setTicks(0);
|
|
|
|
|
items.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FiguredBass::FiguredBass(const FiguredBass& fb)
|
|
|
|
|
: Text(fb)
|
|
|
|
|
{
|
|
|
|
|
setOnNote(fb.onNote());
|
|
|
|
|
setTicks(fb.ticks());
|
|
|
|
|
items = fb.items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FiguredBass::~FiguredBass()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// write
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBass::write(Xml& xml) const
|
|
|
|
|
{
|
|
|
|
|
xml.stag("FiguredBass");
|
|
|
|
|
if(!onNote())
|
|
|
|
|
xml.tag("onNote", onNote());
|
|
|
|
|
if (ticks() > 0)
|
|
|
|
|
xml.tag("ticks", ticks());
|
2013-02-22 19:59:52 +01:00
|
|
|
|
if (textStyleType() != TEXT_STYLE_FIGURED_BASS) {
|
|
|
|
|
if (textStyleType() == TEXT_STYLE_UNSTYLED)
|
|
|
|
|
Text::writeProperties(xml, true);
|
|
|
|
|
else
|
|
|
|
|
xml.tag("style", textStyleType());
|
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
foreach(FiguredBassItem item, items)
|
|
|
|
|
item.write(xml);
|
2013-02-22 19:59:52 +01:00
|
|
|
|
if (textStyleType() != TEXT_STYLE_UNSTYLED)
|
|
|
|
|
Element::writeProperties(xml);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
xml.etag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// read
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
|
void FiguredBass::read(XmlReader& e)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
2013-01-11 18:10:18 +01:00
|
|
|
|
QString normalizedText;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
int idx = 0;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
const QStringRef& tag(e.name());
|
|
|
|
|
if (tag == "ticks")
|
|
|
|
|
setTicks(e.readInt());
|
2013-02-22 19:59:52 +01:00
|
|
|
|
else if (tag == "onNote")
|
2013-01-11 18:10:18 +01:00
|
|
|
|
setOnNote(e.readInt() != 0l);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "FiguredBassItem") {
|
|
|
|
|
FiguredBassItem * pItem = new FiguredBassItem(score(), idx++);
|
|
|
|
|
pItem->setTrack(track());
|
|
|
|
|
pItem->setParent(this);
|
|
|
|
|
pItem->read(e);
|
|
|
|
|
items.append(*pItem);
|
|
|
|
|
// add item normalized text
|
|
|
|
|
if(!normalizedText.isEmpty())
|
|
|
|
|
normalizedText.append('\n');
|
|
|
|
|
normalizedText.append(pItem->normalizedText());
|
|
|
|
|
}
|
2013-02-22 19:59:52 +01:00
|
|
|
|
else if (tag == "style")
|
|
|
|
|
setTextStyleType(e.readInt());
|
|
|
|
|
else if (!Text::readProperties(e))
|
2013-01-11 18:10:18 +01:00
|
|
|
|
e.unknown();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// if text is styled, set normalized text
|
|
|
|
|
if(textStyleType() != TEXT_STYLE_UNSTYLED)
|
|
|
|
|
setText(normalizedText); // this is the text to show while editing
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// layout
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBass::layout()
|
|
|
|
|
{
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// qreal y;
|
|
|
|
|
|
|
|
|
|
// if 'our' style, force 'our' style data from FiguredBass parameters
|
|
|
|
|
if(textStyleType() == TEXT_STYLE_FIGURED_BASS) {
|
|
|
|
|
TextStyle st("figBass", g_FBFonts[0].family, score()->styleD(ST_figuredBassFontSize),
|
|
|
|
|
false, false, false, ALIGN_LEFT | ALIGN_TOP, QPointF(0, score()->styleD(ST_figuredBassYOffset)),
|
|
|
|
|
OFFSET_SPATIUM);
|
|
|
|
|
st.setSizeIsSpatiumDependent(true);
|
|
|
|
|
setTextStyle(st);
|
|
|
|
|
}
|
2013-02-18 20:42:18 +01:00
|
|
|
|
Text::layout(); // Text and/or SimpleText may expect some internal data to be setup
|
2012-05-26 14:26:10 +02:00
|
|
|
|
layoutLines();
|
|
|
|
|
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// if style has been changed (or text not styled), do nothing else, keeping default laying out and formatting
|
|
|
|
|
if(textStyleType() != TEXT_STYLE_FIGURED_BASS)
|
|
|
|
|
return;
|
|
|
|
|
/* already taken into account by Text::layout()
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// vertical position
|
|
|
|
|
y = 0; // default vert. pos.
|
|
|
|
|
// if a staff exists for this F.B., use its y position
|
|
|
|
|
if(parent() && track() >= 0) {
|
|
|
|
|
System* sys = ((Segment*)parent())->measure()->system();
|
|
|
|
|
if (sys == 0)
|
|
|
|
|
qDebug("FiguredBass layout: no system!");
|
|
|
|
|
else {
|
|
|
|
|
SysStaff* staff = sys->staff(staffIdx());
|
|
|
|
|
y = staff->y();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
y += point(score()->styleS(ST_figuredBassYOffset));
|
2013-02-22 19:59:52 +01:00
|
|
|
|
*/
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// bounding box
|
|
|
|
|
if(editMode()) {
|
|
|
|
|
qreal h, w, w1;
|
|
|
|
|
QFontMetricsF fm(textStyle().font(spatium()));
|
|
|
|
|
// box width
|
|
|
|
|
w = 0;
|
2013-02-26 15:50:36 +01:00
|
|
|
|
QStringList list = text().split('\n');
|
2012-05-26 14:26:10 +02:00
|
|
|
|
foreach(QString str, list) {
|
|
|
|
|
w1 = fm.width(str);
|
|
|
|
|
if(w1 > w)
|
|
|
|
|
w = w1;
|
|
|
|
|
}
|
|
|
|
|
// bbox height
|
|
|
|
|
h = fm.lineSpacing();
|
|
|
|
|
h *= score()->styleD(ST_figuredBassLineHeight);
|
|
|
|
|
h *= (list.size() > 1 ? list.size() : 1); // at least 1 line
|
|
|
|
|
// ready to set position and bbox
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// setPos(0, y);
|
2013-01-02 09:29:17 +01:00
|
|
|
|
bbox().setRect(0-2, 0-2, w+4, h+4);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// setPos(0, y);
|
2013-01-02 09:29:17 +01:00
|
|
|
|
bbox().setRect(0, 0, _lineLenghts.at(0), 0);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// if element could be parsed into items, layout each element
|
|
|
|
|
if(items.size() > 0) {
|
|
|
|
|
// layout each item and enlarge bbox to include items bboxes
|
|
|
|
|
for(int i=0; i < items.size(); i++) {
|
|
|
|
|
items[i].layout();
|
|
|
|
|
addbbox(items[i].bbox().translated(items[i].pos()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// adjustReadPos(); // already taken into account by Text::layout()
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// layoutLines
|
|
|
|
|
//
|
|
|
|
|
// lays out the duration indicator line(s), filling the _lineLengths array
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBass::layoutLines()
|
|
|
|
|
{
|
|
|
|
|
if(_ticks <= 0) {
|
|
|
|
|
NoLen:
|
|
|
|
|
_lineLenghts.resize(1);
|
|
|
|
|
_lineLenghts[0] = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-03-01 13:42:05 +01:00
|
|
|
|
|
|
|
|
|
ChordRest * lastCR; // the last ChordRest of this
|
2012-05-26 14:26:10 +02:00
|
|
|
|
Segment * nextSegm; // the Segment beyond this' segment
|
|
|
|
|
int nextTick = segment()->tick() + _ticks; // the tick beyond this' duration
|
|
|
|
|
|
|
|
|
|
// locate the measure containing the last tick of this; it is either:
|
|
|
|
|
// the same measure containing nextTick, if nextTick is not the first tick of a measure
|
|
|
|
|
// (and line should stop right before it)
|
|
|
|
|
// or the previous measure, if nextTick is the first tick of a measure
|
|
|
|
|
// (and line should stop before any measure terminal segment (bar, clef, ...) )
|
|
|
|
|
Measure* m = score()->tick2measure(nextTick-1);
|
|
|
|
|
if (m != 0) {
|
|
|
|
|
// locate the first segment (of ANY type) right after this' last tick
|
2012-08-03 15:54:02 +02:00
|
|
|
|
for (nextSegm = m->first(Segment::SegAll); nextSegm; ) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
if(nextSegm->tick() >= nextTick)
|
|
|
|
|
break;
|
2012-08-03 15:54:02 +02:00
|
|
|
|
nextSegm = nextSegm->next();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-03-01 13:42:05 +01:00
|
|
|
|
// locate the last ChordRest of this
|
|
|
|
|
if (nextSegm)
|
|
|
|
|
lastCR = nextSegm->prev1()->nextChordRest(track(), true);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
if (m == 0 || nextSegm == 0) {
|
|
|
|
|
qDebug("FiguredBass layout: no segment found for tick %d\n", nextTick);
|
|
|
|
|
goto NoLen;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 13:42:05 +01:00
|
|
|
|
// get length of printed lines from horiz. page position of lastCR
|
|
|
|
|
// (enter a bit 'into' the ChordRest for clarity)
|
|
|
|
|
_printedLineLength = lastCR->pageX() - pageX() + 1.5*spatium();
|
|
|
|
|
|
|
|
|
|
// get duration indicator line(s) from page position of nextSegm
|
2012-05-26 14:26:10 +02:00
|
|
|
|
QList<System*>* systems = score()->systems();
|
|
|
|
|
System* s1 = segment()->measure()->system();
|
|
|
|
|
System* s2 = nextSegm->measure()->system();
|
|
|
|
|
int sysIdx1 = systems->indexOf(s1);
|
|
|
|
|
int sysIdx2 = systems->indexOf(s2);
|
|
|
|
|
|
|
|
|
|
int i, len ,segIdx;
|
|
|
|
|
for (i = sysIdx1, segIdx = 0; i <= sysIdx2; ++i, ++segIdx) {
|
|
|
|
|
len = 0;
|
|
|
|
|
if (sysIdx1 == sysIdx2 || i == sysIdx1) {
|
|
|
|
|
// single line
|
|
|
|
|
len = nextSegm->pageX() - pageX() - 4; // stop 4 raster units before next segm
|
|
|
|
|
}
|
|
|
|
|
else if (i == sysIdx1) {
|
|
|
|
|
// initial line
|
|
|
|
|
qreal w = s1->staff(staffIdx())->right();
|
|
|
|
|
qreal x = s1->pageX() + w;
|
|
|
|
|
len = x - pageX();
|
|
|
|
|
}
|
|
|
|
|
else if (i > 0 && i != sysIdx2) {
|
|
|
|
|
// middle line
|
|
|
|
|
qDebug("FiguredBass: duration indicator middle line not implemented");
|
|
|
|
|
}
|
|
|
|
|
else if (i == sysIdx2) {
|
|
|
|
|
// end line
|
|
|
|
|
qDebug("FiguredBass: duration indicator end line not implemented");
|
|
|
|
|
}
|
|
|
|
|
// store length item, reusing array items if already present
|
|
|
|
|
if (_lineLenghts.size() <= segIdx)
|
|
|
|
|
_lineLenghts.append(len);
|
|
|
|
|
else
|
|
|
|
|
_lineLenghts[segIdx] = len;
|
|
|
|
|
}
|
|
|
|
|
// if more array items than needed, truncate array
|
|
|
|
|
if(_lineLenghts.size() > segIdx)
|
|
|
|
|
_lineLenghts.resize(segIdx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// draw
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBass::draw(QPainter* painter) const
|
|
|
|
|
{
|
|
|
|
|
// if not printing, draw duration line(s)
|
|
|
|
|
if( !score()->printing() ) {
|
|
|
|
|
foreach(qreal len, _lineLenghts)
|
|
|
|
|
if(len > 0) {
|
|
|
|
|
painter->setPen(QPen(Qt::lightGray, 1));
|
|
|
|
|
painter->drawLine(0.0, -2, len, -2); // -2: 2 rast. un. above digits
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// if in edit mode or with custom style, use default drawing
|
|
|
|
|
if(editMode() || textStyleType() != TEXT_STYLE_FIGURED_BASS)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
Text::draw(painter);
|
|
|
|
|
else {
|
|
|
|
|
if(items.size() < 1)
|
|
|
|
|
Text::draw(painter);
|
|
|
|
|
else
|
|
|
|
|
foreach(FiguredBassItem item, items) {
|
|
|
|
|
painter->translate(item.pos());
|
|
|
|
|
item.draw(painter);
|
|
|
|
|
painter->translate(-item.pos());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* DEBUG
|
|
|
|
|
QString str = QString();
|
|
|
|
|
str.setNum(_ticks);
|
|
|
|
|
painter->drawText(0, (_onNote ? 40 : 30), str);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// endEdit
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBass::endEdit()
|
|
|
|
|
{
|
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
|
|
Text::endEdit();
|
2013-02-26 15:50:36 +01:00
|
|
|
|
QString txt = text();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
if(txt.isEmpty()) { // if no text, nothing to do
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// split text into lines and create an item for each line
|
|
|
|
|
QStringList list = txt.split('\n', QString::SkipEmptyParts);
|
|
|
|
|
items.clear();
|
|
|
|
|
QString normalizedText = QString();
|
|
|
|
|
idx = 0;
|
|
|
|
|
foreach(QString str, list) {
|
|
|
|
|
FiguredBassItem* pItem = new FiguredBassItem(score(), idx++);
|
|
|
|
|
if(!pItem->parse(str)) { // if any item fails parsing
|
|
|
|
|
items.clear(); // clear item list
|
|
|
|
|
Text::layout(); // keeping text as entered by user
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pItem->setTrack(track());
|
|
|
|
|
pItem->setParent(this);
|
|
|
|
|
items.append(*pItem);
|
|
|
|
|
|
|
|
|
|
// add item normalized text
|
|
|
|
|
if(!normalizedText.isEmpty())
|
|
|
|
|
normalizedText.append('\n');
|
|
|
|
|
normalizedText.append(pItem->normalizedText());
|
|
|
|
|
}
|
2013-02-22 19:59:52 +01:00
|
|
|
|
// if all items parsed and text is styled, replaced entered text with normalized text
|
|
|
|
|
if(textStyleType() != TEXT_STYLE_UNSTYLED) {
|
|
|
|
|
setText(normalizedText);
|
|
|
|
|
layout();
|
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// setSelected /setVisible
|
|
|
|
|
//
|
|
|
|
|
// forward flags to items
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FiguredBass::setSelected(bool flag)
|
|
|
|
|
{
|
|
|
|
|
Element::setSelected(flag);
|
|
|
|
|
for(int i=0; i < items.size(); i++) {
|
|
|
|
|
items[i].setSelected(flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FiguredBass::setVisible(bool flag)
|
|
|
|
|
{
|
|
|
|
|
Element::setVisible(flag);
|
|
|
|
|
for(int i=0; i < items.size(); i++) {
|
|
|
|
|
items[i].setVisible(flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 16:00:05 +01:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// nextFiguredBass
|
|
|
|
|
//
|
|
|
|
|
// returns the next *contiguous* FiguredBass element if it exists,
|
|
|
|
|
// i.e. the FiguredBass element which starts where 'this' ends
|
|
|
|
|
// returns 0 if none
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
FiguredBass* FiguredBass::nextFiguredBass() const
|
|
|
|
|
{
|
|
|
|
|
if (_ticks <= 0) // if _ticks unset, no clear idea of when 'this' ends
|
|
|
|
|
return 0;
|
|
|
|
|
Segment * nextSegm; // the Segment beyond this' segment
|
|
|
|
|
int nextTick = segment()->tick() + _ticks; // the tick beyond this' duration
|
|
|
|
|
|
|
|
|
|
// locate the ChordRest segment right after this' end
|
|
|
|
|
nextSegm = score()->tick2segment(nextTick, true, Segment::SegChordRest);
|
|
|
|
|
if (nextSegm == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// scan segment annotations for an existing FB element in the this' staff
|
2013-05-06 14:20:31 +02:00
|
|
|
|
for (Element* e : nextSegm->annotations())
|
|
|
|
|
if (e->type() == FIGURED_BASS && e->track() == track())
|
|
|
|
|
return static_cast<FiguredBass*>(e);
|
2013-02-12 16:00:05 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// additionalContLineX
|
|
|
|
|
//
|
|
|
|
|
// if there is a continuation line, without other text elements, at pagePosY, returns its X coord (in page coords)
|
|
|
|
|
// returns 0 if no cont.line there or if there are text elements before the cont.line
|
|
|
|
|
//
|
|
|
|
|
// In practice, returns the X coord of a cont. line which can be the continuation of a previous cont. line
|
|
|
|
|
//
|
|
|
|
|
// Note: pagePosY is the Y coord of the FiguredBassItem containing the line, not of the line itself,
|
|
|
|
|
// as line position might depend on styles.
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
qreal FiguredBass::additionalContLineX(qreal pagePosY) const
|
|
|
|
|
{
|
|
|
|
|
QPointF pgPos = pagePos();
|
|
|
|
|
foreach (FiguredBassItem fbi, items)
|
|
|
|
|
// if item has cont.line but nothing before it
|
|
|
|
|
// and item Y coord near enough to pagePosY
|
|
|
|
|
if(fbi.contLine()
|
|
|
|
|
&& fbi.digit() == FBIDigitNone
|
|
|
|
|
&& fbi.prefix() == FiguredBassItem::ModifierNone
|
|
|
|
|
&& fbi.suffix() == FiguredBassItem::ModifierNone
|
|
|
|
|
&& fbi.parenth4() == FiguredBassItem::ParenthesisNone
|
|
|
|
|
&& qAbs(pgPos.y() + fbi.ipos().y() - pagePosY) < 0.05)
|
|
|
|
|
return pgPos.x() + fbi.ipos().x();
|
|
|
|
|
|
|
|
|
|
return 0.0; // no suitable line
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// PROPERTY METHODS
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QVariant FiguredBass::getProperty(P_ID propertyId) const
|
|
|
|
|
{
|
|
|
|
|
switch(propertyId) {
|
|
|
|
|
default:
|
|
|
|
|
return Text::getProperty(propertyId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FiguredBass::setProperty(P_ID propertyId, const QVariant& v)
|
|
|
|
|
{
|
|
|
|
|
score()->addRefresh(canvasBoundingRect());
|
|
|
|
|
switch(propertyId) {
|
|
|
|
|
default:
|
|
|
|
|
return Text::setProperty(propertyId, v);
|
|
|
|
|
}
|
|
|
|
|
score()->setLayoutAll(true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant FiguredBass::propertyDefault(P_ID id) const
|
|
|
|
|
{
|
|
|
|
|
switch(id) {
|
|
|
|
|
default:
|
|
|
|
|
return Text::propertyDefault(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// TEMPORARY HACK!!!
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
FiguredBassItem * FiguredBass::addItem()
|
|
|
|
|
{
|
|
|
|
|
int line = items.size();
|
|
|
|
|
FiguredBassItem fib(score(), line);
|
|
|
|
|
items.append(fib);
|
|
|
|
|
return &(items.last());
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// STATIC FUNCTION
|
|
|
|
|
// adding a new FiguredBass to a Segment;
|
|
|
|
|
// the main purpose of this function is to ensure that ONLY ONE F.b. element exists for each Segment/staff;
|
|
|
|
|
// it either re-uses an existing FiguredBass or creates a new one if none if found;
|
|
|
|
|
// returns the FiguredBass and sets pNew to true if it has been newly created.
|
|
|
|
|
//
|
|
|
|
|
// Sets an initial duration of the element up to the next ChordRest of the same staff.
|
|
|
|
|
//
|
|
|
|
|
// As the F.b. very concept requires the base chord to have ONLY ONE note,
|
|
|
|
|
// FiguredBass elements are created and looked for only in the first track of the staff.
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
FiguredBass * FiguredBass::addFiguredBassToSegment(Segment * seg, int track, int extTicks, bool * pNew)
|
|
|
|
|
{
|
|
|
|
|
int endTick; // where this FB is initially assumed to end
|
|
|
|
|
int staff = track / VOICES; // convert track to staff
|
|
|
|
|
track = staff * VOICES; // first track for this staff
|
|
|
|
|
|
|
|
|
|
// scan segment annotations for an existing FB element in the same staff
|
2013-05-06 14:20:31 +02:00
|
|
|
|
FiguredBass* fb = 0;
|
|
|
|
|
for (Element* e : seg->annotations()) {
|
|
|
|
|
if (e->type() == FIGURED_BASS && (e->track() / VOICES) == staff) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// an FB already exists in segment: re-use it
|
2013-05-06 14:20:31 +02:00
|
|
|
|
fb = static_cast<FiguredBass*>(e);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
*pNew = false;
|
|
|
|
|
endTick = seg->tick() + fb->ticks();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-06 14:20:31 +02:00
|
|
|
|
if (fb == 0) { // no FB at segment: create new
|
2012-05-26 14:26:10 +02:00
|
|
|
|
fb = new FiguredBass(seg->score());
|
|
|
|
|
fb->setTrack(track);
|
|
|
|
|
fb->setParent(seg);
|
|
|
|
|
|
|
|
|
|
// locate next SegChordRest in the same staff to estimate presumed duration of element
|
|
|
|
|
endTick = INT_MAX;
|
|
|
|
|
Segment * nextSegm;
|
|
|
|
|
for (int iVoice = 0; iVoice < VOICES; iVoice++) {
|
|
|
|
|
nextSegm = seg->nextCR(track + iVoice);
|
|
|
|
|
if(nextSegm && nextSegm->tick() < endTick)
|
|
|
|
|
endTick = nextSegm->tick();
|
|
|
|
|
}
|
|
|
|
|
if(endTick == INT_MAX) { // no next segment: set up to score end
|
|
|
|
|
Measure * meas = seg->score()->lastMeasure();
|
|
|
|
|
endTick = meas->tick() + meas->ticks();
|
|
|
|
|
}
|
|
|
|
|
fb->setTicks(endTick - seg->tick());
|
|
|
|
|
|
|
|
|
|
// set onNote status
|
|
|
|
|
fb->setOnNote(false); // assume not onNote
|
2013-05-06 14:20:31 +02:00
|
|
|
|
for (int i = track; i < track + VOICES; i++) // if segment has chord in staff, set onNote
|
|
|
|
|
if (seg->element(i) && seg->element(i)->type() == CHORD) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
fb->setOnNote(true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
*pNew = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we are extending a previous FB
|
|
|
|
|
if(extTicks > 0) {
|
|
|
|
|
// locate previous FB for same staff
|
|
|
|
|
Segment * prevSegm;
|
|
|
|
|
FiguredBass* prevFB = 0;
|
2012-08-03 15:54:02 +02:00
|
|
|
|
for(prevSegm = seg->prev1(Segment::SegChordRest); prevSegm; prevSegm = prevSegm->prev1(Segment::SegChordRest)) {
|
2013-05-06 14:20:31 +02:00
|
|
|
|
for (Element* e : prevSegm->annotations()) {
|
|
|
|
|
if (e->type() == FIGURED_BASS && (e->track() ) == track) {
|
|
|
|
|
prevFB = static_cast<FiguredBass*>(e); // previous FB found
|
2012-05-26 14:26:10 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(prevFB) {
|
|
|
|
|
// if previous FB did not stop more than extTicks before this FB...
|
|
|
|
|
int delta = seg->tick() - prevFB->segment()->tick();
|
|
|
|
|
if(prevFB->ticks() + extTicks >= delta)
|
|
|
|
|
prevFB->setTicks(delta); // update prev FB ticks to last up to this FB
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// STATIC FUNCTIONS FOR FONT CONFIGURATION MANAGEMENT
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
|
bool FiguredBassFont::read(XmlReader& e)
|
|
|
|
|
{
|
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
const QStringRef& tag(e.name());
|
2013-02-10 07:01:31 +01:00
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
|
if (tag == "family")
|
2013-01-11 18:10:18 +01:00
|
|
|
|
family = e.readElementText();
|
|
|
|
|
else if (tag == "displayName")
|
|
|
|
|
displayName = e.readElementText();
|
|
|
|
|
else if (tag == "defaultPitch")
|
|
|
|
|
defPitch = e.readDouble();
|
|
|
|
|
else if (tag == "defaultLineHeight")
|
|
|
|
|
defLineHeight = e.readDouble();
|
|
|
|
|
else if (tag == "parenthesisRoundOpen")
|
|
|
|
|
displayParenthesis[1] = e.readElementText()[0];
|
|
|
|
|
else if (tag == "parenthesisRoundClosed")
|
|
|
|
|
displayParenthesis[2] = e.readElementText()[0];
|
|
|
|
|
else if (tag == "parenthesisSquareOpen")
|
|
|
|
|
displayParenthesis[3] = e.readElementText()[0];
|
|
|
|
|
else if (tag == "parenthesisSquareClosed")
|
|
|
|
|
displayParenthesis[4] = e.readElementText()[0];
|
|
|
|
|
else if (tag == "doubleflat")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayAccidental[FiguredBassItem::ModifierDoubleFlat]= e.readElementText()[0];
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (tag == "flat")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayAccidental[FiguredBassItem::ModifierFlat] = e.readElementText()[0];
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (tag == "natural")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayAccidental[FiguredBassItem::ModifierNatural] = e.readElementText()[0];
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (tag == "sharp")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayAccidental[FiguredBassItem::ModifierSharp] = e.readElementText()[0];
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (tag == "doublesharp")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayAccidental[FiguredBassItem::ModifierDoubleSharp]= e.readElementText()[0];
|
|
|
|
|
else if (tag == "cross")
|
|
|
|
|
displayAccidental[FiguredBassItem::ModifierCross] = e.readElementText()[0];
|
|
|
|
|
else if (tag == "backslash")
|
|
|
|
|
displayAccidental[FiguredBassItem::ModifierBackslash] = e.readElementText()[0];
|
|
|
|
|
else if (tag == "slash")
|
|
|
|
|
displayAccidental[FiguredBassItem::ModifierSlash] = e.readElementText()[0];
|
2013-01-11 18:10:18 +01:00
|
|
|
|
else if (tag == "digit") {
|
|
|
|
|
int digit = e.intAttribute("value");
|
2013-02-10 07:01:31 +01:00
|
|
|
|
if (digit < 0 || digit > 9)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return false;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
const QStringRef& tag(e.name());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
if (tag == "simple")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleModern] [digit][FiguredBassItem::CombSimple] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "crossed")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleModern] [digit][FiguredBassItem::CombCrossed] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "backslashed")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleModern] [digit][FiguredBassItem::CombBackslashed] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "slashed")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleModern] [digit][FiguredBassItem::CombSlashed] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "simpleHistoric")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleHistoric][digit][FiguredBassItem::CombSimple] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "crossedHistoric")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleHistoric][digit][FiguredBassItem::CombCrossed] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "backslashedHistoric")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleHistoric][digit][FiguredBassItem::CombBackslashed] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else if (tag == "slashedHistoric")
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayDigit[FiguredBassItem::StyleHistoric][digit][FiguredBassItem::CombSlashed] = e.readElementText()[0];
|
2012-05-26 14:26:10 +02:00
|
|
|
|
else {
|
2013-01-11 18:10:18 +01:00
|
|
|
|
e.unknown();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-01-11 18:10:18 +01:00
|
|
|
|
e.unknown();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-10 07:01:31 +01:00
|
|
|
|
displayParenthesis[0] = displayAccidental[FiguredBassItem::ModifierNone] = ' ';
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return true;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Read Configuration File
|
|
|
|
|
//
|
2013-02-10 07:01:31 +01:00
|
|
|
|
// reads a configuration and appends read data to g_FBFonts
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// resets everythings and reads the built-in config file if fileName is null or empty
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool FiguredBass::readConfigFile(const QString& fileName)
|
2013-01-11 18:10:18 +01:00
|
|
|
|
{
|
2012-05-26 14:26:10 +02:00
|
|
|
|
QString path;
|
|
|
|
|
|
|
|
|
|
if(fileName == 0 || fileName.isEmpty()) { // defaults to built-in xml
|
2012-07-25 17:37:32 +02:00
|
|
|
|
#ifdef Q_WS_IOS
|
|
|
|
|
{
|
|
|
|
|
extern QString resourcePath();
|
|
|
|
|
QString rpath = resourcePath();
|
|
|
|
|
path = rpath + QString("/fonts_figuredbass.xml");
|
|
|
|
|
}
|
|
|
|
|
#else
|
2012-05-26 14:26:10 +02:00
|
|
|
|
path = ":/fonts/fonts_figuredbass.xml";
|
2012-07-25 17:37:32 +02:00
|
|
|
|
#endif
|
2012-05-26 14:26:10 +02:00
|
|
|
|
g_FBFonts.clear();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
path = fileName;
|
|
|
|
|
|
|
|
|
|
QFile f(path);
|
2013-01-11 18:10:18 +01:00
|
|
|
|
if (!f.open(QIODevice::ReadOnly)) {
|
2012-07-28 19:20:16 +02:00
|
|
|
|
QString s = QT_TRANSLATE_NOOP("file", "cannot open figured bass description:\n%1\n%2");
|
2012-05-26 14:26:10 +02:00
|
|
|
|
MScore::lastError = s.arg(f.fileName()).arg(f.errorString());
|
2012-07-28 19:20:16 +02:00
|
|
|
|
qDebug("FiguredBass::read failed: <%s>\n", qPrintable(path));
|
2012-05-26 14:26:10 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-01-11 18:10:18 +01:00
|
|
|
|
XmlReader e(&f);
|
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
if (e.name() == "museScore") {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
// QString version = e.attribute(QString("version"));
|
|
|
|
|
// QStringList sl = version.split('.');
|
|
|
|
|
// int _mscVersion = sl[0].toInt() * 100 + sl[1].toInt();
|
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
if (e.name() == "font") {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
FiguredBassFont f;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
if (f.read(e))
|
2012-05-26 14:26:10 +02:00
|
|
|
|
g_FBFonts.append(f);
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-01-11 18:10:18 +01:00
|
|
|
|
e.unknown();
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Get Font Names
|
|
|
|
|
//
|
|
|
|
|
// returns a list of display names for the fonts configured to work with Figured Bass;
|
|
|
|
|
// the index of a name in the list can be used to retrieve the font data with fontData()
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QList<QString> FiguredBass::fontNames()
|
|
|
|
|
{
|
|
|
|
|
QList<QString> names;
|
|
|
|
|
foreach(const FiguredBassFont& f, g_FBFonts)
|
|
|
|
|
names.append(f.displayName);
|
|
|
|
|
return names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Get Font Data
|
|
|
|
|
//
|
|
|
|
|
// retrieves data about a Figured Bass font.
|
|
|
|
|
// returns: true if idx is valid | false if it is not
|
|
|
|
|
// any of the pointer parameter can be null, if that datum is not needed
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool FiguredBass::fontData(int nIdx, QString * pFamily, QString * pDisplayName,
|
|
|
|
|
qreal * pSize, qreal * pLineHeight)
|
|
|
|
|
{
|
|
|
|
|
if(nIdx >= 0 && nIdx < g_FBFonts.size()) {
|
|
|
|
|
FiguredBassFont f = g_FBFonts.at(nIdx);
|
|
|
|
|
if(pFamily) *pFamily = f.family;
|
|
|
|
|
if(pDisplayName) *pDisplayName = f.displayName;
|
|
|
|
|
if(pSize) *pSize = f.defPitch;
|
|
|
|
|
if(pLineHeight) *pLineHeight = f.defLineHeight;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 01:15:22 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// MusicXML I/O
|
|
|
|
|
//
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Read MusicXML
|
|
|
|
|
//
|
|
|
|
|
// Set the FiguredBass state based on the MusicXML <figured-bass> node de.
|
|
|
|
|
// Note that onNote and ticks must be set by the MusicXML importer,
|
|
|
|
|
// as the required context is not present in the items DOM tree.
|
|
|
|
|
// Exception: if a <duration> element is present, tick can be set.
|
2013-01-01 14:36:49 +01:00
|
|
|
|
// Return true if valid, non-empty figure(s) are found
|
|
|
|
|
// Set extend to true if extend elements were found
|
2012-05-26 14:26:10 +02:00
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-17 11:33:11 +01:00
|
|
|
|
#if 0
|
2013-01-11 18:10:18 +01:00
|
|
|
|
bool FiguredBass::readMusicXML(XmlReader& e, int divisions, bool& extend)
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
2013-01-01 14:36:49 +01:00
|
|
|
|
extend = false;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
bool parentheses = e.attribute("parentheses") == "yes";
|
2012-05-26 14:26:10 +02:00
|
|
|
|
QString normalizedText;
|
|
|
|
|
int idx = 0;
|
2013-01-11 18:10:18 +01:00
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
|
const QStringRef& tag(e.name());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
if (tag == "duration") {
|
2013-01-11 18:10:18 +01:00
|
|
|
|
QString val(e.readElementText());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
bool ok = true;
|
|
|
|
|
int duration = val.toInt(&ok);
|
|
|
|
|
if (ok) {
|
|
|
|
|
duration *= MScore::division;
|
|
|
|
|
duration /= divisions;
|
|
|
|
|
setTicks(duration);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
qDebug("MusicXml-Import: bad duration value: <%s>",
|
|
|
|
|
qPrintable(val));
|
|
|
|
|
}
|
|
|
|
|
else if (tag == "figure") {
|
2013-01-01 14:36:49 +01:00
|
|
|
|
bool figureExtend = false;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
FiguredBassItem * pItem = new FiguredBassItem(score(), idx++);
|
|
|
|
|
pItem->setTrack(track());
|
|
|
|
|
pItem->setParent(this);
|
2013-01-01 14:36:49 +01:00
|
|
|
|
pItem->readMusicXML(e, parentheses, figureExtend);
|
|
|
|
|
if (figureExtend)
|
|
|
|
|
extend = true;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
items.append(*pItem);
|
|
|
|
|
// add item normalized text
|
2013-01-11 18:10:18 +01:00
|
|
|
|
if (!normalizedText.isEmpty())
|
2012-05-26 14:26:10 +02:00
|
|
|
|
normalizedText.append('\n');
|
|
|
|
|
normalizedText.append(pItem->normalizedText());
|
|
|
|
|
}
|
2013-01-01 14:36:49 +01:00
|
|
|
|
else {
|
2013-01-11 18:10:18 +01:00
|
|
|
|
e.unknown();
|
2013-01-01 14:36:49 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
setText(normalizedText); // this is the text to show while editing
|
2013-01-01 14:36:49 +01:00
|
|
|
|
bool res = !normalizedText.isEmpty();
|
|
|
|
|
return res;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
2013-01-17 11:33:11 +01:00
|
|
|
|
#endif
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// hasParentheses
|
|
|
|
|
//
|
|
|
|
|
// return true if any FiguredBassItem starts with a parenthesis
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool FiguredBass::hasParentheses() const
|
|
|
|
|
{
|
|
|
|
|
foreach(FiguredBassItem item, items)
|
|
|
|
|
if (item.startsWithParenthesis())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Write MusicXML
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
2013-01-01 14:36:49 +01:00
|
|
|
|
void FiguredBass::writeMusicXML(Xml& xml, bool doFigure, bool doExtend) const
|
2012-05-26 14:26:10 +02:00
|
|
|
|
{
|
2013-01-01 14:36:49 +01:00
|
|
|
|
if (doFigure || doExtend) {
|
|
|
|
|
QString stag = "figured-bass";
|
|
|
|
|
if (hasParentheses())
|
|
|
|
|
stag += " parentheses=\"yes\"";
|
|
|
|
|
xml.stag(stag);
|
|
|
|
|
foreach(FiguredBassItem item, items)
|
|
|
|
|
item.writeMusicXML(xml, doFigure, doExtend);
|
|
|
|
|
xml.etag();
|
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// METHODS BELONGING TO OTHER CLASSES
|
|
|
|
|
//
|
|
|
|
|
// Work In Progress: kept here until the FiguredBass framwork is reasonably set up;
|
|
|
|
|
// To be finally moved to their respective class implementation files.
|
|
|
|
|
//
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
// Score::addFiguredBass
|
|
|
|
|
// called from Keyboard Accelerator & menus
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#include "score.h"
|
|
|
|
|
|
|
|
|
|
FiguredBass* Score::addFiguredBass()
|
|
|
|
|
{
|
|
|
|
|
Element* el = selection().element();
|
2012-09-13 18:01:34 +02:00
|
|
|
|
if (el == 0 || (el->type() != Element::NOTE && el->type() != Element::FIGURED_BASS)) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
QMessageBox::information(0,
|
|
|
|
|
QMessageBox::tr("MuseScore:"),
|
|
|
|
|
QMessageBox::tr("No note or figured bass selected:\n"
|
|
|
|
|
"Please select a single note or figured bass and retry.\n"),
|
|
|
|
|
QMessageBox::Ok, QMessageBox::NoButton);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FiguredBass * fb;
|
|
|
|
|
bool bNew;
|
2012-09-13 18:01:34 +02:00
|
|
|
|
if (el->type() == Element::NOTE) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
ChordRest * cr = static_cast<Note*>(el)->chord();
|
|
|
|
|
fb = FiguredBass::addFiguredBassToSegment(cr->segment(),
|
|
|
|
|
(cr->track() / VOICES) * VOICES, 0, &bNew);
|
|
|
|
|
}
|
2012-09-13 18:01:34 +02:00
|
|
|
|
else if (el->type() == Element::FIGURED_BASS) {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
fb = static_cast<FiguredBass*>(el);
|
|
|
|
|
bNew = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if(fb == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if(bNew)
|
|
|
|
|
undoAddElement(fb);
|
|
|
|
|
select(fb, SELECT_SINGLE, 0);
|
|
|
|
|
return fb;
|
|
|
|
|
}
|
|
|
|
|
|