Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 71 additions & 32 deletions src/appshell/view/notationpagemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ void NotationPageModel::init()
});

extensionsProvider()->manifestListChanged().onNotify(this, [this]() {
updateExtensionsToolBarVisibility();
scheduleUpdateExtensionsToolBarVisibility();
});

extensionsProvider()->manifestChanged().onReceive(this, [this](const muse::extensions::Manifest&) {
updateExtensionsToolBarVisibility();
scheduleUpdateExtensionsToolBarVisibility();
});

brailleConfiguration()->braillePanelEnabledChanged().onNotify(this, [this]() {
Expand All @@ -74,17 +74,17 @@ void NotationPageModel::init()

onNotationChanged();

updateDrumsetPanelVisibility();
updatePercussionPanelVisibility();
updateExtensionsToolBarVisibility();
scheduleUpdateDrumsetPanelVisibility();
scheduleUpdatePercussionPanelVisibility();
scheduleUpdateExtensionsToolBarVisibility();

notationConfiguration()->useNewPercussionPanelChanged().onNotify(this, [this]() {
updateDrumsetPanelVisibility();
updatePercussionPanelVisibility();
scheduleUpdateDrumsetPanelVisibility();
scheduleUpdatePercussionPanelVisibility();
});

notationConfiguration()->percussionPanelAutoShowModeChanged().onNotify(this, [this]() {
updatePercussionPanelVisibility();
scheduleUpdatePercussionPanelVisibility();
});
}

Expand Down Expand Up @@ -177,14 +177,14 @@ void NotationPageModel::onNotationChanged()

INotationNoteInputPtr noteInput = notation->interaction()->noteInput();
noteInput->stateChanged().onNotify(this, [this]() {
updateDrumsetPanelVisibility();
updatePercussionPanelVisibility();
scheduleUpdateDrumsetPanelVisibility();
scheduleUpdatePercussionPanelVisibility();
});

INotationInteractionPtr notationInteraction = notation->interaction();
notationInteraction->selectionChanged().onNotify(this, [this]() {
updateDrumsetPanelVisibility();
updatePercussionPanelVisibility();
scheduleUpdateDrumsetPanelVisibility();
scheduleUpdatePercussionPanelVisibility();
});
}

Expand All @@ -205,7 +205,22 @@ void NotationPageModel::toggleDock(const QString& name)
dispatcher()->dispatch("dock-toggle", ActionData::make_arg1<QString>(name));
}

void NotationPageModel::updateDrumsetPanelVisibility()
void NotationPageModel::scheduleUpdateDrumsetPanelVisibility()
{
if (m_updateDrumsetPanelVisibilityScheduled) {
return;
}

m_updateDrumsetPanelVisibilityScheduled = true;

//! NOTE: ensure we don't update it multiple times in succession
muse::async::Async::call(this, [this]() {
doUpdateDrumsetPanelVisibility();
m_updateDrumsetPanelVisibilityScheduled = false;
});
}

void NotationPageModel::doUpdateDrumsetPanelVisibility()
{
TRACEFUNC;

Expand All @@ -219,10 +234,7 @@ void NotationPageModel::updateDrumsetPanelVisibility()
return;
}

//! NOTE: ensure we don't dispatch it multiple times in succession
muse::async::Async::call(this, [=]() {
dispatcher()->dispatch("dock-set-open", ActionData::make_arg2<QString, bool>(DRUMSET_PANEL_NAME, open));
});
dispatcher()->dispatch("dock-set-open", ActionData::make_arg2<QString, bool>(DRUMSET_PANEL_NAME, open));
};

// This should never be open when the new percussion panel is in use...
Expand All @@ -243,7 +255,22 @@ void NotationPageModel::updateDrumsetPanelVisibility()
setDrumsetPanelOpen(shouldOpen);
}

void NotationPageModel::updatePercussionPanelVisibility()
void NotationPageModel::scheduleUpdatePercussionPanelVisibility()
{
if (m_updatePercussionPanelVisibilityScheduled) {
return;
}

m_updatePercussionPanelVisibilityScheduled = true;

//! NOTE: ensure we don't update it multiple times in succession
muse::async::Async::call(this, [this]() {
doUpdatePercussionPanelVisibility();
m_updatePercussionPanelVisibilityScheduled = false;
});
}

void NotationPageModel::doUpdatePercussionPanelVisibility()
{
TRACEFUNC;

Expand All @@ -259,10 +286,7 @@ void NotationPageModel::updatePercussionPanelVisibility()
return;
}

