Skip to main content

sound_to_patch/cli/
preset.rs

1//! The arguments of `preset`.
2
3use std::path::PathBuf;
4
5use clap::{Args, Subcommand};
6
7use crate::preset::format::DescribeOptions;
8use crate::synth::SynthArg;
9
10/// Arguments of `preset`.
11#[derive(Debug, Args)]
12pub struct PresetArgs {
13    /// The preset subcommand.
14    #[command(subcommand)]
15    pub command: PresetCommand,
16}
17
18/// The subcommands of `preset`.
19#[derive(Debug, Subcommand)]
20pub enum PresetCommand {
21    /// Print the header fields and the decoded tree of a preset file.
22    ///
23    /// Example: sound-to-patch preset inspect bass.vital
24    Inspect(InspectArgs),
25    /// Apply an edit list to a template and write a preset.
26    ///
27    /// Values are written with their unit, such as "1.2 kHz", "800 ms",
28    /// "-6 dB", "+12 st" or "25%".
29    ///
30    /// Example: sound-to-patch preset apply edits.json -o bass.vital
31    Apply(ApplyArgs),
32}
33
34/// Arguments of `preset inspect`.
35#[derive(Debug, Args)]
36pub struct InspectArgs {
37    /// The preset file, such as `bass.vital`.
38    pub file: PathBuf,
39    /// The target synth.
40    #[command(flatten)]
41    pub synth: SynthArg,
42    /// Print every list element and every text in full.
43    #[arg(long)]
44    pub full: bool,
45    /// List elements printed before the rest is counted.
46    #[arg(long, value_name = "N", default_value_t = DescribeOptions::default().shown)]
47    pub shown: usize,
48}
49
50impl InspectArgs {
51    /// The describe options these arguments ask for.
52    #[must_use]
53    pub fn describe_options(&self) -> DescribeOptions {
54        DescribeOptions {
55            full: self.full,
56            shown: self.shown,
57        }
58    }
59}
60
61/// Arguments of `preset apply`.
62#[derive(Debug, Args)]
63pub struct ApplyArgs {
64    /// The edit list, a JSON file.
65    pub edits: PathBuf,
66    /// The preset to write, such as `bass.vital`.
67    #[arg(short, long, value_name = "FILE")]
68    pub out: PathBuf,
69    /// A preset to start from instead of the synth's built-in template.
70    #[arg(long, value_name = "FILE")]
71    pub template: Option<PathBuf>,
72    /// The preset name. Without it, the name of the output file.
73    #[arg(long, value_parser = clap::builder::NonEmptyStringValueParser::new())]
74    pub name: Option<String>,
75    /// Replace the output file if it exists.
76    #[arg(long)]
77    pub force: bool,
78    /// The target synth.
79    #[command(flatten)]
80    pub synth: SynthArg,
81}