Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2791
Cargo.lock
generated
2791
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,6 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.102"
|
anyhow = "1.0.102"
|
||||||
#notan = { version = "0.14.0", default-features = false, features = ["backend", "draw", "shaderc"] }
|
|
||||||
notan = { version = "0.14.0" }
|
|
||||||
midly = "0.5.3"
|
midly = "0.5.3"
|
||||||
serialport = "4.9.0"
|
serialport = "4.9.0"
|
||||||
|
raylib = { version = "5.5.1", default-features = false, features = ["wayland"] }
|
||||||
|
|||||||
@@ -69,6 +69,8 @@
|
|||||||
[
|
[
|
||||||
udev
|
udev
|
||||||
libGL
|
libGL
|
||||||
|
glfw
|
||||||
|
llvmPackages.libclang
|
||||||
]
|
]
|
||||||
++ x11Libs
|
++ x11Libs
|
||||||
);
|
);
|
||||||
@@ -90,6 +92,7 @@
|
|||||||
|
|
||||||
nativeBuildInputs = commonNativeBuildInputs;
|
nativeBuildInputs = commonNativeBuildInputs;
|
||||||
buildInputs = commonBuildInputs;
|
buildInputs = commonBuildInputs;
|
||||||
|
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||||
|
|
||||||
postFixup = pkgs.lib.optionalString (!isDarwin) ''
|
postFixup = pkgs.lib.optionalString (!isDarwin) ''
|
||||||
wrapProgram $out/bin/singer \
|
wrapProgram $out/bin/singer \
|
||||||
@@ -121,6 +124,7 @@
|
|||||||
++ commonNativeBuildInputs;
|
++ commonNativeBuildInputs;
|
||||||
|
|
||||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath commonBuildInputs;
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath commonBuildInputs;
|
||||||
|
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
export RUST_SRC_PATH="${pkgs.rustToolchain}/lib/rustlib/src/rust/library"
|
export RUST_SRC_PATH="${pkgs.rustToolchain}/lib/rustlib/src/rust/library"
|
||||||
|
|||||||
62
src/main.rs
62
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
io::Write,
|
||||||
sync::mpsc::{self, Receiver, Sender},
|
sync::mpsc::{self, Receiver, Sender},
|
||||||
thread::{self},
|
thread::{self},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
@@ -6,7 +7,7 @@ use std::{
|
|||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use midly::Smf;
|
use midly::Smf;
|
||||||
use notan::{draw::*, prelude::*};
|
use raylib::prelude::*;
|
||||||
use serialport::SerialPortType;
|
use serialport::SerialPortType;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
@@ -164,29 +165,23 @@ pub enum SerialStatus {
|
|||||||
SerialDisconnected,
|
SerialDisconnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(AppState)]
|
|
||||||
struct SingerApp {
|
struct SingerApp {
|
||||||
song_state: Option<AppSongState>,
|
song_state: Option<AppSongState>,
|
||||||
tx: Sender<SerialCommand>,
|
tx: Sender<SerialCommand>,
|
||||||
rx: Receiver<SerialStatus>,
|
rx: Receiver<SerialStatus>,
|
||||||
connected: Option<String>,
|
connected: Option<String>,
|
||||||
font: Font,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SingerApp {
|
impl SingerApp {
|
||||||
pub fn new(gfx: &mut Graphics) -> Self {
|
pub fn new() -> Self {
|
||||||
let (tx_cmd, rx_cmd) = mpsc::channel();
|
let (tx_cmd, rx_cmd) = mpsc::channel();
|
||||||
let (tx_status, rx_status) = mpsc::channel();
|
let (tx_status, rx_status) = mpsc::channel();
|
||||||
Self::spawn_serial_worker(rx_cmd, tx_status);
|
Self::spawn_serial_worker(rx_cmd, tx_status);
|
||||||
let font = gfx
|
|
||||||
.create_font(include_bytes!("assets/Ubuntu-B.ttf"))
|
|
||||||
.expect("failed to load embedded font");
|
|
||||||
Self {
|
Self {
|
||||||
song_state: None,
|
song_state: None,
|
||||||
tx: tx_cmd,
|
tx: tx_cmd,
|
||||||
rx: rx_status,
|
rx: rx_status,
|
||||||
connected: None,
|
connected: None,
|
||||||
font,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,53 +245,40 @@ impl SingerApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, gfx: &mut Graphics) {
|
fn draw(&mut self, draw: &mut RaylibDrawHandle<'_>) {
|
||||||
let mut draw = gfx.create_draw();
|
draw.clear_background(Color::WHITE);
|
||||||
draw.clear(Color::WHITE);
|
draw.draw_line_ex(
|
||||||
|
Vector2::new(40.0, 40.0),
|
||||||
draw.line((40.0, 40.0), (100.0, 200.0))
|
Vector2::new(100.0, 200.0),
|
||||||
.width(15.0)
|
15.0,
|
||||||
.color(Color::BLUE);
|
Color::BLUE,
|
||||||
draw.rect((220.0, 100.0), (120.0, 60.0)).color(Color::GREEN);
|
);
|
||||||
|
draw.draw_rectangle(220, 100, 120, 60, Color::GREEN);
|
||||||
|
|
||||||
let status_color = if self.connected.is_some() {
|
let status_color = if self.connected.is_some() {
|
||||||
Color::GREEN
|
Color::GREEN
|
||||||
} else {
|
} else {
|
||||||
Color::GRAY
|
Color::GRAY
|
||||||
};
|
};
|
||||||
draw.rect((14.0, 14.0), (20.0, 20.0)).color(status_color);
|
draw.draw_rectangle(14, 14, 20, 20, status_color);
|
||||||
|
|
||||||
let status_text = match &self.connected {
|
let status_text = match &self.connected {
|
||||||
Some(name) => format!("Serial connected: {name}"),
|
Some(name) => format!("Serial connected: {name}"),
|
||||||
None => "Serial disconnected".to_string(),
|
None => "Serial disconnected".to_string(),
|
||||||
};
|
};
|
||||||
draw.text(&self.font, &status_text)
|
draw.draw_text(&status_text, 44, 14, 22, Color::BLACK);
|
||||||
.position(44.0, 30.0)
|
|
||||||
.size(22.0)
|
|
||||||
.color(Color::BLACK);
|
|
||||||
|
|
||||||
gfx.render(&draw);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(gfx: &mut Graphics) -> SingerApp {
|
fn main() {
|
||||||
SingerApp::new(gfx)
|
let (mut rl, thread) = raylib::init().size(1280, 720).title("singer").build();
|
||||||
}
|
rl.toggle_fullscreen();
|
||||||
|
|
||||||
fn update(_app: &mut notan::app::App, state: &mut SingerApp) {
|
let mut app = SingerApp::new();
|
||||||
state.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(gfx: &mut Graphics, state: &mut SingerApp) {
|
while !rl.window_should_close() {
|
||||||
state.draw(gfx);
|
app.update();
|
||||||
|
let mut draw = rl.begin_drawing(&thread);
|
||||||
|
app.draw(&mut draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[notan_main]
|
|
||||||
fn main() -> Result<(), String> {
|
|
||||||
notan::init_with(setup)
|
|
||||||
.add_config(WindowConfig::new().set_title("singer").set_fullscreen(true))
|
|
||||||
.add_config(DrawConfig)
|
|
||||||
.update(update)
|
|
||||||
.draw(draw)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user