//! NOTE: ensure we don't dispatch it multiple times in succession
muse::async::Async::call(this, [=]() {
dispatcher()->dispatch("dock-set-open", ActionData::make_arg2<QString, bool>(PERCUSSION_PANEL_NAME, open));
});
dispatcher()->dispatch("dock-set-open", ActionData::make_arg2<QString, bool>(PERCUSSION_PANEL_NAME, open));
};

// This should never be open when the old drumset panel is in use...
Expand Down Expand Up @@ -328,21 +352,35 @@ void NotationPageModel::updatePercussionPanelVisibility()
setPercussionPanelOpen(true);
}

void NotationPageModel::updateExtensionsToolBarVisibility()
void NotationPageModel::scheduleUpdateExtensionsToolBarVisibility()
{
if (m_updateExtensionsToolBarVisibilityScheduled) {
return;
}

m_updateExtensionsToolBarVisibilityScheduled = true;

//! NOTE: ensure we don't update it multiple times in succession
muse::async::Async::call(this, [this]() {
doUpdateExtensionsToolBarVisibility();
m_updateExtensionsToolBarVisibilityScheduled = false;
});
}

void NotationPageModel::doUpdateExtensionsToolBarVisibility()
{
const muse::dock::IDockWindow* window = dockWindowProvider()->window();
if (!window) {
return;
}

auto setExtensionsToolBarOpen = [this](bool open) {
//! NOTE: ensure we don't dispatch it multiple times in succession
muse::async::Async::call(this, [=]() {
dispatcher()->dispatch("dock-set-open", ActionData::make_arg2<QString, bool>(EXTENSIONS_TOOLBAR_NAME, open));
});
};
auto setExtensionsToolBarOpen = [this, window](bool open) {
if (open == window->isDockOpen(EXTENSIONS_TOOLBAR_NAME)) {
return;
}

bool noItems = true;
dispatcher()->dispatch("dock-set-open", ActionData::make_arg2<QString, bool>(EXTENSIONS_TOOLBAR_NAME, open));
};

muse::extensions::ManifestList enabledExtensions = extensionsProvider()->manifestList(muse::extensions::Filter::Enabled);
for (const muse::extensions::Manifest& m : enabledExtensions) {
Expand All @@ -351,9 +389,10 @@ void NotationPageModel::updateExtensionsToolBarVisibility()
continue;
}

noItems = false;
setExtensionsToolBarOpen(true);
return;
}
}

setExtensionsToolBarOpen(!noItems);
setExtensionsToolBarOpen(false);
}
20 changes: 13 additions & 7 deletions src/appshell/view/notationpagemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MU_APPSHELL_NOTATIONPAGEMODEL_H
#define MU_APPSHELL_NOTATIONPAGEMODEL_H
#pragma once

#include <QQuickItem>

Expand Down Expand Up @@ -89,10 +88,17 @@ class NotationPageModel : public QObject, public muse::Injectable, public muse::

void toggleDock(const QString& name);

void updateDrumsetPanelVisibility();
void updatePercussionPanelVisibility();
void updateExtensionsToolBarVisibility();
void scheduleUpdateDrumsetPanelVisibility();
void doUpdateDrumsetPanelVisibility();

void scheduleUpdatePercussionPanelVisibility();
void doUpdatePercussionPanelVisibility();

void scheduleUpdateExtensionsToolBarVisibility();
void doUpdateExtensionsToolBarVisibility();

bool m_updateDrumsetPanelVisibilityScheduled = false;
bool m_updatePercussionPanelVisibilityScheduled = false;
bool m_updateExtensionsToolBarVisibilityScheduled = false;
};
}

