This repository has no description
1use anyhow::Result;
2use shapemaker::*;
3
4#[cfg(feature = "vst")]
5#[cfg(feature = "mp4")]
6use env_logger;
7use measure_time::debug_time;
8
9#[cfg(feature = "cli")]
10use shapemaker::cli;
11
12extern crate log;
13
14#[cfg(not(feature = "cli"))]
15pub fn main() -> Result<()> {
16 panic!(
17 "Running the command-line program requires the cli feature to be enabled. Enabled features: {:?}",
18 enabled_features()
19 );
20}
21
22#[cfg(feature = "cli")]
23#[tokio::main]
24pub async fn main() -> Result<()> {
25 #[cfg(feature = "vst")]
26 #[cfg(feature = "mp4")]
27 env_logger::init();
28 run(cli::cli_args()).await
29}
30
31#[cfg(feature = "cli")]
32pub async fn run(args: cli::Args) -> Result<()> {
33 debug_time!("run");
34
35 if args.cmd_new {
36 return cli::new::new_project(args.arg_name);
37 }
38
39 if args.cmd_watch {
40 cli::watch::watch_project(
41 match args.arg_directory.as_str() {
42 "" => ".",
43 dir => dir,
44 }
45 .into(),
46 )
47 .await?;
48 return Ok(());
49 }
50
51 if args.cmd_test_video {
52 run_video(args)
53 } else if args.cmd_beacon && args.cmd_start {
54 run_beacon_start(args)
55 } else if args.cmd_beacon && args.cmd_ping {
56 run_beacon_ping(args)
57 } else {
58 Ok(())
59 }
60}
61
62#[cfg(all(feature = "cli", not(feature = "vst")))]
63fn run_beacon_start(_args: cli::Args) -> Result<()> {
64 println!(
65 "VST support is disabled. Enable the vst feature to use VST beaconing."
66 );
67 Ok(())
68}
69
70#[cfg(all(feature = "cli", feature = "vst"))]
71fn run_beacon_start(_args: cli::Args) -> Result<()> {
72 pub use vst::beacon::Beacon;
73 Beacon::start()
74}
75
76#[cfg(all(feature = "cli", not(feature = "vst")))]
77fn run_beacon_ping(_args: cli::Args) -> Result<()> {
78 println!(
79 "VST support is disabled. Enable the vst feature to use VST beaconing."
80 );
81 Ok(())
82}
83
84#[cfg(all(feature = "cli", feature = "vst"))]
85fn run_beacon_ping(_args: cli::Args) -> Result<()> {
86 use rand;
87 use vst::remote_probe::RemoteProbe;
88 let mut probe = RemoteProbe::new(rand::random());
89 Ok(probe.say("ping hehe")?)
90}
91
92#[cfg(all(feature = "cli", not(feature = "mp4")))]
93fn run_video(_args: cli::Args) -> Result<()> {
94 println!(
95 "Video rendering is disabled. Enable the mp4 feature to render videos."
96 );
97 Ok(())
98}
99
100#[cfg(all(feature = "cli", feature = "mp4"))]
101fn run_video(args: cli::Args) -> Result<()> {
102 use shapemaker::fonts::FontOptions;
103
104 let mut canvas = cli::canvas_from_cli(&args);
105 canvas.set_background(Color::Black);
106 canvas.font_options = FontOptions {
107 monospace_family: Some("Victor Mono".into()),
108 ..Default::default()
109 };
110 let mut video = Video::<()>::new(canvas);
111 video.duration_override = args.flag_duration.map(|seconds| seconds * 1000);
112 video.start_rendering_at = args.flag_start.unwrap_or_default() * 1000;
113 video.resolution = args.flag_resolution.unwrap_or(1920);
114 video.fps = args.flag_fps.unwrap_or(30);
115 video.audiofile = args
116 .flag_audio
117 .expect("Provide audio with --audio to render a video")
118 .into();
119 video
120 .sync_audio_with(
121 &args.flag_sync_with.expect(
122 "Provide MIDI sync file with --sync-with to render a video",
123 ),
124 )
125 .each_frame(&|canvas, ctx| {
126 let center = canvas.world_region.center();
127 canvas.root().clear();
128 canvas
129 .root()
130 .set("feur", Object::Dot(center).colored(Color::Red));
131 canvas.root().set(
132 "text",
133 Object::CenteredText(center, ctx.timestamp.to_string(), 30.0)
134 .colored(Color::White),
135 );
136 canvas.root().set(
137 "beat",
138 Object::CenteredText(
139 center.translated(0, 3),
140 format!("beat {}", ctx.beat),
141 30.0,
142 )
143 .colored(Color::Cyan),
144 );
145 Ok(())
146 })
147 .encode(args.arg_file)
148}