diff --git a/musicus/.gitignore b/musicus/.gitignore index 41f19f5..d07d213 100644 --- a/musicus/.gitignore +++ b/musicus/.gitignore @@ -1,4 +1,5 @@ /.flatpak-builder +/.vscode /build /builddir /flatpak diff --git a/musicus/src/database/recordings.rs b/musicus/src/database/recordings.rs index f8ff5b5..3097d2d 100644 --- a/musicus/src/database/recordings.rs +++ b/musicus/src/database/recordings.rs @@ -1,3 +1,4 @@ +use super::generate_id; use super::schema::{ensembles, performances, persons, recordings}; use super::{Database, Ensemble, Instrument, Person, Work}; use anyhow::{anyhow, Error, Result}; @@ -93,6 +94,16 @@ pub struct Recording { } impl Recording { + /// Initialize a new recording with a work. + pub fn new(work: Work) -> Self { + Self { + id: generate_id(), + work, + comment: String::new(), + performances: Vec::new(), + } + } + /// Get a string representation of the performances in this recording. // TODO: Maybe replace with impl Display? pub fn get_performers(&self) -> String { diff --git a/musicus/src/database/works.rs b/musicus/src/database/works.rs index f9b3a33..a8ca80a 100644 --- a/musicus/src/database/works.rs +++ b/musicus/src/database/works.rs @@ -1,3 +1,4 @@ +use super::generate_id; use super::schema::{instrumentations, work_parts, work_sections, works}; use super::{Database, Instrument, Person}; use anyhow::{anyhow, Error, Result}; @@ -83,6 +84,18 @@ pub struct Work { } impl Work { + /// Initialize a new work with a composer. + pub fn new(composer: Person) -> Self { + Self { + id: generate_id(), + title: String::new(), + composer, + instruments: Vec::new(), + parts: Vec::new(), + sections: Vec::new(), + } + } + /// Get a string including the composer and title of the work. // TODO: Replace with impl Display. pub fn get_title(&self) -> String { diff --git a/musicus/src/selectors/recording.rs b/musicus/src/selectors/recording.rs index a4ca845..690f8bb 100644 --- a/musicus/src/selectors/recording.rs +++ b/musicus/src/selectors/recording.rs @@ -47,9 +47,16 @@ impl RecordingSelector { this.selector.set_add_cb(clone!(@strong this => move || { let navigator = this.navigator.borrow().clone(); if let Some(navigator) = navigator { - let editor = RecordingEditor::new(this.backend.clone(), None); + let recording = Recording::new(this.work.clone()); + + let editor = RecordingEditor::new(this.backend.clone(), Some(recording)); + editor - .set_selected_cb(clone!(@strong this => move |recording| this.select(&recording))); + .set_selected_cb(clone!(@strong this, @strong navigator => move |recording| { + navigator.clone().pop(); + this.select(&recording); + })); + navigator.push(editor); } })); diff --git a/musicus/src/selectors/work.rs b/musicus/src/selectors/work.rs index b116276..83e6a5a 100644 --- a/musicus/src/selectors/work.rs +++ b/musicus/src/selectors/work.rs @@ -47,9 +47,16 @@ impl WorkSelector { this.selector.set_add_cb(clone!(@strong this => move || { let navigator = this.navigator.borrow().clone(); if let Some(navigator) = navigator { - let editor = WorkEditor::new(this.backend.clone(), None); + let work = Work::new(this.person.clone()); + + let editor = WorkEditor::new(this.backend.clone(), Some(work)); + editor - .set_saved_cb(clone!(@strong this => move |work| this.select(&work))); + .set_saved_cb(clone!(@strong this, @strong navigator => move |work| { + navigator.clone().pop(); + this.select(&work); + })); + navigator.push(editor); } }));