Skip to content

Commit 58fee5e

Browse files
Merge pull request #29558 from mathesoncalum/460_porting_3
Porting 2 PRs to 4.6.0
2 parents 86aa2c6 + 63c325a commit 58fee5e

6 files changed

Lines changed: 66 additions & 39 deletions

File tree

src/appshell/internal/startupscenario.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QCoreApplication>
2626

2727
#include "async/async.h"
28+
#include "network/networkerrors.h"
2829
#include "translation.h"
2930
#include "log.h"
3031

@@ -94,50 +95,45 @@ muse::async::Promise<muse::Ret> StartupScenario::runOnSplashScreen()
9495
registerAudioPlugins();
9596

9697
if (multiInstancesProvider()->instances().size() != 1) {
97-
const Ret ret = muse::make_ret(Ret::Code::Cancel);
98+
const Ret ret = muse::make_ret(Ret::Code::Ok);
9899
return resolve(ret);
99100
}
100101

101102
// Calculate the total number of expected update checks (TODO: check the
102103
// connection before trying any of this)...
103-
static size_t totalChecksExpected = 0;
104104

105105
const bool canCheckAppUpdate = appUpdateScenario() && appUpdateScenario()->needCheckForUpdate();
106-
if (canCheckAppUpdate) {
107-
++totalChecksExpected;
108-
}
109-
110106
const bool canCheckMuseSoundsUpdate = museSoundsUpdateScenario() && museSoundsUpdateScenario()->needCheckForUpdate();
111-
if (canCheckMuseSoundsUpdate) {
112-
++totalChecksExpected;
113-
}
114-
115107
//! NOTE: A MuseSampler update check also exists but we run it later (see onStartupPageOpened)...
108+
m_totalChecksExpected = size_t(canCheckAppUpdate) + size_t(canCheckMuseSoundsUpdate);
116109

