Skip to content

Commit eae8434

Browse files
feat!: Option<TrackInfo>にする
1 parent 5d8111e commit eae8434

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

crates/aviutl2/src/generic/binding/edit_section.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct MediaInfo {
159159
#[derive(Debug, Clone)]
160160
pub struct TrackInfo {
161161
/// トラックバーの移動モードの名称。
162-
pub mode: Option<String>,
162+
pub mode: String,
163163
/// トラックバーの設定値。
164164
pub params: Vec<f64>,
165165
/// トラックバーの加速度が有効かどうか。
@@ -573,13 +573,18 @@ impl ReadSection {
573573
}
574574

575575
/// オブジェクトのトラックバー項目の情報を取得する。
576+
///
577+
/// # Note
578+
///
579+
/// 移動なしのときは`None`を返します。
580+
/// そもそもトラックバーではない項目の場合はエラーになります。
576581
pub fn get_object_track_info(
577582
&self,
578583
object: ObjectHandle,
579584
effect_name: &str,
580585
effect_index: usize,
581586
item: &str,
582-
) -> EditSectionResult<TrackInfo> {
587+
) -> EditSectionResult<Option<TrackInfo>> {
583588
self.ensure_object_exists(object)?;
584589
let c_effect_name = crate::common::CWString::new(&effect_key(effect_name, effect_index))?;
585590
let c_item = crate::common::CWString::new(item)?;
@@ -598,6 +603,11 @@ impl ReadSection {
598603
}
599604

600605
let info = unsafe { info.assume_init() };
606+
let mode = if info.mode.is_null() {
607+
return Ok(None);
608+
} else {
609+
unsafe { crate::common::load_wide_string(info.mode) }
610+
};
601611
let param_num: usize = info.param_num.try_into()?;
602612
let params = if param_num == 0 {
603613
Vec::new()
@@ -607,20 +617,15 @@ impl ReadSection {
607617
}
608618
unsafe { std::slice::from_raw_parts(info.param, param_num) }.to_vec()
609619
};
610-
let mode = if info.mode.is_null() {
611-
None
612-
} else {
613-
Some(unsafe { crate::common::load_wide_string(info.mode) })
614-
};
615620

616-
Ok(TrackInfo {
621+
Ok(Some(TrackInfo {
617622
mode,
618623
params,
619624
accelerate: info.accelerate,
620625
decelerate: info.decelerate,
621626
twopoint: info.twopoint,
622627
timecontrol: info.timecontrol,
623-
})
628+
}))
624629
}
625630

626631
/// 選択中オブジェクトの区間の位置を取得する。
@@ -1271,7 +1276,7 @@ where
12711276
effect_name: &str,
12721277
effect_index: usize,
12731278
item: &str,
1274-
) -> EditSectionResult<TrackInfo> {
1279+
) -> EditSectionResult<Option<TrackInfo>> {
12751280
self.read_section()
12761281
.get_object_track_info(self.handle, effect_name, effect_index, item)
12771282
}

examples/local-alias-plugin/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ impl LocalAliasPlugin {
208208
Ok(())
209209
})?
210210
}
211+
212+
#[object_item(name = "test")]
213+
fn menu_test_effect(
214+
&mut self,
215+
object: aviutl2::generic::ObjectHandle,
216+
effect: &str,
217+
index: usize,
218+
item: &str,
219+
) -> AnyResult<()> {
220+
let info = EDIT_HANDLE.call_edit_section(|edit_section| {
221+
edit_section.get_object_track_info(object, effect, index, item)
222+
})??;
223+
aviutl2::ldbg!(info);
224+
anyhow::Ok(())
225+
}
211226
}
212227

213228
aviutl2::register_generic_plugin!(LocalAliasPlugin);

0 commit comments

Comments
 (0)