implement App::new

This commit is contained in:
🪞👃🪞 2024-07-09 15:57:25 +03:00
parent 07084656b8
commit afa2a2fd2b
2 changed files with 19 additions and 16 deletions

View file

@ -22,25 +22,10 @@ use crate::{core::*, model::*};
/// Application entrypoint.
pub fn main () -> Usually<()> {
// Construct app
let mut app = App::default();
// Load config
let xdg = Arc::new(microxdg::XdgApp::new("tek")?);
app.xdg = Some(xdg.clone());
if crate::config::AppPaths::new(&xdg)?.should_create() {
app.modal = Some(Box::new(crate::config::SetupModal(Some(xdg.clone()))));
}
let midi_from = ["nanoKEY Studio.*capture.*"];
let audio_into = ["Komplete.+:playback_FL", "Komplete.+:playback_FR"];
// Init view
app.track_cursor = 1;
app.scene_cursor = 1;
app.note_start = 2;
app.time_zoom = 12;
app.quant = 24;
// Start main loop
app.run(Some(|app: Arc<RwLock<App>>|{
App::new()?.run(Some(|app: Arc<RwLock<App>>|{
let mut state = app.write().unwrap();
// Start JACK and setup device graph
let jack = jack_run("tek", &app)?;

View file

@ -72,6 +72,24 @@ pub struct App {
/// Quantization factor
pub quant: usize,
}
impl App {
pub fn new () -> Usually<Self> {
let xdg = Arc::new(microxdg::XdgApp::new("tek")?);
let first_run = crate::config::AppPaths::new(&xdg)?.should_create();
Ok(Self {
modal: first_run.then(||crate::config::SetupModal(Some(xdg.clone())).boxed()),
xdg: Some(xdg),
track_cursor: 1,
scene_cursor: 1,
note_start: 2,
time_zoom: 12,
quant: 24,
..Self::default()
})
}
}
process!(App |self, _client, scope| {
let (
reset, current_frames, current_usecs, next_usecs, period_usecs