117-
if (totalChecksExpected == 0) {
110+
if (m_totalChecksExpected == 0) {
118111
const Ret ret = muse::make_ret(Ret::Code::Ok);
119112
return resolve(ret);
120113
}
121114

115+
m_totalChecksReceived = 0;
116+
122117
// Resolve once all checks are completed...
123118
const auto onUpdateCheckCompleted = [this, resolve](){
124-
static size_t totalChecksReceived = 0;
125-
IF_ASSERT_FAILED(m_updateCheckInProgress && totalChecksReceived < totalChecksExpected) {
126-
m_updateCheckInProgress = false;
127-
return;
119+
if (!m_updateChecksInProgress) {
120+
return; // Already resolved or timed out...
128121
}
129122

130-
++totalChecksReceived;
123+
++m_totalChecksReceived;
131124

132-
if (totalChecksReceived == totalChecksExpected) {
133-
m_updateCheckInProgress = false;
134-
const Ret ret = muse::make_ret(Ret::Code::Ok);
135-
(void)resolve(ret);
125+
if (m_totalChecksReceived < m_totalChecksExpected) {
126+
return; // Not ready to resolve yet...
136127
}
128+
129+
m_updateChecksInProgress = false;
130+
131+
const Ret ret = muse::make_ret(Ret::Code::Ok);
132+
(void)resolve(ret);
137133
};
138134

139135
// Asynchronously start the checks once we know the total number of expected checks...
140-
m_updateCheckInProgress = true;
136+
m_updateChecksInProgress = true;
141137
async::Async::call(this, [this, onUpdateCheckCompleted, canCheckAppUpdate, canCheckMuseSoundsUpdate]() {
142138
if (canCheckAppUpdate) {
143139
muse::async::Promise<Ret> promise = appUpdateScenario()->checkForUpdate(/*manual*/ false);
@@ -155,11 +151,15 @@ muse::async::Promise<muse::Ret> StartupScenario::runOnSplashScreen()
155151

156152
// Timeout if the checks take too long...
157153
QTimer::singleShot(CHECK_FOR_UPDATES_TIMEOUT, [this, resolve]() {
158-
if (m_updateCheckInProgress) {
159-
LOGE() << "Update checks timed out...";
160-
const Ret ret = muse::make_ret(Ret::Code::Cancel);
161-
(void)resolve(ret);
154+
if (!m_updateChecksInProgress) {
155+
return;
162156
}
157+
158+
m_updateChecksInProgress = false;
159+
160+
LOGE() << "Update checks timed out...";
161+
const Ret ret = network::make_ret(network::Err::Timeout);
162+
(void)resolve(ret);
163163
});
164164

165165
return muse::async::Promise<Ret>::dummy_result();

src/appshell/internal/startupscenario.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class StartupScenario : public IStartupScenario, public muse::Injectable, public
9191
project::ProjectFile m_startupScoreFile;
9292
bool m_startupCompleted = false;
9393

94-
bool m_updateCheckInProgress = false;
94+
bool m_updateChecksInProgress = false;
95+
size_t m_totalChecksExpected = 0;
96+
size_t m_totalChecksReceived = 0;
9597
};
9698
}
9799

src/notation/internal/notationnoteinput.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ void NotationNoteInput::addNote(const NoteInputParams& params, NoteAddingMode ad
441441
{
442442
TRACEFUNC;
443443

444+
m_interaction->hideShadowNote();
445+
444446
bool addToUpOnCurrentChord = addingMode == NoteAddingMode::CurrentChord;
445447
bool insertNewChord = addingMode == NoteAddingMode::InsertChord;
446448

@@ -471,6 +473,8 @@ void NotationNoteInput::padNote(const Pad& pad)
471473
{
472474
TRACEFUNC;
473475

476+
m_interaction->hideShadowNote();
477+
474478
startEdit(TranslatableString("undoableAction", "Pad note"));
475479
score()->padToggle(pad);
476480
apply();

src/notation/view/abstractnotationpaintview.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <QMimeData>
2626

2727
#include "actions/actiontypes.h"
28-
28+
#include "engraving/dom/shadownote.h"
2929
#include "log.h"
3030

3131
using namespace mu;
@@ -242,10 +242,7 @@ void AbstractNotationPaintView::onLoadNotation(INotationPtr)
242242
}
243243

244244
m_notation->notationChanged().onNotify(this, [this]() {
245-
if (INotationInteractionPtr interaction = notationInteraction()) {
246-
interaction->hideShadowNote();
247-
}
248-
m_shadowNoteRect = RectF();
245+
updateShadowNoteVisibility();
249246
scheduleRedraw();
250247
});
251248

@@ -431,6 +428,27 @@ void AbstractNotationPaintView::updateLoopMarkers()
431428
scheduleRedraw();
432429
}
433430

431+
void AbstractNotationPaintView::updateShadowNoteVisibility()
432+
{
433+
INotationInteractionPtr interaction = notationInteraction();
434+
const engraving::ShadowNote* shadowNote = interaction ? interaction->shadowNote() : nullptr;
435+
if (!shadowNote || !shadowNote->visible()) {
436+
m_shadowNoteRect = RectF();
437+
return;
438+
}
439+
440+
if (isNoteEnterMode()) {
441+
//! NOTE: The following may actually hide the shadow note
442+
//! if cursorPos is no longer valid...
443+
const QPointF cursorPos = mapFromGlobal(QCursor::pos());
444+
showShadowNote(toLogical(cursorPos));
445+
} else {
446+
interaction->hideShadowNote();
447+
m_shadowNoteRect = RectF();
448+
return;
449+
}
450+
}
451+
434452
NotationViewInputController* AbstractNotationPaintView::inputController() const
435453
{
436454
return m_inputController.get();
@@ -481,12 +499,8 @@ void AbstractNotationPaintView::onNoteInputStateChanged()
481499
TRACEFUNC;
482500

483501
setAcceptHoverEvents(isNoteEnterMode());
484-
485-
if (INotationInteractionPtr interaction = notationInteraction()) {
486-
interaction->hideShadowNote();
487-
m_shadowNoteRect = RectF();
488-
scheduleRedraw();
489-
}
502+
updateShadowNoteVisibility();
503+
scheduleRedraw();
490504
}
491505

492506
void AbstractNotationPaintView::onShowItemRequested(const INotationInteraction::ShowItemRequest& request)
@@ -522,7 +536,12 @@ void AbstractNotationPaintView::showShadowNote(const PointF& pos)
522536
{
523537
TRACEFUNC;
524538

525-
bool visible = notationInteraction()->showShadowNote(pos);
539+
INotationInteractionPtr interaction = notationInteraction();
540+
if (!interaction) {
541+
return;
542+
}
543+
544+
const bool visible = interaction->showShadowNote(pos);
526545

527546
if (m_shadowNoteRect.isValid()) {
528547
scheduleRedraw(m_shadowNoteRect);
@@ -533,7 +552,7 @@ void AbstractNotationPaintView::showShadowNote(const PointF& pos)
533552
}
534553
}
535554

536-
RectF shadowNoteRect = fromLogical(notationInteraction()->shadowNoteRect());
555+
RectF shadowNoteRect = fromLogical(interaction->shadowNoteRect());
537556

538557
if (shadowNoteRect.isValid()) {
539558
compensateFloatPart(shadowNoteRect);

src/notation/view/abstractnotationpaintview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ protected slots:
258258
void onPlaybackCursorRectChanged();
259259

260260
void updateLoopMarkers();
261+
void updateShadowNoteVisibility();
261262

262263
const Page* pageByPoint(const muse::PointF& point) const;
263264
muse::PointF alignToCurrentPageBorder(const muse::RectF& showRect, const muse::PointF& pos) const;

src/notation/view/notationviewinputcontroller.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ void NotationViewInputController::keyPressEvent(QKeyEvent* event)
13521352
} else if (key == Qt::Key_Shift) {
13531353
viewInteraction()->updateTimeTickAnchors(event);
13541354
updateShadowNotePopupVisibility();
1355+
return;
13551356
} else if (isAnchorEditingEvent(event)) {
13561357
viewInteraction()->moveElementAnchors(event);
13571358
}

0 commit comments

Comments
 (0)