Skip to content
Snippets Groups Projects
Commit c64c5817 authored by SeeLook's avatar SeeLook
Browse files

Added class for storing extra note data (guitar position, fingering, bow...

Added class for storing extra note data (guitar position, fingering, bow direction/bellow open/close). Use it in chunk instead of single TfingerPos.
parent c5ce063e
No related branches found
No related tags found
No related merge requests found
/*************************************************************************** /***************************************************************************
* Copyright (C) 2014-2017 by Tomasz Bojczuk * * Copyright (C) 2014-2018 by Tomasz Bojczuk *
* seelook@gmail.com * * seelook@gmail.com *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
...@@ -24,16 +24,12 @@ ...@@ -24,16 +24,12 @@
Tchunk::Tchunk(const Tnote& pitch, const TfingerPos& fretPos) : Tchunk::Tchunk(const Tnote& pitch, const TfingerPos& fretPos) :
m_pitch(pitch), m_pitch(pitch)
m_fretPos(fretPos)
{ {
m_noteData.setFingerPos(fretPos);
} }
Tchunk::~Tchunk()
{}
void Tchunk::toXml(QXmlStreamWriter& xml, int* staffNr) { void Tchunk::toXml(QXmlStreamWriter& xml, int* staffNr) {
xml.writeStartElement(QLatin1String("note")); xml.writeStartElement(QLatin1String("note"));
if (m_pitch.isRest() || !m_pitch.isValid()) if (m_pitch.isRest() || !m_pitch.isValid())
...@@ -57,10 +53,10 @@ void Tchunk::toXml(QXmlStreamWriter& xml, int* staffNr) { ...@@ -57,10 +53,10 @@ void Tchunk::toXml(QXmlStreamWriter& xml, int* staffNr) {
xml.writeEndElement(); // beam xml.writeEndElement(); // beam
} }
} }
if (m_pitch.rtm.tie() || validPos()) { if (m_pitch.rtm.tie() || !m_noteData.isEmpty()) {
xml.writeStartElement(QLatin1String("notations")); xml.writeStartElement(QLatin1String("notations"));
if (validPos()) if (!m_noteData.isEmpty())
g().toXml(xml); m_noteData.toXml(xml);
if (m_pitch.rtm.tie()) if (m_pitch.rtm.tie())
tieToXml(xml, m_pitch.rtm.tie(), e_tied); tieToXml(xml, m_pitch.rtm.tie(), e_tied);
xml.writeEndElement(); xml.writeEndElement();
...@@ -98,7 +94,7 @@ bool Tchunk::fromXml(QXmlStreamReader& xml, int* staffNr) { ...@@ -98,7 +94,7 @@ bool Tchunk::fromXml(QXmlStreamReader& xml, int* staffNr) {
} else if (xml.name() == QLatin1String("notations")) { } else if (xml.name() == QLatin1String("notations")) {
while (xml.readNextStartElement()) { while (xml.readNextStartElement()) {
if (xml.name() == QLatin1String("technical")) if (xml.name() == QLatin1String("technical"))
m_fretPos.fromXml(xml); m_noteData.fromXml(xml);
else if (xml.name() == QLatin1String("tied")) { else if (xml.name() == QLatin1String("tied")) {
auto type = xml.attributes().value(QStringLiteral("type")); auto type = xml.attributes().value(QStringLiteral("type"));
Trhythm::Etie tie = Trhythm::e_noTie; Trhythm::Etie tie = Trhythm::e_noTie;
......
/*************************************************************************** /***************************************************************************
* Copyright (C) 2014-2017 by Tomasz Bojczuk * * Copyright (C) 2014-2018 by Tomasz Bojczuk *
* seelook@gmail.com * * seelook@gmail.com *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
...@@ -19,9 +19,11 @@ ...@@ -19,9 +19,11 @@
#ifndef TCHUNK_H #ifndef TCHUNK_H
#define TCHUNK_H #define TCHUNK_H
#include <nootkacoreglobal.h> #include <nootkacoreglobal.h>
#include "tnote.h" #include "tnote.h"
#include <tfingerpos.h> #include "tnotedata.h"
class QXmlStreamReader; class QXmlStreamReader;
class QXmlStreamWriter; class QXmlStreamWriter;
...@@ -42,7 +44,7 @@ public: ...@@ -42,7 +44,7 @@ public:
* Default constructor - creates 'empty' note and position. * Default constructor - creates 'empty' note and position.
*/ */
Tchunk() {} Tchunk() {}
~Tchunk(); ~Tchunk() {}
/** /**
* The note * The note
...@@ -54,10 +56,36 @@ public: ...@@ -54,10 +56,36 @@ public:
/** /**
* Position a note on a guitar (if any) - by default it is null - invalid * Position a note on a guitar (if any) - by default it is null - invalid
*/ */
TfingerPos& g() { return m_fretPos; } TfingerPos& g() { return m_noteData.fingerPos(); }
/**
* Extra note data like guitar position, bow direction, staff position (upper/lower) and fingering
*/
TnoteData& d() { return m_noteData; }
bool onUpperStaff() const { return m_noteData.onUpperStaff(); }
void setOnUpperStaff(bool onUpper) { m_noteData.setOnUpperStaff(onUpper); }
TnoteData::EbowDirection bow() const { return m_noteData.bow(); }
void setBow(TnoteData::EbowDirection b) { m_noteData.setBow(b); }
/**
* Finger number [0 - 5].
* -1 is returned when undefined
*/
int finger() const { return m_noteData.finger(); }
void setFinger(int fi) { m_noteData.setFinger(fi); }
/**
* Numeric value representing all extra note parameters
*/
quint32 noteData() const { return m_noteData.data(); }
void setNoteData(quint32 nd) { m_noteData.setData(nd); }
/** Returns @p TRUE when position on the guitar is valid. */ /**
bool validPos() { if (g().str() == 7) return false; else return true; } * Returns @p TRUE when position on the guitar is valid.
*/
bool validPos() { return g().str() != 7; }
/** /**
* If @p staffNr is set appropriate <staff>staffNr</staff> is added * If @p staffNr is set appropriate <staff>staffNr</staff> is added
...@@ -89,7 +117,7 @@ public: ...@@ -89,7 +117,7 @@ public:
private: private:
Tnote m_pitch; Tnote m_pitch;
TfingerPos m_fretPos; TnoteData m_noteData;
}; };
#endif // TCHUNK_H #endif // TCHUNK_H
/***************************************************************************
* Copyright (C) 2018 by Tomasz Bojczuk *
* seelook@gmail.com *
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "tnotedata.h"
#include <QtCore/qdebug.h>
TnoteData::TnoteData(quint32 fromData)
{
setData(fromData);
}
/**
* Upper staff id default state so it is for 0 value
*/
void TnoteData::setOnUpperStaff(bool onUpper) {
if (onUpper)
m_otherData &= ~ON_UPPER;
else
m_otherData |= ON_UPPER;
}
void TnoteData::setBow(TnoteData::EbowDirection b) {
m_otherData &= ~BOW_DIRECTION; // reset it first
m_otherData |= b;
}
void TnoteData::setFinger(int fingerNr) {
m_otherData &= ~FINGERING;
if (fingerNr >= -1 && fingerNr < 6)
m_otherData |= (static_cast<quint16>(fingerNr) + 1) << 3;
else
qDebug() << "[TnoteData] wrong finger number to store" << fingerNr << " Igoring.";
}
quint32 TnoteData::data() const {
quint32 d = m_otherData;
d <<= 8;
d += m_fingerPos.data();
return d;
}
void TnoteData::setData(quint32 d) {
m_fingerPos.setData(static_cast<quint8>(d));
m_otherData = static_cast<quint16>(d >> 8);
}
void TnoteData::fromXml(QXmlStreamReader& xml) {
int s = 0, f = 50;
while (xml.readNextStartElement()) {
if (xml.name() == QLatin1String("string"))
s = xml.readElementText().toInt();
else if (xml.name() == QLatin1String("fret"))
f = xml.readElementText().toInt();
else
xml.skipCurrentElement();
}
if (s == 0 || f == 50)
m_fingerPos.setData(255); // invalid
else
m_fingerPos.setPos(s, f);
}
void TnoteData::toXml(QXmlStreamWriter& xml, const QString& tag) const {
if (!tag.isEmpty())
xml.writeStartElement(tag);
xml.writeTextElement(QLatin1String("string"), QString("%1").arg(m_fingerPos.str()));
xml.writeTextElement(QLatin1String("fret"), QString("%1").arg(m_fingerPos.fret()));
if (!tag.isEmpty())
xml.writeEndElement(); // tag
}
/***************************************************************************
* Copyright (C) 2018 by Tomasz Bojczuk *
* seelook@gmail.com *
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef TNOTEDATA_H
#define TNOTEDATA_H
#include "nootkacoreglobal.h"
#include "tfingerpos.h"
#include <QtCore/qobject.h>
#define ON_UPPER (1) // first bit
#define BOW_DIRECTION (6) // 2nd and 3rd bits
#define FINGERING (56) // 4th to 6th bits
/**
* @p TnoteData extends information about note in the score.
* It has guitar position in @p TfingerPos
* - bow direction (down/up) - for bandoneon it is bellow state (opening/closing)
* - note position on the grand staff (on upper staff of or on the lower one)
* - finger number [0 - 5], -1 - is undefined
*
* All parameters can be represented by single @p quint32 value
* available through @p data() and set through @p setData()
*/
class NOOTKACORE_EXPORT TnoteData
{
Q_GADGET
public:
TnoteData() {}
TnoteData(quint32 fromData);
/**
* Returns @p TRUE when all extra note parameters are unset
*/
bool isEmpty() const { return !m_fingerPos.isValid() && m_otherData == 0; }
/**
* Resets all extra note parameters to null
*/
void reset() { m_fingerPos.setData(255); m_otherData = 0; }
TfingerPos& fingerPos() { return m_fingerPos; }
void setFingerPos(TfingerPos fp) { m_fingerPos.setData(fp.data()); }
bool onUpperStaff() const { return !(m_otherData & ON_UPPER); }
void setOnUpperStaff(bool onUpper);
enum EbowDirection {
BowUndefined = 0,
BowDown = 2, /**< For bandoneon it is bellow opening */
BowUp = 4 /**< For bandoneon it is bellow closing */
};
Q_ENUM(EbowDirection)
EbowDirection bow() const { return static_cast<EbowDirection>(m_otherData & BOW_DIRECTION); }
void setBow(EbowDirection b);
/**
* Finger number [0 - 5].
* -1 is returned when undefined
*/
int finger() const { return ((m_otherData & FINGERING) >> 3) - 1; }
void setFinger(int fingerNr);
quint32 data() const;
void setData(quint32 d);
void toXml (QXmlStreamWriter& xml, const QString& tag = QLatin1String("technical")) const;
void fromXml(QXmlStreamReader& xml);
private:
TfingerPos m_fingerPos;
quint16 m_otherData = 0;
};
#endif // TNOTEDATA_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment