diff --git a/README.md b/README.md new file mode 100644 index 0000000..a109278 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ + +build dsp: +```sh +cd dsp +faust2jackconsole -osc mixer.dsp +``` + +build frontend: +```sh +cd frontend +yarn +yarn build +``` + +build and run backend & serve frontend: +```sh +cargo run +``` + +open http://localhost:8080/index.html diff --git a/src/spawn.rs b/src/spawn.rs index 35ed0b7..3950313 100644 --- a/src/spawn.rs +++ b/src/spawn.rs @@ -4,6 +4,7 @@ use futures_lite::prelude::*; use log::*; use regex::Regex; +use std::env; use std::io; #[derive(Debug)] @@ -16,8 +17,18 @@ pub struct FaustHandle { impl FaustHandle { pub async fn spawn() -> Result { - let exec = "/home/bit/Code/studiox/studiox-mixer/mixer-jackconsole"; - let mut child = Command::new(exec) + let bin_path = env::var("FAUST_DSP") + .expect("Set FAUST_DSP env variable to path to mixer faust executable"); + let bin_path = if !bin_path.starts_with("/") { + format!( + "{}/{}", + env::current_dir().unwrap().to_str().unwrap(), + bin_path + ) + } else { + bin_path.to_string() + }; + let mut child = Command::new(bin_path) .arg(".") .stdout(Stdio::piped()) // .stderr(Stdio::piped()) diff --git a/src/ws.rs b/src/ws.rs index 6a1db5f..d9587af 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -3,6 +3,7 @@ use async_std::stream::{Stream, StreamExt}; use async_std::sync::{Arc, Mutex}; use async_std::task::{self, JoinHandle}; use std::collections::HashMap; +use std::env; use std::net::SocketAddr; use std::pin::Pin; use std::task::{Context, Poll}; @@ -83,9 +84,14 @@ pub fn run( } }); - app.at("/") - .serve_dir("/home/bit/Code/studiox/studiox/frontend/build") - .unwrap(); + let frontend_dir = env::var("FRONTEND_PATH").unwrap_or_else(|_| { + format!( + "{}/{}", + env::current_dir().unwrap().to_str().unwrap(), + "frontend/build" + ) + }); + app.at("/").serve_dir(frontend_dir).unwrap(); app.at("/ws") .get(WebSocket::new(move |request, mut stream| {