diff --git a/src/libs/core/instruments/tbandoneonbg.cpp b/src/libs/core/instruments/tbandoneonbg.cpp index 3663d114e45968a26470fb3e62eb3bc6928b1c7d..b9fd0396252c34d4dd61014bb915c52ad77e2511 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 837080a6a29349ba168306f2a59d8def0defb427..91bb4a62a243fc230a2b0af7ba7f9d8f55005661 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 a324aaa4d1b7a086f16232e259fbbd1b73d08296..c11dd1a45ff8d4222c3c89b3127211c98cc19e4a 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 8f3cd75e24198a658c2fd5a5df151eb50e32e0c0..4e8e8d910725a1e49b9de13d177ef8d7281bf299 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 8a79cb4e1b3a37e04cab31cfa383cce44dcaaca4..232a3756a4f77f885abd10d73a0df0fefa2ec1cc 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 389d5043b8081d5e2b978885e53d68f027e9e00b..80fdf474a90c0bcc7a1e120850673192514df6da 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 d5c3a2cd3728f0660eacc9a95452ed48eeb7c454..49ba92daba1dd64cd7fbf55aef603746690a3d21 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 b20ec0790924398b442866a271b66d2dd9f9d1ae..4f9d22d3fdc612bf9cbc68f3ea20eaaaffaeb464 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 405cd01482b9e7c3ba63c4a155becb964381e9ed..752ab567a7a25de6ef6392c326972ddd815991c3 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 9a3519f1dcc58d818abde9ef17c7599d09ef1113..57496ae0801f69e99431cd3d57a6d69fa55d8bbb 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 5362a131b2fd9d9ef72dafab12a7b803089f7ab6..1568a13a71405d78f1ee14de6d26154f773bee2c 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(); }