Skip to main content

ScoreEngine

Struct ScoreEngine 

Source
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

Source

pub fn new() -> Self

Source

pub fn apply(&mut self, cmd: Command) -> Result<ChangeHint, Error>

Source

pub fn undo(&mut self) -> Result<ChangeHint, Error>

Source

pub fn redo(&mut self) -> Result<ChangeHint, Error>

Source

pub fn batch_apply(&mut self, cmds: Vec<Command>) -> Result<ChangeHint, Error>

Apply multiple commands as a single undo entry.

Source

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").

Source

pub fn undo_label(&self) -> Option<String>

Label of the next undoable command (for “Undo: Add Note” menu items).

Source

pub fn redo_label(&self) -> Option<String>

Label of the next redoable command (for “Redo: Add Note” menu items).

Source

pub fn undo_key(&self) -> Option<String>

i18n key of the next undoable command (e.g. "SetTempo").

Source

pub fn redo_key(&self) -> Option<String>

i18n key of the next redoable command.

Source

pub fn replace_score(&mut self, score: Score)

Source

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.

Source

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).

Source

pub fn copy_voice( &mut self, part_index: usize, staff_index: usize, measure_index: usize, voice_index: usize, ) -> Result<(), Error>

Source

pub fn paste_voice( &mut self, part_index: usize, staff_index: usize, measure_index: usize, voice_index: usize, ) -> Result<ChangeHint, Error>

Source

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.

Source

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.

Source

pub fn toggle_slur( &mut self, start: NoteAddr, end: NoteAddr, ) -> Result<ChangeHint, Error>

Toggle the slur between two notes (undo-able).

Source

pub fn add_staff( &mut self, part_index: usize, clef: Clef, ) -> Result<ChangeHint, Error>

Add a staff to a part (undo-able).

Source

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.

Source

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.

Source

pub fn set_duration( &mut self, addr: NoteAddr, duration: Duration, dot_count: u8, ) -> Result<ChangeHint, Error>

Set the duration and dot count on an existing note (undo-able).

Source

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).

Source

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).

Source

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.

Source

pub fn toggle_trill_line( &mut self, start: NoteAddr, end: NoteAddr, ) -> Result<ChangeHint, Error>

Toggle a trill line span between two notes (undo-able).

Source

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.

Source

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).

Source

pub fn respell_score(&mut self, prefer_flat: bool) -> Result<ChangeHint, Error>

Respell all pitches in the score (undo-able).

Source

pub fn respell_score_to_key(&mut self) -> Result<ChangeHint, Error>

Respell all pitches to match the score’s key signature (undo-able).

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for ScoreEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.