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