LCOV - code coverage report
Current view: top level - muse/framework/midiremote/qml/Muse/MidiRemote - editmidimappingmodel.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-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 "editmidimappingmodel.h"
      24              : 
      25              : #include "translation.h"
      26              : 
      27              : using namespace muse::midi;
      28              : using namespace muse::midiremote;
      29              : 
      30            0 : EditMidiMappingModel::EditMidiMappingModel(QObject* parent)
      31            0 :     : QObject(parent), Contextable(muse::iocCtxForQmlObject(this))
      32              : {
      33            0 : }
      34              : 
      35            0 : EditMidiMappingModel::~EditMidiMappingModel()
      36              : {
      37            0 :     if (m_loaded) {
      38            0 :         midiRemote()->setIsSettingMode(false);
      39              :     }
      40            0 : }
      41              : 
      42            0 : void EditMidiMappingModel::load(int originType, int originValue)
      43              : {
      44            0 :     midiRemote()->setIsSettingMode(true);
      45              : 
      46            0 :     midiInPort()->eventReceived().onReceive(this, [this](tick_t, const Event& event) {
      47            0 :         if (event.opcode() == Event::Opcode::NoteOn || event.opcode() == Event::Opcode::ControlChange) {
      48            0 :             m_event = remoteEventFromMidiEvent(event);
      49            0 :             emit mappingTitleChanged(mappingTitle());
      50              :         }
      51            0 :     }, muse::async::Asyncable::Mode::SetReplace);
      52              : 
      53            0 :     m_event = RemoteEvent(static_cast<RemoteEventType>(originType), originValue);
      54            0 :     emit mappingTitleChanged(mappingTitle());
      55              : 
      56            0 :     m_loaded = true;
      57            0 : }
      58              : 
      59            0 : QString EditMidiMappingModel::mappingTitle() const
      60              : {
      61            0 :     MidiDeviceID currentMidiInDeviceId = midiInPort()->deviceID();
      62            0 :     if (currentMidiInDeviceId.empty() || !m_event.isValid()) {
      63            0 :         return muse::qtrc("global", "Waiting…");
      64              :     }
      65              : 
      66            0 :     return deviceName(currentMidiInDeviceId) + " > " + m_event.name().toQString();
      67            0 : }
      68              : 
      69            0 : QVariant EditMidiMappingModel::inputtedEvent() const
      70              : {
      71            0 :     QVariantMap obj;
      72            0 :     obj["type"] = static_cast<int>(m_event.type);
      73            0 :     obj["value"] = m_event.value;
      74            0 :     return obj;
      75            0 : }
      76              : 
      77            0 : QString EditMidiMappingModel::deviceName(const MidiDeviceID& deviceId) const
      78              : {
      79            0 :     for (const MidiDevice& device : midiInPort()->availableDevices()) {
      80            0 :         if (device.id == deviceId) {
      81            0 :             return QString::fromStdString(device.name);
      82              :         }
      83            0 :     }
      84              : 
      85            0 :     return QString();
      86              : }
        

Generated by: LCOV version 2.0-1