From 560b0e51f9174ea53ca1db4c9fd18617d36f347c Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sat, 21 Oct 2023 14:07:11 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88?= =?UTF-8?q?=E3=81=9AStruct=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/cbindgen.toml | 22 ++++++-- .../include/voicevox_core.h | 51 +++++++++++++++++-- crates/voicevox_core_c_api/src/helpers.rs | 6 +-- crates/voicevox_core_c_api/src/lib.rs | 10 ++-- .../src/v014_compatible_engine.rs | 26 ++++++++++ docs/0.14_to_0.15.md | 3 ++ 6 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 crates/voicevox_core_c_api/src/v014_compatible_engine.rs create mode 100644 docs/0.14_to_0.15.md diff --git a/crates/voicevox_core_c_api/cbindgen.toml b/crates/voicevox_core_c_api/cbindgen.toml index 096c6bafd..a0fef4f76 100644 --- a/crates/voicevox_core_c_api/cbindgen.toml +++ b/crates/voicevox_core_c_api/cbindgen.toml @@ -55,7 +55,21 @@ after_includes = """ #else // __cplusplus #include #include -#endif // __cplusplus""" +#endif // __cplusplus + +#if defined(__cplusplus) +#define DEPRECATED [[deprecated]] +#define DEPRECATED_WITH_NOTE(msg) [[deprecated(msg)]] +#elif defined(_MSC_VER) +#define DEPRECATED __declspec(deprecated) +#define DEPRECATED_WITH_NOTE(msg) __declspec(deprecated(msg)) +#elif defined(__GNUC__) +#define DEPRECATED __attribute__((deprecated)) +#define DEPRECATED_WITH_NOTE(msg) __attribute__((deprecated(msg))) +#else +#define DEPRECATED +#define DEPRECATED_WITH_NOTE(msg) +#endif""" # Code Style Options @@ -70,16 +84,16 @@ __declspec(dllimport) #endif""" args = "vertical" deprecated = "DEPRECATED" -deprecated_with_note = "DEPRECATED_WITH_NOTES({})" +deprecated_with_note = "DEPRECATED_WITH_NOTE({})" [struct] deprecated = "DEPRECATED" -deprecated_with_note = "DEPRECATED_WITH_NOTES({})" +deprecated_with_note = "DEPRECATED_WITH_NOTE({})" [enum] rename_variants = "ScreamingSnakeCase" deprecated = "DEPRECATED" -deprecated_with_note = "DEPRECATED_WITH_NOTES({})" +deprecated_with_note = "DEPRECATED_WITH_NOTE({})" # Options for how your Rust library should be parsed diff --git a/crates/voicevox_core_c_api/include/voicevox_core.h b/crates/voicevox_core_c_api/include/voicevox_core.h index 50ab740e1..f8a934a35 100644 --- a/crates/voicevox_core_c_api/include/voicevox_core.h +++ b/crates/voicevox_core_c_api/include/voicevox_core.h @@ -53,6 +53,20 @@ #include #endif // __cplusplus +#if defined(__cplusplus) +#define DEPRECATED [[deprecated]] +#define DEPRECATED_WITH_NOTE(msg) [[deprecated(msg)]] +#elif defined(_MSC_VER) +#define DEPRECATED __declspec(deprecated) +#define DEPRECATED_WITH_NOTE(msg) __declspec(deprecated(msg)) +#elif defined(__GNUC__) +#define DEPRECATED __attribute__((deprecated)) +#define DEPRECATED_WITH_NOTE(msg) __attribute__((deprecated(msg))) +#else +#define DEPRECATED +#define DEPRECATED_WITH_NOTE(msg) +#endif + /** * ハードウェアアクセラレーションモードを設定する設定値。 */ @@ -258,7 +272,7 @@ typedef struct VoicevoxVoiceModel VoicevoxVoiceModel; /** * ::voicevox_synthesizer_new_with_initialize のオプション。 */ -typedef struct VoicevoxInitializeOptions { +typedef struct VoicevoxInitializeSynthesizerOptions { /** * ハードウェアアクセラレーションモード */ @@ -268,7 +282,7 @@ typedef struct VoicevoxInitializeOptions { * 0を指定すると環境に合わせたCPUが利用される */ uint16_t cpu_num_threads; -} VoicevoxInitializeOptions; +} VoicevoxInitializeSynthesizerOptions; /** * 音声モデルID。 @@ -328,6 +342,29 @@ typedef struct VoicevoxUserDictWord { uint32_t priority; } VoicevoxUserDictWord; +/** + * ::voicevox_initialize のオプション。 + */ +typedef struct DEPRECATED_WITH_NOTE("VoicevoxInitializeSynthesizerOptions を使ってください。") VoicevoxInitializeOptions { + /** + * ハードウェアアクセラレーションモード + */ + VoicevoxAccelerationMode acceleration_mode; + /** + * CPU利用数を指定 + * 0を指定すると環境に合わせたCPUが利用される + */ + uint16_t cpu_num_threads; + /** + * 全てのモデルを読み込む + */ + bool load_all_models; + /** + * open_jtalkの辞書ディレクトリ + */ + const char *open_jtalk_dict_dir; +} VoicevoxInitializeOptions; + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -407,7 +444,7 @@ void voicevox_open_jtalk_rc_delete(struct OpenJtalkRc *open_jtalk); #ifdef _WIN32 __declspec(dllimport) #endif -struct VoicevoxInitializeOptions voicevox_make_default_initialize_options(void); +struct VoicevoxInitializeSynthesizerOptions voicevox_make_default_initialize_synthesizer_options(void); /** * voicevoxのバージョンを取得する。 @@ -503,7 +540,7 @@ void voicevox_voice_model_delete(struct VoicevoxVoiceModel *model); __declspec(dllimport) #endif VoicevoxResultCode voicevox_synthesizer_new_with_initialize(const struct OpenJtalkRc *open_jtalk, - struct VoicevoxInitializeOptions options, + struct VoicevoxInitializeSynthesizerOptions options, struct VoicevoxSynthesizer **out_synthesizer); /** @@ -1211,6 +1248,12 @@ __declspec(dllimport) #endif void voicevox_user_dict_delete(struct VoicevoxUserDict *user_dict); +#ifdef _WIN32 +__declspec(dllimport) +#endif +DEPRECATED_WITH_NOTE("voicevox_synthesizer_new_with_initialize を使ってください。") +bool voicevox_initialize(struct VoicevoxInitializeOptions options); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/crates/voicevox_core_c_api/src/helpers.rs b/crates/voicevox_core_c_api/src/helpers.rs index 698e89b45..001a7b930 100644 --- a/crates/voicevox_core_c_api/src/helpers.rs +++ b/crates/voicevox_core_c_api/src/helpers.rs @@ -114,7 +114,7 @@ impl From for voicevox_core::AccelerationMode { } } -impl Default for VoicevoxInitializeOptions { +impl Default for VoicevoxInitializeSynthesizerOptions { fn default() -> Self { let options = voicevox_core::InitializeOptions::default(); Self { @@ -124,8 +124,8 @@ impl Default for VoicevoxInitializeOptions { } } -impl From for voicevox_core::InitializeOptions { - fn from(value: VoicevoxInitializeOptions) -> Self { +impl From for voicevox_core::InitializeOptions { + fn from(value: VoicevoxInitializeSynthesizerOptions) -> Self { voicevox_core::InitializeOptions { acceleration_mode: value.acceleration_mode.into(), cpu_num_threads: value.cpu_num_threads, diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 9bc6698b4..a3930de1c 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -9,6 +9,7 @@ mod drop_check; mod helpers; mod result_code; mod slice_owner; +mod v014_compatible_engine; use self::drop_check::C_STRING_DROP_CHECKER; use self::helpers::*; use self::result_code::VoicevoxResultCode; @@ -200,7 +201,7 @@ pub enum VoicevoxAccelerationMode { /// ::voicevox_synthesizer_new_with_initialize のオプション。 #[repr(C)] -pub struct VoicevoxInitializeOptions { +pub struct VoicevoxInitializeSynthesizerOptions { /// ハードウェアアクセラレーションモード acceleration_mode: VoicevoxAccelerationMode, /// CPU利用数を指定 @@ -211,8 +212,9 @@ pub struct VoicevoxInitializeOptions { /// デフォルトの初期化オプションを生成する /// @return デフォルト値が設定された初期化オプション #[no_mangle] -pub extern "C" fn voicevox_make_default_initialize_options() -> VoicevoxInitializeOptions { - VoicevoxInitializeOptions::default() +pub extern "C" fn voicevox_make_default_initialize_synthesizer_options( +) -> VoicevoxInitializeSynthesizerOptions { + VoicevoxInitializeSynthesizerOptions::default() } /// voicevoxのバージョンを取得する。 @@ -337,7 +339,7 @@ pub struct VoicevoxSynthesizer { #[no_mangle] pub unsafe extern "C" fn voicevox_synthesizer_new_with_initialize( open_jtalk: &OpenJtalkRc, - options: VoicevoxInitializeOptions, + options: VoicevoxInitializeSynthesizerOptions, out_synthesizer: NonNull>, ) -> VoicevoxResultCode { into_result_code_with_error((|| { diff --git a/crates/voicevox_core_c_api/src/v014_compatible_engine.rs b/crates/voicevox_core_c_api/src/v014_compatible_engine.rs new file mode 100644 index 000000000..a58500d51 --- /dev/null +++ b/crates/voicevox_core_c_api/src/v014_compatible_engine.rs @@ -0,0 +1,26 @@ +use super::*; + +/// ::voicevox_initialize のオプション。 +#[deprecated(note = "VoicevoxInitializeSynthesizerOptions を使ってください。")] +#[repr(C)] +pub struct VoicevoxInitializeOptions { + /// ハードウェアアクセラレーションモード + acceleration_mode: VoicevoxAccelerationMode, + /// CPU利用数を指定 + /// 0を指定すると環境に合わせたCPUが利用される + cpu_num_threads: u16, + /// 全てのモデルを読み込む + load_all_models: bool, + /// open_jtalkの辞書ディレクトリ + open_jtalk_dict_dir: *const c_char, +} + +#[no_mangle] +#[deprecated(note = "voicevox_synthesizer_new_with_initialize を使ってください。")] +/// 初期化する。 +/// +/// @param [in] options オプション +/// @returns 結果コード +pub extern "C" fn voicevox_initialize(options: VoicevoxInitializeOptions) -> VoicevoxResultCode { + todo!() +} diff --git a/docs/0.14_to_0.15.md b/docs/0.14_to_0.15.md new file mode 100644 index 000000000..a7faede3e --- /dev/null +++ b/docs/0.14_to_0.15.md @@ -0,0 +1,3 @@ +# 0.14 から 0.15 への移行 + +TODO