Files
AniCraft/src/main.rs
T
Tanish Manku 75eabe8527 feat(audio): play sounds in sync, waveforms on the timeline, Sound properties and library sounds (M5)
Stage playback plays the movie's sounds through cpal (optional default
feature sound-output) and the playhead follows the audio clock; a moved
playhead plays a one-frame snippet of stream sounds (scrubbing). The device
opens on first need, never in screenshot runs or tests, and a failure falls
back to silent wall-clock playback.

Timeline rows draw each keyframe's waveform over its span, repeats
included. Frame Properties gain Sound, Sync and Repeat/Loop. The Library
lists sounds with Preview, Place on timeline and Delete. Import to Stage
and Import to Library take WAV, OGG and MP3; Export Audio writes the
soundtrack.
2026-11-09 03:43:09 -07:00

122 lines
4.7 KiB
Rust

//! AniCraft desktop app.
//!
//! ```text
//! anicraft [file.anicraft] [--screenshot out.png] [--renderer wgpu|gl] [--open <panel>]
//! ```
//! `--screenshot` starts normally, draws ~120 frames, saves the window as PNG and exits.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod app;
mod autosave;
mod dialogs;
mod icons;
mod keymap;
mod menus;
mod motion_editor;
mod panels;
mod pathtools;
mod platform;
mod plugins_ui;
mod prefs;
mod sound;
mod stage;
mod theme;
mod timeline;
use anicraft_engine::Session;
use std::path::{Path, PathBuf};
/// The session to start with: the file given on the command line (through `file.open`, so
/// `.fla` / `.xfl` import works the same as from the menu), else the sample. Also the import
/// report of an Animate document, for the status bar.
fn open_session(file: Option<&Path>) -> (Session, Option<String>) {
let Some(p) = file else { return (Session::new(anicraft_engine::doc::sample::demo()), None) };
let mut s = Session::default();
match s.execute("file.open", &serde_json::json!({"path": p.display().to_string()})) {
Ok(v) => {
let report = v.get("report").and_then(|r| r.as_str()).map(str::to_string);
if let Some(r) = &report {
println!("{r}");
}
(s, report)
}
Err(e) => {
eprintln!("could not open {}: {e}; starting with the sample", p.display());
(Session::new(anicraft_engine::doc::sample::demo()), None)
}
}
}
fn run(renderer: eframe::Renderer, file: Option<&Path>, shot: Option<PathBuf>, open: Option<String>) -> eframe::Result {
let options = eframe::NativeOptions {
viewport: platform::viewport(egui::ViewportBuilder::default().with_title("AniCraft").with_inner_size([1600.0, 940.0]).with_min_inner_size([960.0, 600.0])),
renderer,
..Default::default()
};
// The embedded interface font joins the text library before anything lays text out:
// opening an Animate document from the command line lays its text out right here.
anicraft_engine::text::Fonts::register(theme::embedded_fonts());
let (session, report) = open_session(file);
eframe::run_native(
"AniCraft",
options,
Box::new(move |cc| {
let mut a = app::App::new(cc, session, shot);
a.open_panel(open.as_deref());
// An imported document says what came across, as opening it from the menu does.
if let Some(r) = report {
a.status_ok(format!("{r} Save to keep it as an AniCraft document."));
}
Ok(Box::new(a))
}),
)
}
fn main() -> eframe::Result {
let mut shot: Option<PathBuf> = None;
let mut file: Option<PathBuf> = None;
let mut open: Option<String> = None;
let mut renderer_arg: Option<String> = None;
let mut args = std::env::args().skip(1);
while let Some(a) = args.next() {
match a.as_str() {
"--screenshot" => match args.next() {
Some(p) => shot = Some(PathBuf::from(p)),
None => {
eprintln!("--screenshot needs a file name");
std::process::exit(2);
}
},
"--open" => open = args.next(),
"--renderer" => renderer_arg = args.next(),
"--help" | "-h" => {
println!(
"anicraft [file.anicraft] [--screenshot out.png] [--renderer wgpu|gl] [--open palette|shortcuts|lastscene|select|about|files|confirm|transform|points|pen|frames|span|bucket|tlzoom|tlwide|motion|motionspan|prefs|licenses|zoom|recovery|plugins]\n\
--renderer force the GPU backend (also ANICRAFT_RENDERER); default wgpu, falling back to OpenGL\n\
--open shows a panel at start (handy with --screenshot for visual checks)\n\
Headless use: anicraft-cli --help"
);
return Ok(());
}
other => file = Some(PathBuf::from(other)),
}
}
// wgpu first (Vulkan/Metal/DX12). If it cannot start (old GPU, VM, missing drivers, common
// on some Linux setups) retry once with OpenGL, unless the user forced a backend.
let forced = platform::forced_renderer(renderer_arg.as_deref());
let first = forced.unwrap_or(eframe::Renderer::Wgpu);
match run(first, file.as_deref(), shot.clone(), open.clone()) {
Err(e) if forced.is_none() && first == eframe::Renderer::Wgpu => {
eprintln!("GPU backend (wgpu) failed to start: {e}. Retrying with OpenGL.");
run(eframe::Renderer::Glow, file.as_deref(), shot, open)
}
other => other,
}
}
#[cfg(test)]
mod guidelines_tests;
#[cfg(test)]
mod architecture_tests;