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