-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
557 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* MuseScore-CLA-applies | ||
* | ||
* MuseScore | ||
* Music Composition & Notation | ||
* | ||
* Copyright (C) 2024 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 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/>. | ||
*/ | ||
#pragma once | ||
|
||
#include "modularity/imoduleinterface.h" | ||
|
||
#include "network/networktypes.h" | ||
|
||
namespace mu::musesounds { | ||
class IMuseSoundsConfiguration : MODULE_EXPORT_INTERFACE | ||
{ | ||
INTERFACE_ID(IMuseSoundsConfiguration) | ||
|
||
public: | ||
virtual ~IMuseSoundsConfiguration() = default; | ||
|
||
virtual muse::network::RequestHeaders headers() const = 0; | ||
|
||
virtual QUrl soundsUrl() const = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* MuseScore-CLA-applies | ||
* | ||
* MuseScore | ||
* Music Composition & Notation | ||
* | ||
* Copyright (C) 2024 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 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/>. | ||
*/ | ||
#pragma once | ||
|
||
#include "modularity/imoduleinterface.h" | ||
|
||
#include "async/notification.h" | ||
#include "musesoundstypes.h" | ||
|
||
namespace mu::musesounds { | ||
class IMuseSoundsRepository : MODULE_EXPORT_INTERFACE | ||
{ | ||
INTERFACE_ID(IMuseSoundsRepository) | ||
|
||
public: | ||
virtual ~IMuseSoundsRepository() = default; | ||
|
||
virtual const MuseSoundCategoryInfoList& soundsCategoryList() const = 0; | ||
virtual muse::async::Notification soundsCategoryListChanged() const = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* MuseScore-CLA-applies | ||
* | ||
* MuseScore | ||
* Music Composition & Notation | ||
* | ||
* Copyright (C) 2024 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 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/>. | ||
*/ | ||
#include "musesoundsconfiguration.h" | ||
|
||
#include "settings.h" | ||
|
||
using namespace mu::musesounds; | ||
using namespace muse; | ||
using namespace muse::network; | ||
|
||
static const std::string module_name("musesounds"); | ||
static const Settings::Key GET_SOUNDS_TESTING_MODE_KEY(module_name, "musesounds/getSoundsTestingMode"); | ||
|
||
void MuseSoundsConfiguration::init() | ||
{ | ||
settings()->setDefaultValue(GET_SOUNDS_TESTING_MODE_KEY, Val(false)); | ||
} | ||
|
||
RequestHeaders MuseSoundsConfiguration::headers() const | ||
{ | ||
RequestHeaders headers; | ||
headers.rawHeaders["Accept"] = "application/json"; | ||
return headers; | ||
} | ||
|
||
QUrl MuseSoundsConfiguration::soundsUrl() const | ||
{ | ||
return !isTestingMode() ? QUrl("https://cosmos-customer-webservice.azurewebsites.net/graphql") | ||
: QUrl("https://cosmos-customer-webservice-dev.azurewebsites.net/graphql"); | ||
} | ||
|
||
bool MuseSoundsConfiguration::isTestingMode() const | ||
{ | ||
return settings()->value(GET_SOUNDS_TESTING_MODE_KEY).toBool(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* MuseScore-CLA-applies | ||
* | ||
* MuseScore | ||
* Music Composition & Notation | ||
* | ||
* Copyright (C) 2024 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 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/>. | ||
*/ | ||
#pragma once | ||
|
||
#include "modularity/ioc.h" | ||
#include "iglobalconfiguration.h" | ||
|
||
#include "imusesoundsconfiguration.h" | ||
|
||
namespace mu::musesounds { | ||
class MuseSoundsConfiguration : public IMuseSoundsConfiguration, public muse::Injectable | ||
{ | ||
Inject<muse::IGlobalConfiguration> globalConfiguration = { this }; | ||
|
||
public: | ||
MuseSoundsConfiguration(const muse::modularity::ContextPtr& iocCtx) | ||
: Injectable(iocCtx) {} | ||
|
||
void init(); | ||
|
||
muse::network::RequestHeaders headers() const override; | ||
|
||
QUrl soundsUrl() const override; | ||
|
||
private: | ||
bool isTestingMode() const; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* MuseScore-CLA-applies | ||
* | ||
* MuseScore | ||
* Music Composition & Notation | ||
* | ||
* Copyright (C) 2024 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 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/>. | ||
*/ | ||
|
||
#include "musesoundsrepository.h" | ||
|
||
#include "serialization/json.h" | ||
|
||
#include "global/concurrency/concurrent.h" | ||
|
||
using namespace mu::musesounds; | ||
using namespace muse; | ||
using namespace muse::network; | ||
|
||
void MuseSoundsRepository::init() | ||
{ | ||
auto soundsCallBack = [this](const RetVal<MuseSoundCategoryInfoList>& result) { | ||
if (!result.ret) { | ||
LOGE() << result.ret.toString(); | ||
return; | ||
} | ||
|
||
LOGE() << result.ret.toString(); | ||
|
||
m_soundsCategories = result.val; | ||
m_soundsCategoriesChanged.notify(); | ||
}; | ||
|
||
Concurrent::run(this, &MuseSoundsRepository::th_requestSounds, soundsRequestUrl(), soundsCallBack); | ||
} | ||
|
||
const MuseSoundCategoryInfoList& MuseSoundsRepository::soundsCategoryList() const | ||
{ | ||
return m_soundsCategories; | ||
} | ||
|
||
async::Notification MuseSoundsRepository::soundsCategoryListChanged() const | ||
{ | ||
return m_soundsCategoriesChanged; | ||
} | ||
|
||
QUrl MuseSoundsRepository::soundsRequestUrl() const | ||
{ | ||
String locale = QLocale().name(); | ||
|
||
String query = String( | ||
R"( | ||
query MyQuery { | ||
product_pages_configuration(version: "default") { | ||
librariesPageSections { | ||
... on ProductPageSectionRegular { | ||
title(locale: {locale: "%1"}) | ||
productCards { | ||
... on ProductCardRegular { | ||
title(locale: {locale: "%1"}) | ||
coverImageUrl | ||
description(locale: {locale: "%1"}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
)").arg(locale); | ||
|
||
StringList params = { | ||
"query=" + query | ||
}; | ||
|
||
QUrl url = configuration()->soundsUrl(); | ||
url.setQuery(params.join(u"&")); | ||
|
||
return url; | ||
} | ||
|
||
void MuseSoundsRepository::th_requestSounds(const QUrl& soundsUrl, std::function<void(RetVal<MuseSoundCategoryInfoList>)> callBack) const | ||
{ | ||
TRACEFUNC; | ||
|
||
network::INetworkManagerPtr networkManager = networkManagerCreator()->makeNetworkManager(); | ||
RequestHeaders headers = configuration()->headers(); | ||
|
||
QBuffer soundsInfoData; | ||
Ret soundsItemsRet = networkManager->get(soundsUrl, &soundsInfoData, headers); | ||
if (!soundsItemsRet) { | ||
callBack(soundsItemsRet); | ||
return; | ||
} | ||
|
||
JsonDocument soundsInfoDoc = JsonDocument::fromJson(ByteArray::fromQByteArray(soundsInfoData.data())); | ||
|
||
RetVal<MuseSoundCategoryInfoList> result; | ||
result.ret = make_ret(Ret::Code::Ok); | ||
result.val = parseSounds(soundsInfoDoc); | ||
|
||
callBack(result); | ||
} | ||
|
||
MuseSoundCategoryInfoList MuseSoundsRepository::parseSounds(const JsonDocument& soundsDoc) const | ||
{ | ||
MuseSoundCategoryInfoList result; | ||
|
||
JsonObject obj = soundsDoc.rootObject(); | ||
JsonObject data = !obj.empty() ? obj.value("data").toObject() : JsonObject(); | ||
JsonObject productsSearch = !data.empty() ? data.value("products_search").toObject() : JsonObject(); | ||
JsonArray items = !productsSearch.empty() ? productsSearch.value("items").toArray() : JsonArray(); | ||
|
||
for (size_t i = 0; i < items.size(); i++) { | ||
JsonObject itemObj = items.at(i).toObject(); | ||
|
||
MuseSoundCategoryInfo category; | ||
category.title = itemObj.value("title").toString(); | ||
|
||
JsonArray soundsItems = itemObj.value("items").toArray(); | ||
|
||
for (size_t i = 0; i < soundsItems.size(); i++) { | ||
JsonObject soundItemObj = soundsItems.at(i).toObject(); | ||
|
||
MuseSoundInfo sound; | ||
sound.title = itemObj.value("title").toString(); | ||
sound.description = itemObj.value("description").toString(); | ||
sound.thumbnail = itemObj.value("coverImageUrl").toString(); | ||
|
||
category.sounds.emplace_back(sound); | ||
} | ||
|
||
result.emplace_back(category); | ||
} | ||
|
||
return result; | ||
} |
Oops, something went wrong.