Skip to content

Commit

Permalink
Add: とりあえずStructを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Oct 21, 2023
1 parent d0412e5 commit 560b0e5
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 15 deletions.
22 changes: 18 additions & 4 deletions crates/voicevox_core_c_api/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,21 @@ after_includes = """
#else // __cplusplus
#include <stdbool.h>
#include <stdint.h>
#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

Expand All @@ -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

Expand Down
51 changes: 47 additions & 4 deletions crates/voicevox_core_c_api/include/voicevox_core.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/voicevox_core_c_api/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl From<VoicevoxAccelerationMode> for voicevox_core::AccelerationMode {
}
}

impl Default for VoicevoxInitializeOptions {
impl Default for VoicevoxInitializeSynthesizerOptions {
fn default() -> Self {
let options = voicevox_core::InitializeOptions::default();
Self {
Expand All @@ -124,8 +124,8 @@ impl Default for VoicevoxInitializeOptions {
}
}

impl From<VoicevoxInitializeOptions> for voicevox_core::InitializeOptions {
fn from(value: VoicevoxInitializeOptions) -> Self {
impl From<VoicevoxInitializeSynthesizerOptions> 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,
Expand Down
10 changes: 6 additions & 4 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,7 +201,7 @@ pub enum VoicevoxAccelerationMode {

/// ::voicevox_synthesizer_new_with_initialize のオプション。
#[repr(C)]
pub struct VoicevoxInitializeOptions {
pub struct VoicevoxInitializeSynthesizerOptions {
/// ハードウェアアクセラレーションモード
acceleration_mode: VoicevoxAccelerationMode,
/// CPU利用数を指定
Expand All @@ -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のバージョンを取得する。
Expand Down Expand Up @@ -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<Box<VoicevoxSynthesizer>>,
) -> VoicevoxResultCode {
into_result_code_with_error((|| {
Expand Down
26 changes: 26 additions & 0 deletions crates/voicevox_core_c_api/src/v014_compatible_engine.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
3 changes: 3 additions & 0 deletions docs/0.14_to_0.15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.14 から 0.15 への移行

TODO

0 comments on commit 560b0e5

Please sign in to comment.