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