From 9e74bd33b09438828c4fc40626ee5cfe6791d524 Mon Sep 17 00:00:00 2001 From: Igor Korsukov Date: Sat, 25 Apr 2020 18:50:24 +0200 Subject: [PATCH] added notation view skeleton --- CMakeLists.txt | 5 +- build/module.cmake | 14 +- framework/global/CMakeLists.txt | 1 + framework/global/interfaces/iinteractive.h | 40 +++++ framework/ui/CMakeLists.txt | 2 + framework/ui/uiinteractive.cpp | 28 +++ framework/ui/uiinteractive.h | 37 ++++ framework/ui/uimodule.cpp | 3 + framework/uicomponents/CMakeLists.txt | 1 - libmscore/CMakeLists.txt | 9 +- main/CMakeLists.txt | 22 +-- main/main.cpp | 10 +- main/modulessetup.cpp | 6 + mu4/CMakeLists.txt | 5 + mu4/appshell/appshell.cpp | 4 +- mu4/appshell/appshell.h | 2 +- mu4/appshell/appshell.qrc | 1 + mu4/appshell/dockwindow/qmllistproperty.h | 4 +- mu4/appshell/qml/HomePage/HomeMenu.qml | 2 +- mu4/appshell/qml/HomePage/HomePage.qml | 2 +- mu4/appshell/qml/Main.qml | 4 +- mu4/appshell/qml/MainToolBar.qml | 2 +- .../qml/NotationPage/NotationPage.qml | 37 ++-- .../qml/NotationPage/NotationToolBar.qml | 18 ++ mu4/appshell/qml/PublishPage.qml | 2 +- mu4/appshell/qml/SequencerPage.qml | 2 +- mu4/domain/midi/.keep | 0 mu4/domain/notation/CMakeLists.txt | 44 +++++ mu4/domain/notation/interfaces/inotation.h | 54 ++++++ .../notation/interfaces/inotationcreator.h | 42 +++++ mu4/domain/notation/notation.cpp | 112 ++++++++++++ mu4/domain/notation/notation.h | 52 ++++++ mu4/domain/notation/notationcreator.cpp | 28 +++ mu4/domain/notation/notationcreator.h | 38 ++++ mu4/domain/notation/notationdomainmodule.cpp | 40 +++++ mu4/domain/notation/notationdomainmodule.h | 40 +++++ mu4/domain/tracks/.keep | 0 .../MuseScore/Extensions/ExtensionsModule.qml | 2 +- mu4/scenes/notation/CMakeLists.txt | 40 +++++ mu4/scenes/notation/inspector/.keep | 0 mu4/scenes/notation/notationscenemodule.cpp | 59 ++++++ mu4/scenes/notation/notationscenemodule.h | 45 +++++ mu4/scenes/notation/palette/.keep | 0 mu4/scenes/notation/view/notation_view.qrc | 6 + .../notation/view/notationpaintview.cpp | 170 ++++++++++++++++++ mu4/scenes/notation/view/notationpaintview.h | 80 +++++++++ mu4/scenes/notation/view/notationview.cmake | 7 + .../view/notationviewinputcontroller.cpp | 85 +++++++++ .../view/notationviewinputcontroller.h | 50 ++++++ .../MuseScore/NotationScene/NotationView.qml | 17 ++ .../view/qml/MuseScore/NotationScene/qmldir | 2 + .../qml/MuseScore/Scores/ScoresModule.qml | 2 +- 52 files changed, 1230 insertions(+), 48 deletions(-) create mode 100644 framework/global/interfaces/iinteractive.h create mode 100644 framework/ui/uiinteractive.cpp create mode 100644 framework/ui/uiinteractive.h create mode 100644 mu4/appshell/qml/NotationPage/NotationToolBar.qml create mode 100644 mu4/domain/midi/.keep create mode 100644 mu4/domain/notation/CMakeLists.txt create mode 100644 mu4/domain/notation/interfaces/inotation.h create mode 100644 mu4/domain/notation/interfaces/inotationcreator.h create mode 100644 mu4/domain/notation/notation.cpp create mode 100644 mu4/domain/notation/notation.h create mode 100644 mu4/domain/notation/notationcreator.cpp create mode 100644 mu4/domain/notation/notationcreator.h create mode 100644 mu4/domain/notation/notationdomainmodule.cpp create mode 100644 mu4/domain/notation/notationdomainmodule.h create mode 100644 mu4/domain/tracks/.keep create mode 100644 mu4/scenes/notation/CMakeLists.txt create mode 100644 mu4/scenes/notation/inspector/.keep create mode 100644 mu4/scenes/notation/notationscenemodule.cpp create mode 100644 mu4/scenes/notation/notationscenemodule.h create mode 100644 mu4/scenes/notation/palette/.keep create mode 100644 mu4/scenes/notation/view/notation_view.qrc create mode 100644 mu4/scenes/notation/view/notationpaintview.cpp create mode 100644 mu4/scenes/notation/view/notationpaintview.h create mode 100644 mu4/scenes/notation/view/notationview.cmake create mode 100644 mu4/scenes/notation/view/notationviewinputcontroller.cpp create mode 100644 mu4/scenes/notation/view/notationviewinputcontroller.h create mode 100644 mu4/scenes/notation/view/qml/MuseScore/NotationScene/NotationView.qml create mode 100644 mu4/scenes/notation/view/qml/MuseScore/NotationScene/qmldir diff --git a/CMakeLists.txt b/CMakeLists.txt index 43b1728c6c..e92ebc0c69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -940,9 +940,12 @@ if (MSVC) endif (MSVC) add_subdirectory(framework) -add_subdirectory(mu4) add_subdirectory(global) #todo remove +if (BUILD_UI_MU4) + add_subdirectory(mu4) +endif(BUILD_UI_MU4) + ## TEMP: Display all variables! ### message(STATUS "===========================================================") ### message(STATUS "VARIABLES:") diff --git a/build/module.cmake b/build/module.cmake index 2a2696f260..2e02aad339 100644 --- a/build/module.cmake +++ b/build/module.cmake @@ -18,12 +18,14 @@ #============================================================================= ## Setup -# set(MODULE somename) -# set(MODULE_INCLUDE ...) -# set(MODULE_QRC somename.qrc) -# set(MODULE_QML_IMPORT ...) -# set(MODULE_SRC ...) -# set(MODULE_LINK ...) +# set(MODULE somename) - set module (target) name +# set(MODULE_INCLUDE ...) - set include (by default see below include_directories) +# set(MODULE_SRC ...) - set sources and headers files +# set(MODULE_LINK ...) - set libraries for link +# set(MODULE_QRC somename.qrc) - set resource (qrc) file +# set(MODULE_QML_IMPORT ...) - set Qml import for QtCreator (so that there is code highlighting, jump, etc.) + +# After all the settings you need to do: # include(${PROJECT_SOURCE_DIR}/build/module.cmake) message(STATUS "Configuring " ${MODULE}) diff --git a/framework/global/CMakeLists.txt b/framework/global/CMakeLists.txt index bbae674d41..6066ee804e 100644 --- a/framework/global/CMakeLists.txt +++ b/framework/global/CMakeLists.txt @@ -26,6 +26,7 @@ set(MODULE_SRC ${CMAKE_CURRENT_LIST_DIR}/log.h ${CMAKE_CURRENT_LIST_DIR}/dataformatter.cpp ${CMAKE_CURRENT_LIST_DIR}/dataformatter.h + ${CMAKE_CURRENT_LIST_DIR}/interfaces/iinteractive.h ) include(${PROJECT_SOURCE_DIR}/build/module.cmake) diff --git a/framework/global/interfaces/iinteractive.h b/framework/global/interfaces/iinteractive.h new file mode 100644 index 0000000000..c33050ed4f --- /dev/null +++ b/framework/global/interfaces/iinteractive.h @@ -0,0 +1,40 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_FRAMEWORK_IINTERACTIVE_H +#define MU_FRAMEWORK_IINTERACTIVE_H + +#include + +#include "modularity/imoduleexport.h" + +namespace mu { +namespace framework { +class IInteractive : MODULE_EXPORT_INTERFACE +{ + INTERFACE_ID(IInteractive) + +public: + virtual ~IInteractive() = default; + + virtual QString selectOpeningFile(const QString& title, const QString& dir, const QString& filter) = 0; +}; +} +} + +#endif // MU_FRAMEWORK_IINTERACTIVE_H diff --git a/framework/ui/CMakeLists.txt b/framework/ui/CMakeLists.txt index bfd21c581a..9d95b680c1 100644 --- a/framework/ui/CMakeLists.txt +++ b/framework/ui/CMakeLists.txt @@ -28,6 +28,8 @@ set(MODULE_SRC ${CMAKE_CURRENT_LIST_DIR}/qmltheme.cpp ${CMAKE_CURRENT_LIST_DIR}/qmltheme.h ${CMAKE_CURRENT_LIST_DIR}/iconcodes.h + ${CMAKE_CURRENT_LIST_DIR}/uiinteractive.cpp + ${CMAKE_CURRENT_LIST_DIR}/uiinteractive.h ) include(${PROJECT_SOURCE_DIR}/build/module.cmake) diff --git a/framework/ui/uiinteractive.cpp b/framework/ui/uiinteractive.cpp new file mode 100644 index 0000000000..bd23cd14f4 --- /dev/null +++ b/framework/ui/uiinteractive.cpp @@ -0,0 +1,28 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "uiinteractive.h" + +#include + +using namespace mu::framework; + +QString UiInteractive::selectOpeningFile(const QString& title, const QString& dir, const QString& filter) +{ + return QFileDialog::getOpenFileName(nullptr /*parent*/, title, dir, filter); +} diff --git a/framework/ui/uiinteractive.h b/framework/ui/uiinteractive.h new file mode 100644 index 0000000000..f61bc04da5 --- /dev/null +++ b/framework/ui/uiinteractive.h @@ -0,0 +1,37 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_FRAMEWORK_UIINTERACTIVE_H +#define MU_FRAMEWORK_UIINTERACTIVE_H + +#include "interfaces/iinteractive.h" + +namespace mu { +namespace framework { +class UiInteractive : public IInteractive +{ +public: + + UiInteractive() = default; + + QString selectOpeningFile(const QString& title, const QString& dir, const QString& filter) override; +}; +} +} + +#endif // MU_FRAMEWORK_UIINTERACTIVE_H diff --git a/framework/ui/uimodule.cpp b/framework/ui/uimodule.cpp index fd5382920e..fcb8d0e91d 100644 --- a/framework/ui/uimodule.cpp +++ b/framework/ui/uimodule.cpp @@ -8,6 +8,8 @@ #include "qmltheme.h" #include "iconcodes.h" +#include "uiinteractive.h" + using namespace mu::framework; std::string UiModule::moduleName() const @@ -19,6 +21,7 @@ std::string UiModule::moduleName() const void UiModule::registerExports() { ioc()->registerExport(moduleName(), UiEngine::instance()); + ioc()->registerExport(moduleName(), new UiInteractive()); } void UiModule::registerUiTypes() diff --git a/framework/uicomponents/CMakeLists.txt b/framework/uicomponents/CMakeLists.txt index ad54b4d7b2..aa28f61735 100644 --- a/framework/uicomponents/CMakeLists.txt +++ b/framework/uicomponents/CMakeLists.txt @@ -33,4 +33,3 @@ set(MODULE_SRC include(${PROJECT_SOURCE_DIR}/build/module.cmake) - diff --git a/libmscore/CMakeLists.txt b/libmscore/CMakeLists.txt index 68e28d2cfd..64ce8da2c9 100644 --- a/libmscore/CMakeLists.txt +++ b/libmscore/CMakeLists.txt @@ -103,10 +103,17 @@ add_library ( unrollrepeats.cpp ) +set (LINK_LIBS ) if (AVSOMR) - target_link_libraries(libmscore avsomr) + set(LINK_LIBS ${LINK_LIBS} avsomr) endif (AVSOMR) +if (BUILD_UI_MU4) + set(LINK_LIBS ${LINK_LIBS} audio) +endif(BUILD_UI_MU4) + +target_link_libraries(libmscore ${LINK_LIBS}) + ## ## Code coverage. Only affects DEBUG builds. ## diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 4952f5e522..872c40adab 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -77,17 +77,19 @@ target_include_directories(mscore PRIVATE ${PROJECT_SOURCE_DIR}/thirdparty ) -target_link_libraries(mscore - mscoreapp - global - global_old #todo remove - ui - uicomponents - appshell - scores - extensions -) +set(LINK_LIB mscoreapp global global_old ui uicomponents) +if (BUILD_UI_MU4) + set(LINK_LIB ${LINK_LIB} + appshell + scores + extensions + notation + notation_scene + ) +endif(BUILD_UI_MU4) + +target_link_libraries(mscore ${LINK_LIB} ) if (APPLE) set_target_properties (mscore diff --git a/main/main.cpp b/main/main.cpp index 045148ec18..1ab1369037 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -60,7 +60,15 @@ int main(int argc, char** argv) initResources(); +#ifndef BUILD_UI_MU4 ModulesSetup::instance()->setup(); +#else + //! HACK A temporary hack is required because some modules + //! can only be initialized after the creation of the QApplication + auto moduleSetup = []() { + ModulesSetup::instance()->setup(); + }; +#endif #if (defined (_MSCVER) || defined (_MSC_VER)) // On MSVC under Windows, we need to manually retrieve the command-line arguments and convert them from UTF-16 to UTF-8. @@ -98,7 +106,7 @@ int main(int argc, char** argv) #ifdef BUILD_UI_MU4 mu::appshell::AppShell app; - return app.run(argcFinal, argvFinal); + return app.run(argcFinal, argvFinal, moduleSetup); #else return Ms::runApplication(argcFinal, argvFinal); #endif diff --git a/main/modulessetup.cpp b/main/modulessetup.cpp index 048a66b05f..3547d3921b 100644 --- a/main/modulessetup.cpp +++ b/main/modulessetup.cpp @@ -25,6 +25,8 @@ #include "mu4/appshell/appshellmodule.h" #include "mu4/scores/scoresmodule.h" #include "mu4/extensions/extensionsmodule.h" +#include "mu4/domain/notation/notationdomainmodule.h" +#include "mu4/scenes/notation/notationscenemodule.h" #ifdef BUILD_TELEMETRY_MODULE #include "framework/telemetry/telemetrysetup.h" @@ -43,11 +45,15 @@ ModulesSetup::ModulesSetup() { m_modulesSetupList +#ifdef BUILD_UI_MU4 << new mu::framework::UiModule() << new mu::framework::UiComponentsModule() << new mu::appshell::AppShellModule() << new mu::scores::ScoresModule() << new mu::extensions::ExtensionsModule() + << new mu::domain::notation::NotationDomainModule() + << new mu::scene::notation::NotationSceneModule() +#endif #ifdef BUILD_TELEMETRY_MODULE << new TelemetrySetup() diff --git a/mu4/CMakeLists.txt b/mu4/CMakeLists.txt index 95140e9ba5..e172751c6f 100644 --- a/mu4/CMakeLists.txt +++ b/mu4/CMakeLists.txt @@ -2,7 +2,12 @@ add_subdirectory(appshell) +# Domain +add_subdirectory(domain/notation) + # Home add_subdirectory(scores) add_subdirectory(extensions) +# Notation +add_subdirectory(scenes/notation) diff --git a/mu4/appshell/appshell.cpp b/mu4/appshell/appshell.cpp index 0f69d765eb..5079dc70c0 100644 --- a/mu4/appshell/appshell.cpp +++ b/mu4/appshell/appshell.cpp @@ -32,7 +32,7 @@ AppShell::AppShell() { } -int AppShell::run(int argc, char** argv) +int AppShell::run(int argc, char** argv, std::function moduleSetup) { LOGI() << "start run"; @@ -41,6 +41,8 @@ int AppShell::run(int argc, char** argv) QApplication app(argc, argv); + moduleSetup(); + QQmlApplicationEngine* engine = new QQmlApplicationEngine(); //! NOTE Move ownership to UiEngine framework::UiEngine::instance()->moveQQmlEngine(engine); diff --git a/mu4/appshell/appshell.h b/mu4/appshell/appshell.h index dc1cc7c836..b4a71849a2 100644 --- a/mu4/appshell/appshell.h +++ b/mu4/appshell/appshell.h @@ -29,7 +29,7 @@ class AppShell public: AppShell(); - int run(int argc, char** argv); + int run(int argc, char** argv, std::function moduleSetup); }; } } diff --git a/mu4/appshell/appshell.qrc b/mu4/appshell/appshell.qrc index 2196518f9f..6e657337c9 100644 --- a/mu4/appshell/appshell.qrc +++ b/mu4/appshell/appshell.qrc @@ -7,5 +7,6 @@ qml/HomePage/HomePage.qml qml/HomePage/HomeMenu.qml qml/NotationPage/NotationPage.qml + qml/NotationPage/NotationToolBar.qml diff --git a/mu4/appshell/dockwindow/qmllistproperty.h b/mu4/appshell/dockwindow/qmllistproperty.h index 50ef8d978c..9f3702e149 100644 --- a/mu4/appshell/dockwindow/qmllistproperty.h +++ b/mu4/appshell/dockwindow/qmllistproperty.h @@ -44,9 +44,9 @@ template class QmlListProperty { public: + explicit QmlListProperty(QObject* parent) - : _parent(parent), - _notifier(new QmlListPropertyNotifier()) + : _parent(parent), _notifier(new QmlListPropertyNotifier()) {} ~QmlListProperty() { delete _notifier; } diff --git a/mu4/appshell/qml/HomePage/HomeMenu.qml b/mu4/appshell/qml/HomePage/HomeMenu.qml index 149c2e0bfa..bbac6914cb 100644 --- a/mu4/appshell/qml/HomePage/HomeMenu.qml +++ b/mu4/appshell/qml/HomePage/HomeMenu.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 import QtQuick.Controls 2.2 Rectangle { diff --git a/mu4/appshell/qml/HomePage/HomePage.qml b/mu4/appshell/qml/HomePage/HomePage.qml index b9766e481e..97310ee5b7 100644 --- a/mu4/appshell/qml/HomePage/HomePage.qml +++ b/mu4/appshell/qml/HomePage/HomePage.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 import MuseScore.Ui 1.0 import MuseScore.Dock 1.0 diff --git a/mu4/appshell/qml/Main.qml b/mu4/appshell/qml/Main.qml index 0d0b1e6fcd..1971f8b2f4 100644 --- a/mu4/appshell/qml/Main.qml +++ b/mu4/appshell/qml/Main.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 import MuseScore.Dock 1.0 import "./HomePage" @@ -12,7 +12,7 @@ DockWindow { color: ui.theme.window - currentPageName: "notation" + currentPageName: "home" toolbar: DockToolBar { diff --git a/mu4/appshell/qml/MainToolBar.qml b/mu4/appshell/qml/MainToolBar.qml index ffa5f983ad..46cca56555 100644 --- a/mu4/appshell/qml/MainToolBar.qml +++ b/mu4/appshell/qml/MainToolBar.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 Rectangle { diff --git a/mu4/appshell/qml/NotationPage/NotationPage.qml b/mu4/appshell/qml/NotationPage/NotationPage.qml index 8c5c344a09..17cdad04d8 100644 --- a/mu4/appshell/qml/NotationPage/NotationPage.qml +++ b/mu4/appshell/qml/NotationPage/NotationPage.qml @@ -1,7 +1,8 @@ -import QtQuick 2.9 +import QtQuick 2.7 import QtQuick.Controls 2.2 import MuseScore.Ui 1.0 import MuseScore.Dock 1.0 +import MuseScore.NotationScene 1.0 DockPage { id: notationPage @@ -9,6 +10,20 @@ DockPage { property var color: ui.theme.window + //! NOTE Temporary solution + QtObject { + id: observer + + property var _callbacks: ({}) + function register(target, callback) { + _callbacks[target] = callback; + } + + function call(target, cmd) { + _callbacks[target](cmd) + } + } + toolbar: DockToolBar { id: notationToolBar objectName: "notationToolBar" @@ -17,14 +32,8 @@ DockPage { width: 400 color: notationPage.color - Rectangle { - color: notationPage.color - - Text { - anchors.fill: parent - verticalAlignment: Text.AlignVCenter - text: "Notation toolbar" - } + NotationToolBar { + onClicked: observer.call("view", cmd) } } @@ -77,13 +86,11 @@ DockPage { id: notationCentral objectName: "notationCentral" - Rectangle { + NotationView { + id: notationView - Text { - anchors.fill: parent - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - text: "Notation" + Component.onCompleted: { + observer.register("view", notationView.cmd) } } } diff --git a/mu4/appshell/qml/NotationPage/NotationToolBar.qml b/mu4/appshell/qml/NotationPage/NotationToolBar.qml new file mode 100644 index 0000000000..78a312472c --- /dev/null +++ b/mu4/appshell/qml/NotationPage/NotationToolBar.qml @@ -0,0 +1,18 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +ToolBar { + id: root + + signal clicked(string cmd) + + RowLayout { + anchors.fill: parent + + ToolButton { + text: "Open" + onClicked: root.clicked("open") + } + } +} diff --git a/mu4/appshell/qml/PublishPage.qml b/mu4/appshell/qml/PublishPage.qml index 7e06856742..d9de4bc57e 100644 --- a/mu4/appshell/qml/PublishPage.qml +++ b/mu4/appshell/qml/PublishPage.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 import MuseScore.Ui 1.0 import MuseScore.Dock 1.0 diff --git a/mu4/appshell/qml/SequencerPage.qml b/mu4/appshell/qml/SequencerPage.qml index 4d9ca1f2e8..65baaaecae 100644 --- a/mu4/appshell/qml/SequencerPage.qml +++ b/mu4/appshell/qml/SequencerPage.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 import MuseScore.Ui 1.0 import MuseScore.Dock 1.0 diff --git a/mu4/domain/midi/.keep b/mu4/domain/midi/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mu4/domain/notation/CMakeLists.txt b/mu4/domain/notation/CMakeLists.txt new file mode 100644 index 0000000000..be2a6d21a3 --- /dev/null +++ b/mu4/domain/notation/CMakeLists.txt @@ -0,0 +1,44 @@ +#============================================================================= +# MuseScore +# Music Composition & Notation +# +# Copyright (C) 2020 MuseScore BVBA and others +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#============================================================================= + +set(MODULE notation) + +find_package(Qt5 COMPONENTS Svg REQUIRED) + +set(MODULE_SRC + ${CMAKE_CURRENT_LIST_DIR}/notationdomainmodule.cpp + ${CMAKE_CURRENT_LIST_DIR}/notationdomainmodule.h + ${CMAKE_CURRENT_LIST_DIR}/interfaces/inotation.h + ${CMAKE_CURRENT_LIST_DIR}/interfaces/inotationcreator.h + ${CMAKE_CURRENT_LIST_DIR}/notation.cpp + ${CMAKE_CURRENT_LIST_DIR}/notation.h + ${CMAKE_CURRENT_LIST_DIR}/notationcreator.cpp + ${CMAKE_CURRENT_LIST_DIR}/notationcreator.h + ) + +set(MODULE_LINK + Qt5::Svg + freetype + qzip + z + libmscore + ) + +include(${PROJECT_SOURCE_DIR}/build/module.cmake) + diff --git a/mu4/domain/notation/interfaces/inotation.h b/mu4/domain/notation/interfaces/inotation.h new file mode 100644 index 0000000000..faf91299a0 --- /dev/null +++ b/mu4/domain/notation/interfaces/inotation.h @@ -0,0 +1,54 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_DOMAIN_INOTATION_H +#define MU_DOMAIN_INOTATION_H + +#include +#include + +#include "modularity/imoduleexport.h" + +class QPainter; +namespace mu { +namespace domain { +namespace notation { +class INotation : MODULE_EXPORT_INTERFACE +{ + INTERFACE_ID(mu::domain::notation::INotation) + +public: + ~INotation() = default; + + struct PageSize { + int width = -1; + int height = -1; + }; + + struct Params { + PageSize pageSize; + }; + + virtual bool load(const std::string& path, const Params& params) = 0; + virtual void paint(QPainter* p, const QRect& r) = 0; +}; +} +} +} + +#endif // MU_DOMAIN_INOTATION_H diff --git a/mu4/domain/notation/interfaces/inotationcreator.h b/mu4/domain/notation/interfaces/inotationcreator.h new file mode 100644 index 0000000000..b92ee04e4f --- /dev/null +++ b/mu4/domain/notation/interfaces/inotationcreator.h @@ -0,0 +1,42 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_DOMAIN_INOTATIONCREATOR_H +#define MU_DOMAIN_INOTATIONCREATOR_H + +#include +#include "inotation.h" +#include "modularity/imoduleexport.h" + +namespace mu { +namespace domain { +namespace notation { +class INotationCreator : MODULE_EXPORT_INTERFACE +{ + INTERFACE_ID(mu::domain::notation::INotationCreator) + +public: + ~INotationCreator() = default; + + virtual std::shared_ptr newNotation() = 0; +}; +} +} +} + +#endif // MU_DOMAIN_INOTATIONCREATOR_H diff --git a/mu4/domain/notation/notation.cpp b/mu4/domain/notation/notation.cpp new file mode 100644 index 0000000000..75d22847f8 --- /dev/null +++ b/mu4/domain/notation/notation.cpp @@ -0,0 +1,112 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "notation.h" + +#include +#include + +#include "config.h" +#include "libmscore/score.h" +#include "libmscore/page.h" + +#ifdef BUILD_UI_MU4 +//! HACK Temporary hack to link libmscore +Q_LOGGING_CATEGORY(undoRedo, "undoRedo", QtCriticalMsg) + +namespace Ms { +QString revision; +MasterSynthesizer* synti; +QString dataPath; +QString mscoreGlobalShare; +} +//! --------- +#endif + +using namespace mu::domain::notation; +using namespace Ms; + +Notation::Notation() +{ + m_scoreGlobal = new MScore(); + m_score = new MasterScore(m_scoreGlobal->baseStyle()); +} + +void Notation::init() +{ + MScore::init(); // initialize libmscore +} + +bool Notation::load(const std::string& path, const Params& params) +{ + Score::FileError rv = m_score->loadMsc(QString::fromStdString(path), true); + if (rv != Score::FileError::FILE_NO_ERROR) { + return false; + } + +// Ms::MStyle& styleRef = m_score->style(); +// styleRef.set(Ms::Sid::pageWidth, params.pageSize.width / Ms::DPI); +// styleRef.set(Ms::Sid::pageHeight, params.pageSize.height / Ms::DPI); + +// styleRef.set(Ms::Sid::pagePrintableWidth, (pageSize.pageWidth - pageSize.margingLeft +// - pageSize.margingRight) / Ms::DPI); +// styleRef.set(Ms::Sid::pageEvenLeftMargin, pageSize.margingLeft / Ms::DPI); +// styleRef.set(Ms::Sid::pageOddLeftMargin, pageSize.margingLeft / Ms::DPI); + +// styleRef.set(Ms::Sid::pageEvenTopMargin, pageSize.margingTop / Ms::DPI); +// styleRef.set(Ms::Sid::pageOddTopMargin, pageSize.margingTop / Ms::DPI); +// styleRef.set(Ms::Sid::pageEvenBottomMargin, pageSize.margingBottom / Ms::DPI); +// styleRef.set(Ms::Sid::pageOddBottomMargin, pageSize.margingBottom / Ms::DPI); + + m_score->setUpdateAll(); + m_score->doLayout(); + + return true; +} + +void Notation::paint(QPainter* p, const QRect& r) +{ + const QList& mspages = m_score->pages(); + + if (mspages.isEmpty()) { + p->drawText(10, 10, "no pages"); + return; + } + + Ms::Page* page = mspages.first(); + page->draw(p); + + p->fillRect(page->bbox(), QColor("#ffffff")); + + QList ell = page->elements(); + for (const Ms::Element* e : ell) { + if (!e->visible()) { + continue; + } + + e->itemDiscovered = false; + QPointF pos(e->pagePos()); + //LOGI() << e->name() << ", x: " << pos.x() << ", y: " << pos.y() << "\n"; + + p->translate(pos); + + e->draw(p); + + p->translate(-pos); + } +} diff --git a/mu4/domain/notation/notation.h b/mu4/domain/notation/notation.h new file mode 100644 index 0000000000..c643d6b936 --- /dev/null +++ b/mu4/domain/notation/notation.h @@ -0,0 +1,52 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_DOMAIN_NOTATION_H +#define MU_DOMAIN_NOTATION_H + +#include "interfaces/inotation.h" + +namespace Ms { +class MScore; +class MasterScore; +} + +namespace mu { +namespace domain { +namespace notation { +class Notation : public INotation +{ +public: + Notation(); + + //! NOTE Needed at the moment to initialize libmscore + static void init(); + + bool load(const std::string& path, const Params& params) override; + void paint(QPainter* p, const QRect& r) override; + +private: + + Ms::MScore* m_scoreGlobal = nullptr; + Ms::MasterScore* m_score = nullptr; +}; +} +} +} + +#endif // MU_DOMAIN_NOTATION_H diff --git a/mu4/domain/notation/notationcreator.cpp b/mu4/domain/notation/notationcreator.cpp new file mode 100644 index 0000000000..2e4f45aa00 --- /dev/null +++ b/mu4/domain/notation/notationcreator.cpp @@ -0,0 +1,28 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "notationcreator.h" + +#include "notation.h" + +using namespace mu::domain::notation; + +std::shared_ptr NotationCreator::newNotation() +{ + return std::make_shared(); +} diff --git a/mu4/domain/notation/notationcreator.h b/mu4/domain/notation/notationcreator.h new file mode 100644 index 0000000000..dca7b51ca9 --- /dev/null +++ b/mu4/domain/notation/notationcreator.h @@ -0,0 +1,38 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_DOMAIN_NOTATIONCREATOR_H +#define MU_DOMAIN_NOTATIONCREATOR_H + +#include "interfaces/inotationcreator.h" + +namespace mu { +namespace domain { +namespace notation { +class NotationCreator : public INotationCreator +{ +public: + NotationCreator() = default; + + std::shared_ptr newNotation() override; +}; +} +} +} + +#endif // MU_DOMAIN_NOTATIONCREATOR_H diff --git a/mu4/domain/notation/notationdomainmodule.cpp b/mu4/domain/notation/notationdomainmodule.cpp new file mode 100644 index 0000000000..0d73d5bb84 --- /dev/null +++ b/mu4/domain/notation/notationdomainmodule.cpp @@ -0,0 +1,40 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "notationdomainmodule.h" + +#include "modularity/ioc.h" +#include "notationcreator.h" +#include "notation.h" + +using namespace mu::domain::notation; + +std::string NotationDomainModule::moduleName() const +{ + return "notation"; +} + +void NotationDomainModule::registerExports() +{ + framework::ioc()->registerExport(moduleName(), new NotationCreator()); +} + +void NotationDomainModule::onInit() +{ + Notation::init(); +} diff --git a/mu4/domain/notation/notationdomainmodule.h b/mu4/domain/notation/notationdomainmodule.h new file mode 100644 index 0000000000..39d23e0f69 --- /dev/null +++ b/mu4/domain/notation/notationdomainmodule.h @@ -0,0 +1,40 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_DOMAIN_NOTATIONMODULE_H +#define MU_DOMAIN_NOTATIONMODULE_H + +#include "modularity/imodulesetup.h" + +namespace mu { +namespace domain { +namespace notation { +class NotationDomainModule : public framework::IModuleSetup +{ +public: + + std::string moduleName() const; + + void registerExports() override; + void onInit() override; +}; +} +} +} + +#endif // MU_DOMAIN_NOTATIONMODULE_H diff --git a/mu4/domain/tracks/.keep b/mu4/domain/tracks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mu4/extensions/qml/MuseScore/Extensions/ExtensionsModule.qml b/mu4/extensions/qml/MuseScore/Extensions/ExtensionsModule.qml index 6f25517382..fe590d8e83 100644 --- a/mu4/extensions/qml/MuseScore/Extensions/ExtensionsModule.qml +++ b/mu4/extensions/qml/MuseScore/Extensions/ExtensionsModule.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 Rectangle { Text { diff --git a/mu4/scenes/notation/CMakeLists.txt b/mu4/scenes/notation/CMakeLists.txt new file mode 100644 index 0000000000..fd12286ec6 --- /dev/null +++ b/mu4/scenes/notation/CMakeLists.txt @@ -0,0 +1,40 @@ +#============================================================================= +# MuseScore +# Music Composition & Notation +# +# Copyright (C) 2020 MuseScore BVBA and others +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#============================================================================= + +set(MODULE notation_scene) + +set(MODULE_QRC + ${CMAKE_CURRENT_LIST_DIR}/view/notation_view.qrc + ) + +set(MODULE_QML_IMPORT ${CMAKE_CURRENT_LIST_DIR}/view/qml) + +include(${CMAKE_CURRENT_LIST_DIR}/view/notationview.cmake) + +set(MODULE_SRC + ${NOTATIONVIEW_SRC} + ${CMAKE_CURRENT_LIST_DIR}/notationscenemodule.cpp + ${CMAKE_CURRENT_LIST_DIR}/notationscenemodule.h + ) + +include(${PROJECT_SOURCE_DIR}/build/module.cmake) + + + + diff --git a/mu4/scenes/notation/inspector/.keep b/mu4/scenes/notation/inspector/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mu4/scenes/notation/notationscenemodule.cpp b/mu4/scenes/notation/notationscenemodule.cpp new file mode 100644 index 0000000000..429d18e6a4 --- /dev/null +++ b/mu4/scenes/notation/notationscenemodule.cpp @@ -0,0 +1,59 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "notationscenemodule.h" + +#include "view/notationpaintview.h" + +using namespace mu::scene::notation; + +static void notation_view_init_qrc() +{ + Q_INIT_RESOURCE(notation_view); +} + +NotationSceneModule::NotationSceneModule() +{ + +} + +std::string NotationSceneModule::moduleName() const +{ + return "notation_scene"; +} + +void NotationSceneModule::registerExports() +{ + +} + +void NotationSceneModule::resolveImports() +{ + +} + +void NotationSceneModule::registerResources() +{ + notation_view_init_qrc(); +} + +void NotationSceneModule::registerUiTypes() +{ + qmlRegisterType("MuseScore.NotationScene", 1, 0, "NotationPaintView"); +} + diff --git a/mu4/scenes/notation/notationscenemodule.h b/mu4/scenes/notation/notationscenemodule.h new file mode 100644 index 0000000000..6fc3efc818 --- /dev/null +++ b/mu4/scenes/notation/notationscenemodule.h @@ -0,0 +1,45 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_NOTATION_NOTATIONSCENEMODULE_H +#define MU_NOTATION_NOTATIONSCENEMODULE_H + +#include "modularity/imodulesetup.h" + +namespace mu { +namespace scene { +namespace notation { +class NotationSceneModule : public framework::IModuleSetup +{ +public: + + NotationSceneModule(); + + std::string moduleName() const override; + + void registerExports() override; + void resolveImports() override; + + void registerResources() override; + void registerUiTypes() override; +}; +} +} +} + +#endif // MU_NOTATION_NOTATIONSCENEMODULE_H diff --git a/mu4/scenes/notation/palette/.keep b/mu4/scenes/notation/palette/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mu4/scenes/notation/view/notation_view.qrc b/mu4/scenes/notation/view/notation_view.qrc new file mode 100644 index 0000000000..e848b4a5d5 --- /dev/null +++ b/mu4/scenes/notation/view/notation_view.qrc @@ -0,0 +1,6 @@ + + + qml/MuseScore/NotationScene/NotationView.qml + qml/MuseScore/NotationScene/qmldir + + diff --git a/mu4/scenes/notation/view/notationpaintview.cpp b/mu4/scenes/notation/view/notationpaintview.cpp new file mode 100644 index 0000000000..9140ac851a --- /dev/null +++ b/mu4/scenes/notation/view/notationpaintview.cpp @@ -0,0 +1,170 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "notationpaintview.h" + +#include +#include + +#include "log.h" +#include "notationviewinputcontroller.h" + +using namespace mu::scene::notation; + +static constexpr int PREF_UI_CANVAS_MISC_SELECTIONPROXIMITY = 6; + +NotationPaintView::NotationPaintView() : + QQuickPaintedItem() +{ + setFlag(ItemHasContents, true); + setAcceptedMouseButtons(Qt::AllButtons); + + //! TODO + double mag = 0.267;//preferences.getDouble(PREF_SCORE_MAGNIFICATION) * (mscore->physicalDotsPerInch() / DPI); + m_matrix = QTransform::fromScale(mag, mag); + + m_inputController = new NotationViewInputController(this); +} + +void NotationPaintView::cmd(const QString& name) +{ + //! NOTE Temporary + if ("open" == name) { + open(); + } +} + +//! NOTE Temporary method for tests +void NotationPaintView::open() +{ + QString filePath = interactive()->selectOpeningFile("Score", "", ""); + if (filePath.isEmpty()) { + return; + } + + m_notation = notationCreator()->newNotation(); + IF_ASSERT_FAILED(m_notation) { + return; + } + + domain::notation::INotation::Params params; + params.pageSize.width = width(); + params.pageSize.height = height(); + bool ok = m_notation->load(filePath.toStdString(), params); + if (!ok) { + LOGE() << "failed load: " << filePath; + } + + update(); +} + +void NotationPaintView::paint(QPainter* p) +{ + QRect rect(0, 0, width(), height()); + p->fillRect(rect, QColor("#D6E0E9")); + + p->setTransform(m_matrix); + + if (m_notation) { + m_notation->paint(p, rect); + } else { + p->drawText(10, 10, "no notation"); + } +} + +void NotationPaintView::moveScene(int dx, int dy) +{ + m_matrix.translate(dx, dy); + update(); +} + +void NotationPaintView::scrollVertical(int dy) +{ + m_matrix.translate(0, dy); + update(); +} + +void NotationPaintView::scrollHorizontal(int dx) +{ + m_matrix.translate(dx, 0); + update(); +} + +void NotationPaintView::zoomStep(qreal step, const QPoint& pos) +{ + qreal mag = m_matrix.m11(); + mag *= qPow(1.1, step); + zoom(mag, pos); +} + +void NotationPaintView::zoom(qreal mag, const QPoint& pos) +{ + //! TODO Zoom to point not completed + mag = qBound(0.05, mag, 16.0); + + qreal cmag = m_matrix.m11(); + if (qFuzzyCompare(mag, cmag)) { + return; + } + + qreal deltamag = mag / mag; + + QPointF p1 = m_matrix.inverted().map(pos); + + m_matrix.setMatrix(mag, m_matrix.m12(), m_matrix.m13(), m_matrix.m21(), + mag, m_matrix.m23(), m_matrix.dx() * deltamag, m_matrix.dy() * deltamag, m_matrix.m33()); + + QPointF p2 = m_matrix.inverted().map(pos); + QPointF p3 = p2 - p1; + int dx = std::lrint(p3.x() * cmag); + int dy = std::lrint(p3.y() * cmag); + + m_matrix.translate(dx, dy); + + update(); +} + +void NotationPaintView::wheelEvent(QWheelEvent* ev) +{ + m_inputController->wheelEvent(ev); +} + +void NotationPaintView::mousePressEvent(QMouseEvent* ev) +{ + m_inputController->mousePressEvent(ev); +} + +void NotationPaintView::mouseMoveEvent(QMouseEvent* ev) +{ + m_inputController->mouseMoveEvent(ev); +} + +void NotationPaintView::mouseReleaseEvent(QMouseEvent* ev) +{ + m_inputController->mouseReleaseEvent(ev); +} + +QPoint NotationPaintView::toLogical(const QPoint& p) const +{ + return m_matrix.inverted().map(p); +} + +QPoint NotationPaintView::toPhysical(const QPoint& p) const +{ + return m_matrix.map(p); +} diff --git a/mu4/scenes/notation/view/notationpaintview.h b/mu4/scenes/notation/view/notationpaintview.h new file mode 100644 index 0000000000..44e68938cf --- /dev/null +++ b/mu4/scenes/notation/view/notationpaintview.h @@ -0,0 +1,80 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_NOTATIONSCENE_NOTATIONPAINTVIEW_H +#define MU_NOTATIONSCENE_NOTATIONPAINTVIEW_H + +#include +#include +#include + +#include "modularity/ioc.h" +#include "interfaces/iinteractive.h" +#include "domain/notation/interfaces/inotationcreator.h" + +namespace mu { +namespace scene { +namespace notation { +class NotationViewInputController; +class NotationPaintView : public QQuickPaintedItem +{ + Q_OBJECT + + INJECT(notation, framework::IInteractive, interactive) + INJECT(notation, domain::notation::INotationCreator, notationCreator) + +public: + NotationPaintView(); + + Q_INVOKABLE void cmd(const QString& name); + + void open(); + + // Draw + void paint(QPainter* painter) override; + + // Input + void wheelEvent(QWheelEvent*) override; + void mousePressEvent(QMouseEvent*) override; + void mouseMoveEvent(QMouseEvent*) override; + void mouseReleaseEvent(QMouseEvent*) override; + +private: + + friend class NotationViewInputController; + + QPoint toLogical(const QPoint& p) const; + QPoint toPhysical(const QPoint& p) const; + + void moveScene(int dx, int dy); + void scrollVertical(int dy); + void scrollHorizontal(int dx); + void zoomStep(qreal step, const QPoint& pos); + void zoom(qreal mag, const QPoint& pos); + + // --- + + std::shared_ptr m_notation; + QTransform m_matrix; + NotationViewInputController* m_inputController = nullptr; +}; +} +} +} + +#endif // MU_NOTATIONSCENE_NOTATIONPAINTVIEW_H diff --git a/mu4/scenes/notation/view/notationview.cmake b/mu4/scenes/notation/view/notationview.cmake new file mode 100644 index 0000000000..9ac1244bb1 --- /dev/null +++ b/mu4/scenes/notation/view/notationview.cmake @@ -0,0 +1,7 @@ + +set (NOTATIONVIEW_SRC + ${CMAKE_CURRENT_LIST_DIR}/notationpaintview.cpp + ${CMAKE_CURRENT_LIST_DIR}/notationpaintview.h + ${CMAKE_CURRENT_LIST_DIR}/notationviewinputcontroller.cpp + ${CMAKE_CURRENT_LIST_DIR}/notationviewinputcontroller.h + ) diff --git a/mu4/scenes/notation/view/notationviewinputcontroller.cpp b/mu4/scenes/notation/view/notationviewinputcontroller.cpp new file mode 100644 index 0000000000..a5376bfa79 --- /dev/null +++ b/mu4/scenes/notation/view/notationviewinputcontroller.cpp @@ -0,0 +1,85 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#include "notationviewinputcontroller.h" + +#include "log.h" +#include "notationpaintview.h" + +using namespace mu::scene::notation; + +static constexpr int PIXELSSTEPSFACTOR = 5; + +NotationViewInputController::NotationViewInputController(NotationPaintView* view) : + m_view(view) +{ +} + +void NotationViewInputController::wheelEvent(QWheelEvent* ev) +{ + QPoint pixelsScrolled = ev->pixelDelta(); + QPoint stepsScrolled = ev->angleDelta(); + + int dx = 0; + int dy = 0; + qreal steps = 0.0; + + if (!pixelsScrolled.isNull()) { + dx = pixelsScrolled.x(); + dy = pixelsScrolled.y(); + steps = static_cast(dy) / static_cast(PIXELSSTEPSFACTOR); + } else if (!stepsScrolled.isNull()) { + dx = (stepsScrolled.x() * qMax(2.0, m_view->width() / 10.0)) / 120; + dy = (stepsScrolled.y() * qMax(2.0, m_view->height() / 10.0)) / 120; + steps = static_cast(stepsScrolled.y()) / 120.0; + } + + // Windows touch pad pinches also execute this + if (ev->modifiers() & Qt::ControlModifier) { + m_view->zoomStep(steps, m_view->toLogical(ev->pos())); + } else if (ev->modifiers() & Qt::ShiftModifier && dx == 0) { + dx = dy; + m_view->scrollHorizontal(dx); + } else { + m_view->scrollVertical(dy); + } +} + +void NotationViewInputController::mousePressEvent(QMouseEvent* ev) +{ + QPoint logicPos = m_view->toLogical(ev->pos()); + m_interactData.beginPoint = logicPos; +} + +void NotationViewInputController::mouseMoveEvent(QMouseEvent* ev) +{ + QPoint pos = m_view->toLogical(ev->pos()); + QPoint d = pos - m_interactData.beginPoint; + int dx = d.x(); + int dy = d.y(); + + if (dx == 0 && dy == 0) { + return; + } + + m_view->moveScene(dx, dy); +} + +void NotationViewInputController::mouseReleaseEvent(QMouseEvent* /*ev*/) +{ +} diff --git a/mu4/scenes/notation/view/notationviewinputcontroller.h b/mu4/scenes/notation/view/notationviewinputcontroller.h new file mode 100644 index 0000000000..4451ff75b3 --- /dev/null +++ b/mu4/scenes/notation/view/notationviewinputcontroller.h @@ -0,0 +1,50 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 MuseScore BVBA and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= +#ifndef MU_NOTATIONSCENE_NOTATIONVIEWINPUTCONTROLLER_H +#define MU_NOTATIONSCENE_NOTATIONVIEWINPUTCONTROLLER_H + +#include + +namespace mu { +namespace scene { +namespace notation { +class NotationPaintView; +class NotationViewInputController +{ +public: + NotationViewInputController(NotationPaintView* view); + + void wheelEvent(QWheelEvent* ev); + void mousePressEvent(QMouseEvent* ev); + void mouseMoveEvent(QMouseEvent* ev); + void mouseReleaseEvent(QMouseEvent* ev); + +private: + + struct InteractData { + QPoint beginPoint; + }; + + NotationPaintView* m_view = nullptr; + InteractData m_interactData; +}; +} +} +} +#endif // MU_NOTATIONSCENE_NOTATIONVIEWINPUTCONTROLLER_H diff --git a/mu4/scenes/notation/view/qml/MuseScore/NotationScene/NotationView.qml b/mu4/scenes/notation/view/qml/MuseScore/NotationScene/NotationView.qml new file mode 100644 index 0000000000..7b3149b650 --- /dev/null +++ b/mu4/scenes/notation/view/qml/MuseScore/NotationScene/NotationView.qml @@ -0,0 +1,17 @@ +import QtQuick 2.7 +import MuseScore.NotationScene 1.0 + +Rectangle { + + id: root + + function cmd(name) { + console.info("cmd: " + name) + view.cmd(name); + } + + NotationPaintView { + id: view + anchors.fill: parent + } +} diff --git a/mu4/scenes/notation/view/qml/MuseScore/NotationScene/qmldir b/mu4/scenes/notation/view/qml/MuseScore/NotationScene/qmldir new file mode 100644 index 0000000000..5011386233 --- /dev/null +++ b/mu4/scenes/notation/view/qml/MuseScore/NotationScene/qmldir @@ -0,0 +1,2 @@ +module MuseScore.NotationScene +NotationView 1.0 NotationView.qml diff --git a/mu4/scores/qml/MuseScore/Scores/ScoresModule.qml b/mu4/scores/qml/MuseScore/Scores/ScoresModule.qml index cf35f6a2c9..bb7dc5f9fa 100644 --- a/mu4/scores/qml/MuseScore/Scores/ScoresModule.qml +++ b/mu4/scores/qml/MuseScore/Scores/ScoresModule.qml @@ -1,4 +1,4 @@ -import QtQuick 2.9 +import QtQuick 2.7 Rectangle { Text {