Skip to content

Commit

Permalink
experimental WASM build
Browse files Browse the repository at this point in the history
  • Loading branch information
psmokotnin authored and vpereverzev committed Dec 24, 2020
1 parent 4e7d426 commit 6fdcf30
Show file tree
Hide file tree
Showing 43 changed files with 552 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ MuseScore_General_License.md
MuseScore_General_Changelog.txt
MuseScore_General_Readme.md
VERSION
SF_VERSION
/mscore/data/mscore.aps
/msvc.*
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ endif(BUILD_JACK)

if (BUILD_AUTOUPDATE)

if (APPLE)
if (OS_IS_MAC)
set(MAC_APPCAST_URL "")
endif (APPLE)
endif (OS_IS_MAC)

include(SetupSparkle)
endif(BUILD_AUTOUPDATE)
Expand Down
4 changes: 2 additions & 2 deletions build/cmake/DownloadSoundFont.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


set (SF_VERSION_REMOTE_FILE ${PROJECT_BINARY_DIR}/VERSION)
set (SF_VERSION_LOCAL_FILE ${PROJECT_SOURCE_DIR}/share/sound/VERSION)
set (SF_VERSION_REMOTE_FILE ${PROJECT_BINARY_DIR}/SF_VERSION)
set (SF_VERSION_LOCAL_FILE ${PROJECT_SOURCE_DIR}/share/sound/SF_VERSION)
set (DOWNLOAD_URL_ROOT "https://ftp.osuosl.org/pub/musescore/soundfont/MuseScore_General")
set (SOUND_DIRECTORY ${PROJECT_SOURCE_DIR}/share/sound)

Expand Down
8 changes: 7 additions & 1 deletion build/cmake/FindQt5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ set(_components
Svg
Widgets
PrintSupport
Concurrent
OpenGL
LinguistTools
)
Expand All @@ -35,6 +34,13 @@ if (USE_WEBENGINE)
)
endif(USE_WEBENGINE)

if (NOT OS_IS_WASM)
set(_components
${_components}
Concurrent
)
endif()

if (WIN32)
set(_components
${_components}
Expand Down
6 changes: 5 additions & 1 deletion build/cmake/GetCompilerInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

include(GetPlatformInfo)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if (OS_IS_WASM)

set(CC_IS_EMSCRIPTEN 1)

elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")

set(CC_IS_CLANG 1)

Expand Down
5 changes: 3 additions & 2 deletions build/cmake/GetPlatformInfo.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
if(${CMAKE_CXX_COMPILER} MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$")
set(OS_IS_WASM 1)
elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
set(OS_IS_WIN 1)
elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
set(OS_IS_LIN 1)
Expand Down
28 changes: 24 additions & 4 deletions build/cmake/SetupBuildEnvironment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ elseif(CC_IS_CLANG)
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")

elseif(CC_IS_EMSCRIPTEN)
message(STATUS "Using Compiler Emscripten ${CMAKE_CXX_COMPILER_VERSION}")

set(EMCC_CMAKE_TOOLCHAIN "" CACHE FILEPATH "Path to EMCC CMake Emscripten.cmake")
set(EMCC_INCLUDE_PATH "." CACHE PATH "Path to EMCC include dir")
set(EMCC_COMPILE_FLAGS "--bind -o .html")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/public_html)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EMCC_COMPILE_FLAGS}")
set(CMAKE_TOOLCHAIN_FILE ${EMCC_CMAKE_TOOLCHAIN})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

#for QtCreator
include_directories(
${EMCC_INCLUDE_PATH}
${EMCC_INCLUDE_PATH}/libcxx
${EMCC_INCLUDE_PATH}/libc
)

