#![doc = include_str!("../README.md")]
pub mod cdnz_serde;
pub mod lilypond;
pub mod upgrade;
use num::Rational32 as Rat32;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use std::collections::BTreeMap;
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
pub struct Project {
pub cdnz: Metadata,
pub global: GlobalData,
pub parts: BTreeMap<PartName, Part>,
pub layouts: BTreeMap<LayoutName, Layout>,
}
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
pub struct Metadata {
pub score_title: String,
pub composer: PersonInfo,
pub arranger: PersonInfo,
pub engraver: PersonInfo,
pub description: String,
pub music_license: String,
pub engraving_license: String,
}
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
#[skip_serializing_none]
pub struct PersonInfo {
pub name: String,
pub email: Option<String>,
pub is_person: bool,
}
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
pub struct GlobalData {
pub mod_events: BTreeMap<Position, Vec<GlobalModEvent>>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum GlobalModEvent {
KeyChange {
note: Pitch,
mode: KeyMode,
},
TimeChange {
count: u16,
unit: u16,
},
TempoChange {
bpm: Bpm,
display_tempo: bool,
label: Option<String>,
},
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum KeyMode {
Major,
Minor,
Dorian,
Phrygian,
Lydian,
Mixolydian,
Locrian,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Bpm {
pub unit: Rat32,
}
pub type PartName = String;
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
pub struct Part {
pub voices: Vec<Voice>,
}
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
pub struct Voice {
pub instrument: Instrument,
pub rhythmic_events: BTreeMap<Position, RhythmicEvent>,
pub mod_events: BTreeMap<Position, Vec<LocalModEvent>>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum RhythmicEvent {
Note { pitches: Vec<Pitch> },
DrumNote {},
Rest {},
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum LocalModEvent {}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum ClefSign {
G,
F,
C,
}
pub type LayoutName = String;
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Layout {
pub header: Header,
pub layout: LayoutElement,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Header {}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum LayoutElement {
Staff { voices: Vec<LayoutVoice> },
StaffGroup { children: Vec<LayoutElement> },
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct LayoutVoice {
pub mod_events: Vec<LayoutModEvent>,
pub referenced_voice: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum LayoutModEvent {
ClefChange {
sign: ClefSign,
pos: i32,
octave: i32,
},
Transposition {
pitch: Pitch,
},
}
impl LayoutModEvent {
pub fn new_treble_clef() -> LayoutModEvent {
LayoutModEvent::ClefChange {
sign: ClefSign::G,
pos: -2,
octave: 0,
}
}
pub fn new_bass_clef() -> LayoutModEvent {
LayoutModEvent::ClefChange {
sign: ClefSign::F,
pos: 2,
octave: 0,
}
}
pub fn new_alto_clef() -> LayoutModEvent {
LayoutModEvent::ClefChange {
sign: ClefSign::C,
pos: 0,
octave: 0,
}
}
}
#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct Position {
pub measure: u32,
pub pos: Rat32,
pub grace_index: u32,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Pitch {
pub step: i32,
pub alteration: Rat32,
}
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
pub enum Instrument {
Violin,
Viola,
Cello,
DoubleBass,
Harp,
Guitar,
ElectricGuitar,
BassGuitar,
ElectricBassGuitar,
Banjo,
Mandolin,
Lute,
Flute,
Piccolo,
Oboe,
EnglishHorn,
Clarinet,
BassClarinet,
Bassoon,
Contrabassoon,
SopranoSaxophone,
AltoSaxophone,
TenorSaxophone,
BaritoneSaxophone,
Trumpet,
Cornet,
FrenchHorn,
Trombone,
BassTrombone,
Euphonium,
Tuba,
SnareDrum,
BassDrum,
Cymbals,
Triangle,
Tambourine,
Timpani,
Xylophone,
Marimba,
Glockenspiel,
Vibraphone,
#[default]
Piano,
Harpsichord,
Organ,
Celesta,
Accordion,
Synthesizer,
}