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, SetTabPositionCmd,
21    SetTechniqueTextCmd, SetTempoAtMeasureCmd, SetTempoCmd, SetTimeSignatureCmd, SetTransposeCmd,
22    SetTupletCmd, SetVoltaCmd, ToggleArticulationCmd, ToggleSlurCmd, ToggleTieCmd,
23    ToggleTrillLineCmd, 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, MidiPitchBend, Note, NoteAddr, Part, PartGroup, PartGroupSymbol, Score, ScoreChange,
44    ScoreMetadata, ScorePatch, ScoreSettings, ScoreStats, ScoreTemplate, Staff, VoltaBracket,
45    apply_patch, assign_tablature_positions, compute_beams, diff, measure_beats_remaining,
46    optimize_tablature_positions, respell_score, respell_score_to_key, score_duration_secs,
47    score_duration_secs_region, score_patch, suggested_stem_up, transpose,
48};
49pub use model::validate::{
50    TablatureValidationReason, ValidationError, ValidationReport, ValidationWarning, validate,
51};
52
53/// Current Score JSON schema version produced by this crate.
54pub const SCORE_SCHEMA_VERSION: u32 = 1;
55
56#[derive(Debug, thiserror::Error)]
57pub enum Error {
58    #[error("part index {0} out of range")]
59    PartNotFound(usize),
60    #[error("staff index {0} out of range")]
61    StaffNotFound(usize),
62    #[error("measure index {0} out of range")]
63    MeasureNotFound(usize),
64    #[error("note index {0} out of range")]
65    NoteNotFound(usize),
66    #[error("voice index {0} out of range")]
67    VoiceOutOfRange(usize),
68    #[error("{0}")]
69    InvalidCommand(String),
70    #[error("nothing to undo")]
71    NothingToUndo,
72    #[error("nothing to redo")]
73    NothingToRedo,
74    #[error("clipboard is empty")]
75    ClipboardEmpty,
76    #[error("cannot delete the last staff of a part")]
77    CannotDeleteLastStaff,
78    #[error("invalid patch: {0}")]
79    InvalidPatch(String),
80}