diff --git a/mu4/context/internal/globalcontext.cpp b/mu4/context/internal/globalcontext.cpp index bd46aae141..0a84d0495d 100644 --- a/mu4/context/internal/globalcontext.cpp +++ b/mu4/context/internal/globalcontext.cpp @@ -20,10 +20,12 @@ using namespace mu::context; using namespace mu::domain::notation; +using namespace mu::shortcuts; void GlobalContext::setCurrentNotation(const std::shared_ptr& notation) { m_notation = notation; + updateShortcutContext(); m_notationChanged.notify(); } @@ -45,6 +47,7 @@ bool GlobalContext::isPlaying() const void GlobalContext::setIsPlaying(bool arg) { m_isPlaying = arg; + updateShortcutContext(); m_isPlayingChanged.notify(); } @@ -52,3 +55,20 @@ mu::async::Notification GlobalContext::isPlayingChanged() const { return m_isPlayingChanged; } + +ShortcutContext GlobalContext::currentShortcutContext() const +{ + //! TODO Temporary solution, it does not correctly determine the current context for shortcuts + if (isPlaying()) { + return ShortcutContext::Playing; + } else if (currentNotation()) { + return ShortcutContext::NotationActive; + } + return ShortcutContext::Undefined; +} + +void GlobalContext::updateShortcutContext() +{ + ShortcutContext ctx = currentShortcutContext(); + shortcutsController()->setActiveContext(ctx); +} diff --git a/mu4/context/internal/globalcontext.h b/mu4/context/internal/globalcontext.h index 65d3f2f7d6..6bf44bd143 100644 --- a/mu4/context/internal/globalcontext.h +++ b/mu4/context/internal/globalcontext.h @@ -22,10 +22,16 @@ #include #include "../iglobalcontext.h" +#include "modularity/ioc.h" +#include "shortcuts/ishortcutscontroller.h" +#include "shortcuts/shortcutstypes.h" + namespace mu { namespace context { class GlobalContext : public IGlobalContext { + INJECT(context, shortcuts::IShortcutsController, shortcutsController) + public: GlobalContext() = default; @@ -39,6 +45,9 @@ public: private: + shortcuts::ShortcutContext currentShortcutContext() const; + void updateShortcutContext(); + std::shared_ptr m_notation; async::Notification m_notationChanged; diff --git a/mu4/domain/notation/internal/notationactions.cpp b/mu4/domain/notation/internal/notationactions.cpp index 8dbebf31df..b112bfe976 100644 --- a/mu4/domain/notation/internal/notationactions.cpp +++ b/mu4/domain/notation/internal/notationactions.cpp @@ -33,23 +33,23 @@ const std::vector NotationActions::m_actions = { ), Action("domain/notation/note-input", QT_TRANSLATE_NOOP("action", "Note Input"), - ShortcutContext::NotationViewFocused + ShortcutContext::NotationActive ), Action("domain/notation/pad-note-4", QT_TRANSLATE_NOOP("action", "4th"), - ShortcutContext::NotationViewFocused + ShortcutContext::NotationActive ), Action("domain/notation/pad-note-8", QT_TRANSLATE_NOOP("action", "8th"), - ShortcutContext::NotationViewFocused + ShortcutContext::NotationActive ), Action("domain/notation/pad-note-16", QT_TRANSLATE_NOOP("action", "16th"), - ShortcutContext::NotationViewFocused + ShortcutContext::NotationActive ), Action("domain/notation/put-note", // args: QPoint pos, bool replace, bool insert QT_TRANSLATE_NOOP("action", "Put Note"), - ShortcutContext::NotationViewFocused + ShortcutContext::NotationActive ) }; diff --git a/mu4/shortcuts/internal/shortcutsregister.cpp b/mu4/shortcuts/internal/shortcutsregister.cpp index ba1c5129e5..83ca685022 100644 --- a/mu4/shortcuts/internal/shortcutsregister.cpp +++ b/mu4/shortcuts/internal/shortcutsregister.cpp @@ -30,7 +30,7 @@ static const std::map m_actionsMap = { { "note-input", "domain/notation/note-input" }, { "pad-note-4", "domain/notation/pad-note-4" }, { "pad-note-8", "domain/notation/pad-note-8" }, - { "pad-note-16", "domain/notation/pad-note-16" }, + { "pad-note-16", "domain/notation/pad-note-16" } }; void ShortcutsRegister::load() @@ -71,7 +71,7 @@ void ShortcutsRegister::expandStandartKeys(std::list& shortcuts) const const QKeySequence& first = kslist.first(); sc.sequence = first.toString().toStdString(); - LOGD() << "for standart key: " << sc.standartKey << ", sequence: " << sc.sequence; + //LOGD() << "for standart key: " << sc.standartKey << ", sequence: " << sc.sequence; //! NOTE If the keyBindings contains more than one result, //! these can be considered alternative shortcuts on the same platform for the given key. @@ -79,7 +79,7 @@ void ShortcutsRegister::expandStandartKeys(std::list& shortcuts) const const QKeySequence& seq = kslist.at(i); Shortcut esc = sc; esc.sequence = seq.toString().toStdString(); - LOGD() << "for standart key: " << esc.standartKey << ", alternative sequence: " << esc.sequence; + //LOGD() << "for standart key: " << esc.standartKey << ", alternative sequence: " << esc.sequence; expanded.push_back(esc); } } diff --git a/mu4/shortcuts/shortcutstypes.h b/mu4/shortcuts/shortcutstypes.h index fe6491dca9..4fa9459e74 100644 --- a/mu4/shortcuts/shortcutstypes.h +++ b/mu4/shortcuts/shortcutstypes.h @@ -44,7 +44,7 @@ struct Shortcut enum class ShortcutContext { Undefined = 0, Any, - NotationViewFocused, + NotationActive, Playing }; }