diff --git a/src/main.rs b/src/main.rs index 6ad00e92..aebe8cc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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>|{ + App::new()?.run(Some(|app: Arc>|{ let mut state = app.write().unwrap(); // Start JACK and setup device graph let jack = jack_run("tek", &app)?; diff --git a/src/model.rs b/src/model.rs index cc0b9980..40087fea 100644 --- a/src/model.rs +++ b/src/model.rs @@ -72,6 +72,24 @@ pub struct App { /// Quantization factor pub quant: usize, } + +impl App { + pub fn new () -> Usually { + 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