LCOV - code coverage report
Current view: top level - src/notationscene/widgets - realizeharmonydialog.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 67 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "realizeharmonydialog.h"
      24              : 
      25              : #include "engraving/dom/harmony.h"
      26              : #include "engraving/dom/realizedharmony.h"
      27              : 
      28              : #include "notation/inotation.h"
      29              : #include "notation/inotationinteraction.h"
      30              : #include "notation/inotationselection.h" // IWYU pragma: keep
      31              : 
      32              : #include "translation.h"
      33              : 
      34              : using namespace mu::notation;
      35              : using namespace mu::engraving;
      36              : 
      37            0 : RealizeHarmonyDialog::RealizeHarmonyDialog(QWidget* parent)
      38            0 :     : muse::ui::WidgetDialog(parent)
      39              : {
      40            0 :     setObjectName("RealizeHarmonyDialog");
      41            0 :     setupUi(this);
      42            0 : }
      43              : 
      44            0 : void RealizeHarmonyDialog::componentComplete()
      45              : {
      46            0 :     chordTable->setVisible(false);
      47            0 :     connect(showButton, SIGNAL(clicked()), SLOT(toggleChordTable()));
      48              : 
      49            0 :     voicingSelect->setLiteral(true);
      50              : 
      51              :     //make the chord list uneditable
      52            0 :     chordTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
      53              : 
      54            0 :     INotationInteractionPtr interaction = this->interaction();
      55            0 :     if (!interaction) {
      56            0 :         return;
      57              :     }
      58              : 
      59            0 :     const std::vector<EngravingItem*>& selectedElements = interaction->selection()->elements();
      60            0 :     QList<Harmony*> selectedHarmonyList;
      61              : 
      62            0 :     for (EngravingItem* element : selectedElements) {
      63            0 :         if (element->isHarmony()) {
      64            0 :             selectedHarmonyList << toHarmony(element);
      65              :         }
      66              :     }
      67              : 
      68            0 :     setChordList(selectedHarmonyList);
      69            0 : }
      70              : 
      71            0 : INotationInteractionPtr RealizeHarmonyDialog::interaction() const
      72              : {
      73            0 :     const INotationPtr notation = projectSession()->currentNotation();
      74            0 :     return notation ? notation->interaction() : nullptr;
      75            0 : }
      76              : 
      77            0 : void RealizeHarmonyDialog::accept()
      78              : {
      79            0 :     INotationInteractionPtr interaction = this->interaction();
      80            0 :     if (!interaction) {
      81            0 :         return;
      82              :     }
      83              : 
      84            0 :     bool optionsOverride = optionsBox->isChecked();
      85            0 :     Voicing voicing = optionsOverride ? Voicing(voicingSelect->getVoicing()) : Voicing::INVALID;
      86            0 :     HDuration durationType = optionsOverride ? HDuration(voicingSelect->getDuration()) : HDuration::INVALID;
      87              : 
      88            0 :     interaction->realizeSelectedChordSymbols(voicingSelect->getLiteral(), voicing, durationType);
      89              : 
      90            0 :     QDialog::accept();
      91            0 : }
      92              : 
      93            0 : void RealizeHarmonyDialog::toggleChordTable()
      94              : {
      95            0 :     int visible = chordTable->isVisible();
      96            0 :     chordTable->setVisible(!visible);
      97            0 :     showButton->setText(!visible ? muse::qtrc("global", "Show less…") : muse::qtrc("global", "Show more…"));
      98            0 : }
      99              : 
     100              : //---------------------------------------------------------
     101              : //   setChordList
     102              : ///   fill the chord list with the list of harmonies
     103              : //---------------------------------------------------------
     104            0 : void RealizeHarmonyDialog::setChordList(const QList<Harmony*>& hlist)
     105              : {
     106            0 :     static const QStringList header = { "ID", "Name", "Intervals", "Notes" };
     107            0 :     QString s;    //chord label string
     108            0 :     int rows = hlist.size();
     109              : 
     110            0 :     chordTable->setRowCount(rows);
     111            0 :     chordTable->setColumnCount(header.size());
     112            0 :     chordTable->setHorizontalHeaderLabels(header);
     113            0 :     for (int i = 0; i < rows; ++i) {
     114            0 :         Harmony* h = hlist.at(i);
     115            0 :         if (!h->isRealizable()) {
     116            0 :             continue;
     117              :         }
     118              : 
     119            0 :         s += h->harmonyName() + u" ";
     120            0 :         QString intervals;
     121            0 :         QString noteNames;
     122            0 :         int rootTpc = h->rootTpc();
     123              : 
     124            0 :         noteNames = tpc2name(rootTpc, mu::engraving::NoteSpellingType::STANDARD, mu::engraving::NoteCaseType::AUTO);
     125            0 :         const mu::engraving::RealizedHarmony::PitchMap& notes = h->getRealizedHarmony().notes();
     126              : 
     127            0 :         for (const auto& [pitch, tpc] : notes) {
     128            0 :             intervals += QString::number((pitch - mu::engraving::tpc2pitch(rootTpc)) % 128 % 12) + " ";
     129            0 :             noteNames += u", " + mu::engraving::tpc2name(tpc, mu::engraving::NoteSpellingType::STANDARD, mu::engraving::NoteCaseType::AUTO);
     130              :         }
     131              : 
     132            0 :         chordTable->setItem(i, 0, new QTableWidgetItem(QString::number(h->id())));
     133            0 :         chordTable->setItem(i, 1, new QTableWidgetItem(h->harmonyName()));
     134            0 :         chordTable->setItem(i, 2, new QTableWidgetItem(intervals));
     135            0 :         chordTable->setItem(i, 3, new QTableWidgetItem(noteNames));
     136            0 :     }
     137            0 :     chordLabel->setText(s);
     138              : 
     139              :     //set table uneditable again
     140            0 :     chordTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
     141            0 : }
        

Generated by: LCOV version 2.0-1