else()
message(FATAL_ERROR "Unsupported Compiler CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
endif()
Expand All @@ -84,11 +104,11 @@ endif()


# APPLE specific
if (APPLE)
if (OS_IS_MAC)
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(MACOSX_DEPLOYMENT_TARGET 10.10)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
endif(APPLE)
endif(OS_IS_MAC)


# string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
Expand All @@ -108,9 +128,9 @@ endif(APPLE)
# endif(CMAKE_BUILD_TYPE MATCHES "DEBUG")


#if (APPLE)
#if (OS_IS_MAC)

#else (APPLE)
#else (OS_IS_MAC)
# if (MSVC)
# # Set compiler options for VS2017/19 toolchain.
# # Note: /D_CRT_SECURE_NO WARNINGS disables warnings when using "non-secure" library functions like sscanf...
Expand Down
6 changes: 3 additions & 3 deletions build/cmake/SetupFreetype.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##

if (USE_SYSTEM_FREETYPE)
if (APPLE)
if (OS_IS_MAC)
PKGCONFIG1 (freetype2 2.5.2 FREETYPE_INCLUDE_DIRS FREETYPE_LIBDIR FREETYPE_LIBRARIES FREETYPE_CPP)
if (FREETYPE_INCLUDE_DIRS)
STRING(REGEX REPLACE "\"" "" FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
Expand All @@ -13,9 +13,9 @@ if (USE_SYSTEM_FREETYPE)
else (FREETYPE_INCLUDE_DIRS)
message(FATAL_ERROR "freetype >= 2.5.2 is required\n")
endif (FREETYPE_INCLUDE_DIRS)
else (APPLE)
else (OS_IS_MAC)
find_package(Freetype REQUIRED)
endif (APPLE)
endif (OS_IS_MAC)
endif (USE_SYSTEM_FREETYPE)


Expand Down
6 changes: 5 additions & 1 deletion build/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ if (NOT ${MODULE_QML_IMPORT} STREQUAL "")
set(QML_IMPORT_PATH "${QML_IMPORT_PATH};${MODULE_QML_IMPORT}" CACHE STRING "QtCreator extra import paths for QML modules" FORCE)
endif()

add_library(${MODULE}) # STATIC/SHARED set global in the SetupBuildEnvironment.cmake
if (CC_IS_EMSCRIPTEN)
add_library(${MODULE} OBJECT)
else()
add_library(${MODULE}) # STATIC/SHARED set global in the SetupBuildEnvironment.cmake
endif()

if (BUILD_SHARED_LIBS)
install(TARGETS ${MODULE} DESTINATION ${SHARED_LIBS_INSTALL_DESTINATION})
Expand Down
11 changes: 9 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ add_subdirectory(appshell)
add_subdirectory(awl)
add_subdirectory(audiofile)
add_subdirectory(context)
add_subdirectory(cloud)
add_subdirectory(notation)
add_subdirectory(importexport)
add_subdirectory(userscores)

if (NOT OS_IS_WASM)
add_subdirectory(importexport)
add_subdirectory(cloud)
add_subdirectory(extensions)
add_subdirectory(languages)
add_subdirectory(plugins)
endif()

# Scenes common
add_subdirectory(commonscene)
Expand All @@ -37,3 +40,7 @@ if (BUILD_UNIT_TESTS)
add_subdirectory(userscores/tests)
add_subdirectory(libmscore/tests)
endif(BUILD_UNIT_TESTS)

if (OS_IS_WASM)
add_subdirectory(wasmtest)
endif()
9 changes: 7 additions & 2 deletions src/appshell/appshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ int AppShell::run(int argc, char** argv, std::function<void()> moduleSetup)
//! NOTE Move ownership to UiEngine
framework::UiEngine::instance()->moveQQmlEngine(engine);

#ifndef Q_OS_WASM
QString mainQmlFile = "/Main.qml";
#else
QString mainQmlFile = "/main.wasm.qml";
#endif
#ifdef QML_LOAD_FROM_SOURCE
QUrl url(QString(appshell_QML_IMPORT) + "/Main.qml");
QUrl url(QString(appshell_QML_IMPORT) + mainQmlFile);
#else
const QUrl url(QStringLiteral("qrc:/qml/Main.qml"));
const QUrl url(QStringLiteral("qrc:/qml") + mainQmlFile);
#endif

QObject::connect(engine, &QQmlApplicationEngine::objectCreated,
Expand Down
1 change: 1 addition & 0 deletions src/appshell/appshell.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<file>qml/DevTools/Plugins/PluginsTests.qml</file>
<file>qml/DevTools/Gallery/GeneralComponentsGallery.qml</file>
<file>qml/DevTools/Telemetry/TelemetryInfo.qml</file>
<file>qml/main.wasm.qml</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion src/appshell/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Rectangle {
id: windowLoader
anchors.fill: parent
onStatusChanged: {
item.anchors.fill = item.parent
if (item && item.anchors) item.anchors.fill = item ? item.parent : null
item.visible = true
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/appshell/qml/main.wasm.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import QtQuick 2.0
import QtQuick.Controls 2.2
import MuseScore.NotationScene 1.0
import MuseScore.Playback 1.0

ApplicationWindow {
id: window
width: 640
height: 480

visible: true
title: qsTr("Muse Score")

header: ToolBar {
contentHeight: 40

PlaybackToolBar {
id: playbackToolbar
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
color: ui.theme.backgroundPrimaryColor
}

Label {
text: "position: "
anchors.centerIn: parent
}
}


NotationView {
id: notationView
anchors.fill: parent

Component.onCompleted: {
}
}

}
1 change: 0 additions & 1 deletion src/cloud/internal/cloudmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ void CloudManager::mediaUploadProgress(qint64 progress, qint64 total)
void CloudManager::upload(const QString& path, int nid, const QString& title)
{
qDebug() << "file upload" << nid;

ApiRequest* r = new ApiRequest(this);
r->setPath("/score/upload-light")
.setToken(m_accessToken);
Expand Down
3 changes: 1 addition & 2 deletions src/cloud/internal/cloudmanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
#define MU_CLOUD_CLOUDMANAGER_P_H

#include <QUrlQuery>
#include <QHttpMultiPart>
#include <QNetworkReply>
#include <QEventLoop>

#include <QHttpMultiPart>
#include "config.h"

#ifdef USE_WEBENGINE
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/internal/extensionscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#include "extensionscontroller.h"

#include <QBuffer>
#include <QFile>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QtConcurrent>

#include "log.h"
#include "translation.h"
#include "extensionserrors.h"
Expand All @@ -36,7 +38,6 @@ void ExtensionsController::init()
{
fileSystem()->makePath(configuration()->extensionsSharePath());
fileSystem()->makePath(configuration()->extensionsDataPath());

QtConcurrent::run(this, &ExtensionsController::th_refreshExtensions);
}

Expand Down
5 changes: 5 additions & 0 deletions src/framework/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ elseif(OS_IS_MAC)
${CMAKE_CURRENT_LIST_DIR}/internal/platform/osx/osxaudiodriver.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/platform/osx/osxaudiodriver.h
)
elseif(OS_IS_WASM)
set(DRIVER_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/platform/web/webaudiodriver.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/platform/web/webaudiodriver.h
)
endif()

set(MODULE_SRC
Expand Down
10 changes: 10 additions & 0 deletions src/framework/audio/audiomodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#include "internal/platform/osx/osxaudiodriver.h"
#endif

#ifdef Q_OS_WASM
#include "internal/platform/web/webaudiodriver.h"
#endif

using namespace mu::audio;
using namespace mu::audio::worker;

Expand Down Expand Up @@ -76,6 +80,10 @@ void AudioModule::registerExports()
#ifdef Q_OS_MACOS
framework::ioc()->registerExport<IAudioDriver>(moduleName(), new OSXAudioDriver());
#endif

#ifdef Q_OS_WASM
framework::ioc()->registerExport<IAudioDriver>(moduleName(), new WebAudioDriver());
#endif
}

void AudioModule::registerUiTypes()
Expand All @@ -100,7 +108,9 @@ void AudioModule::onInit()
});
});

#ifndef Q_OS_WASM
s_worker->run();
#endif
}

void AudioModule::onDeinit()
Expand Down
47 changes: 47 additions & 0 deletions src/framework/audio/internal/platform/web/webaudiodriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//=============================================================================
// 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 "webaudiodriver.h"

using namespace mu::audio;

WebAudioDriver::WebAudioDriver()
{
}

std::string WebAudioDriver::name() const
{
return "MUAUDIO(WEB)";
}

bool WebAudioDriver::open(const Spec& spec, Spec* activeSpec)
{
//TODO:
m_opened = true;
return m_opened;
}

void WebAudioDriver::close()
{
//TODO:
}

bool WebAudioDriver::isOpened() const
{
return m_opened;
}
Loading

0 comments on commit 6fdcf30

Please sign in to comment.