Skip to content

Commit

Permalink
[4.4.2] added websocket api
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Sep 9, 2024
1 parent f015c65 commit 5d75bf5
Show file tree
Hide file tree
Showing 20 changed files with 543 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ if (MUE_COMPILE_MACOS_PRECOMPILED_DEPS_PATH)
endif()

set(QT_MIN_VERSION "6.2.4")
if (MUSE_MODULE_NETWORK_WEBSOCKET)
set(QT_ADD_WEBSOCKET ON)
endif()

include(FindQt6)

if (MUE_DOWNLOAD_SOUNDFONT)
Expand Down
1 change: 1 addition & 0 deletions buildscripts/ci/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ MUSESCORE_BUILD_VST_MODULE=$BUILD_VST \
MUSESCORE_VST3_SDK_PATH=$VST3_SDK_PATH \
MUSESCORE_BUILD_CRASHPAD_CLIENT=${MUSESCORE_BUILD_CRASHPAD_CLIENT:-"ON"} \
MUSESCORE_BUILD_UPDATE_MODULE=${MUSESCORE_BUILD_UPDATE_MODULE:-"ON"} \
MUSESCORE_BUILD_WEBSOCKET="ON" \
bash ./ninja_build.sh -t appimage


Expand Down
3 changes: 2 additions & 1 deletion buildscripts/ci/linux/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ sudo apt-get install -y --no-install-recommends \

# Get newer Qt (only used cached version if it is the same)
qt_version="624"
qt_revision="r2" # added websocket module
qt_dir="$BUILD_TOOLS/Qt/${qt_version}"
if [[ ! -d "${qt_dir}" ]]; then
mkdir -p "${qt_dir}"
qt_url="https://s3.amazonaws.com/utils.musescore.org/Qt${qt_version}_gcc64.7z"
qt_url="https://s3.amazonaws.com/utils.musescore.org/Qt${qt_version}_gcc64_${qt_revision}.7z"
wget -q --show-progress -O qt.7z "${qt_url}"
7z x -y qt.7z -o"${qt_dir}"
rm qt.7z
Expand Down
1 change: 1 addition & 0 deletions buildscripts/ci/macos/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MUSESCORE_REVISION=$MUSESCORE_REVISION \
MUSESCORE_CRASHREPORT_URL=$CRASH_REPORT_URL \
MUSESCORE_BUILD_VST_MODULE=$BUILD_VST \
MUSESCORE_VST3_SDK_PATH=$VST3_SDK_PATH \
MUSESCORE_BUILD_WEBSOCKET="ON" \
bash ./ninja_build.sh -t install

bash ./buildscripts/ci/tools/make_release_channel_env.sh -c $MUSE_APP_BUILD_MODE
Expand Down
3 changes: 2 additions & 1 deletion buildscripts/ci/macos/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ echo "Download Qt $QT_SHORT_VERSION"
export QT_PATH=$HOME/Qt/$QT_SHORT_VERSION/
export PATH=$PATH:$QT_PATH/macos/bin
echo "PATH=$PATH" >> $GITHUB_ENV
wget -nv -O qt.7z https://s3.amazonaws.com/utils.musescore.org/Qt624_mac.7z
# r2 - added websocket support
wget -nv -O qt.7z https://s3.amazonaws.com/utils.musescore.org/Qt624_mac_r2.7z
mkdir -p $QT_PATH
7z x -y qt.7z -o$QT_PATH
rm qt.7z
Expand Down
1 change: 1 addition & 0 deletions buildscripts/ci/windows/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ SET MUSESCORE_INSTALL_DIR=%INSTALL_DIR%
SET MUSESCORE_CRASHREPORT_URL="%CRASH_LOG_SERVER_URL%"
SET MUSESCORE_BUILD_VST_MODULE=%BUILD_VST%
SET MUSESCORE_VST3_SDK_PATH=%VST3_SDK_PATH%
SET MUSESCORE_BUILD_WEBSOCKET="ON"

CALL ninja_build.bat -t installrelwithdebinfo || exit \b 1

Expand Down
3 changes: 2 additions & 1 deletion buildscripts/ci/windows/setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ MKDIR %TEMP_DIR%
:: Install Qt
ECHO "=== Install Qt ==="

SET "Qt_ARCHIVE=Qt624_msvc2019_64.7z"
:: r2 - added websocket module
SET "Qt_ARCHIVE=Qt624_msvc2019_64_r2.7z"
SET "QT_DIR=C:\Qt\6.2.4"
SET "QT_URL=https://s3.amazonaws.com/utils.musescore.org/%Qt_ARCHIVE%"

Expand Down
7 changes: 7 additions & 0 deletions buildscripts/cmake/FindQt6.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ if (OS_IS_LIN)
)
endif()

if (QT_ADD_WEBSOCKET)
set(_components
${_components}
WebSockets
)
endif()

foreach(_component ${_components})
find_package(Qt6${_component} REQUIRED)
list(APPEND QT_LIBRARIES ${Qt6${_component}_LIBRARIES})
Expand Down
2 changes: 2 additions & 0 deletions ninja_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MUSESCORE_NO_RPATH=${MUSESCORE_NO_RPATH:-"OFF"}
MUSESCORE_MODULE_UPDATE=${MUSESCORE_MODULE_UPDATEE:-"ON"}
MUSESCORE_BUILD_VST_MODULE=${MUSESCORE_BUILD_VST_MODULE:-"OFF"}
MUSESCORE_BUILD_VIDEOEXPORT_MODULE=${MUSESCORE_BUILD_VIDEOEXPORT_MODULE:-"OFF"}
MUSESCORE_BUILD_WEBSOCKET=${MUSESCORE_BUILD_WEBSOCKET:-"OFF"}

