Skip to main content

music21_rs/
lib.rs

1//! Rust helpers inspired by selected parts of Python's `music21`.
2//!
3//! The crate currently focuses on pitch construction, chord naming and
4//! lightweight theory utilities such as polyrhythm and tuning-system helpers.
5#![cfg_attr(docsrs, feature(doc_cfg))]
6#![deny(missing_docs)]
7#![deny(missing_debug_implementations)]
8#![forbid(unsafe_code)]
9
10/// The README's examples, run as doctests so they cannot go stale.
11#[cfg(doctest)]
12#[doc = include_str!("../README.md")]
13mod readme {}
14// #![feature(inline_const_pat)]
15// #![feature(negative_impls)]
16// #![feature(specialization)]
17// #![feature(lazy_get)]
18/// ABC notation export helpers.
19pub mod abc;
20/// Key-finding and compact analysis helpers.
21pub mod analysis;
22/// Chord construction, common-name analysis and chord input conversion traits.
23pub mod chord;
24/// Lead-sheet chord-symbol parsing.
25pub mod chordsymbol;
26pub(crate) mod common;
27pub(crate) mod defaults;
28pub(crate) mod display;
29/// Rhythmic duration primitives.
30pub mod duration;
31/// Error and result types used by the crate.
32pub mod error;
33
34/// Figured bass: the numbers written under a bass note.
35pub mod figuredbass;
36/// Harte chord notation: `C:maj7/3`, `Bb:(b3,5,b7,9)`, `N`.
37pub mod harte;
38
39pub(crate) mod fraction_pow;
40/// Public interval parsing, naming and transposition helpers.
41pub mod interval;
42/// Public key and key-signature helpers.
43pub mod key;
44/// Time signatures: bar length, beat count, beat length and beat division.
45pub mod meter;
46/// Minimal MIDI import/export helpers.
47pub mod midi;
48/// Ties, noteheads, stem direction, colour, lyrics and beams.
49pub mod notation;
50/// Note construction and pitch access helpers.
51pub mod note;
52/// Pitch construction, spelling and pitch-space helpers.
53pub mod pitch;
54/// Polyrhythm timing and pitch-set helpers.
55pub mod polyrhythm;
56/// Silent duration-bearing musical event.
57pub mod rest;
58/// Roman numeral parsing and compact harmonic analysis.
59pub mod roman;
60/// Public scale helpers.
61pub mod scale;
62/// Tone rows, twelve-tone matrices and serial transformations.
63pub mod serial;
64pub mod sieve;
65pub(crate) mod stepname;
66/// Small ordered timeline container.
67pub mod stream;
68/// Metronome marks and tempo-word conventions.
69pub mod tempo;
70/// Tuning-system ratios, labels and frequency helpers.
71pub mod tuningsystem;
72/// Two-voice voice-leading classification and parallel-interval checks.
73pub mod voiceleading;
74pub mod volume;
75// #[macro_use]
76// pub(crate) mod macros;
77
78pub use abc::{
79    abc_chord, abc_duration, abc_note, abc_rest, pitch_name_from_abc_note,
80    pitch_names_from_abc_chord,
81};
82pub use analysis::{
83    KeyEstimate, KeyProfile, estimate_key_from_chords, estimate_key_from_chords_with,
84    estimate_key_from_pitches, estimate_key_from_pitches_with,
85};
86pub use analysis::{tonal_certainty, tonal_certainty_from_scores};
87pub use chord::{
88    Chord, ChordResolutionSuggestion, ChordTableAddress, GuitarFingering, GuitarStringFingering,
89    GuitarTuning, GuitarTuningString, IntoNotes, KnownChordType, TriadQuality,
90    format_vector_string,
91};
92pub use chordsymbol::{
93    ChordAlteration, ChordQuality, ChordSymbol, Music21ChordType, chord_symbol_figure_from_chord,
94    chord_symbol_from_chord, known_chord_symbol_types,
95};
96pub use defaults::{FloatType, FractionType, IntegerType, Octave, UnsignedIntegerType};
97pub use duration::{Duration, DurationType, Tuplet, quarter_length_to_closest_type};
98pub use error::{Error, Result};
99pub use harte::{Harte, HarteInterval, SHORTHAND_DEGREES, convert_interval};
100pub use interval::{
101    ChromaticInterval, DiatonicInterval, GenericInterval, Interval, IntervalDirection, Specifier,
102    absolute_higher_pitch, absolute_lower_pitch, convert_diatonic_number_to_step, convert_generic,
103    convert_semitone_to_specifier_generic, convert_semitone_to_specifier_generic_microtone,
104    intervals_to_diatonic, notes_to_chromatic, notes_to_generic, parse_specifier,
105    staff_distance_to_generic_number, written_higher_pitch, written_lower_pitch,
106};
107pub use key::{Key, KeySignature, convert_key_string_to_music21_key_string};
108pub use meter::{BeamedNote, BeatDivision, MeterTerminal, OffsetAlign, TimeSignature};
109pub use midi::{
110    DEFAULT_TICKS_PER_QUARTER, MidiNote, midi_notes_from_stream, read_midi_bytes,
111    read_midi_bytes_with_tempo, stream_from_midi_notes, write_midi_bytes,
112};
113pub use notation::{
114    Beam, BeamDirection, BeamType, Beams, Lyric, Notehead, Placement, StemDirection, Syllabic, Tie,
115    TieStyle, TieType,
116};
117pub use note::{IntoNote, Note};
118pub use pitch::{
119    Accidental, AccidentalAttribute, AccidentalDisplayOptions, AccidentalSpecifier,
120    CHROMATIC_PITCH_CLASS_NAMES, Microtone, MicrotoneSpecifier, Pitch, PitchClass,
121    PitchClassSpecifier, PitchName, PitchOptions, convert_pitch_class_to_str, dissonance_score,
122    pitch_class_name, simplify_multiple_enharmonics,
123};
124pub use polyrhythm::{Polyrhythm, PolyrhythmAnalysis, PolyrhythmEvent, PolyrhythmRatioTone};
125pub use rest::Rest;
126pub use roman::roman_numeral_from_chord;
127pub use roman::{
128    ImpliedQuality, Minor67Default, NumeralAlone, RomanNumeral, analyze_chord,
129    analyze_chord_with_root, identify_as_tonic_or_dominant, roman_inversion_name,
130};
131pub use scale::{
132    BluesForm, DegreeComparison, DiatonicScale, Scale, ScaleType, SolfegVariant, StepScale,
133    WeightedHexatonicBlues,
134};
135pub use serial::{
136    HISTORICAL_ROWS, HistoricalRow, IndexedTransformation, LinkClassification, ToneRow,
137    Transformation, TransformationConvention, TwelveToneMatrix, historical_row_by_name,
138    row_to_matrix,
139};
140pub use sieve::Sieve;
141pub use stream::{Stream, StreamElement, StreamEvent, StreamKind};
142pub use tempo::{DEFAULT_TEMPO_VALUES, MetronomeMark, convert_tempo_by_referent};
143pub use tuningsystem::{
144    ALL_TUNING_SYSTEMS, COMMON_EQUAL_TEMPERAMENTS, COMMON_TWELVE_TONE_TUNING_SYSTEMS,
145    EqualDivision, Fraction, HISTORICAL_TEMPERAMENTS, Monzo, Mos, MosScale, OCTAVE_CENTS,
146    TRITAVE_CENTS, Temperament, TuningSystem, Val, moment_of_symmetry_sizes,
147    scala::{ScalaArchive, ScalaDegree, ScalaScale},
148};
149pub use voiceleading::{MotionType, VoiceLeadingQuartet};
150pub use volume::Volume;