Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.0.2 #22

Merged
merged 24 commits into from
Aug 13, 2024
18 changes: 11 additions & 7 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ on:
workflow_dispatch:

jobs:
core:
base:
env:
CRATENAME: ${{ github.event.repository.name }}-${{ matrix.features }}
name: Publish (${{ github.event.repository.name }})
runs-on: ubuntu-latest
strategy:
Expand All @@ -26,21 +28,23 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Publish (${{ matrix.features }})
run: cargo publish --all-features -v -p ${{ github.event.repository.name }}-${{ matrix.features }}
run: cargo publish --all-features -v -p ${{ env.CRATENAME }}
features:
name: Publish (${{ github.event.repository.name }})
needs: [ core ]
env:
CRATENAME: ${{ github.event.repository.name }}-${{ matrix.features }}
name: Publish (features)
needs: base
runs-on: ubuntu-latest
strategy:
matrix:
features: [ neo ]
steps:
- uses: actions/checkout@v4
- name: Publish (${{ matrix.features }})
run: cargo publish --all-features -v -p ${{ github.event.repository.name }}-${{ matrix.features }}
- name: Publish (${{ env.CRATENAME }})
run: cargo publish --all-features -v -p ${{ env.CRATENAME }}
publish:
name: Publish (${{ github.event.repository.name }})
needs: [ features ]
needs: features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
28 changes: 10 additions & 18 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,19 @@ jobs:
- name: cache
uses: actions/cache@v4
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.toolchain }}-
${{ runner.os }}-cargo-
${{ runner.os }}-
path: |
~/.cargo/registry
~/.cargo/git
target/debug
target/release
bench:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup (rustup)
run: rustup default nightly && rustup update
- name: cargo (bench)
if: matrix.toolchain == 'nightly'
run: cargo bench --features full -v --workspace
test:
name: Test
strategy:
matrix:
toolchain: [ stable, nightly ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup default ${{ matrix.toolchain }} && rustup update
- run: cargo test --features full -v --workspace
- name: cargo (test) [full]
id: test
run: cargo test --features full -v --workspace
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ thiserror = "1"
[workspace.package]
authors = ["Joe McCain III <[email protected]>",]
categories = [ ]
description = "This project focuses on providing concrete abstractions of musical objects discussed within the neo-Riemannian theory."
description = "This crate focuses on building a music theory library that can be used to generate music theory data structures and algorithms."
edition = "2021"
homepage = "https://github.com/FL03/triad/wiki"
homepage = "https://github.com/FL03/rstmt/wiki"
keywords = [ "music" ]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/FL03/triad.git"
version = "0.0.1"
repository = "https://github.com/FL03/rstmt.git"
version = "0.0.2"

[profile.dev]
opt-level = 0
Expand Down
5 changes: 1 addition & 4 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test = true
lazy_static.workspace = true
paste.workspace = true
smart-default.workspace = true

thiserror.workspace = true
[dependencies.num]
default-features = false
version = "0.4"
Expand All @@ -82,9 +82,6 @@ default-features = false
features = ["derive"]
version = "0.26"

[dev-dependencies]
lazy_static.workspace = true

[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "docsrs"]
Expand Down
67 changes: 67 additions & 0 deletions core/src/chords/chord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Appellation: chord <module>
Contrib: FL03 <[email protected]>
*/
use super::ChordData;

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Chord<S>
where
S: ChordData,
{
pub(crate) len: usize,
pub(crate) notes: S,
}

impl<S> Chord<S>
where
S: ChordData,
{
pub fn new() -> Self
where
S: Default,
{
Self {
len: 0,
notes: Default::default(),
}
}

pub fn from_notes(notes: S) -> Self {
Self {
len: notes.len(),
notes,
}
}

pub fn from_iter<I>(iter: I) -> Self
where
I: IntoIterator<Item = S::Elem>,
S: Default,
{
let mut notes = S::default();
for note in iter {
notes.push(note);
}
Self::from_notes(notes)
}

pub fn get(&self, idx: usize) -> &S::Elem {
self.notes.get(idx)
}

pub fn len(&self) -> usize {
debug_assert_eq!(
self.len,
self.notes.len(),
"Chord length is inconsistent with notes length"
);
self.len
}

pub fn push(&mut self, note: S::Elem) {
self.len += 1;
self.notes.push(note);
}
}
50 changes: 50 additions & 0 deletions core/src/chords/dyad.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Appellation: dyad <module>
Contrib: FL03 <[email protected]>
*/
use crate::notes::Note;
use crate::{Intervals, Pair};

fn _interval<A, B>(lhs: A, rhs: B) -> Intervals
where
A: core::ops::Sub<B, Output = Intervals>,
{
lhs - rhs
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Dyad {
chord: Pair<Note>,
interval: Intervals,
}

impl Dyad {
pub fn new(src: Note, tgt: Note) -> Self {
let chord = Pair::new(src, tgt);
let interval = Intervals::dist(src, tgt);
Self { chord, interval }
}

pub fn from_tuple((lhs, rhs): (Note, Note)) -> Self {
let chord = Pair::new(lhs, rhs);
let interval = Intervals::dist(lhs, rhs);
Self { chord, interval }
}

pub const fn chord(&self) -> &Pair<Note> {
&self.chord
}

pub fn chord_mut(&mut self) -> &mut Pair<Note> {
&mut self.chord
}

pub const fn interval(&self) -> &Intervals {
&self.interval
}

pub fn interval_mut(&mut self) -> &mut Intervals {
&mut self.interval
}
}
35 changes: 35 additions & 0 deletions core/src/chords/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Appellation: chord <module>
Contrib: FL03 <[email protected]>
*/
#[doc(inline)]
pub use self::{chord::Chord, dyad::Dyad};

pub(crate) mod chord;
pub(crate) mod dyad;

pub(crate) mod prelude {
pub use super::chord::*;
pub use super::dyad::*;
}

pub trait Container {
type Elem;
}

impl<T> Container for Vec<T> {
type Elem = T;
}

/// [ChordData] provides common methods for viable representations of chords.
/// Typically, implementations of [ChordData] describe linear data-structures
/// such as arrays, vectors, or slices.
pub trait ChordData {
type Elem;

fn get(&self, idx: usize) -> &Self::Elem;

fn len(&self) -> usize;

fn push(&mut self, elem: Self::Elem);
}
Loading
Loading