Skip to main content

acorde_core/
lib.rs

1//! Platform-agnostic music score data model and command engine (undo/redo), with zero I/O
2//! and zero rendering. Pairs with [`acorde-io`](https://docs.rs/acorde-io) for MusicXML/MIDI/ABC
3//! parsing and [`acorde-layout`](https://docs.rs/acorde-layout) for logical score layout.
4
5pub mod model;
6
7pub use model::arrange::{analyze_for_accordion, arrange_for_accordion, AccordionAnalysis, ArrangeResult, PartCandidate};
8pub use model::score::{
9    Measure, Note, NoteAddr, Part, PartGroup, PartGroupSymbol, Score, ScoreChange, ScoreMetadata, ScoreSettings, ScoreStats,
10    ScoreTemplate, Staff, VoltaBracket, ScorePatch,
11    diff, score_patch, apply_patch,
12    transpose, respell_score, respell_score_to_key,
13    score_duration_secs, score_duration_secs_region, measure_beats_remaining,
14    suggested_stem_up, compute_beams,
15};
16pub use model::pitch::{Pitch, Step};
17pub use model::duration::Duration;
18pub use model::notation::{
19    Articulation, Barline, BeamState, ChordSymbol, Clef, Dynamic, GuitarTechnique,
20    HairpinKind, KeySignature, Lyric, NoteHead, OttavaKind, TimeSignature, TupletInfo,
21};
22pub use model::commands::{
23    AddHairpinCmd, AddMeasureCmd, AddNoteCmd, AddPartCmd, AddPedalCmd, AddPitchCmd,
24    AddStaffCmd, BatchCmd, Command, CommandStack, DeleteMeasureCmd, DeleteNoteCmd,
25    DeletePartCmd, DeleteStaffCmd, NewScoreCmd,
26    RespellScoreCmd, RespellScoreToKeyCmd, SetArpeggioCmd, SetBarlineCmd, SetChordSymbolCmd, SetClefCmd, SetDynamicCmd, SetGraceCmd,
27    SetKeySignatureCmd, SetLyricCmd, SetMetadataCmd, SetMidiInstrumentCmd, SetMultiRestCmd,
28    SetNavigationMarkCmd, SetOttavaCmd, SetPageBreakCmd, SetPartNameCmd, SetRehearsalMarkCmd,
29    SetSystemBreakCmd, SetStemCmd, SetTempoCmd, SetTempoAtMeasureCmd, SetTimeSignatureCmd, SetTransposeCmd,
30    SetTupletCmd, SetVoltaCmd, ToggleArticulationCmd, ToggleSlurCmd, ToggleTieCmd,
31    PasteVoiceCmd, PasteRangeCmd, command_key, command_label,
32    SetTechniqueTextCmd, SetFingeringCmd, SetStringNumberCmd, SetNoteHeadCmd, SetCueCmd,
33    SetGuitarTechniqueCmd,
34    SetExpressionTextCmd, ToggleTrillLineCmd, SetPartGroupCmd,
35};
36pub use model::change_hint::{ChangeHint, ChangeScope};
37pub use model::engine::{EngineHistory, ScoreEngine};
38pub use model::gm::{drum_name, program_name};
39pub use model::harmony::{detect_chord, roman_numeral};
40pub use model::interval::{Interval, IntervalQuality};
41pub use model::playback::{
42    MetronomeConfig, PlaybackEvent, PlaybackOptions, PlaybackPosition,
43    compute_playback_position, to_playback_events,
44};
45pub use model::repeat::measure_sequence;
46pub use model::scale::{Scale, ScaleKind};
47pub use model::validate::{ValidationError, ValidationWarning, ValidationReport, validate};
48
49/// Current Score JSON schema version produced by this crate.
50pub const SCORE_SCHEMA_VERSION: u32 = 1;
51
52#[derive(Debug, thiserror::Error)]
53pub enum Error {
54    #[error("part index {0} out of range")]
55    PartNotFound(usize),
56    #[error("staff index {0} out of range")]
57    StaffNotFound(usize),
58    #[error("measure index {0} out of range")]
59    MeasureNotFound(usize),
60    #[error("note index {0} out of range")]
61    NoteNotFound(usize),
62    #[error("voice index {0} out of range")]
63    VoiceOutOfRange(usize),
64    #[error("{0}")]
65    InvalidCommand(String),
66    #[error("nothing to undo")]
67    NothingToUndo,
68    #[error("nothing to redo")]
69    NothingToRedo,
70    #[error("clipboard is empty")]
71    ClipboardEmpty,
72    #[error("cannot delete the last staff of a part")]
73    CannotDeleteLastStaff,
74    #[error("invalid patch: {0}")]
75    InvalidPatch(String),
76}