ustx/
part.rs

1use serde::{Deserialize, Serialize};
2
3use crate::expression::Curve;
4use crate::note::Note;
5
6/// Represents a voice part in an `OpenUtau` project.
7///
8/// A voice part contains a sequence of notes and expression curves.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub struct VoicePart {
12    /// The name of the voice part.
13    #[serde(default = "default_part_name")]
14    pub name: String,
15    /// A comment for the voice part.
16    #[serde(default)]
17    pub comment: String,
18    /// The track number that this part belongs to.
19    #[serde(default)]
20    pub track_no: i32,
21    /// The position of the voice part in ticks.
22    #[serde(default)]
23    pub position: i32,
24    /// The duration of the voice part in ticks.
25    #[serde(default)]
26    pub notes: Vec<Note>,
27    /// A list of expression curves in the voice part.
28    #[serde(default)]
29    pub curves: Vec<Curve>,
30}
31
32/// Represents a wave part in an `OpenUtau` project.
33///
34/// A wave part contains a reference to an audio file.
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(rename_all = "snake_case")]
37pub struct WavePart {
38    /// The name of the wave part.
39    #[serde(default = "default_part_name")]
40    pub name: String,
41    /// A comment for the wave part.
42    #[serde(default)]
43    pub comment: String,
44    /// The track number that this part belongs to.
45    #[serde(default)]
46    pub track_no: i32,
47    /// The position of the wave part in ticks.
48    #[serde(default)]
49    pub position: i32,
50    /// The relative path to the audio file.
51    #[serde(default)]
52    pub relative_path: String,
53    /// The duration of the audio file in milliseconds.
54    #[serde(default)]
55    pub file_duration_ms: f64,
56    /// The number of milliseconds to skip at the beginning of the audio file.
57    #[serde(default)]
58    pub skip_ms: f64,
59    /// The number of milliseconds to trim from the end of the audio file.
60    #[serde(default)]
61    pub trim_ms: f64,
62}
63
64#[inline]
65fn default_part_name() -> String {
66    String::from("New Part")
67}