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