Skip to content

Commit

Permalink
Some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
slerpyyy committed Sep 15, 2021
1 parent 9e489d8 commit 0977e52
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 50 deletions.
16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
[package]
name = "sh4der-jockey"
version = "0.2.0"
description = "A custom VJ tool written by sp4ghet and slerpy"
description = "A tool for shader coding and live performances"
edition = "2018"
build = "build.rs"

#[profile.release]
#lto = "fat"
#codegen-units = 1
#panic = "abort"
[profile.release]
lto = "fat"

[dependencies]
alloca = { git = "https://github.com/slerpyyy/alloca-rs", branch = "v2" }
anyhow = "1.0"
as-any = "0.2"
async-std = { version = "1.9", default-features = false, features = ["std"] }
clap = "3.0.0-beta"
cpal = "0.13"
ctrlc = { version = "3.2", features = ["termination"] }
futures = { version = "0.3", default-features = false }
winapi = "0.3"
clap = "3.0.0-beta"
gl = "0.14"
glutin = "0.26"
glutin = "0.26" # must match version used in imgui forks
image = "0.23"
imgui = { git = "https://github.com/sp4ghet/imgui-rs", branch = "master" }
imgui-opengl-renderer = { git = "https://github.com/sp4ghet/rust-imgui-opengl-renderer", branch = "master" }
imgui-winit-support = { git = "https://github.com/sp4ghet/imgui-rs", branch = "master" }
lazy_static = "1.4"
log = "0.4"
midir = "0.7"
ndi = { git = "https://github.com/slerpyyy/ndi-rs", branch = "main" }
nfd = { git = "https://github.com/saurvs/nfd-rs.git" }
Expand All @@ -36,9 +34,9 @@ rand = "0.8"
regex = "1.4"
rustfft = "6.0"
serde_yaml = "0.8"
log = "0.4"
simplelog = "0.10"
take_mut = "0.2"
winapi = "0.3"

[build-dependencies]
anyhow = "1.0"
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<img align="left" style="float: left; height: 9em; margin: 2em" src="docs/logo.png">
<img align="left" style="height: 9em; margin: 2em" src="docs/logo.png">

# Sh4derJockey
*A custom VJ tool written by sp4ghet and slerpy*
*A tool for shader coding and live performances*

<br>

Expand All @@ -14,6 +13,11 @@ The documentation on how to use this tool can be found in the [docs](docs/) fold

## Setup

To build this project from source, you will need a Rust compiler and the Cargo package manager.
We highly recommend installing `rustup` which takes care of installing and updating the entire Rust toolchain.

