Skip to content

Commit

Permalink
Improved CLI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LaineZ committed Oct 28, 2022
1 parent ebb76da commit 478b551
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 12 deletions.
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ base64 = "0.13.0"
webbrowser = "0.8.0"
copypasta = "0.8"
num_cpus = "1.13.1"
indicatif = "0.17.1"

[target.'cfg(unix)'.dependencies]
messagebox-x11 = { git = "https://github.com/LaineZ/messagebox-x11" }
Expand Down
13 changes: 12 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ This software allows you apply almost any VST™ 2.4 effect and bound audio VST

**This software currently in development. breakable changes and random bugs are inevitable.**

# Interface modes (since 2.1.0)

PhotoConsequences has 2 UI modes:

* **CLI** - For batch image processing e.g frame sequences from videos. To run PhotoConsequences in this mode, you need use command like this: ```photoconsequences [project path] [input directory] [output directory]```. Program will be started in CLI mode automatically
* **GUI** - Default UI mode.

# Building

Build insturctions is typical for any Rust project

* Clone this repository
* Run ``cargo build --release`` command

# Screenshots
# Screenshots and other media

![PhotoConsequences](/resources/screenshoot1.png)

![PhotoConsequences](/resources/screenshoot2.png)
Expand Down
41 changes: 36 additions & 5 deletions src/interfaces/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
sync::Arc,
};

use indicatif::{MultiProgress, ProgressStyle, ProgressBar};

use crate::state_headless::StateHeadless;

pub fn cli(args: Vec<String>) -> anyhow::Result<()> {
Expand All @@ -13,7 +15,7 @@ pub fn cli(args: Vec<String>) -> anyhow::Result<()> {
let image_path = PathBuf::from_str(&args[2])?;
let image_export_path = Arc::new(PathBuf::from_str(&args[3])?);

let cpus = 2;
let cpus = num_cpus::get();
let mut paths = fs::read_dir(image_path)?
.collect::<Vec<Result<DirEntry, std::io::Error>>>();

Expand All @@ -23,33 +25,62 @@ pub fn cli(args: Vec<String>) -> anyhow::Result<()> {
let paths_arc = Arc::new(paths);
let mut threads = Vec::new();

let m = MultiProgress::new();
let sty = ProgressStyle::with_template(
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg:>50}",
)
.unwrap()
.progress_chars("##-");


let pb = m.add(ProgressBar::new(100));
pb.set_style(sty.clone());

for i in 0..cpus {
let paths_ar = Arc::clone(&paths_arc);
let project_path = Arc::clone(&project_path);
let image_export_path = Arc::clone(&image_export_path);
let pb = m.add(ProgressBar::new(100));
pb.set_style(sty.clone());

let m_clone = m.clone();
threads.push(std::thread::spawn(move || {
println!("Starting thread: {}", i);

let chunks: Vec<_> = paths_ar.chunks((path_size / cpus) + 1).collect();
let my_chunk = chunks[i];

let mut state = StateHeadless::new();

state.load_project(project_path.as_path()).unwrap();
state.rack.block_size = 16384;

for image_path in my_chunk {
for (idx, image_path) in my_chunk.iter().enumerate() {
let img_path = image_path.as_ref().unwrap();
let export_path = image_export_path.join(img_path.file_name());
println!("Processing: {}", img_path.path().display());
//println!("Processing: {}", img_path.path().display());
state.load_image(img_path.path()).unwrap_or_else(|op| println!("Unable to load image: {}", op));
state.process();
state.rack.start_process();

pb.set_message(format!("{}", img_path.path().display()));
pb.set_length(my_chunk.len() as u64);
pb.set_position(idx as u64);

while !state.rack.is_finished() {
state.rack.process_next();
}

state.rack.save_image(export_path.as_path()).unwrap_or_else(|op| println!("Unable to save image: {}", op));
println!("Saved: {}", export_path.display());
m_clone.println(format!("Saved: {}", export_path.display())).unwrap();
}
}))
}

for thread in threads {
let _ = thread.join();
}

println!("Processing is done!");
} else {
eprintln!("Not enough arguments. Exiting");
println!("Usage: photoconsequences [project .viproj path] [input image folder pathj] [output path]");
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
fn main() {
let args: Vec<String> = std::env::args().collect();

println!("PhotoConsequences by @140bpmdubstep");
println!("Version {}", VERSION);

if args.len() > 2 {
println!("Running in cli mode");
cli::cli(args).unwrap();
cli::cli(args).expect("Error while running cli mode");
} else {
println!("Running in gui mode");
gui::gui(args);
Expand Down
8 changes: 8 additions & 0 deletions src/plugin_rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ impl PluginRack {
self.position.checked_div(self.total).unwrap_or(0) * 100
}

pub fn get_processed_position(&self) -> usize {
self.position
}

pub fn get_processing_size(&self) -> usize {
self.total
}

pub fn load_uninitialzed_plugins(&mut self) -> anyhow::Result<()> {
for plugin in &mut self.plugins {
if let Ok(mut loader) = PluginLoader::load(&plugin.path, Arc::clone(&self.host)) {
Expand Down
5 changes: 0 additions & 5 deletions src/state_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ impl StateHeadless {
}

pub fn process(&mut self) {
self.rack.start_process();

while !self.rack.is_finished() {
self.rack.process_next();
}
}
}

0 comments on commit 478b551

Please sign in to comment.