| ... | @@ -2,38 +2,35 @@ | ... | @@ -2,38 +2,35 @@ |
| 2 | //! built on Knife's `draw`, `ui`, `dock`, and `theme::KNIFE` (soft toned quiet iris). | 2 | //! built on Knife's `draw`, `ui`, `dock`, and `theme::KNIFE` (soft toned quiet iris). |
| 3 | | 3 | |
| 4 | mod add_tool; | 4 | mod add_tool; |
| | 5 | mod export_ui; |
| 5 | mod inspector; | 6 | mod inspector; |
| 6 | mod keyframes; | 7 | mod keyframes; |
| | 8 | mod menus; |
| | 9 | mod playback_ui; |
| 7 | | 10 | |
| 8 | use add_tool::{AddToolLauncher, ToolEntry}; | 11 | use add_tool::{AddToolLauncher, ToolEntry}; |
| 9 | use dock::{Axis as DockAxis, Command, Dock, Event, GroupId, Node as DockNode, Part as DockPart, Place, Plus, Side, SplitId, Tab}; | 12 | use dock::{Axis as DockAxis, Dock, Event, GroupId, Node as DockNode, Part as DockPart, Place, Plus, SplitId, Tab}; |
| 10 | use engine::export::{ | 13 | use engine::{AudioPlayer, AudioTrack, DEFAULT_RAM_CACHE_MB, Engine, RamFrameCache, RamPrefetcher}; |
| 11 | ExportControl, ExportProgress, VideoCodec, VideoExportOptions, export_node_frame_png, | 14 | use export_ui::{ActiveExport, build_status_strip}; |
| 12 | export_node_video_ffmpeg_with_progress, export_saver_png_sequence_with_progress, select_saver, | | |
| 13 | }; | | |
| 14 | use engine::{ | | |
| 15 | AudioPlayer, AudioTrack, CacheMode, DEFAULT_RAM_CACHE_MB, Engine, ExportOptions, PrefetchJob, | | |
| 16 | RamFrameCache, RamPrefetcher, | | |
| 17 | }; | | |
| 18 | use flow::{FlowAction, FlowView}; | 15 | use flow::{FlowAction, FlowView}; |
| 19 | use inspector::{InspectorAction, InspectorState}; | 16 | use inspector::{InspectorAction, InspectorState}; |
| 20 | use keyframes::{KeyframesAction, KeyframesView}; | 17 | use keyframes::{KeyframesAction, KeyframesView}; |
| | 18 | use menus::{build_flow_toolbar, handle_global_shortcut}; |
| 21 | use model::{Comp, CompHistory, NodeId, default_main_input_port}; | 19 | use model::{Comp, CompHistory, NodeId, default_main_input_port}; |
| | 20 | use playback_ui::{load_snapshot_audio_peaks, spawn_audio_loader}; |
| 22 | use spline::{SplineAction, SplineView}; | 21 | use spline::{SplineAction, SplineView}; |
| 23 | use std::collections::HashMap; | 22 | use std::collections::HashMap; |
| 24 | use std::error::Error; | 23 | use std::error::Error; |
| 25 | use std::fs::File; | 24 | use std::fs::File; |
| 26 | use std::path::{Path, PathBuf}; | 25 | use std::path::{Path, PathBuf}; |
| 27 | use std::process::Command as ProcessCommand; | | |
| 28 | use std::sync::{Arc, mpsc}; | 26 | use std::sync::{Arc, mpsc}; |
| 29 | use std::time::{Duration, Instant}; | 27 | use std::time::{Duration, Instant}; |
| 30 | use ui::host::{Accessibility, Clipboard, Surface}; | 28 | use ui::host::{Accessibility, Clipboard, Surface}; |
| 31 | use viewer::{PlaybackClock, SyncMode, ViewerAction, ViewerState}; | 29 | use viewer::{PlaybackClock, ViewerAction, ViewerState}; |
| 32 | use winit::application::ApplicationHandler; | 30 | use winit::application::ApplicationHandler; |
| 33 | use winit::dpi::LogicalSize; | 31 | use winit::dpi::LogicalSize; |
| 34 | use winit::event::{ElementState, WindowEvent}; | 32 | use winit::event::WindowEvent; |
| 35 | use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop, EventLoopProxy}; | 33 | use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop, EventLoopProxy}; |
| 36 | use winit::keyboard::{Key, KeyCode, NamedKey, PhysicalKey}; | | |
| 37 | use winit::window::{CursorIcon, Window, WindowId}; | 34 | use winit::window::{CursorIcon, Window, WindowId}; |
| 38 | | 35 | |
| 39 | const DEFAULT_COMP: &str = "/Volumes/Project/trees/fusion/20_falling.comp"; | 36 | const DEFAULT_COMP: &str = "/Volumes/Project/trees/fusion/20_falling.comp"; |
| ... | @@ -115,28 +112,6 @@ fn main() { | ... | @@ -115,28 +112,6 @@ fn main() { |
| 115 | } | 112 | } |
| 116 | } | 113 | } |
| 117 | | 114 | |
| 118 | enum ExportOutcome { | | |
| 119 | Completed(String), | | |
| 120 | Cancelled, | | |
| 121 | Failed(String), | | |
| 122 | } | | |
| 123 | | | |
| 124 | struct ActiveExport { | | |
| 125 | control: ExportControl, | | |
| 126 | rx: mpsc::Receiver<ExportOutcome>, | | |
| 127 | cancelling: bool, | | |
| 128 | handle: Option<std::thread::JoinHandle<()>>, | | |
| 129 | } | | |
| 130 | | | |
| 131 | impl Drop for ActiveExport { | | |
| 132 | fn drop(&mut self) { | | |
| 133 | self.control.cancel(); | | |
| 134 | if let Some(handle) = self.handle.take() { | | |
| 135 | let _ = handle.join(); | | |
| 136 | } | | |
| 137 | } | | |
| 138 | } | | |
| 139 | | | |
| 140 | struct Studio { | 115 | struct Studio { |
| 141 | ui: ui::Ui, | 116 | ui: ui::Ui, |
| 142 | dock: Dock<String>, | 117 | dock: Dock<String>, |
| ... | @@ -383,353 +358,10 @@ impl Studio { | ... | @@ -383,353 +358,10 @@ impl Studio { |
| 383 | } | 358 | } |
| 384 | } | 359 | } |
| 385 | | 360 | |
| 386 | fn audio_time_secs(&self) -> f64 { | | |
| 387 | self.playback.audio_target_secs(&self.comp) | | |
| 388 | } | | |
| 389 | | | |
| 390 | fn refresh_audio_peaks(&mut self) { | | |
| 391 | if let Some(track) = &self.loaded_audio_track { | | |
| 392 | let peaks = track.waveform_peaks( | | |
| 393 | self.comp.fps, | | |
| 394 | self.comp.audio_offset, | | |
| 395 | self.comp.render_range[0], | | |
| 396 | self.comp.render_range[1], | | |
| 397 | ); | | |
| 398 | self.viewers[0].audio_peaks = peaks.clone(); | | |
| 399 | self.keyframes.audio_peaks = peaks; | | |
| 400 | self.keyframes.audio_range = self.comp.render_range; | | |
| 401 | } | | |
| 402 | } | | |
| 403 | | | |
| 404 | fn poll_audio_load(&mut self) { | | |
| 405 | let Some(rx) = &self.audio_rx else { return }; | | |
| 406 | match rx.try_recv() { | | |
| 407 | Ok(Ok(track)) => { | | |
| 408 | eprintln!( | | |
| 409 | "Loaded audio {} ({:.2}s @ {}Hz)", | | |
| 410 | track.path.display(), | | |
| 411 | track.duration_secs, | | |
| 412 | track.sample_rate | | |
| 413 | ); | | |
| 414 | let arc_track = Arc::new(track); | | |
| 415 | self.loaded_audio_track = Some(Arc::clone(&arc_track)); | | |
| 416 | self.refresh_audio_peaks(); | | |
| 417 | let t = self.audio_time_secs(); | | |
| 418 | let playing = self.playback.playing; | | |
| 419 | if let Some(player) = &mut self.audio_player { | | |
| 420 | player.set_track(Some(arc_track)); | | |
| 421 | if playing { | | |
| 422 | player.play_from(t); | | |
| 423 | } else { | | |
| 424 | player.seek(t); | | |
| 425 | } | | |
| 426 | } | | |
| 427 | self.audio_rx = None; | | |
| 428 | } | | |
| 429 | Ok(Err(e)) => { | | |
| 430 | eprintln!("fission audio load error: {e}"); | | |
| 431 | self.audio_rx = None; | | |
| 432 | } | | |
| 433 | Err(mpsc::TryRecvError::Disconnected) => { | | |
| 434 | self.audio_rx = None; | | |
| 435 | } | | |
| 436 | Err(mpsc::TryRecvError::Empty) => {} | | |
| 437 | } | | |
| 438 | } | | |
| 439 | | | |
| 440 | fn sync_audio(&mut self, state_changed: bool, seeked: bool) { | | |
| 441 | let t = self.audio_time_secs(); | | |
| 442 | let playing = self.playback.playing; | | |
| 443 | if let Some(player) = &mut self.audio_player { | | |
| 444 | if playing { | | |
| 445 | if state_changed || !player.is_playing() { | | |
| 446 | player.play_from(t); | | |
| 447 | } else if seeked { | | |
| 448 | player.seek(t); | | |
| 449 | } | | |
| 450 | } else { | | |
| 451 | if state_changed || player.is_playing() { | | |
| 452 | player.pause(); | | |
| 453 | } | | |
| 454 | if seeked || state_changed { | | |
| 455 | player.seek(t); | | |
| 456 | } | | |
| 457 | } | | |
| 458 | } | | |
| 459 | } | | |
| 460 | | | |
| 461 | fn check_audio_sync_and_metadata(&mut self, now: Instant) { | | |
| 462 | if self.comp.audio_filename != self.last_audio_filename { | | |
| 463 | self.last_audio_filename = self.comp.audio_filename.clone(); | | |
| 464 | self.loaded_audio_track = None; | | |
| 465 | self.viewers[0].audio_peaks.clear(); | | |
| 466 | self.keyframes.audio_peaks.clear(); | | |
| 467 | if self.enable_audio { | | |
| 468 | if let Some(player) = &mut self.audio_player { | | |
| 469 | player.set_track(None); | | |
| 470 | } | | |
| 471 | self.audio_rx = spawn_audio_loader(&self.comp); | | |
| 472 | } | | |
| 473 | } | | |
| 474 | let offset_changed = (self.comp.audio_offset - self.last_audio_offset).abs() > 1e-6; | | |
| 475 | let fps_changed = (self.comp.fps - self.last_fps).abs() > 1e-6; | | |
| 476 | if offset_changed || fps_changed { | | |
| 477 | self.last_audio_offset = self.comp.audio_offset; | | |
| 478 | self.last_fps = self.comp.fps; | | |
| 479 | self.refresh_audio_peaks(); | | |
| 480 | self.sync_audio(false, true); | | |
| 481 | } | | |
| 482 | | | |
| 483 | if self.playback.playing { | | |
| 484 | if let Some(player) = &mut self.audio_player { | | |
| 485 | let expected = self.playback.expected_audio_secs(&self.comp, now); | | |
| 486 | if !player.is_playing() { | | |
| 487 | player.play_from(expected); | | |
| 488 | } else { | | |
| 489 | let actual = player.current_time_secs(); | | |
| 490 | let frame_dur = 1.0 / self.comp.fps.max(1.0); | | |
| 491 | let max_drift = (frame_dur * 1.25).max(0.045); | | |
| 492 | if (actual - expected).abs() > max_drift { | | |
| 493 | player.seek(expected); | | |
| 494 | } | | |
| 495 | } | | |
| 496 | } | | |
| 497 | } | | |
| 498 | } | | |
| 499 | | | |
| 500 | fn set_notice(&mut self, msg: impl Into<String>) { | 361 | fn set_notice(&mut self, msg: impl Into<String>) { |
| 501 | self.status_notice = Some((msg.into(), Instant::now())); | 362 | self.status_notice = Some((msg.into(), Instant::now())); |
| 502 | } | 363 | } |
| 503 | | 364 | |
| 504 | fn invalidate_node(&mut self, node: Option<NodeId>) { | | |
| 505 | if let Some(id) = node { | | |
| 506 | self.engine.bust_subtree(id); | | |
| 507 | } else { | | |
| 508 | self.engine.bust_all_caches(); | | |
| 509 | } | | |
| 510 | self.ram_cache.invalidate_other_revisions(self.comp.revision); | | |
| 511 | if let Some(pf) = &self.prefetcher { | | |
| 512 | pf.cancel(); | | |
| 513 | } | | |
| 514 | self.last_prefetch_sig = None; | | |
| 515 | for v in &mut self.viewers { | | |
| 516 | v.cached_frames.clear(); | | |
| 517 | v.dirty = true; | | |
| 518 | } | | |
| 519 | } | | |
| 520 | | | |
| 521 | fn sync_ram_ranges_and_prefetch(&mut self) { | | |
| 522 | let sel = self.flow.primary; | | |
| 523 | for v in &mut self.viewers { | | |
| 524 | v.selected_node = sel; | | |
| 525 | } | | |
| 526 | if let Some(target) = self.viewers[0].viewed_node { | | |
| 527 | let ranges = self.ram_cache.cached_frame_ranges( | | |
| 528 | target, | | |
| 529 | self.comp.revision, | | |
| 530 | self.engine.proxy_scale, | | |
| 531 | self.engine.hiq, | | |
| 532 | self.engine.use_proxy_clips, | | |
| 533 | ); | | |
| 534 | self.viewers[0].ram_cached_ranges = ranges.clone(); | | |
| 535 | self.keyframes.cached_ranges = ranges; | | |
| 536 | | | |
| 537 | if let Some(pf) = &mut self.prefetcher { | | |
| 538 | if self.engine.cache.mode == CacheMode::Enabled { | | |
| 539 | let cur_f = self.playback.current_frame.round() as i64; | | |
| 540 | let sig = ( | | |
| 541 | target, | | |
| 542 | cur_f, | | |
| 543 | self.comp.revision, | | |
| 544 | self.engine.proxy_scale, | | |
| 545 | self.engine.hiq, | | |
| 546 | self.engine.use_proxy_clips, | | |
| 547 | ); | | |
| 548 | if self.last_prefetch_sig != Some(sig) { | | |
| 549 | self.last_prefetch_sig = Some(sig); | | |
| 550 | self.ram_cache.invalidate_other_revisions(self.comp.revision); | | |
| 551 | pf.request_lookahead(PrefetchJob { | | |
| 552 | comp: self.comp.clone(), | | |
| 553 | target, | | |
| 554 | center_frame: cur_f, | | |
| 555 | range: self.comp.render_range, | | |
| 556 | lookahead: 24, | | |
| 557 | proxy_scale: self.engine.proxy_scale, | | |
| 558 | hiq: self.engine.hiq, | | |
| 559 | use_proxy_clips: self.engine.use_proxy_clips, | | |
| 560 | }); | | |
| 561 | } | | |
| 562 | } | | |
| 563 | } | | |
| 564 | } else { | | |
| 565 | self.viewers[0].ram_cached_ranges.clear(); | | |
| 566 | self.keyframes.cached_ranges.clear(); | | |
| 567 | } | | |
| 568 | } | | |
| 569 | | | |
| 570 | fn undo(&mut self) { | | |
| 571 | let label = self.history.undo_label().unwrap_or("Edit").to_owned(); | | |
| 572 | if self.history.undo(&mut self.comp) { | | |
| 573 | self.flow.sanitize_ids(&self.comp); | | |
| 574 | for slot in [0usize, 1] { | | |
| 575 | if self.viewers[slot].viewed_node.is_some_and(|id| id.0 >= self.comp.nodes.len()) { | | |
| 576 | self.viewers[slot].viewed_node = self.comp.default_output_node(); | | |
| 577 | } | | |
| 578 | } | | |
| 579 | self.flow.viewed_nodes = [self.viewers[0].viewed_node, self.viewers[1].viewed_node]; | | |
| 580 | self.spline.set_target_node(&self.comp, self.flow.primary); | | |
| 581 | self.renaming_node = None; | | |
| 582 | self.invalidate_node(None); | | |
| 583 | self.set_notice(format!("Undo: {label}")); | | |
| 584 | } else { | | |
| 585 | self.set_notice("Nothing to undo"); | | |
| 586 | } | | |
| 587 | } | | |
| 588 | | | |
| 589 | fn redo(&mut self) { | | |
| 590 | let label = self.history.redo_label().unwrap_or("Edit").to_owned(); | | |
| 591 | if self.history.redo(&mut self.comp) { | | |
| 592 | self.flow.sanitize_ids(&self.comp); | | |
| 593 | for slot in [0usize, 1] { | | |
| 594 | if self.viewers[slot].viewed_node.is_some_and(|id| id.0 >= self.comp.nodes.len()) { | | |
| 595 | self.viewers[slot].viewed_node = self.comp.default_output_node(); | | |
| 596 | } | | |
| 597 | } | | |
| 598 | self.flow.viewed_nodes = [self.viewers[0].viewed_node, self.viewers[1].viewed_node]; | | |
| 599 | self.spline.set_target_node(&self.comp, self.flow.primary); | | |
| 600 | self.renaming_node = None; | | |
| 601 | self.invalidate_node(None); | | |
| 602 | self.set_notice(format!("Redo: {label}")); | | |
| 603 | } else { | | |
| 604 | self.set_notice("Nothing to redo"); | | |
| 605 | } | | |
| 606 | } | | |
| 607 | | | |
| 608 | fn save_comp(&mut self) -> Result<String, String> { | | |
| 609 | let Some(path) = self.comp.path.clone() else { | | |
| 610 | return self.save_comp_as(); | | |
| 611 | }; | | |
| 612 | self.save_to_path(&path) | | |
| 613 | } | | |
| 614 | | | |
| 615 | fn save_to_path(&mut self, path: &Path) -> Result<String, String> { | | |
| 616 | self.comp.current_time = self.playback.current_frame; | | |
| 617 | match self.comp.save_to_file(path) { | | |
| 618 | Ok(backup) => { | | |
| 619 | self.comp.path = Some(path.to_path_buf()); | | |
| 620 | if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) { | | |
| 621 | self.comp.name = stem.to_owned(); | | |
| 622 | } | | |
| 623 | self.history.mark_saved(&self.comp); | | |
| 624 | let msg = match backup { | | |
| 625 | Some(bak) => { | | |
| 626 | eprintln!("Saved {} (backup -> {})", path.display(), bak.display()); | | |
| 627 | "Saved (backup in temp)".to_owned() | | |
| 628 | } | | |
| 629 | None => { | | |
| 630 | eprintln!("Saved {}", path.display()); | | |
| 631 | format!("Saved {}", self.comp.name) | | |
| 632 | } | | |
| 633 | }; | | |
| 634 | self.set_notice(msg.clone()); | | |
| 635 | Ok(msg) | | |
| 636 | } | | |
| 637 | Err(e) => { | | |
| 638 | let err = format!("Save failed: {e}"); | | |
| 639 | eprintln!("{err}"); | | |
| 640 | self.set_notice(err.clone()); | | |
| 641 | Err(err) | | |
| 642 | } | | |
| 643 | } | | |
| 644 | } | | |
| 645 | | | |
| 646 | fn save_comp_as(&mut self) -> Result<String, String> { | | |
| 647 | let default_name = format!("{}.comp", self.comp.name); | | |
| 648 | let Some(mut path) = native_save_comp_dialog(&default_name) else { | | |
| 649 | return Err("Save As cancelled".to_owned()); | | |
| 650 | }; | | |
| 651 | if path.extension().is_none() { | | |
| 652 | path.set_extension("comp"); | | |
| 653 | } | | |
| 654 | self.save_to_path(&path) | | |
| 655 | } | | |
| 656 | | | |
| 657 | fn open_comp_dialog(&mut self) { | | |
| 658 | let Some(path) = native_open_comp_dialog() else { | | |
| 659 | return; | | |
| 660 | }; | | |
| 661 | match Comp::from_fusion_file(&path) { | | |
| 662 | Ok(new_comp) => { | | |
| 663 | self.reload_comp(new_comp); | | |
| 664 | self.set_notice(format!("Opened {}", self.comp.name)); | | |
| 665 | } | | |
| 666 | Err(e) => { | | |
| 667 | let msg = format!("Open failed: {e}"); | | |
| 668 | eprintln!("{msg}"); | | |
| 669 | self.set_notice(msg); | | |
| 670 | } | | |
| 671 | } | | |
| 672 | } | | |
| 673 | | | |
| 674 | fn reload_comp(&mut self, new_comp: Comp) { | | |
| 675 | if self.playback.playing { | | |
| 676 | self.playback.toggle_play(Instant::now()); | | |
| 677 | self.sync_audio(true, false); | | |
| 678 | } | | |
| 679 | self.comp = new_comp; | | |
| 680 | self.history.clear(); | | |
| 681 | self.history.mark_saved(&self.comp); | | |
| 682 | self.engine.bust_all_caches(); | | |
| 683 | self.playback.init_from_comp(&self.comp); | | |
| 684 | | | |
| 685 | let out_node = self.comp.default_output_node(); | | |
| 686 | for (slot, v) in self.viewers.iter_mut().enumerate() { | | |
| 687 | v.viewed_node = out_node; | | |
| 688 | v.cached_frames.clear(); | | |
| 689 | v.dirty = true; | | |
| 690 | if slot == 0 { | | |
| 691 | v.fit(); | | |
| 692 | } | | |
| 693 | } | | |
| 694 | self.flow.reset_for_comp(&self.comp); | | |
| 695 | self.flow.viewed_nodes = [self.viewers[0].viewed_node, None]; | | |
| 696 | let default_sel = self | | |
| 697 | .comp | | |
| 698 | .nodes | | |
| 699 | .iter() | | |
| 700 | .find(|n| !self.comp.node_splines(n.id).is_empty()) | | |
| 701 | .map(|n| n.id) | | |
| 702 | .or(out_node); | | |
| 703 | if let Some(id) = default_sel { | | |
| 704 | self.flow.selected.insert(id); | | |
| 705 | self.flow.primary = Some(id); | | |
| 706 | } | | |
| 707 | self.spline.set_target_node(&self.comp, default_sel); | | |
| 708 | self.keyframes.audio_peaks.clear(); | | |
| 709 | self.keyframes.cached_ranges.clear(); | | |
| 710 | self.keyframes.fit_comp(&self.comp); | | |
| 711 | self.keyframes.sync_tracks(&self.comp, default_sel); | | |
| 712 | self.viewers[0].audio_peaks.clear(); | | |
| 713 | self.ram_cache.clear(); | | |
| 714 | if let Some(pf) = &self.prefetcher { | | |
| 715 | pf.cancel(); | | |
| 716 | } | | |
| 717 | self.last_prefetch_sig = None; | | |
| 718 | self.inspector.reset(); | | |
| 719 | self.renaming_node = None; | | |
| 720 | self.loaded_audio_track = None; | | |
| 721 | self.last_audio_offset = self.comp.audio_offset; | | |
| 722 | self.last_fps = self.comp.fps; | | |
| 723 | self.last_audio_filename = self.comp.audio_filename.clone(); | | |
| 724 | | | |
| 725 | if self.enable_audio { | | |
| 726 | if let Some(player) = &mut self.audio_player { | | |
| 727 | player.set_track(None); | | |
| 728 | } | | |
| 729 | self.audio_rx = spawn_audio_loader(&self.comp); | | |
| 730 | } | | |
| 731 | } | | |
| 732 | | | |
| 733 | fn add_tool_from_entry(&mut self, entry: ToolEntry) { | 365 | fn add_tool_from_entry(&mut self, entry: ToolEntry) { |
| 734 | let prev_sel = self.flow.primary.filter(|id| id.0 < self.comp.nodes.len()); | 366 | let prev_sel = self.flow.primary.filter(|id| id.0 < self.comp.nodes.len()); |
| 735 | let pos = self.flow.spawn_position(&self.comp, entry.is_generator); | 367 | let pos = self.flow.spawn_position(&self.comp, entry.is_generator); |
| ... | @@ -749,34 +381,6 @@ impl Studio { | ... | @@ -749,34 +381,6 @@ impl Studio { |
| 749 | self.set_notice(format!("Added {}", self.comp.node(new_id).name)); | 381 | self.set_notice(format!("Added {}", self.comp.node(new_id).name)); |
| 750 | } | 382 | } |
| 751 | | 383 | |
| 752 | fn copy_nodes(&mut self, ids: &[NodeId]) { | | |
| 753 | self.ui.clipboard.set_text(self.comp.export_fusion_clipboard(ids)); | | |
| 754 | let n = ids.len(); | | |
| 755 | self.set_notice(format!("Copied {n} node{}", if n == 1 { "" } else { "s" })); | | |
| 756 | } | | |
| 757 | | | |
| 758 | fn paste_nodes(&mut self) { | | |
| 759 | if !self.flow.scope_path().is_empty() { | | |
| 760 | self.set_notice("Group contents are read-only; press Esc to leave the group before pasting"); | | |
| 761 | return; | | |
| 762 | } | | |
| 763 | let Some(text) = self.ui.clipboard.text() else { | | |
| 764 | self.set_notice("Clipboard is empty"); | | |
| 765 | return; | | |
| 766 | }; | | |
| 767 | match self.history.paste_fusion_clipboard(&mut self.comp, &text, (60.0, 40.0)) { | | |
| 768 | Ok(ids) => { | | |
| 769 | self.flow.selected = ids.iter().copied().collect(); | | |
| 770 | self.flow.primary = ids.first().copied(); | | |
| 771 | self.spline.set_target_node(&self.comp, self.flow.primary); | | |
| 772 | self.invalidate_node(None); | | |
| 773 | let n = ids.len(); | | |
| 774 | self.set_notice(format!("Pasted {n} node{}", if n == 1 { "" } else { "s" })); | | |
| 775 | } | | |
| 776 | Err(e) => self.set_notice(format!("Nothing pasted: {e}")), | | |
| 777 | } | | |
| 778 | } | | |
| 779 | | | |
| 780 | fn begin_inline_rename(&mut self, id: NodeId) { | 384 | fn begin_inline_rename(&mut self, id: NodeId) { |
| 781 | if id.0 >= self.comp.nodes.len() { | 385 | if id.0 >= self.comp.nodes.len() { |
| 782 | return; | 386 | return; |
| ... | @@ -786,296 +390,6 @@ impl Studio { | ... | @@ -786,296 +390,6 @@ impl Studio { |
| 786 | self.rename_needs_focus = true; | 390 | self.rename_needs_focus = true; |
| 787 | } | 391 | } |
| 788 | | 392 | |
| 789 | fn poll_export(&mut self) { | | |
| 790 | let Some(exp) = &self.active_export else { | | |
| 791 | return; | | |
| 792 | }; | | |
| 793 | match exp.rx.try_recv() { | | |
| 794 | Ok(outcome) => { | | |
| 795 | let mut finished = self.active_export.take().unwrap(); | | |
| 796 | if let Some(handle) = finished.handle.take() { | | |
| 797 | let _ = handle.join(); | | |
| 798 | } | | |
| 799 | match outcome { | | |
| 800 | ExportOutcome::Completed(msg) => { | | |
| 801 | eprintln!("{msg}"); | | |
| 802 | self.set_notice(msg); | | |
| 803 | } | | |
| 804 | ExportOutcome::Cancelled => { | | |
| 805 | eprintln!("Export cancelled"); | | |
| 806 | self.set_notice("Export cancelled"); | | |
| 807 | } | | |
| 808 | ExportOutcome::Failed(err) => { | | |
| 809 | eprintln!("{err}"); | | |
| 810 | self.set_notice(err); | | |
| 811 | } | | |
| 812 | } | | |
| 813 | } | | |
| 814 | Err(mpsc::TryRecvError::Disconnected) => { | | |
| 815 | let mut finished = self.active_export.take().unwrap(); | | |
| 816 | if let Some(handle) = finished.handle.take() { | | |
| 817 | let _ = handle.join(); | | |
| 818 | } | | |
| 819 | self.set_notice("Export worker stopped unexpectedly"); | | |
| 820 | } | | |
| 821 | Err(mpsc::TryRecvError::Empty) => {} | | |
| 822 | } | | |
| 823 | } | | |
| 824 | | | |
| 825 | fn spawn_export_worker<F>(&mut self, initial_progress: ExportProgress, job: F) -> Result<String, String> | | |
| 826 | where | | |
| 827 | F: FnOnce(&mut Engine, &ExportControl, &dyn Fn()) -> Result<String, String> + Send + 'static, | | |
| 828 | { | | |
| 829 | let control = ExportControl::new(); | | |
| 830 | control.update_progress(&initial_progress); | | |
| 831 | let ctrl_worker = control.clone(); | | |
| 832 | let proxy = self.redraw_proxy.clone(); | | |
| 833 | let (tx, rx) = mpsc::channel(); | | |
| 834 | | | |
| 835 | let handle = std::thread::Builder::new() | | |
| 836 | .name("fission-export".to_owned()) | | |
| 837 | .spawn(move || { | | |
| 838 | let notify_redraw = move || { | | |
| 839 | if let Some(p) = &proxy { | | |
| 840 | let _ = p.send_event(UserEvent::Redraw); | | |
| 841 | } | | |
| 842 | }; | | |
| 843 | let outcome = match Engine::new_headless() { | | |
| 844 | Ok(mut export_engine) => match job(&mut export_engine, &ctrl_worker, &notify_redraw) { | | |
| 845 | Ok(msg) => ExportOutcome::Completed(msg), | | |
| 846 | Err(e) if e == "Cancelled" => ExportOutcome::Cancelled, | | |
| 847 | Err(e) => ExportOutcome::Failed(e), | | |
| 848 | }, | | |
| 849 | Err(e) => ExportOutcome::Failed(format!("Failed to initialize export GPU: {e}")), | | |
| 850 | }; | | |
| 851 | let _ = tx.send(outcome); | | |
| 852 | notify_redraw(); | | |
| 853 | }) | | |
| 854 | .map_err(|e| format!("Failed to start export thread: {e}"))?; | | |
| 855 | | | |
| 856 | self.active_export = Some(ActiveExport { | | |
| 857 | control, | | |
| 858 | rx, | | |
| 859 | cancelling: false, | | |
| 860 | handle: Some(handle), | | |
| 861 | }); | | |
| 862 | Ok("Export started".to_owned()) | | |
| 863 | } | | |
| 864 | | | |
| 865 | fn export_saver_pngs(&mut self) -> Result<String, String> { | | |
| 866 | if self.active_export.is_some() { | | |
| 867 | let msg = "Export already in progress".to_owned(); | | |
| 868 | self.set_notice(msg.clone()); | | |
| 869 | return Err(msg); | | |
| 870 | } | | |
| 871 | let saver = match select_saver(&self.comp, None) { | | |
| 872 | Ok(s) => s, | | |
| 873 | Err(e) => { | | |
| 874 | let err = format!("Export failed: {e}"); | | |
| 875 | self.set_notice(err.clone()); | | |
| 876 | return Err(err); | | |
| 877 | } | | |
| 878 | }; | | |
| 879 | let [start, end] = saver.range; | | |
| 880 | if end < start { | | |
| 881 | let err = format!("Invalid Saver frame range {start}..={end}"); | | |
| 882 | self.set_notice(err.clone()); | | |
| 883 | return Err(err); | | |
| 884 | } | | |
| 885 | | | |
| 886 | let comp_snapshot = self.comp.clone(); | | |
| 887 | let opts = ExportOptions { | | |
| 888 | hiq: self.engine.hiq, | | |
| 889 | proxy_scale: self.engine.proxy_scale, | | |
| 890 | ..Default::default() | | |
| 891 | }; | | |
| 892 | let total = (end - start + 1) as u32; | | |
| 893 | let initial = ExportProgress { | | |
| 894 | frame: start, | | |
| 895 | total: total as usize, | | |
| 896 | saver_name: saver.name.clone(), | | |
| 897 | current_frame: start.max(0) as u32, | | |
| 898 | total_frames: total, | | |
| 899 | label: saver.name, | | |
| 900 | ..Default::default() | | |
| 901 | }; | | |
| 902 | | | |
| 903 | self.spawn_export_worker(initial, move |engine, control, notify| { | | |
| 904 | let t0 = Instant::now(); | | |
| 905 | match export_saver_png_sequence_with_progress(engine, &comp_snapshot, &opts, Some(control), |p| { | | |
| 906 | if p.index == 0 || (p.index + 1) % 10 == 0 || p.index + 1 == p.total { | | |
| 907 | let fps = (p.index + 1) as f64 / t0.elapsed().as_secs_f64().max(1e-6); | | |
| 908 | eprintln!( | | |
| 909 | " [export {}/{}] {} f{:04} ({:.1}ms, {:.1} fps) -> {}", | | |
| 910 | p.index + 1, | | |
| 911 | p.total, | | |
| 912 | p.saver_name, | | |
| 913 | p.frame, | | |
| 914 | p.eval_ms, | | |
| 915 | fps, | | |
| 916 | p.out_path.display() | | |
| 917 | ); | | |
| 918 | } | | |
| 919 | notify(); | | |
| 920 | }) { | | |
| 921 | Ok(summary) => { | | |
| 922 | let secs = (summary.total_ms / 1000.0).max(1e-6); | | |
| 923 | Ok(format!( | | |
| 924 | "Exported {} PNGs via {} ({:.1} fps)", | | |
| 925 | summary.frames_written, | | |
| 926 | summary.saver_name, | | |
| 927 | summary.frames_written as f64 / secs | | |
| 928 | )) | | |
| 929 | } | | |
| 930 | Err(e) if e == "Cancelled" => Err(e), | | |
| 931 | Err(e) => Err(format!("Export failed: {e}")), | | |
| 932 | } | | |
| 933 | }) | | |
| 934 | } | | |
| 935 | | | |
| 936 | fn active_viewer_slot(&self) -> usize { | | |
| 937 | if let Some(focused) = self.seen.focused { | | |
| 938 | if self.layout.group_of(&"Viewer 2".to_owned(), String::clone) == Some(focused) { | | |
| 939 | return 1; | | |
| 940 | } | | |
| 941 | } | | |
| 942 | 0 | | |
| 943 | } | | |
| 944 | | | |
| 945 | fn export_viewer_mp4(&mut self, slot: usize) -> Result<String, String> { | | |
| 946 | if self.active_export.is_some() { | | |
| 947 | let msg = "Export already in progress".to_owned(); | | |
| 948 | self.set_notice(msg.clone()); | | |
| 949 | return Err(msg); | | |
| 950 | } | | |
| 951 | let Some(target) = self.viewers[slot].viewed_node else { | | |
| 952 | let msg = format!("Viewer {} has no node loaded", slot + 1); | | |
| 953 | self.set_notice(msg.clone()); | | |
| 954 | return Err(msg); | | |
| 955 | }; | | |
| 956 | let [in_f, out_f] = self.playback.effective_preview_range(&self.comp); | | |
| 957 | let node_name = self.comp.node(target).name.clone(); | | |
| 958 | let default_name = format!( | | |
| 959 | "{}_{}_f{}-{}.mp4", | | |
| 960 | sanitize_filename(&self.comp.name), | | |
| 961 | sanitize_filename(&node_name), | | |
| 962 | in_f, | | |
| 963 | out_f | | |
| 964 | ); | | |
| 965 | let Some(mut path) = native_save_file_dialog("Export Preview MP4 / ProRes", &default_name) else { | | |
| 966 | return Err("Export cancelled".to_owned()); | | |
| 967 | }; | | |
| 968 | if path.extension().is_none() { | | |
| 969 | path.set_extension("mp4"); | | |
| 970 | } | | |
| 971 | let codec = if path | | |
| 972 | .extension() | | |
| 973 | .and_then(|e| e.to_str()) | | |
| 974 | .is_some_and(|e| e.eq_ignore_ascii_case("mov")) | | |
| 975 | { | | |
| 976 | VideoCodec::ProRes422 | | |
| 977 | } else { | | |
| 978 | VideoCodec::H264Share | | |
| 979 | }; | | |
| 980 | | | |
| 981 | let comp_snapshot = self.comp.clone(); | | |
| 982 | let opts = VideoExportOptions { | | |
| 983 | target, | | |
| 984 | out_path: path.clone(), | | |
| 985 | range: [in_f, out_f], | | |
| 986 | codec, | | |
| 987 | crf: 26, | | |
| 988 | max_height: None, | | |
| 989 | include_audio: true, | | |
| 990 | hiq: self.engine.hiq, | | |
| 991 | proxy_scale: self.engine.proxy_scale, | | |
| 992 | }; | | |
| 993 | let total = (out_f - in_f + 1).max(1) as u32; | | |
| 994 | let label = match codec { | | |
| 995 | VideoCodec::ProRes422 | VideoCodec::ProRes4444 => format!("{node_name} (ProRes)"), | | |
| 996 | VideoCodec::H264Share => format!("{node_name} (MP4)"), | | |
| 997 | }; | | |
| 998 | let initial = ExportProgress { | | |
| 999 | frame: in_f, | | |
| 1000 | total: total as usize, | | |
| 1001 | out_path: path, | | |
| 1002 | saver_name: node_name, | | |
| 1003 | current_frame: in_f.max(0) as u32, | | |
| 1004 | total_frames: total, | | |
| 1005 | label, | | |
| 1006 | ..Default::default() | | |
| 1007 | }; | | |
| 1008 | | | |
| 1009 | self.spawn_export_worker(initial, move |engine, control, notify| { | | |
| 1010 | let t0 = Instant::now(); | | |
| 1011 | match export_node_video_ffmpeg_with_progress(engine, &comp_snapshot, &opts, Some(control), |p| { | | |
| 1012 | if p.index == 0 || (p.index + 1) % 10 == 0 || p.index + 1 == p.total { | | |
| 1013 | let fps = (p.index + 1) as f64 / t0.elapsed().as_secs_f64().max(1e-6); | | |
| 1014 | eprintln!( | | |
| 1015 | " [video {}/{}] {} f{:04} ({:.1}ms, {:.1} fps) -> {}", | | |
| 1016 | p.index + 1, | | |
| 1017 | p.total, | | |
| 1018 | p.saver_name, | | |
| 1019 | p.frame, | | |
| 1020 | p.eval_ms, | | |
| 1021 | fps, | | |
| 1022 | p.out_path.display() | | |
| 1023 | ); | | |
| 1024 | } | | |
| 1025 | notify(); | | |
| 1026 | }) { | | |
| 1027 | Ok(summary) => { | | |
| 1028 | let mb = summary.file_bytes as f64 / (1024.0 * 1024.0); | | |
| 1029 | let audio_tag = if summary.has_audio { " + audio" } else { "" }; | | |
| 1030 | Ok(format!( | | |
| 1031 | "Exported {} frames{audio_tag} ({mb:.2} MB) -> {}", | | |
| 1032 | summary.frames_written, | | |
| 1033 | summary.out_path.file_name().and_then(|n| n.to_str()).unwrap_or("video") | | |
| 1034 | )) | | |
| 1035 | } | | |
| 1036 | Err(e) if e == "Cancelled" => Err(e), | | |
| 1037 | Err(e) => Err(format!("Video export failed: {e}")), | | |
| 1038 | } | | |
| 1039 | }) | | |
| 1040 | } | | |
| 1041 | | | |
| 1042 | fn save_viewer_frame_png(&mut self, slot: usize) -> Result<String, String> { | | |
| 1043 | let Some(target) = self.viewers[slot].viewed_node else { | | |
| 1044 | let msg = format!("Viewer {} has no node loaded", slot + 1); | | |
| 1045 | self.set_notice(msg.clone()); | | |
| 1046 | return Err(msg); | | |
| 1047 | }; | | |
| 1048 | let frame_f = self.playback.current_frame; | | |
| 1049 | let frame_i = frame_f.round() as i64; | | |
| 1050 | let node_name = self.comp.node(target).name.clone(); | | |
| 1051 | let default_name = format!( | | |
| 1052 | "{}_{}_f{}.png", | | |
| 1053 | sanitize_filename(&self.comp.name), | | |
| 1054 | sanitize_filename(&node_name), | | |
| 1055 | frame_i | | |
| 1056 | ); | | |
| 1057 | let Some(mut path) = native_save_file_dialog("Save Frame PNG", &default_name) else { | | |
| 1058 | return Err("Save Frame cancelled".to_owned()); | | |
| 1059 | }; | | |
| 1060 | if path.extension().is_none() { | | |
| 1061 | path.set_extension("png"); | | |
| 1062 | } | | |
| 1063 | match export_node_frame_png(&mut self.engine, &self.comp, target, frame_f, &path) { | | |
| 1064 | Ok(saved) => { | | |
| 1065 | let msg = format!("Saved frame f{frame_i} PNG"); | | |
| 1066 | eprintln!("{msg} -> {}", saved.display()); | | |
| 1067 | self.set_notice(msg.clone()); | | |
| 1068 | Ok(msg) | | |
| 1069 | } | | |
| 1070 | Err(e) => { | | |
| 1071 | let err = format!("Save PNG failed: {e}"); | | |
| 1072 | eprintln!("{err}"); | | |
| 1073 | self.set_notice(err.clone()); | | |
| 1074 | Err(err) | | |
| 1075 | } | | |
| 1076 | } | | |
| 1077 | } | | |
| 1078 | | | |
| 1079 | fn window_title(&self) -> String { | 393 | fn window_title(&self) -> String { |
| 1080 | let dirty = if self.history.is_dirty(&self.comp) { "*" } else { "" }; | 394 | let dirty = if self.history.is_dirty(&self.comp) { "*" } else { "" }; |
| 1081 | if let Some((msg, at)) = &self.status_notice { | 395 | if let Some((msg, at)) = &self.status_notice { |
| ... | @@ -1086,56 +400,9 @@ impl Studio { | ... | @@ -1086,56 +400,9 @@ impl Studio { |
| 1086 | format!("Fission — {}{dirty}", self.comp.name) | 400 | format!("Fission — {}{dirty}", self.comp.name) |
| 1087 | } | 401 | } |
| 1088 | | 402 | |
| 1089 | fn ensure_viewer2_open(&mut self) { | | |
| 1090 | if self.layout.group_of(&"Viewer 2".to_owned(), String::clone).is_some() { | | |
| 1091 | return; | | |
| 1092 | } | | |
| 1093 | let target_group = self | | |
| 1094 | .layout | | |
| 1095 | .group_of(&"Viewer 1".to_owned(), String::clone) | | |
| 1096 | .unwrap_or_else(|| self.dock.at(&mut self.layout, &mut self.seen, &String::clone).focused()); | | |
| 1097 | self.dock | | |
| 1098 | .at(&mut self.layout, &mut self.seen, &String::clone) | | |
| 1099 | .open("Viewer 2".to_owned(), Place::Beside(target_group, Side::Right)); | | |
| 1100 | } | | |
| 1101 | | | |
| 1102 | fn clear_viewers(&mut self) { | | |
| 1103 | for v in &mut self.viewers { | | |
| 1104 | v.clear(); | | |
| 1105 | } | | |
| 1106 | self.flow.viewed_nodes = [None, None]; | | |
| 1107 | } | | |
| 1108 | | | |
| 1109 | fn frame(&mut self, now: Instant) -> bool { | 403 | fn frame(&mut self, now: Instant) -> bool { |
| 1110 | self.clock = now; | 404 | let animating = self.step_playback_and_audio(now); |
| 1111 | self.poll_audio_load(); | 405 | self.render_visible_viewers(false); |
| 1112 | self.poll_export(); | | |
| 1113 | let tick = self.playback.tick_synced(&self.comp, now); | | |
| 1114 | if tick.frame_changed { | | |
| 1115 | for v in &mut self.viewers { | | |
| 1116 | v.dirty = true; | | |
| 1117 | } | | |
| 1118 | } | | |
| 1119 | if tick.looped { | | |
| 1120 | self.sync_audio(false, true); | | |
| 1121 | } | | |
| 1122 | self.check_audio_sync_and_metadata(now); | | |
| 1123 | let animating = tick.playing; | | |
| 1124 | | | |
| 1125 | self.sync_ram_ranges_and_prefetch(); | | |
| 1126 | let shown = self.dock.at(&mut self.layout, &mut self.seen, &String::clone).shown(); | | |
| 1127 | for (slot, pane_name) in [(0, "Viewer 1"), (1, "Viewer 2")] { | | |
| 1128 | if shown.contains(&pane_name.to_owned()) { | | |
| 1129 | self.viewers[slot].ensure_rendered_with_ram( | | |
| 1130 | &mut self.engine, | | |
| 1131 | Some(&self.ram_cache), | | |
| 1132 | &self.comp, | | |
| 1133 | self.playback.current_frame, | | |
| 1134 | self.scale, | | |
| 1135 | ); | | |
| 1136 | self.viewers[slot].prepare_hud(&self.comp, &self.engine, &self.playback); | | |
| 1137 | } | | |
| 1138 | } | | |
| 1139 | self.flow.prepare_labels(&self.comp); | 406 | self.flow.prepare_labels(&self.comp); |
| 1140 | self.spline.prepare_labels(&self.comp); | 407 | self.spline.prepare_labels(&self.comp); |
| 1141 | self.keyframes.sync_tracks(&self.comp, self.flow.primary); | 408 | self.keyframes.sync_tracks(&self.comp, self.flow.primary); |
| ... | @@ -1157,7 +424,7 @@ impl Studio { | ... | @@ -1157,7 +424,7 @@ impl Studio { |
| 1157 | let export_snapshot = self | 424 | let export_snapshot = self |
| 1158 | .active_export | 425 | .active_export |
| 1159 | .as_ref() | 426 | .as_ref() |
| 1160 | .map(|exp| (exp.control.snapshot_progress(), exp.cancelling)); | 427 | .map(|exp| (exp.control.snapshot_progress(), exp.kind, exp.cancelling)); |
| 1161 | let notice_banner = if export_snapshot.is_none() { | 428 | let notice_banner = if export_snapshot.is_none() { |
| 1162 | self.status_notice.as_ref().and_then(|(msg, at)| { | 429 | self.status_notice.as_ref().and_then(|(msg, at)| { |
| 1163 | if at.elapsed() < Duration::from_secs(8) { | 430 | if at.elapsed() < Duration::from_secs(8) { |
| ... | @@ -1273,114 +540,27 @@ impl Studio { | ... | @@ -1273,114 +540,27 @@ impl Studio { |
| 1273 | ..ui::Spec::default() | 540 | ..ui::Spec::default() |
| 1274 | }, | 541 | }, |
| 1275 | ); | 542 | ); |
| 1276 | // Compact Flow toolbar with `+ Add`, Undo/Redo, Open/Save/Save As, and inline F2 rename | | |
| 1277 | let bar_bg = ui.theme.strip; | | |
| 1278 | ui.open( | | |
| 1279 | "flow-toolbar", | | |
| 1280 | ui::Spec { | | |
| 1281 | size: [ui::fill(), ui::px(28.0)], | | |
| 1282 | axis: ui::Axis::X, | | |
| 1283 | pad: [6.0, 3.0], | | |
| 1284 | gap: 4.0, | | |
| 1285 | fill: Some(bar_bg), | | |
| 1286 | ..ui::Spec::default() | | |
| 1287 | }, | | |
| 1288 | ); | | |
| 1289 | if studio_btn(ui, "flow-add-btn", "+ Add", false).clicked { | | |
| 1290 | req_open_add_tool = true; | | |
| 1291 | } | | |
| 1292 | if studio_btn(ui, "flow-undo-btn", "Undo", can_undo).clicked && can_undo { | | |
| 1293 | req_undo = true; | | |
| 1294 | } | | |
| 1295 | if studio_btn(ui, "flow-redo-btn", "Redo", can_redo).clicked && can_redo { | | |
| 1296 | req_redo = true; | | |
| 1297 | } | | |
| 1298 | if studio_btn(ui, "flow-open-btn", "Open", false).clicked { | | |
| 1299 | req_open = true; | | |
| 1300 | } | | |
| 1301 | if studio_btn(ui, "flow-save-btn", if comp_unsaved { "Save*" } else { "Save" }, comp_unsaved).clicked { | | |
| 1302 | req_save = true; | | |
| 1303 | } | | |
| 1304 | if studio_btn(ui, "flow-saveas-btn", "Save As", false).clicked { | | |
| 1305 | req_save_as = true; | | |
| 1306 | } | | |
| 1307 | let scope_path = flow.scope_path(); | 543 | let scope_path = flow.scope_path(); |
| 1308 | if !scope_path.is_empty() { | 544 | let tb = build_flow_toolbar( |
| 1309 | let crumb_sep = |ui: &mut ui::Ui, part: usize| { | 545 | ui, |
| 1310 | let ink = ui.theme.text_dim; | 546 | comp, |
| 1311 | ui.leaf( | 547 | &scope_path, |
| 1312 | ("flow-crumb-sep", part), | 548 | can_undo, |
| 1313 | ui::Spec { | 549 | can_redo, |
| 1314 | size: [ui::fit(), ui::px(22.0)], | 550 | comp_unsaved, |
| 1315 | text: Some(">"), | 551 | renaming_node, |
| 1316 | font_size: Some(11.0), | 552 | rename_buf, |
| 1317 | color: Some(ink), | 553 | rename_needs_focus, |
| 1318 | pad: [2.0, 0.0], | 554 | ); |
| 1319 | center: true, | 555 | req_open_add_tool = tb.open_add_tool; |
| 1320 | ..ui::Spec::default() | 556 | req_undo = tb.undo; |
| 1321 | }, | 557 | req_redo = tb.redo; |
| 1322 | ); | 558 | req_open = tb.open; |
| 1323 | }; | 559 | req_save = tb.save; |
| 1324 | if studio_btn(ui, "flow-crumb-root", "Root", false).clicked { | 560 | req_save_as = tb.save_as; |
| 1325 | req_exit_to_depth = Some(0); | 561 | req_exit_to_depth = tb.exit_to_depth; |
| 1326 | } | 562 | commit_rename = tb.commit_rename; |
| 1327 | for (depth, &group) in scope_path.iter().enumerate() { | 563 | cancel_rename = tb.cancel_rename; |
| 1328 | crumb_sep(ui, depth); | | |
| 1329 | let current = depth + 1 == scope_path.len(); | | |
| 1330 | let crumb = studio_btn(ui, ("flow-crumb", depth), &comp.node(group).name, current); | | |
| 1331 | if crumb.clicked && !current { | | |
| 1332 | req_exit_to_depth = Some(depth + 1); | | |
| 1333 | } | | |
| 1334 | } | | |
| 1335 | crumb_sep(ui, scope_path.len()); | | |
| 1336 | ui.leaf( | | |
| 1337 | "flow-crumb-hint", | | |
| 1338 | ui::Spec { | | |
| 1339 | size: [ui::fit(), ui::px(22.0)], | | |
| 1340 | text: Some("Esc: back"), | | |
| 1341 | font_size: Some(10.5), | | |
| 1342 | color: Some(ui.theme.text_dim), | | |
| 1343 | center: true, | | |
| 1344 | ..ui::Spec::default() | | |
| 1345 | }, | | |
| 1346 | ); | | |
| 1347 | } | | |
| 1348 | if let Some(rn_id) = *renaming_node { | | |
| 1349 | let rn_field_id = flow_pane_id().child(("rename-field", rn_id.0)); | | |
| 1350 | let rn_sig = ui::text_field( | | |
| 1351 | ui, | | |
| 1352 | rn_field_id, | | |
| 1353 | rename_buf, | | |
| 1354 | "Rename node…", | | |
| 1355 | ui::Spec { | | |
| 1356 | size: [ui::px(160.0), ui::px(22.0)], | | |
| 1357 | font_size: Some(11.5), | | |
| 1358 | fill: Some(ui.theme.base), | | |
| 1359 | border: Some(ui.theme.accent), | | |
| 1360 | radius: 4.0, | | |
| 1361 | pad: [6.0, 1.0], | | |
| 1362 | ..ui::Spec::default() | | |
| 1363 | }, | | |
| 1364 | ); | | |
| 1365 | if *rename_needs_focus { | | |
| 1366 | ui.set_focus(Some(rn_field_id)); | | |
| 1367 | *rename_needs_focus = false; | | |
| 1368 | } | | |
| 1369 | for ev in &rn_sig.events { | | |
| 1370 | if let ui::Event::Key { key, .. } = ev { | | |
| 1371 | match key { | | |
| 1372 | Key::Named(NamedKey::Enter) => { | | |
| 1373 | commit_rename = Some((rn_id, rename_buf.trim().to_owned())); | | |
| 1374 | } | | |
| 1375 | Key::Named(NamedKey::Escape) => { | | |
| 1376 | cancel_rename = true; | | |
| 1377 | } | | |
| 1378 | _ => {} | | |
| 1379 | } | | |
| 1380 | } | | |
| 1381 | } | | |
| 1382 | } | | |
| 1383 | ui.close(); // flow-toolbar | | |
| 1384 | | 564 | |
| 1385 | let id = ui.open_as( | 565 | let id = ui.open_as( |
| 1386 | flow_canvas_id(), | 566 | flow_canvas_id(), |
| ... | @@ -1437,99 +617,9 @@ impl Studio { | ... | @@ -1437,99 +617,9 @@ impl Studio { |
| 1437 | ); | 617 | ); |
| 1438 | | 618 | |
| 1439 | if show_status_strip { | 619 | if show_status_strip { |
| 1440 | ui.open( | 620 | let strip_acts = build_status_strip(ui, strip_h, &export_snapshot, &notice_banner); |
| 1441 | "studio-status-strip", | 621 | req_cancel_export = strip_acts.cancel_export; |
| 1442 | ui::Spec { | 622 | req_dismiss_notice = strip_acts.dismiss_notice; |
| 1443 | size: [ui::fill(), ui::px(strip_h)], | | |
| 1444 | axis: ui::Axis::X, | | |
| 1445 | pad: [10.0, 3.0], | | |
| 1446 | gap: 8.0, | | |
| 1447 | fill: Some(ui.theme.strip), | | |
| 1448 | border: Some(ui.theme.rule), | | |
| 1449 | ..ui::Spec::default() | | |
| 1450 | }, | | |
| 1451 | ); | | |
| 1452 | if let Some((prog, cancelling)) = &export_snapshot { | | |
| 1453 | let total = prog.total_frames.max(1); | | |
| 1454 | let frac = (prog.completed_frames as f32 / total as f32).clamp(0.0, 1.0); | | |
| 1455 | let pct = (frac * 100.0).round() as u32; | | |
| 1456 | let fill_w = (frac * 176.0).round(); | | |
| 1457 | let bar_bg = ui.theme.base; | | |
| 1458 | let bar_border = ui.theme.rule; | | |
| 1459 | let bar_accent = ui.theme.accent; | | |
| 1460 | ui.open( | | |
| 1461 | "export-progress-track", | | |
| 1462 | ui::Spec { | | |
| 1463 | size: [ui::px(180.0), ui::px(12.0)], | | |
| 1464 | axis: ui::Axis::X, | | |
| 1465 | pad: [2.0, 2.0], | | |
| 1466 | fill: Some(bar_bg), | | |
| 1467 | border: Some(bar_border), | | |
| 1468 | radius: 4.0, | | |
| 1469 | ..ui::Spec::default() | | |
| 1470 | }, | | |
| 1471 | ); | | |
| 1472 | if fill_w > 0.0 { | | |
| 1473 | ui.leaf( | | |
| 1474 | "export-progress-fill", | | |
| 1475 | ui::Spec { | | |
| 1476 | size: [ui::px(fill_w), ui::fill()], | | |
| 1477 | fill: Some(bar_accent), | | |
| 1478 | radius: 2.0, | | |
| 1479 | ..ui::Spec::default() | | |
| 1480 | }, | | |
| 1481 | ); | | |
| 1482 | } | | |
| 1483 | ui.close(); | | |
| 1484 | | | |
| 1485 | let status_txt = if *cancelling { | | |
| 1486 | format!( | | |
| 1487 | "Cancelling {} ({}/{})…", | | |
| 1488 | prog.label, prog.completed_frames, prog.total_frames | | |
| 1489 | ) | | |
| 1490 | } else { | | |
| 1491 | format!( | | |
| 1492 | "Exporting {} {}/{} ({pct}%) · f{:04} · {:.1}s", | | |
| 1493 | prog.label, | | |
| 1494 | prog.completed_frames, | | |
| 1495 | prog.total_frames, | | |
| 1496 | prog.frame, | | |
| 1497 | prog.elapsed_secs | | |
| 1498 | ) | | |
| 1499 | }; | | |
| 1500 | let ink = ui.theme.text; | | |
| 1501 | ui.leaf( | | |
| 1502 | "export-progress-label", | | |
| 1503 | ui::Spec { | | |
| 1504 | size: [ui::fill(), ui::fill()], | | |
| 1505 | text: Some(&status_txt), | | |
| 1506 | font_size: Some(11.0), | | |
| 1507 | medium: true, | | |
| 1508 | color: Some(ink), | | |
| 1509 | ..ui::Spec::default() | | |
| 1510 | }, | | |
| 1511 | ); | | |
| 1512 | let cancel_lbl = if *cancelling { "Cancelling…" } else { "Cancel" }; | | |
| 1513 | if studio_btn(ui, "export-cancel-btn", cancel_lbl, *cancelling).clicked && !*cancelling { | | |
| 1514 | req_cancel_export = true; | | |
| 1515 | } | | |
| 1516 | } else if let Some(msg) = &notice_banner { | | |
| 1517 | let ink = ui.theme.text; | | |
| 1518 | ui.leaf( | | |
| 1519 | "status-notice-label", | | |
| 1520 | ui::Spec { | | |
| 1521 | size: [ui::fill(), ui::fill()], | | |
| 1522 | text: Some(msg), | | |
| 1523 | font_size: Some(11.0), | | |
| 1524 | color: Some(ink), | | |
| 1525 | ..ui::Spec::default() | | |
| 1526 | }, | | |
| 1527 | ); | | |
| 1528 | if studio_btn(ui, "status-notice-dismiss", "×", false).clicked { | | |
| 1529 | req_dismiss_notice = true; | | |
| 1530 | } | | |
| 1531 | } | | |
| 1532 | ui.close(); | | |
| 1533 | } | 623 | } |
| 1534 | ui.close(); // studio-root | 624 | ui.close(); // studio-root |
| 1535 | | 625 | |
| ... | @@ -1560,7 +650,7 @@ impl Studio { | ... | @@ -1560,7 +650,7 @@ impl Studio { |
| 1560 | self.redo(); | 650 | self.redo(); |
| 1561 | } | 651 | } |
| 1562 | if req_open { | 652 | if req_open { |
| 1563 | self.open_comp_dialog(); | 653 | self.open_comp(); |
| 1564 | } | 654 | } |
| 1565 | if req_save { | 655 | if req_save { |
| 1566 | let _ = self.save_comp(); | 656 | let _ = self.save_comp(); |
| ... | @@ -1624,27 +714,7 @@ impl Studio { | ... | @@ -1624,27 +714,7 @@ impl Studio { |
| 1624 | } | 714 | } |
| 1625 | | 715 | |
| 1626 | self.route_viewer_actions(viewer_actions, now); | 716 | self.route_viewer_actions(viewer_actions, now); |
| 1627 | | 717 | self.poll_viewer_inputs(now); |
| 1628 | for slot in [0usize, 1] { | | |
| 1629 | let cid = viewer_canvas_id(slot); | | |
| 1630 | if let Some(rect) = self.ui.laid_out(cid) { | | |
| 1631 | self.viewers[slot].resize([rect[2] - rect[0], rect[3] - rect[1]]); | | |
| 1632 | let sig = self.ui.signal(cid); | | |
| 1633 | let ptr = self.ui.last_pointer(); | | |
| 1634 | let mods = self.ui.modifiers(); | | |
| 1635 | let was_open = self.viewers[slot].is_context_menu_open(); | | |
| 1636 | let mut acts = Vec::new(); | | |
| 1637 | for ev in sig.events { | | |
| 1638 | for a in self.viewers[slot].input(&self.comp, &self.playback, ev, rect, ptr, mods) { | | |
| 1639 | acts.push((slot, a)); | | |
| 1640 | } | | |
| 1641 | } | | |
| 1642 | if !was_open && self.viewers[slot].is_context_menu_open() { | | |
| 1643 | self.viewers[1 - slot].close_context_menu(); | | |
| 1644 | } | | |
| 1645 | self.route_viewer_actions(acts, now); | | |
| 1646 | } | | |
| 1647 | } | | |
| 1648 | | 718 | |
| 1649 | if let Some(rect) = self.ui.laid_out(flow_canvas_id()) { | 719 | if let Some(rect) = self.ui.laid_out(flow_canvas_id()) { |
| 1650 | self.flow.resize([rect[2] - rect[0], rect[3] - rect[1]]); | 720 | self.flow.resize([rect[2] - rect[0], rect[3] - rect[1]]); |
| ... | @@ -1774,169 +844,11 @@ impl Studio { | ... | @@ -1774,169 +844,11 @@ impl Studio { |
| 1774 | } | 844 | } |
| 1775 | | 845 | |
| 1776 | // Immediately re-render any dirty visible viewer before painting this frame! | 846 | // Immediately re-render any dirty visible viewer before painting this frame! |
| 1777 | self.sync_ram_ranges_and_prefetch(); | 847 | self.render_visible_viewers(true); |
| 1778 | let shown_now = self.dock.at(&mut self.layout, &mut self.seen, &String::clone).shown(); | | |
| 1779 | for (slot, pane_name) in [(0, "Viewer 1"), (1, "Viewer 2")] { | | |
| 1780 | if shown_now.contains(&pane_name.to_owned()) && self.viewers[slot].dirty { | | |
| 1781 | self.viewers[slot].ensure_rendered_with_ram( | | |
| 1782 | &mut self.engine, | | |
| 1783 | Some(&self.ram_cache), | | |
| 1784 | &self.comp, | | |
| 1785 | self.playback.current_frame, | | |
| 1786 | self.scale, | | |
| 1787 | ); | | |
| 1788 | self.viewers[slot].prepare_hud(&self.comp, &self.engine, &self.playback); | | |
| 1789 | } | | |
| 1790 | } | | |
| 1791 | | 848 | |
| 1792 | animating || self.ui.wants_frame() || self.dock.moving() | 849 | animating || self.ui.wants_frame() || self.dock.moving() |
| 1793 | } | 850 | } |
| 1794 | | 851 | |
| 1795 | fn route_viewer_actions(&mut self, actions: Vec<(usize, ViewerAction)>, now: Instant) { | | |
| 1796 | for (slot, a) in actions { | | |
| 1797 | match a { | | |
| 1798 | ViewerAction::TogglePlay => { | | |
| 1799 | self.playback.toggle_play_with_comp(&self.comp, now); | | |
| 1800 | self.sync_audio(true, false); | | |
| 1801 | } | | |
| 1802 | ViewerAction::SetFrame(f) => { | | |
| 1803 | if self.playback.set_frame(&self.comp, f, now) { | | |
| 1804 | self.sync_audio(false, true); | | |
| 1805 | for v in &mut self.viewers { | | |
| 1806 | v.dirty = true; | | |
| 1807 | } | | |
| 1808 | } | | |
| 1809 | } | | |
| 1810 | ViewerAction::ToggleSyncMode => { | | |
| 1811 | self.playback.sync_mode = match self.playback.sync_mode { | | |
| 1812 | SyncMode::RealtimeDrop => SyncMode::EveryFrame, | | |
| 1813 | SyncMode::EveryFrame => SyncMode::RealtimeDrop, | | |
| 1814 | }; | | |
| 1815 | } | | |
| 1816 | ViewerAction::NeedRender => { | | |
| 1817 | self.viewers[slot].dirty = true; | | |
| 1818 | } | | |
| 1819 | ViewerAction::BustFrame(f) => { | | |
| 1820 | self.engine.bust_frame(f); | | |
| 1821 | self.ram_cache.clear(); | | |
| 1822 | self.last_prefetch_sig = None; | | |
| 1823 | for v in &mut self.viewers { | | |
| 1824 | v.cached_frames.remove(&f); | | |
| 1825 | v.dirty = true; | | |
| 1826 | } | | |
| 1827 | } | | |
| 1828 | ViewerAction::BustSubtree => { | | |
| 1829 | if let Some(id) = self.flow.primary.or(self.viewers[slot].viewed_node) { | | |
| 1830 | self.engine.bust_subtree(id); | | |
| 1831 | } | | |
| 1832 | self.ram_cache.clear(); | | |
| 1833 | self.last_prefetch_sig = None; | | |
| 1834 | for v in &mut self.viewers { | | |
| 1835 | v.cached_frames.clear(); | | |
| 1836 | v.dirty = true; | | |
| 1837 | } | | |
| 1838 | } | | |
| 1839 | ViewerAction::BustGpu => { | | |
| 1840 | self.engine.bust_gpu_cache(); | | |
| 1841 | self.ram_cache.clear(); | | |
| 1842 | self.last_prefetch_sig = None; | | |
| 1843 | for v in &mut self.viewers { | | |
| 1844 | v.cached_frames.clear(); | | |
| 1845 | v.dirty = true; | | |
| 1846 | } | | |
| 1847 | } | | |
| 1848 | ViewerAction::BustAll => { | | |
| 1849 | self.engine.bust_all_caches(); | | |
| 1850 | self.ram_cache.clear(); | | |
| 1851 | self.last_prefetch_sig = None; | | |
| 1852 | for v in &mut self.viewers { | | |
| 1853 | v.cached_frames.clear(); | | |
| 1854 | v.dirty = true; | | |
| 1855 | } | | |
| 1856 | } | | |
| 1857 | ViewerAction::ToggleCacheBypass => { | | |
| 1858 | let next = match self.engine.cache.mode { | | |
| 1859 | CacheMode::Enabled => CacheMode::Bypass, | | |
| 1860 | CacheMode::Bypass => CacheMode::Enabled, | | |
| 1861 | }; | | |
| 1862 | self.engine.set_cache_mode(next); | | |
| 1863 | for v in &mut self.viewers { | | |
| 1864 | v.dirty = true; | | |
| 1865 | } | | |
| 1866 | } | | |
| 1867 | ViewerAction::SetProxy(scale) => { | | |
| 1868 | if self.engine.proxy_scale != scale { | | |
| 1869 | self.engine.proxy_scale = scale; | | |
| 1870 | self.engine.bust_gpu_cache(); | | |
| 1871 | for v in &mut self.viewers { | | |
| 1872 | v.cached_frames.clear(); | | |
| 1873 | v.dirty = true; | | |
| 1874 | } | | |
| 1875 | } | | |
| 1876 | } | | |
| 1877 | ViewerAction::ToggleHiQ => { | | |
| 1878 | self.engine.hiq = !self.engine.hiq; | | |
| 1879 | for v in &mut self.viewers { | | |
| 1880 | v.cached_frames.clear(); | | |
| 1881 | v.dirty = true; | | |
| 1882 | } | | |
| 1883 | } | | |
| 1884 | ViewerAction::ClearViewers => { | | |
| 1885 | self.clear_viewers(); | | |
| 1886 | } | | |
| 1887 | ViewerAction::GizmoEdited(edit) => { | | |
| 1888 | self.history.push_coalesced(&self.comp, edit.label, &edit.coalesce_key); | | |
| 1889 | self.comp.set_input_value(edit.node_id, edit.input, edit.value); | | |
| 1890 | self.invalidate_node(Some(edit.node_id)); | | |
| 1891 | } | | |
| 1892 | ViewerAction::ExportPreviewMp4(v_slot) => { | | |
| 1893 | let _ = self.export_viewer_mp4(v_slot); | | |
| 1894 | } | | |
| 1895 | ViewerAction::SaveFramePng(v_slot) => { | | |
| 1896 | let _ = self.save_viewer_frame_png(v_slot); | | |
| 1897 | } | | |
| 1898 | ViewerAction::SetInPoint => { | | |
| 1899 | self.playback.set_in_point(&self.comp); | | |
| 1900 | if self.playback.playing { | | |
| 1901 | self.sync_audio(false, true); | | |
| 1902 | } | | |
| 1903 | let [a, b] = self.playback.effective_preview_range(&self.comp); | | |
| 1904 | self.set_notice(format!( | | |
| 1905 | "In: f{} (preview f{a}..f{b})", | | |
| 1906 | self.playback.current_frame.round() as i64 | | |
| 1907 | )); | | |
| 1908 | for v in &mut self.viewers { | | |
| 1909 | v.prepare_hud(&self.comp, &self.engine, &self.playback); | | |
| 1910 | } | | |
| 1911 | } | | |
| 1912 | ViewerAction::SetOutPoint => { | | |
| 1913 | self.playback.set_out_point(&self.comp); | | |
| 1914 | if self.playback.playing { | | |
| 1915 | self.sync_audio(false, true); | | |
| 1916 | } | | |
| 1917 | let [a, b] = self.playback.effective_preview_range(&self.comp); | | |
| 1918 | self.set_notice(format!( | | |
| 1919 | "Out: f{} (preview f{a}..f{b})", | | |
| 1920 | self.playback.current_frame.round() as i64 | | |
| 1921 | )); | | |
| 1922 | for v in &mut self.viewers { | | |
| 1923 | v.prepare_hud(&self.comp, &self.engine, &self.playback); | | |
| 1924 | } | | |
| 1925 | } | | |
| 1926 | ViewerAction::ClearInOut => { | | |
| 1927 | self.playback.clear_in_out(); | | |
| 1928 | if self.playback.playing { | | |
| 1929 | self.sync_audio(false, true); | | |
| 1930 | } | | |
| 1931 | self.set_notice("Reset In/Out range"); | | |
| 1932 | for v in &mut self.viewers { | | |
| 1933 | v.prepare_hud(&self.comp, &self.engine, &self.playback); | | |
| 1934 | } | | |
| 1935 | } | | |
| 1936 | } | | |
| 1937 | } | | |
| 1938 | } | | |
| 1939 | | | |
| 1940 | fn paint(&mut self, target: &wgpu::TextureView, pixels: [u32; 2]) -> Result<(), Box<dyn Error>> { | 852 | fn paint(&mut self, target: &wgpu::TextureView, pixels: [u32; 2]) -> Result<(), Box<dyn Error>> { |
| 1941 | let scale = self.scale; | 853 | let scale = self.scale; |
| 1942 | let cur_f = self.playback.current_frame; | 854 | let cur_f = self.playback.current_frame; |
| ... | @@ -2011,22 +923,7 @@ fn run_snapshot(cli: &Cli, out_path: &Path) -> Result<(), Box<dyn Error>> { | ... | @@ -2011,22 +923,7 @@ fn run_snapshot(cli: &Cli, out_path: &Path) -> Result<(), Box<dyn Error>> { |
| 2011 | false, | 923 | false, |
| 2012 | ); | 924 | ); |
| 2013 | // Load audio waveform peaks if available so snapshot verifies the waveform overlay too | 925 | // Load audio waveform peaks if available so snapshot verifies the waveform overlay too |
| 2014 | if let Some(af) = studio.comp.audio_filename.clone() { | 926 | load_snapshot_audio_peaks(&mut studio); |
| 2015 | let p = PathBuf::from(af); | | |
| 2016 | if p.exists() { | | |
| 2017 | if let Ok(track) = AudioTrack::load(&p) { | | |
| 2018 | let peaks = track.waveform_peaks( | | |
| 2019 | studio.comp.fps, | | |
| 2020 | studio.comp.audio_offset, | | |
| 2021 | studio.comp.render_range[0], | | |
| 2022 | studio.comp.render_range[1], | | |
| 2023 | ); | | |
| 2024 | studio.viewers[0].audio_peaks = peaks.clone(); | | |
| 2025 | studio.keyframes.audio_peaks = peaks; | | |
| 2026 | studio.keyframes.audio_range = studio.comp.render_range; | | |
| 2027 | } | | |
| 2028 | } | | |
| 2029 | } | | |
| 2030 | if cli.open_add_tool { | 927 | if cli.open_add_tool { |
| 2031 | studio.add_tool.open(); | 928 | studio.add_tool.open(); |
| 2032 | } | 929 | } |
| ... | @@ -2176,128 +1073,11 @@ impl WindowHost { | ... | @@ -2176,128 +1073,11 @@ impl WindowHost { |
| 2176 | } | 1073 | } |
| 2177 | | 1074 | |
| 2178 | fn input(&mut self, event: ui::Event) { | 1075 | fn input(&mut self, event: ui::Event) { |
| 2179 | let typing = self.studio.ui.typing(); | 1076 | if handle_global_shortcut(&mut self.studio, &event) { |
| 2180 | // Global file & history shortcuts: Cmd+S, Cmd+Shift+S, Cmd+O, Cmd+Z, Cmd+Shift+Z / Cmd+Y, Cmd+Shift+R, Cmd+Shift+E | | |
| 2181 | let key_cmd = match &event { | | |
| 2182 | ui::Event::KeyInput { physical, modifiers, state: ElementState::Pressed, repeat: false, .. } => { | | |
| 2183 | let cmd = modifiers.super_key() || modifiers.control_key(); | | |
| 2184 | let shift = modifiers.shift_key(); | | |
| 2185 | if cmd && !shift && *physical == PhysicalKey::Code(KeyCode::KeyS) { | | |
| 2186 | Some("save") | | |
| 2187 | } else if cmd && shift && *physical == PhysicalKey::Code(KeyCode::KeyS) { | | |
| 2188 | Some("save_as") | | |
| 2189 | } else if cmd && !shift && *physical == PhysicalKey::Code(KeyCode::KeyO) { | | |
| 2190 | Some("open") | | |
| 2191 | } else if cmd && !shift && !typing && *physical == PhysicalKey::Code(KeyCode::KeyZ) { | | |
| 2192 | Some("undo") | | |
| 2193 | } else if cmd && shift && !typing && *physical == PhysicalKey::Code(KeyCode::KeyZ) { | | |
| 2194 | Some("redo") | | |
| 2195 | } else if cmd && !shift && !typing && *physical == PhysicalKey::Code(KeyCode::KeyY) { | | |
| 2196 | Some("redo") | | |
| 2197 | } else if cmd && shift && *physical == PhysicalKey::Code(KeyCode::KeyR) { | | |
| 2198 | Some("export") | | |
| 2199 | } else if cmd && shift && *physical == PhysicalKey::Code(KeyCode::KeyE) { | | |
| 2200 | Some("export_preview_mp4") | | |
| 2201 | } else { | | |
| 2202 | None | | |
| 2203 | } | | |
| 2204 | } | | |
| 2205 | ui::Event::Key { key: Key::Character(c), modifiers, .. } => { | | |
| 2206 | let cmd = modifiers.super_key() || modifiers.control_key(); | | |
| 2207 | let shift = modifiers.shift_key(); | | |
| 2208 | if cmd && !shift && c.eq_ignore_ascii_case("s") { | | |
| 2209 | Some("save") | | |
| 2210 | } else if cmd && shift && c.eq_ignore_ascii_case("s") { | | |
| 2211 | Some("save_as") | | |
| 2212 | } else if cmd && !shift && c.eq_ignore_ascii_case("o") { | | |
| 2213 | Some("open") | | |
| 2214 | } else if cmd && !shift && !typing && c.eq_ignore_ascii_case("z") { | | |
| 2215 | Some("undo") | | |
| 2216 | } else if cmd && shift && !typing && c.eq_ignore_ascii_case("z") { | | |
| 2217 | Some("redo") | | |
| 2218 | } else if cmd && !shift && !typing && c.eq_ignore_ascii_case("y") { | | |
| 2219 | Some("redo") | | |
| 2220 | } else if cmd && shift && c.eq_ignore_ascii_case("r") { | | |
| 2221 | Some("export") | | |
| 2222 | } else if cmd && shift && c.eq_ignore_ascii_case("e") { | | |
| 2223 | Some("export_preview_mp4") | | |
| 2224 | } else { | | |
| 2225 | None | | |
| 2226 | } | | |
| 2227 | } | | |
| 2228 | _ => None, | | |
| 2229 | }; | | |
| 2230 | if let Some(action) = key_cmd { | | |
| 2231 | match action { | | |
| 2232 | "save" => { let _ = self.studio.save_comp(); } | | |
| 2233 | "save_as" => { let _ = self.studio.save_comp_as(); } | | |
| 2234 | "open" => self.studio.open_comp_dialog(), | | |
| 2235 | "undo" => self.studio.undo(), | | |
| 2236 | "redo" => self.studio.redo(), | | |
| 2237 | "export" => { let _ = self.studio.export_saver_pngs(); } | | |
| 2238 | "export_preview_mp4" => { | | |
| 2239 | let slot = self.studio.active_viewer_slot(); | | |
| 2240 | let _ = self.studio.export_viewer_mp4(slot); | | |
| 2241 | } | | |
| 2242 | _ => {} | | |
| 2243 | } | | |
| 2244 | self.window.set_title(&self.studio.window_title()); | 1077 | self.window.set_title(&self.studio.window_title()); |
| 2245 | self.window.request_redraw(); | 1078 | self.window.request_redraw(); |
| 2246 | return; | 1079 | return; |
| 2247 | } | 1080 | } |
| 2248 | | | |
| 2249 | // Shift+Space opens Add Tool launcher (when not typing in a text field) | | |
| 2250 | if !typing { | | |
| 2251 | let is_shift_space = match &event { | | |
| 2252 | ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. } | | |
| 2253 | | ui::Event::Key { key: Key::Named(NamedKey::Space), modifiers, .. } => { | | |
| 2254 | modifiers.shift_key() && !modifiers.super_key() && !modifiers.control_key() | | |
| 2255 | } | | |
| 2256 | _ => false, | | |
| 2257 | }; | | |
| 2258 | if is_shift_space { | | |
| 2259 | self.studio.add_tool.open(); | | |
| 2260 | self.window.request_redraw(); | | |
| 2261 | return; | | |
| 2262 | } | | |
| 2263 | // Global Space toggles playback (synced with audio) and `` ` `` clears both viewers from any focused pane! | | |
| 2264 | let is_space = match &event { | | |
| 2265 | ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. } | | |
| 2266 | | ui::Event::Key { key: Key::Named(NamedKey::Space), modifiers, .. } => { | | |
| 2267 | !modifiers.shift_key() && !modifiers.super_key() && !modifiers.control_key() | | |
| 2268 | } | | |
| 2269 | _ => false, | | |
| 2270 | }; | | |
| 2271 | if is_space && !self.studio.add_tool.open { | | |
| 2272 | self.studio.playback.toggle_play_with_comp(&self.studio.comp, Instant::now()); | | |
| 2273 | self.studio.sync_audio(true, false); | | |
| 2274 | self.window.request_redraw(); | | |
| 2275 | return; | | |
| 2276 | } | | |
| 2277 | let is_backquote = match &event { | | |
| 2278 | ui::Event::KeyInput { physical: PhysicalKey::Code(KeyCode::Backquote), state: ElementState::Pressed, repeat: false, .. } => true, | | |
| 2279 | ui::Event::Key { key: Key::Character(c), .. } if c.as_str() == "`" || c.as_str() == "~" => true, | | |
| 2280 | _ => false, | | |
| 2281 | }; | | |
| 2282 | if is_backquote && !self.studio.add_tool.open { | | |
| 2283 | self.studio.clear_viewers(); | | |
| 2284 | self.window.request_redraw(); | | |
| 2285 | return; | | |
| 2286 | } | | |
| 2287 | } | | |
| 2288 | if !self.studio.ui.popups_open() && !self.studio.add_tool.open && let ui::Event::Key { key, modifiers, .. } = &event { | | |
| 2289 | let cmd = match key { | | |
| 2290 | Key::Named(NamedKey::Tab) if modifiers.control_key() => { | | |
| 2291 | Some(if modifiers.shift_key() { Command::Previous } else { Command::Next }) | | |
| 2292 | } | | |
| 2293 | _ => None, | | |
| 2294 | }; | | |
| 2295 | if let Some(cmd) = cmd { | | |
| 2296 | let _ = self.studio.dock.at(&mut self.studio.layout, &mut self.studio.seen, &String::clone).run(cmd); | | |
| 2297 | self.window.request_redraw(); | | |
| 2298 | return; | | |
| 2299 | } | | |
| 2300 | } | | |
| 2301 | self.studio.ui.event(event); | 1081 | self.studio.ui.event(event); |
| 2302 | self.window.request_redraw(); | 1082 | self.window.request_redraw(); |
| 2303 | } | 1083 | } |
| ... | @@ -2406,20 +1186,6 @@ impl ApplicationHandler<UserEvent> for App { | ... | @@ -2406,20 +1186,6 @@ impl ApplicationHandler<UserEvent> for App { |
| 2406 | } | 1186 | } |
| 2407 | } | 1187 | } |
| 2408 | | 1188 | |
| 2409 | fn spawn_audio_loader(comp: &Comp) -> Option<mpsc::Receiver<Result<AudioTrack, String>>> { | | |
| 2410 | comp.audio_filename.as_ref().and_then(|af| { | | |
| 2411 | let p = PathBuf::from(af); | | |
| 2412 | if !p.exists() { | | |
| 2413 | return None; | | |
| 2414 | } | | |
| 2415 | let (tx, rx) = mpsc::channel(); | | |
| 2416 | std::thread::spawn(move || { | | |
| 2417 | let _ = tx.send(AudioTrack::load(&p)); | | |
| 2418 | }); | | |
| 2419 | Some(rx) | | |
| 2420 | }) | | |
| 2421 | } | | |
| 2422 | | | |
| 2423 | fn studio_btn(ui: &mut ui::Ui, part: impl std::hash::Hash, label: &str, active: bool) -> ui::Signal { | 1189 | fn studio_btn(ui: &mut ui::Ui, part: impl std::hash::Hash, label: &str, active: bool) -> ui::Signal { |
| 2424 | let t = &ui.theme; | 1190 | let t = &ui.theme; |
| 2425 | let fill = if active { | 1191 | let fill = if active { |
| ... | @@ -2454,46 +1220,3 @@ fn studio_btn(ui: &mut ui::Ui, part: impl std::hash::Hash, label: &str, active: | ... | @@ -2454,46 +1220,3 @@ fn studio_btn(ui: &mut ui::Ui, part: impl std::hash::Hash, label: &str, active: |
| 2454 | }, | 1220 | }, |
| 2455 | ) | 1221 | ) |
| 2456 | } | 1222 | } |
| 2457 | | | |
| 2458 | fn native_open_comp_dialog() -> Option<PathBuf> { | | |
| 2459 | let script = r#"POSIX path of (choose file with prompt "Open Fusion Composition" of type {"comp"})"#; | | |
| 2460 | let out = ProcessCommand::new("osascript").args(["-e", script]).output().ok()?; | | |
| 2461 | if !out.status.success() { | | |
| 2462 | return None; | | |
| 2463 | } | | |
| 2464 | let s = String::from_utf8_lossy(&out.stdout).trim().to_owned(); | | |
| 2465 | if s.is_empty() { None } else { Some(PathBuf::from(s)) } | | |
| 2466 | } | | |
| 2467 | | | |
| 2468 | fn sanitize_filename(name: &str) -> String { | | |
| 2469 | let cleaned: String = name | | |
| 2470 | .chars() | | |
| 2471 | .map(|c| match c { | | |
| 2472 | '/' | '\\' | ':' | '"' | '\n' | '\r' => '_', | | |
| 2473 | other => other, | | |
| 2474 | }) | | |
| 2475 | .collect(); | | |
| 2476 | if cleaned.is_empty() { | | |
| 2477 | "untitled".to_owned() | | |
| 2478 | } else { | | |
| 2479 | cleaned | | |
| 2480 | } | | |
| 2481 | } | | |
| 2482 | | | |
| 2483 | fn native_save_file_dialog(prompt: &str, default_name: &str) -> Option<PathBuf> { | | |
| 2484 | let safe_prompt = prompt.replace('"', ""); | | |
| 2485 | let safe_name = default_name.replace('"', ""); | | |
| 2486 | let script = format!( | | |
| 2487 | r#"POSIX path of (choose file name with prompt "{safe_prompt}" default name "{safe_name}")"# | | |
| 2488 | ); | | |
| 2489 | let out = ProcessCommand::new("osascript").args(["-e", &script]).output().ok()?; | | |
| 2490 | if !out.status.success() { | | |
| 2491 | return None; | | |
| 2492 | } | | |
| 2493 | let s = String::from_utf8_lossy(&out.stdout).trim().to_owned(); | | |
| 2494 | if s.is_empty() { None } else { Some(PathBuf::from(s)) } | | |
| 2495 | } | | |
| 2496 | | | |
| 2497 | fn native_save_comp_dialog(default_name: &str) -> Option<PathBuf> { | | |
| 2498 | native_save_file_dialog("Save Fusion Composition As", default_name) | | |
| 2499 | } | | |