From 919739e704e1afec894a9c172671dbab24de4180 Mon Sep 17 00:00:00 2001 From: SeeLook <SeeLook@localhost> Date: Fri, 5 Jan 2018 09:46:16 +0100 Subject: [PATCH] Use integer type as a data transport value for extra information about note - like position on a guitar or bandoneon related. So TcommonInstrument has virtual method askQuestion and noteData to set and get those information from instrument instance. For piano and sax this is unused. Executor finally can set and get guitar position. --- src/libs/core/instruments/tbandoneonbg.cpp | 10 ++++-- src/libs/core/instruments/tbandoneonbg.h | 6 ++-- src/libs/core/instruments/tcommoninstrument.h | 13 ++++++-- src/libs/core/instruments/tguitarbg.cpp | 24 +++++++++++--- src/libs/core/instruments/tguitarbg.h | 5 ++- src/libs/core/instruments/tpianobg.cpp | 5 +-- src/libs/core/instruments/tpianobg.h | 6 ++-- src/libs/core/instruments/tsaxbg.cpp | 5 +-- src/libs/core/instruments/tsaxbg.h | 6 ++-- src/libs/core/tfingerpos.h | 18 +++++++++-- src/main/texamexecutor.cpp | 32 ++++++++----------- 11 files changed, 90 insertions(+), 40 deletions(-) diff --git a/src/libs/core/instruments/tbandoneonbg.cpp b/src/libs/core/instruments/tbandoneonbg.cpp index 3663d114e..b9fd03962 100644 --- a/src/libs/core/instruments/tbandoneonbg.cpp +++ b/src/libs/core/instruments/tbandoneonbg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -267,11 +267,17 @@ void TbandoneonBg::setNote(const Tnote& n) { } -void TbandoneonBg::askQuestion(const Tnote& n) { +void TbandoneonBg::askQuestion(const Tnote& n, int noteData) { + Q_UNUSED(noteData) // TODO setNote(n); } +int TbandoneonBg::noteData() { + return 0; // TODO +} + + void TbandoneonBg::setRightX(qreal rx) { if (m_rightX != rx) { m_rightX = rx; diff --git a/src/libs/core/instruments/tbandoneonbg.h b/src/libs/core/instruments/tbandoneonbg.h index 837080a6a..91bb4a62a 100644 --- a/src/libs/core/instruments/tbandoneonbg.h +++ b/src/libs/core/instruments/tbandoneonbg.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -68,7 +68,9 @@ public: void setNote(const Tnote& n) override; - void askQuestion(const Tnote & n) override; + void askQuestion(const Tnote& n, int noteData) override; + + int noteData() override; qreal rightX() const { return m_rightX; } void setRightX(qreal rx); diff --git a/src/libs/core/instruments/tcommoninstrument.h b/src/libs/core/instruments/tcommoninstrument.h index a324aaa4d..c11dd1a45 100644 --- a/src/libs/core/instruments/tcommoninstrument.h +++ b/src/libs/core/instruments/tcommoninstrument.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -50,7 +50,16 @@ public: Tnote note() const { return p_note; } virtual void setNote(const Tnote& n) = 0; - virtual void askQuestion(const Tnote& n) = 0; + /** + * @p noteData is extra information about note needed for some instruments (guitars, bandoneon). + * In case of guitar it is more important than note itself + */ + virtual void askQuestion(const Tnote& n, int noteData) = 0; + + /** + * Returns additional note data like position on the guitar or left/right hand on bandoneon + */ + virtual int noteData() = 0; signals: void activeChanged(); diff --git a/src/libs/core/instruments/tguitarbg.cpp b/src/libs/core/instruments/tguitarbg.cpp index 8f3cd75e2..4e8e8d910 100644 --- a/src/libs/core/instruments/tguitarbg.cpp +++ b/src/libs/core/instruments/tguitarbg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -257,8 +257,24 @@ void TguitarBg::paint(QPainter* painter) { } -void TguitarBg::askQuestion(const Tnote& n) { - setNote(n); +void TguitarBg::askQuestion(const Tnote& n, int noteData) { + p_note = n; + TfingerPos fp(static_cast<quint8>(noteData)); + QPoint p = fretToPos(fp).toPoint(); + for (int s = 0; s < 6; ++ s) { + if (fp.fret() == 0) { // open string + m_fingerItems[s]->setVisible(false); + m_stringItems[s]->setVisible(fp.str() == s + 1); + } else { // some fret + if (fp.str() == s + 1) { + m_fingerItems[s]->setVisible(true); + m_fingerItems[s]->setX(p.x()); + m_fingerItems[s]->setY(p.y() - m_fingerItems[s]->height() * 0.15); + } else + m_fingerItems[s]->setVisible(false); + m_stringItems[s]->setVisible(false); + } + } } @@ -350,6 +366,7 @@ CHECKTIME ( if (m_curStr < 7) { Tnote n(GLOB->Gtune()->strChromatic(m_curStr + 1) + m_curFret); setNote(n); + m_selectedPos.setPos(m_curStr + 1, m_curFret); emit fingerPosChanged(); emit noteChanged(); } @@ -357,7 +374,6 @@ CHECKTIME ( ) } - //################################################################################################ //################################################ PROTECTED ##################################### //################################################################################################ diff --git a/src/libs/core/instruments/tguitarbg.h b/src/libs/core/instruments/tguitarbg.h index 8a79cb4e1..232a3756a 100644 --- a/src/libs/core/instruments/tguitarbg.h +++ b/src/libs/core/instruments/tguitarbg.h @@ -65,7 +65,9 @@ public: void paint(QPainter* painter) override; - void askQuestion(const Tnote & n) override; + void askQuestion(const Tnote& n, int noteData) override; + + int noteData() override { return static_cast<int>(m_selectedPos.data()); } /** * Guitar fingerboard rectangle @@ -122,6 +124,7 @@ private: QPointF m_fingerPos; QQuickItem *m_fingerItems[6]; QQuickItem *m_stringItems[6]; + TfingerPos m_selectedPos; }; diff --git a/src/libs/core/instruments/tpianobg.cpp b/src/libs/core/instruments/tpianobg.cpp index 389d5043b..80fdf474a 100644 --- a/src/libs/core/instruments/tpianobg.cpp +++ b/src/libs/core/instruments/tpianobg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -73,7 +73,8 @@ void TpianoBg::setNote(const Tnote& n) { } -void TpianoBg::askQuestion(const Tnote& n) { +void TpianoBg::askQuestion(const Tnote& n, int noteData) { + Q_UNUSED(noteData) setNote(n); } diff --git a/src/libs/core/instruments/tpianobg.h b/src/libs/core/instruments/tpianobg.h index d5c3a2cd3..49ba92dab 100644 --- a/src/libs/core/instruments/tpianobg.h +++ b/src/libs/core/instruments/tpianobg.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -47,7 +47,9 @@ public: void setNote(const Tnote& n) override; - void askQuestion(const Tnote & n) override; + void askQuestion(const Tnote& n, int noteData) override; + + int noteData() override { return 0; } // Fake - piano has no extra note data int firstOctave() const { return static_cast<int>(m_firstOctave); } void setFirstOctave(int firstO); diff --git a/src/libs/core/instruments/tsaxbg.cpp b/src/libs/core/instruments/tsaxbg.cpp index b20ec0790..4f9d22d3f 100644 --- a/src/libs/core/instruments/tsaxbg.cpp +++ b/src/libs/core/instruments/tsaxbg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -110,7 +110,8 @@ CHECKTIME ( } -void TsaxBg::askQuestion(const Tnote& n) { +void TsaxBg::askQuestion(const Tnote& n, int noteData) { + Q_UNUSED(noteData) setNote(n); } diff --git a/src/libs/core/instruments/tsaxbg.h b/src/libs/core/instruments/tsaxbg.h index 405cd0148..752ab567a 100644 --- a/src/libs/core/instruments/tsaxbg.h +++ b/src/libs/core/instruments/tsaxbg.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Tomasz Bojczuk * + * Copyright (C) 2017-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -47,7 +47,9 @@ public: void setNote(const Tnote& n) override; - void askQuestion(const Tnote & n) override; + void askQuestion(const Tnote& n, int noteData) override; + + int noteData() override { return 0; } // Fake - saxophone has no extra note data int flapNumber() const { return m_flapNumber; } diff --git a/src/libs/core/tfingerpos.h b/src/libs/core/tfingerpos.h index 9a3519f1d..57496ae08 100644 --- a/src/libs/core/tfingerpos.h +++ b/src/libs/core/tfingerpos.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2017 by Tomasz Bojczuk * + * Copyright (C) 2011-2018 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -20,9 +20,10 @@ #ifndef TFINGERPOS_H #define TFINGERPOS_H + #include <nootkacoreglobal.h> -#include <QDataStream> -#include <QXmlStreamWriter> +#include <QtCore/qdatastream.h> +#include <QtCore/qxmlstream.h> /** @@ -39,6 +40,17 @@ public: setPos(realStr, fret); } + /** + * Constructor making @p TfingerPos instance from given integer value + */ + TfingerPos(quint8 positionData) { setData(positionData); } + + /** + * Returns integer value represents fret string number as @p TfingerPos stores that + */ + quint8 data() const { return m_pos; } + void setData(quint8 d) { m_pos = d; } + /** * Returns string number (real [1-6]) */ diff --git a/src/main/texamexecutor.cpp b/src/main/texamexecutor.cpp index 5362a131b..1568a13a7 100755 --- a/src/main/texamexecutor.cpp +++ b/src/main/texamexecutor.cpp @@ -386,7 +386,7 @@ void TexamExecutor::askQuestion(bool isAttempt) { } else { char strNr = 0; if ((curQ->answerAsFret() || curQ->answerAsSound()) && !m_level.onlyLowPos && m_level.showStrNr) - strNr = curQ->qa.pos.str(); // do show string number or not + strNr = static_cast<char>(curQ->qa.pos.str()); // do show string number or not if (m_level.useKeySign && !curQ->answerAsNote()) MAIN_SCORE->askQuestion(curQ->qa.note, curQ->key, strNr); // when answer is also asNote we determine key in preparing answer part else @@ -432,8 +432,7 @@ void TexamExecutor::askQuestion(bool isAttempt) { } if (curQ->questionAsFret()) { - INSTRUMENT->askQuestion(curQ->qa.note); // TODO: Questioned position on the guitar is not known that way -// INSTRUMENT->askQuestion(curQ->qa.pos); + INSTRUMENT->askQuestion(curQ->qa.note, curQ->qa.pos.data()); if (curQ->answerAsNote()) m_answRequire.octave = true; // checking accidental determined by level if (curQ->answerAsSound()) { @@ -512,9 +511,7 @@ void TexamExecutor::askQuestion(bool isAttempt) { NOTENAME->forceAccidental(answerAlter); } -// if (curQ->answerAsFret()) { -// // INSTRUMENT->setGuitarDisabled(false); -// // INSTRUMENT->prepareAnswer(); + if (curQ->answerAsFret()) { // m_answRequire.accid = false; // Ignored in checking, positions are comparing // if (curQ->questionAsFret()) { // QList<TfingerPos> posList; @@ -530,9 +527,9 @@ void TexamExecutor::askQuestion(bool isAttempt) { // } else // if (m_level.showStrNr) // INSTRUMENT->setHighlitedString(curQ->qa.pos.str()); -// INSTRUMENT->setGuitarDisabled(false); + INSTRUMENT->setEnabled(true); // INSTRUMENT->prepareAnswer(); -// } + } if (curQ->answerAsSound()) { // SOUND->prepareAnswer(); @@ -613,18 +610,17 @@ void TexamExecutor::checkAnswer(bool showResults) { } // Now we can check if (curQ->answerAsFret()) { // 1. Comparing positions - TfingerPos answPos, questPos; -// answPos = INSTRUMENT->getfingerPos(); + TfingerPos answPos(INSTRUMENT->noteData()), questPos; if (curQ->questionAsFret()) { - if (answPos == curQ->qa.pos) { // check has not user got answer the same as question position - curQ->setMistake(TQAunit::e_wrongPos); - qDebug("Cheater!"); - } else - questPos = curQ->qa_2.pos; + if (answPos == curQ->qa.pos) { // check has not user got answer the same as question position + curQ->setMistake(TQAunit::e_wrongPos); + qDebug("Cheater!"); + } else + questPos = curQ->qa_2.pos; } else - questPos = curQ->qa.pos; + questPos = curQ->qa.pos; if (questPos != answPos && curQ->isCorrect()) { // if no cheater give him a chance - QList <TfingerPos> tmpPosList; // Maybe hi gave correct note but on incorrect string only + QList <TfingerPos> tmpPosList; // Maybe he gave correct note but on incorrect string only m_supp->getTheSamePosNoOrder(answPos, tmpPosList); // get other positions bool otherPosFound = false; for (int i = 0; i < tmpPosList.size(); i++) { @@ -1174,7 +1170,7 @@ void TexamExecutor::clearWidgets() { MAIN_SCORE->clearScore(); if (NOTENAME) NOTENAME->setNote(Tnote()); -// INSTRUMENT->clearFingerBoard(); + INSTRUMENT->setNote(Tnote()); // SOUND->restoreAfterAnswer(); } -- GitLab