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