/// /// JHybridTtsSessionSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © Marc Rousavy @ Margelo /// #include "JHybridTtsSessionSpec.hpp" // Forward declaration of `ListenerSubscription` to properly resolve imports. namespace margelo::nitro::nitrotts { struct ListenerSubscription; } // Forward declaration of `TtsParagraph` to properly resolve imports. namespace margelo::nitro::nitrotts { struct TtsParagraph; } // Forward declaration of `TtsMetadata` to properly resolve imports. namespace margelo::nitro::nitrotts { struct TtsMetadata; } // Forward declaration of `TtsSettings` to properly resolve imports. namespace margelo::nitro::nitrotts { struct TtsSettings; } // Forward declaration of `TtsPlaybackState` to properly resolve imports. namespace margelo::nitro::nitrotts { enum class TtsPlaybackState; } // Forward declaration of `TtsProgress` to properly resolve imports. namespace margelo::nitro::nitrotts { struct TtsProgress; } #include #include #include #include "ListenerSubscription.hpp" #include "JListenerSubscription.hpp" #include #include "JFunc_void.hpp" #include #include "TtsParagraph.hpp" #include #include "JTtsParagraph.hpp" #include #include "TtsMetadata.hpp" #include "JTtsMetadata.hpp" #include #include "TtsSettings.hpp" #include "JTtsSettings.hpp" #include "TtsPlaybackState.hpp" #include "JFunc_void_TtsPlaybackState.hpp" #include "JTtsPlaybackState.hpp" #include "TtsProgress.hpp" #include "JFunc_void_TtsProgress.hpp" #include "JTtsProgress.hpp" #include "JFunc_void_std__string.hpp" namespace margelo::nitro::nitrotts { std::shared_ptr JHybridTtsSessionSpec::JavaPart::getJHybridTtsSessionSpec() { auto hybridObject = JHybridObject::JavaPart::getJHybridObject(); auto castHybridObject = std::dynamic_pointer_cast(hybridObject); if (castHybridObject == nullptr) [[unlikely]] { throw std::runtime_error("Failed to downcast JHybridObject to JHybridTtsSessionSpec!"); } return castHybridObject; } jni::local_ref JHybridTtsSessionSpec::CxxPart::initHybrid(jni::alias_ref jThis) { return makeCxxInstance(jThis); } std::shared_ptr JHybridTtsSessionSpec::CxxPart::createHybridObject(const jni::local_ref& javaPart) { auto castJavaPart = jni::dynamic_ref_cast(javaPart); if (castJavaPart == nullptr) [[unlikely]] { throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridTtsSessionSpec::JavaPart!"); } return std::make_shared(castJavaPart); } void JHybridTtsSessionSpec::CxxPart::registerNatives() { registerHybrid({ makeNativeMethod("initHybrid", JHybridTtsSessionSpec::CxxPart::initHybrid), }); } // Properties // Methods std::shared_ptr> JHybridTtsSessionSpec::load(const std::vector& paragraphs, double initialIndex, const TtsMetadata& metadata, const TtsSettings& settings) { static const auto method = _javaPart->javaClassStatic()->getMethod(jni::alias_ref> /* paragraphs */, double /* initialIndex */, jni::alias_ref /* metadata */, jni::alias_ref /* settings */)>("load"); auto __result = method(_javaPart, [&](auto&& __input) { size_t __size = __input.size(); jni::local_ref> __array = jni::JArrayClass::newArray(__size); for (size_t __i = 0; __i < __size; __i++) { const auto& __element = __input[__i]; auto __elementJni = JTtsParagraph::fromCpp(__element); __array->setElement(__i, *__elementJni); } return __array; }(paragraphs), initialIndex, JTtsMetadata::fromCpp(metadata), JTtsSettings::fromCpp(settings)); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::play() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("play"); auto __result = method(_javaPart); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::pause() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("pause"); auto __result = method(_javaPart); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::stop() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("stop"); auto __result = method(_javaPart); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::skipPrevious() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("skipPrevious"); auto __result = method(_javaPart); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::skipNext() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("skipNext"); auto __result = method(_javaPart); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::replayCurrent() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("replayCurrent"); auto __result = method(_javaPart); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::seekTo(double index) { static const auto method = _javaPart->javaClassStatic()->getMethod(double /* index */)>("seekTo"); auto __result = method(_javaPart, index); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } std::shared_ptr> JHybridTtsSessionSpec::updateSettings(const TtsSettings& settings) { static const auto method = _javaPart->javaClassStatic()->getMethod(jni::alias_ref /* settings */)>("updateSettings"); auto __result = method(_javaPart, JTtsSettings::fromCpp(settings)); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { __promise->resolve(); }); __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { jni::JniException __jniError(__throwable); __promise->reject(std::make_exception_ptr(__jniError)); }); return __promise; }(); } ListenerSubscription JHybridTtsSessionSpec::addOnStateChangedListener(const std::function& listener) { static const auto method = _javaPart->javaClassStatic()->getMethod(jni::alias_ref /* listener */)>("addOnStateChangedListener_cxx"); auto __result = method(_javaPart, JFunc_void_TtsPlaybackState_cxx::fromCpp(listener)); return __result->toCpp(); } ListenerSubscription JHybridTtsSessionSpec::addOnProgressChangedListener(const std::function& listener) { static const auto method = _javaPart->javaClassStatic()->getMethod(jni::alias_ref /* listener */)>("addOnProgressChangedListener_cxx"); auto __result = method(_javaPart, JFunc_void_TtsProgress_cxx::fromCpp(listener)); return __result->toCpp(); } ListenerSubscription JHybridTtsSessionSpec::addOnErrorListener(const std::function& listener) { static const auto method = _javaPart->javaClassStatic()->getMethod(jni::alias_ref /* listener */)>("addOnErrorListener_cxx"); auto __result = method(_javaPart, JFunc_void_std__string_cxx::fromCpp(listener)); return __result->toCpp(); } } // namespace margelo::nitro::nitrotts