LCOV - code coverage report
Current view: top level - src/instrumentsscene/internal - instrumentscommandsstate.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 36 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) 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 "instrumentscommandsstate.h"
      24              : 
      25              : #include "../instrumentscommands.h"
      26              : 
      27              : using namespace muse;
      28              : using namespace muse::rcommand;
      29              : using namespace mu::instrumentsscene;
      30              : 
      31            0 : std::string InstrumentsCommandsState::moduleName() const
      32              : {
      33            0 :     return "instruments";
      34              : }
      35              : 
      36            0 : void InstrumentsCommandsState::init()
      37              : {
      38            0 :     m_moduleRegister = commandsRegister()->moduleRegister(moduleName());
      39            0 :     IF_ASSERT_FAILED(m_moduleRegister) {
      40            0 :         return;
      41              :     }
      42              : 
      43            0 :     projectSession()->projectChanged().onNotify(this, [this]() {
      44            0 :         updateCommandStates();
      45            0 :     });
      46              : 
      47            0 :     updateCommandStates();
      48              : }
      49              : 
      50            0 : void InstrumentsCommandsState::deinit()
      51              : {
      52            0 :     projectSession()->projectChanged().disconnect(this);
      53            0 : }
      54              : 
      55            0 : void InstrumentsCommandsState::updateCommandStates(const std::vector<Command>& commands)
      56              : {
      57            0 :     IF_ASSERT_FAILED(m_moduleRegister) {
      58            0 :         return;
      59              :     }
      60              : 
      61            0 :     const auto& commandList = commands.empty() ? m_moduleRegister->commandList() : commands;
      62              : 
      63            0 :     for (const auto& command : commandList) {
      64            0 :         CommandState newState = commandState(command);
      65            0 :         if (m_commandStates[command] != newState) {
      66            0 :             m_commandStates[command] = newState;
      67            0 :             m_commandStateChanged.send(command, newState);
      68              :         }
      69              :     }
      70              : }
      71              : 
      72            0 : CommandState InstrumentsCommandsState::commandState(const Command& command) const
      73              : {
      74            0 :     if (!isProjectOpened()) {
      75            0 :         return CommandState(false, false);
      76              :     }
      77              : 
      78            0 :     if (command == INSTRUMENTS_SELECT_COMMAND) {
      79            0 :         return CommandState(true, false);
      80            0 :     } else if (command == INSTRUMENTS_CHANGE_COMMAND) {
      81            0 :         return CommandState(true, false);
      82              :     }
      83              : 
      84            0 :     return CommandState(true, false);
      85              : }
      86              : 
      87            0 : async::Channel<Command, CommandState> InstrumentsCommandsState::commandStateChanged() const
      88              : {
      89            0 :     return m_commandStateChanged;
      90              : }
      91              : 
      92            0 : bool InstrumentsCommandsState::isProjectOpened() const
      93              : {
      94            0 :     if (!projectSession()->project()) {
      95            0 :         return false;
      96              :     }
      97              : 
      98            0 :     return true;
      99              : }
        

Generated by: LCOV version 2.0-1