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