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