Trying to come up with the structure
This commit is contained in:
26
engine/src/audio_engine/jack_ab.rs
Normal file
26
engine/src/audio_engine/jack_ab.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
use crate::audio_engine::AudioBackend;
|
||||||
|
|
||||||
|
pub(crate) struct JackAudioBackend {
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) running: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JackAudioBackend {
|
||||||
|
pub(crate) fn new(name: String, running: bool) -> Self {
|
||||||
|
Self { name, running }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AudioBackend for JackAudioBackend {
|
||||||
|
fn start_client(&self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_client(&self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn discover(&self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
mod jack;
|
#[cfg(feature = "jack")]
|
||||||
mod coreaudio;
|
pub(crate) mod jack_ab;
|
||||||
|
|
||||||
trait AudioBackend {
|
pub(crate) trait AudioBackend {
|
||||||
// Start a audio backend client
|
// Start a audio backend client
|
||||||
// It should be executed either on the startup,
|
// It should be executed either on the startup,
|
||||||
// or when the audio backend is switched
|
// or when the audio backend is switched
|
||||||
fn start_client();
|
fn start_client(&self);
|
||||||
// Initialization of the client should happen
|
// Initialization of the client should happen
|
||||||
// when a project is opened.
|
// when a project is opened.
|
||||||
fn init_client();
|
fn init_client(&self);
|
||||||
|
fn discover(&self);
|
||||||
}
|
}
|
||||||
|
|||||||
9
engine/src/control_pane/dummy.rs
Normal file
9
engine/src/control_pane/dummy.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use crate::control_pane::ControlPane;
|
||||||
|
|
||||||
|
struct Dummy {}
|
||||||
|
|
||||||
|
impl ControlPane for Dummy {
|
||||||
|
async fn start_server(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
76
engine/src/control_pane/grpc/mod.rs
Normal file
76
engine/src/control_pane/grpc/mod.rs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
use lib::termix::audio_backend::{
|
||||||
|
self, Backend, BackendList, FILE_DESCRIPTOR_SET,
|
||||||
|
audio_backend_server::{AudioBackend, AudioBackendServer},
|
||||||
|
};
|
||||||
|
use log::info;
|
||||||
|
use tonic::{Response, transport::Server};
|
||||||
|
use tonic_reflection::server;
|
||||||
|
|
||||||
|
|
||||||
|
use crate::control_pane::ControlPane;
|
||||||
|
#[cfg(feature = "jack") ]
|
||||||
|
use crate::audio_engine::jack_ab::JackAudioBackend;
|
||||||
|
|
||||||
|
pub(crate) struct Grpc {
|
||||||
|
pub(crate) port: i32,
|
||||||
|
pub(crate) enable_reflections: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ControlPane for Grpc {
|
||||||
|
async fn start_server(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
info!("starting the grpc server on port {}", self.port);
|
||||||
|
// TODO: Use the port from self
|
||||||
|
let addr = "[::1]:50051".parse()?;
|
||||||
|
let mut server = Server::builder();
|
||||||
|
let audio_backend_reflections = server::Builder::configure()
|
||||||
|
.register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET)
|
||||||
|
.build_v1()
|
||||||
|
.unwrap();
|
||||||
|
let audio_backend = TermixAudioBackend::default();
|
||||||
|
|
||||||
|
server
|
||||||
|
.add_service(audio_backend_reflections)
|
||||||
|
.add_service(AudioBackendServer::new(audio_backend))
|
||||||
|
.serve(addr)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct TermixAudioBackend {}
|
||||||
|
|
||||||
|
#[tonic::async_trait]
|
||||||
|
impl AudioBackend for TermixAudioBackend {
|
||||||
|
async fn start_client(
|
||||||
|
&self,
|
||||||
|
requesa: tonic::Request<()>,
|
||||||
|
) -> std::result::Result<tonic::Response<()>, tonic::Status> {
|
||||||
|
info!("starting the audio backend client");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init_connection(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<()>,
|
||||||
|
) -> std::result::Result<tonic::Response<()>, tonic::Status> {
|
||||||
|
info!("initializing the connection to the audio backend");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_available_backends(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<()>,
|
||||||
|
) -> Result<Response<BackendList>, tonic::Status> {
|
||||||
|
info!("discovering available backends");
|
||||||
|
let mut response = BackendList::default();
|
||||||
|
if cfg!(feature = "jack") {
|
||||||
|
let jack = JackAudioBackend{ name: "jack".to_string(), running: todo!() };
|
||||||
|
response.backends.push(Backend {
|
||||||
|
name: "jack".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(Response::new(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
6
engine/src/control_pane/mod.rs
Normal file
6
engine/src/control_pane/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
pub(crate) mod dummy;
|
||||||
|
pub(crate) mod grpc;
|
||||||
|
|
||||||
|
pub(crate) trait ControlPane {
|
||||||
|
async fn start_server(&self) -> Result<(), Box<dyn std::error::Error>>;
|
||||||
|
}
|
||||||
@@ -1,58 +1,29 @@
|
|||||||
mod audio_engine;
|
pub(crate) mod audio_engine;
|
||||||
|
pub(crate) mod control_pane;
|
||||||
|
|
||||||
|
use crate::control_pane::ControlPane;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lib::termix::audio_backend::{Backend, BackendList, FILE_DESCRIPTOR_SET, audio_backend_server::{AudioBackend, AudioBackendServer}};
|
|
||||||
use tonic::{Request, Response, Result, Status, transport::Server};
|
|
||||||
use log::{debug, error, log_enabled, info, Level};
|
|
||||||
use tonic_reflection::server::v1::{ReflectionService, ServerReflection};
|
|
||||||
/// Simple program to greet a person
|
/// Simple program to greet a person
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[arg(long, default_value_t = 50051)]
|
#[arg(long, default_value_t = 50051)]
|
||||||
grpc_port: i32,
|
grpc_port: i32,
|
||||||
|
#[arg(long, default_value_t = true)]
|
||||||
|
grpc_enable_reflections: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct TermixAudioBackend {}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl AudioBackend for TermixAudioBackend {
|
|
||||||
async fn start_client(&self,requesa:tonic::Request<()>,) -> std::result::Result<tonic::Response<()>,tonic::Status> {
|
|
||||||
info!("starting the audio backend client");
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn init_connection(&self,request:tonic::Request<()>,) -> std::result::Result<tonic::Response<()>,tonic::Status> {
|
|
||||||
info!("initializing the connection to the audio backend");
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_available_backends(&self, request:tonic::Request<()>) -> Result<Response<BackendList>, tonic::Status> {
|
|
||||||
info!("discovering available backends");
|
|
||||||
let mut response = BackendList::default();
|
|
||||||
if cfg!(feature = "jack") {
|
|
||||||
response.backends.push(Backend{ name: "jack".to_string() });
|
|
||||||
}
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
// start_grpc_server()
|
|
||||||
info!("starting the grpc server on port {}", args.grpc_port);
|
|
||||||
let reflections = tonic_reflection::server::Builder::configure().register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET).build_v1().unwrap();
|
|
||||||
let addr = "[::1]:50051".parse()?;
|
|
||||||
let greeter = TermixAudioBackend::default();
|
|
||||||
|
|
||||||
Server::builder()
|
let grpc_control_pane = control_pane::grpc::Grpc {
|
||||||
.add_service(AudioBackendServer::new(greeter))
|
port: args.grpc_port,
|
||||||
.add_service(reflections)
|
enable_reflections: args.grpc_enable_reflections,
|
||||||
.serve(addr)
|
};
|
||||||
.await?;
|
grpc_control_pane.start_server().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod termix {
|
pub mod termix {
|
||||||
pub mod audio_backend {
|
pub mod audio_backend {
|
||||||
pub const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("audio_backend_descriptor");
|
pub const FILE_DESCRIPTOR_SET: &[u8] =
|
||||||
|
tonic::include_file_descriptor_set!("audio_backend_descriptor");
|
||||||
tonic::include_proto!("termix.audio_backend");
|
tonic::include_proto!("termix.audio_backend");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
use clap::Parser;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::event::{self, Event};
|
use crossterm::event::{self, Event};
|
||||||
use ratatui::{DefaultTerminal, Frame};
|
use ratatui::{DefaultTerminal, Frame};
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
/// Simple program to greet a person
|
/// Simple program to greet a person
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user