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