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, AddSpannerCmd,
13    AddStaffCmd, BatchCmd, Command, CommandStack, CycleEnharmonicSpellingCmd, DeleteMeasureCmd,
14    DeleteNoteCmd, DeletePartCmd, DeleteStaffCmd, DurationScale, ExchangeVoicesCmd,
15    ExplodeChordPitchesCmd, ExplodeVoicesCmd, ImplodeStavesCmd, JoinMeasuresCmd,
16    MoveOrCopyVoiceRangeCmd, NewScoreCmd, PasteRangeCmd, PasteScoreFragmentCmd, PasteVoiceCmd,
17    RemoveScoreViewCmd, RemoveSpannerCmd, RemoveTrailingEmptyMeasuresCmd, ReorderPartsCmd,
18    ResequenceRehearsalMarksCmd, RespellScoreCmd, RespellScoreToKeyCmd, RespellStaffRegionCmd,
19    ScaleVoiceRangeCmd, ScoreFragmentPastePolicy, SetArpeggioCmd, SetBarlineCmd, SetChordSymbolCmd,
20    SetClefCmd, SetCrossStaffCmd, SetCueCmd, SetDurationCmd, SetDynamicCmd, SetExpressionTextCmd,
21    SetFiguredBassCmd, SetFingeringCmd, SetFingeringsCmd, SetGlissandoCmd, SetGraceCmd,
22    SetGuitarBendAlterCmd, SetGuitarBendCurveCmd, SetGuitarTechniqueCmd, SetHarmonyRangeCmd,
23    SetHarpPedalDiagramsCmd, SetInstrumentDefinitionCmd, SetInstrumentIdCmd, SetKeySignatureCmd,
24    SetLyricCmd, SetMeasureInstrumentChangeCmd, SetMeasureTablatureChangeCmd, SetMeasureTextCmd,
25    SetMetadataCmd, SetMidiInstrumentCmd, SetMultiRestCmd, SetNavigationMarkCmd, SetNoteHeadCmd,
26    SetNotePlacementCmd, SetObjectStyleOverridesCmd, SetOttavaCmd, SetPageBreakCmd,
27    SetPartGroupCmd, SetPartNameCmd, SetPercussionKitCmd, SetRehearsalMarkCmd,
28    SetScoreStyleOverridesCmd, SetScoreTextCmd, SetSectionBreakCmd, SetStaffPresentationCmd,
29    SetStemCmd, SetStringNumberCmd, SetSystemBreakCmd, SetSystemBreakIntervalCmd,
30    SetTabPositionCmd, SetTablatureConfigCmd, SetTechniqueTextCmd, SetTempoAtMeasureCmd,
31    SetTempoCmd, SetTimeSignatureCmd, SetTransposeCmd, SetTupletCmd, SetUnpitchedCmd, SetVoltaCmd,
32    SplitMeasureCmd, ToggleArticulationCmd, ToggleSlurCmd, ToggleTieCmd, ToggleTrillLineCmd,
33    TransposeStaffRegionCmd, TupletScalePolicy, UpdateSpannerCmd, UpsertScoreViewCmd, command_key,
34    command_label,
35};
36pub use model::duration::Duration;
37pub use model::engine::{EngineHistory, HistoryConflict, HistoryRelation, ScoreEngine};
38pub use model::fragment::{
39    MIN_SUPPORTED_SCORE_FRAGMENT_CONTRACT_VERSION, SCORE_FRAGMENT_CONTRACT_VERSION, ScoreFragment,
40    ScoreFragmentCrossStaffTarget, ScoreFragmentDiagnostic, ScoreFragmentMeasure,
41    ScoreFragmentMeasureAttributes, ScoreFragmentSelection, ScoreFragmentVoice,
42    extract_score_fragment,
43};
44pub use model::gm::{drum_name, program_name};
45pub use model::harmony::{detect_chord, roman_numeral};
46pub use model::interval::{Interval, IntervalQuality};
47pub use model::notation::{
48    Articulation, Barline, BeamState, ChordBarre, ChordDefinition, ChordDefinitionMember,
49    ChordDegree, ChordSymbol, Clef, CrossStaff, Dynamic, FiguredBassFigure,
50    FingeringSelectionPolicy, GuitarTechnique, HairpinKind, KeySignature, Lyric, NoteHead,
51    OttavaKind, StyledText, TabPosition, TablatureConfig, TextStyle, TimeSignature, TupletInfo,
52    VerseLyric,
53};
54pub use model::pitch::{Pitch, Step};
55pub use model::playback::{
56    MAX_PLAYBACK_COMPARISON_EVENTS, MAX_TAB_PERFORMANCE_EVENTS, MetronomeConfig,
57    OFFLINE_RENDER_CONTRACT_VERSION, OfflineRenderDiagnostic, OfflineRenderDiagnosticKind,
58    OfflineRenderFormat, OfflineRenderFrameEvent, OfflineRenderManifest,
59    OfflineRenderMeasureAddress, OfflineRenderNavigationPolicy, OfflineRenderRequest,
60    OfflineRenderResult, OfflineRenderScope, OfflineRenderSemanticEventKind,
61    OfflineRenderSemanticFrameEvent, PLAYBACK_COMPARISON_CONTRACT_VERSION,
62    PLAYBACK_ROUTING_CONTRACT_VERSION, PLAYBACK_TIMING_CORPUS_CONTRACT_VERSION, PlaybackAuxSend,
63    PlaybackBusRoute, PlaybackEffectRoute, PlaybackEvent, PlaybackOptions, PlaybackPosition,
64    PlaybackRealizationProfile, PlaybackRoutingConfig, PlaybackRoutingManifest, PlaybackTimingCase,
65    PlaybackTimingCaseReport, PlaybackTimingCorpusReport, PlaybackTimingMismatch,
66    PlaybackTimingReport, PlaybackTimingTolerance, TAB_PERFORMANCE_CONTRACT_VERSION,
67    TAB_ROUND_TRIP_CONTRACT_VERSION, TablaturePerformanceDiagnostic, TablaturePerformanceEvent,
68    TablaturePerformanceReport, TablatureRoundTripDiagnostic, TablatureRoundTripReport,
69    build_offline_render_manifest, build_playback_routing_manifest, compare_playback_timing,
70    compute_playback_position, evaluate_playback_timing_corpus, project_tablature_performance,
71    tablature_round_trip_report, to_playback_events, to_playback_events_bounded,
72};
73pub use model::repeat::measure_sequence;
74pub use model::scale::{Scale, ScaleKind};
75pub use model::score::{
76    GuitarBendPoint, HarpPedalDiagram, HarpPedalPosition, InstrumentDefinition, InstrumentRange,
77    Measure, MeasureLength, MidiAftertouch, MidiControlChange, MidiPitchBend, MidiProgramChange,
78    NotationSpanner, NotationSpannerKind, Note, NoteAddr, ObjectStyleOverride, ObjectStyleTarget,
79    Part, PartGroup, PartGroupSymbol, PercussionInstrument, RegionalTranspositionTarget,
80    RespellPolicy, Score, ScoreChange, ScoreMetadata, ScorePatch, ScoreSettings, ScoreStats,
81    ScoreTemplate, ScoreView, ScoreViewLayoutOverrides, Staff, StaffGroup, StaffKind,
82    StaffNoteheadScheme, StaffPresentation, StyleImportProvenance, TablatureFretMarkStyle,
83    TablatureRhythmDisplay, ViewStaffKindOverride, ViewStaffRef, ViewStyle, ViewStyleOverride,
84    ViewStyleProperty, ViewTranspositionPolicy, VoltaBracket, apply_patch,
85    assign_tablature_positions, compute_beams, diff, measure_beats_remaining,
86    optimize_tablature_positions, respell_score, respell_score_to_key, respell_staff_region,
87    score_duration_secs, score_duration_secs_region, score_patch, suggested_stem_up, transpose,
88    transpose_checked, transpose_staff_region_checked,
89};
90pub use model::structural_plan::{
91    STRUCTURAL_CHANGE_PLAN_CONTRACT_VERSION, StructuralChangeDiagnostic,
92    StructuralChangeDiagnosticKind, StructuralChangePlan, StructuralMeasureStructure,
93    plan_structural_change,
94};
95pub use model::validate::{
96    GuitarBendCurveValidationReason, InstrumentDefinitionValidationReason, InstrumentRangeKind,
97    ObjectStyleValidationReason, PercussionInstrumentValidationReason, ScoreViewValidationReason,
98    SpannerEndpoint, StaffPresentationValidationReason, TablatureValidationReason, ValidationError,
99    ValidationReport, ValidationWarning, validate,
100};
101
102/// Current Score JSON schema version produced by this crate.
103pub const SCORE_SCHEMA_VERSION: u32 = 1;
104
105#[derive(Debug, thiserror::Error)]
106pub enum Error {
107    #[error("part index {0} out of range")]
108    PartNotFound(usize),
109    #[error("staff index {0} out of range")]
110    StaffNotFound(usize),
111    #[error("measure index {0} out of range")]
112    MeasureNotFound(usize),
113    #[error("note index {0} out of range")]
114    NoteNotFound(usize),
115    #[error("voice index {0} out of range")]
116    VoiceOutOfRange(usize),
117    #[error("{0}")]
118    InvalidCommand(String),
119    #[error("nothing to undo")]
120    NothingToUndo,
121    #[error("nothing to redo")]
122    NothingToRedo,
123    #[error("clipboard is empty")]
124    ClipboardEmpty,
125    #[error("cannot delete the last staff of a part")]
126    CannotDeleteLastStaff,
127    #[error("invalid patch: {0}")]
128    InvalidPatch(String),
129    #[error("score failed structural validation")]
130    InvalidScore,
131    #[error("engine history base score does not match the supplied score")]
132    HistoryBaseMismatch,
133    #[error("engine history is not a safe append-only extension")]
134    HistoryNotAppendable,
135    #[error("invalid playback comparison tolerance")]
136    InvalidPlaybackComparison,
137    #[error("invalid offline render request")]
138    InvalidOfflineRenderRequest,
139    #[error("invalid playback routing configuration")]
140    InvalidPlaybackRouting,
141    #[error("invalid playback timing corpus")]
142    InvalidPlaybackTimingCorpus,
143    #[error("playback comparison contains too many events ({0})")]
144    PlaybackComparisonTooLarge(usize),
145    #[error("tablature performance projection contains too many events ({0})")]
146    TabPerformanceTooLarge(usize),
147    #[error("tablature round-trip serialization failed: {0}")]
148    TabRoundTripSerialization(String),
149}