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