Adds workspaces and basic example

This commit is contained in:
Dandaedre 2025-03-24 23:48:09 +01:00
parent 763e201a87
commit 7edc640adc
11 changed files with 202 additions and 4 deletions

View File

@ -1,6 +1,23 @@
[package]
name = "fader_master"
# cargo-features = ["codegen-backend"]
[workspace]
members = [ "tui", "sound" , "fader_master", "midi"]
resolver = "3"
[workspace.package]
version = "0.1.0"
edition = "2024"
[dependencies]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev]
debug = true
strip = false
# codegen-backend = "cranelift"
split-debuginfo = "off"
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
strip = "none"

View File

@ -1,3 +1,9 @@
# fader_master
Fast test implementation of a midi-fader based software
Rushed test implementation of a midi-fader based software
# References
* [pwvucontrol](https://github.com/saivert/pwvucontrol/blob/main/src/backend/pwnodeobject/mixerapi.rs)
* [ratatui](https://ratatui.rs/)
* [midir](https://github.com/Boddlnagg/midir)

6
fader_master/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "fader_master"
version.workspace = true
edition.workspace = true
[dependencies]

6
midi/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "midi"
version.workspace = true
edition.workspace = true
[dependencies]

14
midi/src/lib.rs Normal file
View File

@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

6
sound/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "volume_lib"
version = "0.1.0"
edition = "2024"
[dependencies]

14
sound/src/lib.rs Normal file
View File

@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

7
tui/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "tui"
version = "0.1.0"
edition = "2024"
[dependencies]
ratatui = { version = "0.29.0", features = ["all-widgets", "serde"] }

9
tui/examples/tui_test.rs Normal file
View File

@ -0,0 +1,9 @@
use std::io;
use tui::Tui;
fn main() -> io::Result<()> {
let mut terminal = ratatui::init();
let app_result = Tui::default().run(&mut terminal);
ratatui::restore();
app_result
}

113
tui/src/lib.rs Normal file
View File

@ -0,0 +1,113 @@
//! Simple lib to handle creation of a simple TUI to visualisize faders
//!
//! Kinda specless for now, there are faders, volume, menu nav, fader creation, destruction and outputs
//!
//!
use std::io;
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
use ratatui::{
DefaultTerminal, Frame,
buffer::Buffer,
crossterm,
layout::Rect,
style::Stylize,
symbols::border,
text::{Line, Text},
widgets::{Block, Paragraph, Widget},
};
/// Experimental global runner
#[allow(dead_code)]
#[derive(Debug, Default)]
pub struct Tui {
volume: u8,
exit: bool,
}
impl Tui {
/// Runs the application's main loop until the user quits
pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
while !self.exit {
terminal.draw(|frame| self.draw(frame))?;
self.handle_events()?;
}
Ok(())
}
/// Draw a frame
fn draw(&self, frame: &mut Frame) {
frame.render_widget(self, frame.area());
}
/// Process all the event handling
fn handle_events(&mut self) -> io::Result<()> {
match event::read()? {
// it's important to check that the event is a key press event as
// crossterm also emits key release and repeat events on Windows.
Event::Key(key_event) if key_event.kind == KeyEventKind::Press => {
self.handle_key_event(key_event)
}
_ => {}
};
Ok(())
}
fn handle_key_event(&mut self, key_event: KeyEvent) {
match key_event.code {
KeyCode::Char('q') => self.exit(),
// KeyCode::Left => self.decrement_counter(),
// KeyCode::Right => self.increment_counter(),
_ => {}
}
}
fn exit(&mut self) {
self.exit = true;
}
}
/// Makes the Tui into a Widget to use it as
impl Widget for &Tui {
fn render(self, area: Rect, buf: &mut Buffer) {
let title = Line::from("TUI Title".bold());
let instructions = Line::from(vec![
" Decrement ".into(),
"<Left>".blue().bold(),
" Increment ".into(),
"<Right>".blue().bold(),
" Quit ".into(),
"<Q> ".blue().bold(),
]);
let block = Block::bordered()
.title(title.centered())
.title_bottom(instructions.centered())
.border_set(border::THICK);
let counter_text = Text::from(vec![Line::from(vec![
"Volume: ".into(),
self.volume.to_string().yellow(),
])]);
Paragraph::new(counter_text)
.centered()
.block(block)
.render(area, buf);
}
}
#[allow(dead_code)]
/// An individual volume widget
pub struct SingleFader {
/// The individual volume of the fader
volume: usize,
// application: String,
midi_note: Vec<usize>,
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {}
}