Trying to come up with the structure
Some checks failed
ci/woodpecker/push/code_tests Pipeline failed
ci/woodpecker/push/pre_commit_test Pipeline was successful

This commit is contained in:
Nikolai Rodionov
2025-12-01 14:35:28 +01:00
parent dcb6d7b0ea
commit af97801d31
10 changed files with 138 additions and 48 deletions

View 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!()
}
}

View File

@@ -1,12 +1,13 @@
mod jack;
mod coreaudio;
#[cfg(feature = "jack")]
pub(crate) mod jack_ab;
trait AudioBackend {
pub(crate) trait AudioBackend {
// Start a audio backend client
// It should be executed either on the startup,
// or when the audio backend is switched
fn start_client();
fn start_client(&self);
// Initialization of the client should happen
// when a project is opened.
fn init_client();
fn init_client(&self);
fn discover(&self);
}

View 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!()
}
}

View 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))
}
}

View 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>>;
}

View File

@@ -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 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
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(long, default_value_t = 50051)]
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]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
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()
.add_service(AudioBackendServer::new(greeter))
.add_service(reflections)
.serve(addr)
.await?;
let grpc_control_pane = control_pane::grpc::Grpc {
port: args.grpc_port,
enable_reflections: args.grpc_enable_reflections,
};
grpc_control_pane.start_server().await?;
Ok(())
}

View File

@@ -1,6 +1,7 @@
pub mod termix {
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");
}
}

View File

@@ -1,7 +1,7 @@
use clap::Parser;
use color_eyre::Result;
use crossterm::event::{self, Event};
use ratatui::{DefaultTerminal, Frame};
use clap::Parser;
/// Simple program to greet a person
#[derive(Parser, Debug)]