Checkout the [Getting Started](https://www.rust-lang.org/learn/get-started) section on the rust-lang website for more.

```sh
# clone the repo
git clone https://github.com/slerpyyy/sh4der-jockey.git
Expand All @@ -26,9 +30,12 @@ cargo run
cargo install --path .
```

| ⚠️ | Please note that the tool may drop config files in the folder where the executable is located. |
| ⚠️ | Please note that the tool drops config files in the folder where the executable is located. |
|-|-|

It is up to the user to ensure that additional files in the install directory do not interfere with other programs.
The tool does also work when placed into a read-only directory, but user comfort will suffer.

## License

This project is licensed under either of
Expand Down
48 changes: 25 additions & 23 deletions src/jockey/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,25 +332,39 @@ impl Jockey {

fn update_pipeline_incremental(&mut self, timeout: Duration) {
let start = Instant::now();
if let Some(part) = self.pipeline_partial.as_mut() {
while let Some(part) = self.pipeline_partial.as_mut() {
if start.elapsed() > timeout {
return;
}

if let Some(result) = futures::FutureExt::now_or_never(part) {
self.pipeline_partial = None;
let update = match result {
Ok((pl, update)) => {
self.pipeline = pl;
update
}

// set waker on current working directory
self.ctx.watcher = Some({
let event_fn = |_| unsafe { PIPELINE_STALE.store(true, Ordering::Release) };
let mut watcher = notify::immediate_watcher(event_fn).unwrap();
watcher
.watch(".", notify::RecursiveMode::Recursive)
.unwrap();

watcher
});

// unwrap pipeline build result
let (new_pipeline, update) = match result {
Ok(t) => t,
Err(err) => {
self.console = format!("Failed to build pipeline:\n{}", err);
log::error!("{}", &self.console);
return;
}
};

// set new pipeline
self.pipeline = new_pipeline;

// log build time
let build_time = self.last_build.elapsed().as_secs_f64();
self.console = format!("Build pipeline over a span of {}s", build_time);
log::info!("{}", &self.console);
Expand All @@ -362,23 +376,11 @@ impl Jockey {
self.audio.resize(update.audio_samples);
}

let requests: Vec<_> = self
.pipeline
.requested_ndi_sources
.values()
.map(|x| x.as_str())
.collect();
self.ndi.connect(&requests).unwrap();

self.ctx.watcher = Some({
let event_fn = |_| unsafe { PIPELINE_STALE.store(true, Ordering::Release) };
let mut watcher = notify::immediate_watcher(event_fn).unwrap();
watcher
.watch(".", notify::RecursiveMode::Recursive)
.unwrap();

watcher
});
// update ndi module
let requests = self.pipeline.requested_ndi_sources.values();
if let Err(err) = self.ndi.connect(&requests) {
log::error!("Failed to connect to NDI sources: {}", err);
}
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/jockey/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ impl Ndi {
}
}

pub fn connect(&mut self, requested: &[&str]) -> Result<(), ndi::RecvCreateError> {
if requested.is_empty() {
pub fn connect<I, T>(&mut self, requested: &I) -> Result<(), ndi::RecvCreateError>
where
I: ExactSizeIterator<Item = T> + Clone,
T: AsRef<str>,
{
if requested.len() == 0 {
return Ok(());
}

Expand All @@ -151,7 +155,8 @@ impl Ndi {
.iter()
.filter_map(|src| {
let src_name = src.get_name();
for &pat in requested {
for pat in requested.clone() {
let pat = pat.as_ref();
if src_name.contains(pat) {
return Some((pat.into(), src));
}
Expand Down
32 changes: 21 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
mod util;
mod jockey;

use std::sync::atomic::{AtomicBool, Ordering};
use std::{
path::Path,
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};

use clap::{AppSettings, Clap};
use jockey::Jockey;
Expand Down Expand Up @@ -61,8 +65,8 @@ fn main() {
.unwrap();

if let Some(SubCommand::Init) = args.subcmd {
let plf = std::path::Path::new("./pipeline.yaml");
let shf = std::path::Path::new("./scene.frag");
let plf = Path::new("./pipeline.yaml");
let shf = Path::new("./scene.frag");

if plf.exists() || shf.exists() {
log::error!(
Expand All @@ -74,8 +78,12 @@ fn main() {
return;
}

std::fs::write(plf, include_str!("defaults/pipeline.yaml")).unwrap();
std::fs::write(shf, include_str!("defaults/scene.frag")).unwrap();
let plf_res = std::fs::write(plf, include_str!("defaults/pipeline.yaml"));
let shf_res = std::fs::write(shf, include_str!("defaults/scene.frag"));

if let Err(err) = plf_res.and(shf_res) {
log::error!("{}", err);
}

return;
}
Expand All @@ -87,7 +95,7 @@ fn main() {
kill_signal.store(true, Ordering::Release);

// give it a moment to exit peacefully
std::thread::sleep(std::time::Duration::from_secs(3));
std::thread::sleep(Duration::from_secs(3));

log::info!("Alright, let's kill this thing");
std::process::exit(0);
Expand Down Expand Up @@ -120,24 +128,26 @@ fn main() {
log::info!("Bye bye!");
}

// https://github.com/kirillkovalenko/nssm/blob/master/console.cpp
#[cfg(all(windows, not(debug_assertions)))]
fn close_console() {
let console = unsafe { winapi::um::wincon::GetConsoleWindow() };
use winapi::um::{processthreadsapi, wincon, winuser};

let console = unsafe { wincon::GetConsoleWindow() };
if console.is_null() {
return;
}

let mut console_pid = 0;
let status =
unsafe { winapi::um::winuser::GetWindowThreadProcessId(console, &mut console_pid) };
let status = unsafe { winuser::GetWindowThreadProcessId(console, &mut console_pid) };
if status == 0 {
return;
}

let self_pid = unsafe { winapi::um::processthreadsapi::GetCurrentProcessId() };
let self_pid = unsafe { processthreadsapi::GetCurrentProcessId() };
if console_pid != self_pid {
return;
}

unsafe { winapi::um::wincon::FreeConsole() };
unsafe { wincon::FreeConsole() };
}

0 comments on commit 0977e52

Please sign in to comment.