pub struct ScoreEngine {
pub score: Score,
pub commands: CommandStack,
pub version: u64,
pub clipboard: Option<Vec<Note>>,
/* private fields */
}Fields§
§score: Score§commands: CommandStack§version: u64§clipboard: Option<Vec<Note>>Implementations§
Source§impl ScoreEngine
impl ScoreEngine
pub fn new() -> Self
pub fn apply(&mut self, cmd: Command) -> Result<ChangeHint, Error>
pub fn undo(&mut self) -> Result<ChangeHint, Error>
pub fn redo(&mut self) -> Result<ChangeHint, Error>
Sourcepub fn batch_apply(&mut self, cmds: Vec<Command>) -> Result<ChangeHint, Error>
pub fn batch_apply(&mut self, cmds: Vec<Command>) -> Result<ChangeHint, Error>
Apply multiple commands as a single undo entry.
Sourcepub fn batch_apply_labeled(
&mut self,
cmds: Vec<Command>,
label: &str,
) -> Result<ChangeHint, Error>
pub fn batch_apply_labeled( &mut self, cmds: Vec<Command>, label: &str, ) -> Result<ChangeHint, Error>
Apply a batch of commands as a single undo entry with an explicit label.
The label appears as the [command_key] in undo/redo UI (e.g. "ApplyAI").
Sourcepub fn undo_label(&self) -> Option<String>
pub fn undo_label(&self) -> Option<String>
Label of the next undoable command (for “Undo: Add Note” menu items).
Sourcepub fn redo_label(&self) -> Option<String>
pub fn redo_label(&self) -> Option<String>
Label of the next redoable command (for “Redo: Add Note” menu items).
Sourcepub fn undo_key(&self) -> Option<String>
pub fn undo_key(&self) -> Option<String>
i18n key of the next undoable command (e.g. "SetTempo").
pub fn replace_score(&mut self, score: Score)
Sourcepub fn export_history(&self) -> EngineHistory
pub fn export_history(&self) -> EngineHistory
Export the command history for serialization (crash recovery, AI replay).
The returned EngineHistory can be stored as JSON and later restored with
ScoreEngine::from_history.
Sourcepub fn from_history(history: EngineHistory) -> Result<Self, Error>
pub fn from_history(history: EngineHistory) -> Result<Self, Error>
Reconstruct an engine from a previously exported EngineHistory.
Replays all commands against history.initial_score in order.
Returns an error if any command fails (e.g. index out of bounds due to stale data).
pub fn copy_voice( &mut self, part_index: usize, staff_index: usize, measure_index: usize, voice_index: usize, ) -> Result<(), Error>
pub fn paste_voice( &mut self, part_index: usize, staff_index: usize, measure_index: usize, voice_index: usize, ) -> Result<ChangeHint, Error>
Sourcepub fn copy_range(
&mut self,
start: NoteAddr,
end: NoteAddr,
) -> Result<(), Error>
pub fn copy_range( &mut self, start: NoteAddr, end: NoteAddr, ) -> Result<(), Error>
Copy a range of measures from a single voice into the range clipboard.
The range is inclusive: all measures from start.measure to end.measure.
start and end must share the same part, staff, and voice.
Sourcepub fn paste_range(&mut self, target: NoteAddr) -> Result<ChangeHint, Error>
pub fn paste_range(&mut self, target: NoteAddr) -> Result<ChangeHint, Error>
Paste the range clipboard starting at target, creating an undo-able command.
The voice index from the original copy_range call is used; target.voice is ignored.
Sourcepub fn toggle_slur(
&mut self,
start: NoteAddr,
end: NoteAddr,
) -> Result<ChangeHint, Error>
pub fn toggle_slur( &mut self, start: NoteAddr, end: NoteAddr, ) -> Result<ChangeHint, Error>
Toggle the slur between two notes (undo-able).
Sourcepub fn add_staff(
&mut self,
part_index: usize,
clef: Clef,
) -> Result<ChangeHint, Error>
pub fn add_staff( &mut self, part_index: usize, clef: Clef, ) -> Result<ChangeHint, Error>
Add a staff to a part (undo-able).
Sourcepub fn delete_staff(
&mut self,
part_index: usize,
staff_index: usize,
) -> Result<ChangeHint, Error>
pub fn delete_staff( &mut self, part_index: usize, staff_index: usize, ) -> Result<ChangeHint, Error>
Remove a staff from a part (undo-able). Fails if it is the last remaining staff.
Sourcepub fn set_stem(
&mut self,
addr: NoteAddr,
stem_up: Option<bool>,
) -> Result<ChangeHint, Error>
pub fn set_stem( &mut self, addr: NoteAddr, stem_up: Option<bool>, ) -> Result<ChangeHint, Error>
Set or clear the stem direction on an existing note (undo-able).
stem_up: None = auto, Some(true) = up, Some(false) = down.
Sourcepub fn set_arpeggio(
&mut self,
addr: NoteAddr,
direction: Option<bool>,
) -> Result<ChangeHint, Error>
pub fn set_arpeggio( &mut self, addr: NoteAddr, direction: Option<bool>, ) -> Result<ChangeHint, Error>
Set or clear the arpeggio direction on an existing note (undo-able).
Sourcepub fn set_note_head(
&mut self,
addr: NoteAddr,
note_head: NoteHead,
) -> Result<ChangeHint, Error>
pub fn set_note_head( &mut self, addr: NoteAddr, note_head: NoteHead, ) -> Result<ChangeHint, Error>
Set the note head shape on an existing note (undo-able).
Sourcepub fn set_part_group(
&mut self,
group: Option<PartGroup>,
) -> Result<ChangeHint, Error>
pub fn set_part_group( &mut self, group: Option<PartGroup>, ) -> Result<ChangeHint, Error>
Add or replace a part group (undo-able). Pass None to clear all groups.
Sourcepub fn toggle_trill_line(
&mut self,
start: NoteAddr,
end: NoteAddr,
) -> Result<ChangeHint, Error>
pub fn toggle_trill_line( &mut self, start: NoteAddr, end: NoteAddr, ) -> Result<ChangeHint, Error>
Toggle a trill line span between two notes (undo-able).
Sourcepub fn set_cue(
&mut self,
addr: NoteAddr,
is_cue: bool,
) -> Result<ChangeHint, Error>
pub fn set_cue( &mut self, addr: NoteAddr, is_cue: bool, ) -> Result<ChangeHint, Error>
Set or clear the cue flag on a note (undo-able). Cue notes have zero beats.
Sourcepub fn set_tuplet(
&mut self,
addr: NoteAddr,
tuplet: Option<TupletInfo>,
) -> Result<ChangeHint, Error>
pub fn set_tuplet( &mut self, addr: NoteAddr, tuplet: Option<TupletInfo>, ) -> Result<ChangeHint, Error>
Set or clear the tuplet on an existing note (undo-able).
Sourcepub fn respell_score(&mut self, prefer_flat: bool) -> Result<ChangeHint, Error>
pub fn respell_score(&mut self, prefer_flat: bool) -> Result<ChangeHint, Error>
Respell all pitches in the score (undo-able).
Sourcepub fn respell_score_to_key(&mut self) -> Result<ChangeHint, Error>
pub fn respell_score_to_key(&mut self) -> Result<ChangeHint, Error>
Respell all pitches to match the score’s key signature (undo-able).
Sourcepub fn begin_slur(&mut self, start: NoteAddr) -> Result<(), Error>
pub fn begin_slur(&mut self, start: NoteAddr) -> Result<(), Error>
Begin a two-step slur: record start and wait for end_slur.
Returns an error if start does not point to a valid note.
Sourcepub fn end_slur(&mut self, end: NoteAddr) -> Result<ChangeHint, Error>
pub fn end_slur(&mut self, end: NoteAddr) -> Result<ChangeHint, Error>
Complete the slur started by begin_slur (undo-able).
Returns Error::InvalidCommand if begin_slur has not been called.