#endif // MU_APPSHELL_NOTATIONPAGEMODEL_H
1 change: 1 addition & 0 deletions src/engraving/dom/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ void TextBase::endEdit(EditData& ed)
undo->reopen();
if (newlyAdded) {
score()->endCmd(true); // rollback the "add element" command
ted->deleteText = true;
} else {
score()->undoRemoveElement(this);
commitText();
Expand Down
27 changes: 24 additions & 3 deletions src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,8 +2035,15 @@ void NotationActionController::navigateToTextElement(MoveDirection direction, bo
currentNotationInteraction()->navigateToLyrics(direction, moveOnly);
} else if (element->isHarmony()) {
const Harmony* chordSymbol = editedChordSymbol();

// otherwise, chord symbol will be deleted when navigating away from it
const bool canPlay = chordSymbol && !chordSymbol->plainText().empty();

currentNotationInteraction()->navigateToNearHarmony(direction, nearNoteOrRest);
playbackController()->playElements({ chordSymbol });

if (canPlay) {
playbackController()->playElements({ chordSymbol });
}
} else if (element->isFiguredBass()) {
currentNotationInteraction()->navigateToNearFiguredBass(direction);
} else {
Expand All @@ -2053,8 +2060,15 @@ void NotationActionController::navigateToTextElementByFraction(const Fraction& f

if (element->isHarmony()) {
const Harmony* chordSymbol = editedChordSymbol();

// otherwise, chord symbol will be deleted when navigating away from it
const bool canPlay = chordSymbol && !chordSymbol->plainText().empty();

currentNotationInteraction()->navigateToHarmony(fraction);
playbackController()->playElements({ chordSymbol });

if (canPlay) {
playbackController()->playElements({ chordSymbol });
}
} else if (element->isFiguredBass()) {
currentNotationInteraction()->navigateToFiguredBass(fraction);
}
Expand All @@ -2069,8 +2083,15 @@ void NotationActionController::navigateToTextElementInNearMeasure(MoveDirection

if (element->isHarmony()) {
const Harmony* chordSymbol = editedChordSymbol();

// otherwise, chord symbol will be deleted when navigating away from it
const bool canPlay = chordSymbol && !chordSymbol->plainText().empty();

currentNotationInteraction()->navigateToHarmonyInNearMeasure(direction);
playbackController()->playElements({ chordSymbol });

if (canPlay) {
playbackController()->playElements({ chordSymbol });
}
} else if (element->isFiguredBass()) {
currentNotationInteraction()->navigateToFiguredBassInNearMeasure(direction);
}
Expand Down
14 changes: 12 additions & 2 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7052,6 +7052,8 @@ void NotationInteraction::navigateToHarmonyInNearMeasure(MoveDirection direction

track_idx_t track = harmony->track();

doEndEditElement();

mu::engraving::Harmony* nextHarmony = findHarmonyInSegment(segment, track, harmony->textStyleType());
if (!nextHarmony) {
nextHarmony = createHarmony(segment, track, harmony->harmonyType());
Expand Down Expand Up @@ -7097,6 +7099,8 @@ void NotationInteraction::navigateToHarmony(const Fraction& ticks)
segment = segment->next1(mu::engraving::SegmentType::ChordRest);
}

doEndEditElement();

startEdit(TranslatableString("undoableAction", "Navigate to chord symbol"));

if (!segment || segment->tick() > newTick) { // no ChordRest segment at this tick
Expand Down Expand Up @@ -7148,6 +7152,8 @@ void NotationInteraction::navigateToNearFiguredBass(MoveDirection direction)
return;
}

doEndEditElement();

bool bNew = false;
// add a (new) FB element, using chord duration as default duration
mu::engraving::FiguredBass* fbNew = mu::engraving::FiguredBass::addFiguredBassToSegment(nextSegm, track, Fraction(0, 1), &bNew);
Expand Down Expand Up @@ -7192,6 +7198,8 @@ void NotationInteraction::navigateToFiguredBassInNearMeasure(MoveDirection direc
return;
}

doEndEditElement();

bool bNew = false;
// add a (new) FB element, using chord duration as default duration
mu::engraving::FiguredBass* fbNew = mu::engraving::FiguredBass::addFiguredBassToSegment(nextSegm, fb->track(), Fraction(0, 1), &bNew);
Expand Down Expand Up @@ -7228,8 +7236,6 @@ void NotationInteraction::navigateToFiguredBass(const Fraction& ticks)
}
}

doEndEditElement();

// look for a segment at this tick; if none, create one
mu::engraving::Segment* nextSegm = segm;
while (nextSegm && nextSegm->tick() < nextSegTick) {
Expand All @@ -7244,6 +7250,8 @@ void NotationInteraction::navigateToFiguredBass(const Fraction& ticks)
}
}

doEndEditElement();

startEdit(TranslatableString("undoableAction", "Navigate to figured bass"));

bool bNew = false;
Expand Down Expand Up @@ -7445,6 +7453,8 @@ void NotationInteraction::navigateToNearText(MoveDirection direction)
}
}

doEndEditElement();

if (textEl) {
// edit existing text
TextBase* text = dynamic_cast<TextBase*>(textEl);
Expand Down
Loading