SHOW_HELP=0
while [[ "$#" -gt 0 ]]; do
Expand Down Expand Up @@ -99,6 +100,7 @@ function do_build() {
-DMUSE_MODULE_GLOBAL_LOGGER_DEBUGLEVEL="${MUSESCORE_DEBUGLEVEL_ENABLED}" \
-DMUSE_MODULE_VST="${MUSESCORE_BUILD_VST_MODULE}" \
-DMUSE_MODULE_VST_VST3_SDK_PATH="${MUSESCORE_VST3_SDK_PATH}" \
-DMUSE_MODULE_NETWORK_WEBSOCKET="${MUSESCORE_BUILD_WEBSOCKET}" \
-DCMAKE_SKIP_RPATH="${MUSESCORE_NO_RPATH}" \


Expand Down
73 changes: 73 additions & 0 deletions share/plugins/dev_test_websocket/dev_test_websocket.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see <https://www.gnu.org/licenses/>.
*/

import QtQuick 2.2
import MuseScore 3.0

MuseScore {

id: root

title: "Test WebSocket"

property int connectedToServerSocketId: -1
property int clientSocketId: -1

function onMessageToServer(msg) {
console.log("received message to server: " + msg)
}

function onMessageToClient(msg) {
console.log("received message to client: " + msg)
}

function onConnected() {
// NOTE Send message from client to server
api.websocket.send(root.clientSocketId, "msg from client")

// NOTE Send message from server to client
api.websocketserver.send(root.connectedToServerSocketId, "msg from server")
}

onRun: {
console.log("Run " + root.title);

//! NOTE Listen server
api.websocketserver.listen(8084, function(id) {
console.log("new connected to server, client id: " + id);
if (root.connectedToServerSocketId === -1) {
root.connectedToServerSocketId = id;
api.websocketserver.onMessage(root.connectedToServerSocketId, root.onMessageToServer)
}
})

//! NOTE Open client
api.websocket.open(8084, function(id) {
console.log("connected socket id: " + id);
root.clientSocketId = id;

api.websocket.onMessage(root.clientSocketId, root.onMessageToClient)

root.onConnected()
});
}
}
3 changes: 3 additions & 0 deletions src/framework/cmake/MuseDeclareOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ declare_muse_module_opt(MIDI ON)
declare_muse_module_opt(MPE ON)
declare_muse_module_opt(MULTIINSTANCES ON)
declare_muse_module_opt(MUSESAMPLER ON)

declare_muse_module_opt(NETWORK ON)
option(MUSE_MODULE_NETWORK_WEBSOCKET "Enable websocket support" OFF)

declare_muse_module_opt(SHORTCUTS ON)

declare_muse_module_opt(UI ON)
Expand Down
6 changes: 6 additions & 0 deletions src/framework/extensions/api/extapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ExtApi : public QObject
//Q_PROPERTY(QJSValue process READ process CONSTANT)
//Q_PROPERTY(QJSValue filesystem READ filesystem CONSTANT)

Q_PROPERTY(QJSValue websocket READ websocket CONSTANT)
Q_PROPERTY(QJSValue websocketserver READ websocketserver CONSTANT)

Inject<muse::api::IApiRegister> apiRegister;

public:
Expand All @@ -68,6 +71,9 @@ class ExtApi : public QObject
QJSValue keyboard() const { return api("api.keyboard"); }
QJSValue accessibility() const { return api("api.accessibility"); }

QJSValue websocket() const { return api("api.websocket"); }
QJSValue websocketserver() const { return api("api.websocketserver"); }

private:
QJSValue api(const std::string& name) const;

Expand Down
5 changes: 5 additions & 0 deletions src/framework/extensions/api/v1/extapiv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class ExtApiV1 : public QObject
Q_PROPERTY(QJSValue log READ log CONSTANT)
Q_PROPERTY(QJSValue engraving READ engraving CONSTANT)

Q_PROPERTY(QJSValue websocket READ websocket CONSTANT)
Q_PROPERTY(QJSValue websocketserver READ websocketserver CONSTANT)

Inject<muse::api::IApiRegister> apiRegister;

public:
Expand All @@ -47,6 +50,8 @@ class ExtApiV1 : public QObject

QJSValue log() const { return api("api.log"); }
QJSValue engraving() const { return api("api.engraving.v1"); }
QJSValue websocket() const { return api("api.websocket"); }
QJSValue websocketserver() const { return api("api.websocketserver"); }

static void registerQmlTypes();

Expand Down
12 changes: 12 additions & 0 deletions src/framework/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/networktypes.h
${CMAKE_CURRENT_LIST_DIR}/inetworkmanager.h
${CMAKE_CURRENT_LIST_DIR}/inetworkmanagercreator.h

${CMAKE_CURRENT_LIST_DIR}/internal/networkmanager.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/networkmanager.h
${CMAKE_CURRENT_LIST_DIR}/internal/networkmanagercreator.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/networkmanagercreator.h
)

if (MUSE_MODULE_NETWORK_WEBSOCKET)
set(MODULE_SRC ${MODULE_SRC}
${CMAKE_CURRENT_LIST_DIR}/api/websocketapi.cpp
${CMAKE_CURRENT_LIST_DIR}/api/websocketapi.h
${CMAKE_CURRENT_LIST_DIR}/api/websocketserverapi.cpp
${CMAKE_CURRENT_LIST_DIR}/api/websocketserverapi.h
)

set(MODULE_DEF -DMUSE_MODULE_NETWORK_WEBSOCKET)
endif()

setup_module()

if (MUSE_MODULE_NETWORK_TESTS)
Expand Down
Loading

0 comments on commit 5d75bf5

Please sign in to comment.