From 462d8128eebdbf09f39f612600f3716086dd116c Mon Sep 17 00:00:00 2001 From: gjdv Date: Sun, 5 Feb 2023 22:57:41 +0100 Subject: [PATCH] first attempt to have editable clefs --- src/Draw.cpp | 10 +++++++++- src/GuiSidePanel.cpp | 26 ++++++++++++++++++++++++-- src/GuiSidePanel.h | 19 +++++++++++++++++++ src/GuiSidePanel.ui | 28 ++++++++++++++++++++++++++++ src/Score.cpp | 10 ++++++++-- src/StavePosition.cpp | 14 +++++++++++--- src/StavePosition.h | 2 +- 7 files changed, 100 insertions(+), 9 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index b6499d7..740b155 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -826,7 +826,15 @@ void CDraw::drawSlot(CSlot* slot) //int av8Left = slot->getAv8Left(); for (int i=0; i < slot->length(); i++) { - stavePos.notePos(slot->getSymbol(i).getHand(), slot->getSymbol(i).getNote()); + whichPart_t hand = slot->getSymbol(i).getHand(); + int clef = PB_SYMBOL_gClef; + if (hand == PB_PART_right) { + clef = m_settings->value("SidePanel/clefRight").toInt(); + } + else if (hand == PB_PART_left) { + clef = m_settings->value("SidePanel/clefLeft").toInt(); + } + stavePos.notePos(hand, slot->getSymbol(i).getNote(), clef); //ppLogTrace ("compileSlot len %d id %2d next %2d time %2d type %2d note %2d", slot->length(), slot->m_displayListId, //slot->m_nextDisplayListId, slot->getDeltaTime(), slot->getSymbol(i).getType(), slot->getSymbol(i).getNote()); diff --git a/src/GuiSidePanel.cpp b/src/GuiSidePanel.cpp index 3661d73..04e0bcb 100644 --- a/src/GuiSidePanel.cpp +++ b/src/GuiSidePanel.cpp @@ -82,7 +82,6 @@ void GuiSidePanel::init(CSong* songObj, CTrackList* trackList, GuiTopBar* topBar on_rhythmTappingCombo_activated(m_settings->value("SidePanel/rhythmTapping",0).toInt()); rhythmTappingCombo->setCurrentIndex(m_song->cfg_rhythmTapping); - repeatSong->setChecked(m_settings->value("SidePanel/repeatSong",false).toBool()); connect(repeatSong,SIGNAL(stateChanged(int)),this,SLOT(on_repeatSong_released())); @@ -105,6 +104,18 @@ void GuiSidePanel::init(CSong* songObj, CTrackList* trackList, GuiTopBar* topBar connect(act, SIGNAL(triggered()), this, SLOT(clearTrackPart())); trackListWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + + m_settings->setValue("SidePanel/clefRight",PB_SYMBOL_gClef); + m_settings->setValue("SidePanel/clefLeft",PB_SYMBOL_fClef); + clefRightCombo->addItem(tr("Treble"),PB_SYMBOL_gClef); + clefRightCombo->addItem(tr("Bass"),PB_SYMBOL_fClef); + clefLeftCombo->addItem(tr("Treble"),PB_SYMBOL_gClef); + clefLeftCombo->addItem(tr("Bass"),PB_SYMBOL_fClef); + clefRightCombo->setCurrentIndex(0); + clefLeftCombo->setCurrentIndex(1); + trackListWidget->addAction(act); + connect(clefRightCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(on_clefRightComboChange(QString))); + connect(clefLeftCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(on_clefLeftComboChange(QString))); } void GuiSidePanel::refresh() { @@ -269,13 +280,17 @@ void GuiSidePanel::updateTranslate(){ rhythmTappingCombo->setItemText(0,tr("Drums")); rhythmTappingCombo->setItemText(1,tr("Melody")); + clefRightCombo->setItemText(0,tr("Treble")); + clefRightCombo->setItemText(1,tr("Bass")); + clefLeftCombo->setItemText(0,tr("Treble")); + clefLeftCombo->setItemText(1,tr("Bass")); retranslateUi(this); // --- smart resize panel --- // int maxDeltaWidth=0; this->setMaximumWidth(300); // default - QVector listCheckWidget {label2,listenRadio,rhythmTapRadio,followYouRadio,playAlongRadio,rightHandRadio,bothHandsRadio,leftHandRadio}; + QVector listCheckWidget {label2,listenRadio,rhythmTapRadio,followYouRadio,playAlongRadio,rightHandRadio,bothHandsRadio,leftHandRadio,clefRightCombo,clefLeftCombo}; for (QWidget* w:listCheckWidget){ int delta = 0; @@ -313,3 +328,10 @@ void GuiSidePanel::on_rhythmTappingCombo_activated (int index) autoSetMuteYourPart(); } +void GuiSidePanel::on_clefComboChange (const QString &name, int value) +{ + m_settings->setValue(name,value); + m_song->refreshScroll(); + //m_score->drawScore(); // TODO makes it crash + //TODO do I need to do more to request a redraw? +} diff --git a/src/GuiSidePanel.h b/src/GuiSidePanel.h index 7634d01..4b47746 100644 --- a/src/GuiSidePanel.h +++ b/src/GuiSidePanel.h @@ -145,6 +145,25 @@ private slots: void on_rhythmTappingCombo_activated (int index); + void on_clefComboChange (const QString &name, int value); + void on_clefComboChange (const QString &name, const QString &text) + { + int value = -1; + if (text.toLower() == "treble") + value = PB_SYMBOL_gClef; + else if (text.toLower() == "bass") + value = PB_SYMBOL_fClef; + on_clefComboChange(name, value); + } + void on_clefRightComboChange (const QString &text) + { + on_clefComboChange("SidePanel/clefRight", text); + } + void on_clefLeftComboChange (const QString &text) + { + on_clefComboChange("SidePanel/clefLeft", text); + } + void on_muteYourPartCheck_toggled (bool checked) { if (m_song) m_song->mutePianistPart(checked); diff --git a/src/GuiSidePanel.ui b/src/GuiSidePanel.ui index c8390bd..f4e3f81 100644 --- a/src/GuiSidePanel.ui +++ b/src/GuiSidePanel.ui @@ -285,6 +285,34 @@ + + + + + + Right Hand Clef: + + + + + + + + + + + + + + Left Hand Clef: + + + + + + + + diff --git a/src/Score.cpp b/src/Score.cpp index 0fcb7ce..df52052 100644 --- a/src/Score.cpp +++ b/src/Score.cpp @@ -248,8 +248,14 @@ void CScore::drawScore() glNewList (m_scoreDisplayListId, GL_COMPILE_AND_EXECUTE); drColor (Cfg::colorTheme().staveColor); - drawSymbol(CSymbol(PB_SYMBOL_gClef, CStavePos(PB_PART_right, -1)), Cfg::clefX()); // The Treble Clef - drawSymbol(CSymbol(PB_SYMBOL_fClef, CStavePos(PB_PART_left, 1)), Cfg::clefX()); + if (m_settings->value("SidePanel/clefRight").toInt() == PB_SYMBOL_gClef) + drawSymbol(CSymbol(PB_SYMBOL_gClef, CStavePos(PB_PART_right, -1)), Cfg::clefX()); // The Treble Clef + else if (m_settings->value("SidePanel/clefRight").toInt() == PB_SYMBOL_fClef) + drawSymbol(CSymbol(PB_SYMBOL_fClef, CStavePos(PB_PART_right, -1)), Cfg::clefX()); + if (m_settings->value("SidePanel/clefLeft").toInt() == PB_SYMBOL_gClef) + drawSymbol(CSymbol(PB_SYMBOL_gClef, CStavePos(PB_PART_left, 1)), Cfg::clefX()); + else if (m_settings->value("SidePanel/clefLeft").toInt() == PB_SYMBOL_fClef) + drawSymbol(CSymbol(PB_SYMBOL_fClef, CStavePos(PB_PART_left, 1)), Cfg::clefX()); drawKeySignature(CStavePos::getKeySignature()); drawStaves(Cfg::staveStartX(), Cfg::scrollStartX()); glEndList (); diff --git a/src/StavePosition.cpp b/src/StavePosition.cpp index 5822cdb..f1577da 100644 --- a/src/StavePosition.cpp +++ b/src/StavePosition.cpp @@ -37,7 +37,7 @@ float CStavePos::m_staveCentralOffset = (staveHeight() * 3)/2; //////////////////////////////////////////////////////////////////////////////// //! @brief Calculates the position of a note on the stave -void CStavePos::notePos(whichPart_t hand, int midiNote) +void CStavePos::notePos(whichPart_t hand, int midiNote, int clef) // in fact clef is of type musicalSymbol_t but causes circular reference { const int notesInAnOctive = 7; // Don't count middle C twice const int semitonesInAnOctive = 12; @@ -48,13 +48,21 @@ void CStavePos::notePos(whichPart_t hand, int midiNote) lookUpItem = &m_staveLookUpTable[index]; - if (m_hand == PB_PART_right) + if (clef == -1) { + if (m_hand == PB_PART_right) + clef = PB_SYMBOL_gClef; + if (m_hand == PB_PART_left) + clef = PB_SYMBOL_fClef; + } + if (m_hand == PB_PART_right && clef == PB_SYMBOL_gClef || m_hand == PB_PART_left && clef == PB_SYMBOL_gClef) m_staveIndex = lookUpItem->pianoNote - 7; - else if (m_hand == PB_PART_left) + else if (m_hand == PB_PART_left && clef == PB_SYMBOL_fClef || m_hand == PB_PART_right && clef == PB_SYMBOL_fClef) m_staveIndex = lookUpItem->pianoNote + 5; m_staveIndex += (midiNote/semitonesInAnOctive)*notesInAnOctive - notesInAnOctive*5 ; m_accidental = lookUpItem->accidental; + ppLogInfo("chan %d clef %2d Note %2d - %2d (%d %d %d),\n", midiNote, clef, m_staveIndex, m_accidental, + index%semitonesInAnOctive, lookUpItem->pianoNote, (midiNote/semitonesInAnOctive)*notesInAnOctive); //ppLogTrace("chan %d Note %2d - %2d (%d %d %d),\n", midiNote, m_staveIndex, m_accidental, //index%semitonesInAnOctive, lookUpItem->pianoNote, (midiNote/semitonesInAnOctive)*notesInAnOctive); } diff --git a/src/StavePosition.h b/src/StavePosition.h index 94bddc7..09955c9 100644 --- a/src/StavePosition.h +++ b/src/StavePosition.h @@ -83,7 +83,7 @@ public: m_offsetY -= staveCentralOffset(); } - void notePos(whichPart_t hand, int midiNote); + void notePos(whichPart_t hand, int midiNote, int clef = -1); // in fact clef is of type musicalSymbol_t but causes circular reference //////////////////////////////////////////////////////////////////////////////// //! @brief Sets which stave the note will appear on