Skip to content

Commit ce0211f

Browse files
authored
Merge pull request #22 from FL03/v0.0.2
V0.0.2
2 parents 32a6602 + 6f631c3 commit ce0211f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2863
-1078
lines changed

.github/workflows/crates.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ on:
1717
workflow_dispatch:
1818

1919
jobs:
20-
core:
20+
base:
21+
env:
22+
CRATENAME: ${{ github.event.repository.name }}-${{ matrix.features }}
2123
name: Publish (${{ github.event.repository.name }})
2224
runs-on: ubuntu-latest
2325
strategy:
@@ -26,21 +28,23 @@ jobs:
2628
steps:
2729
- uses: actions/checkout@v4
2830
- name: Publish (${{ matrix.features }})
29-
run: cargo publish --all-features -v -p ${{ github.event.repository.name }}-${{ matrix.features }}
31+
run: cargo publish --all-features -v -p ${{ env.CRATENAME }}
3032
features:
31-
name: Publish (${{ github.event.repository.name }})
32-
needs: [ core ]
33+
env:
34+
CRATENAME: ${{ github.event.repository.name }}-${{ matrix.features }}
35+
name: Publish (features)
36+
needs: base
3337
runs-on: ubuntu-latest
3438
strategy:
3539
matrix:
3640
features: [ neo ]
3741
steps:
3842
- uses: actions/checkout@v4
39-
- name: Publish (${{ matrix.features }})
40-
run: cargo publish --all-features -v -p ${{ github.event.repository.name }}-${{ matrix.features }}
43+
- name: Publish (${{ env.CRATENAME }})
44+
run: cargo publish --all-features -v -p ${{ env.CRATENAME }}
4145
publish:
4246
name: Publish (${{ github.event.repository.name }})
43-
needs: [ features ]
47+
needs: features
4448
runs-on: ubuntu-latest
4549
steps:
4650
- uses: actions/checkout@v4

.github/workflows/rust.yml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,19 @@ jobs:
4343
- name: cache
4444
uses: actions/cache@v4
4545
with:
46-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
46+
key: ${{ runner.os }}-cargo-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
47+
restore-keys: |
48+
${{ runner.os }}-cargo-${{ matrix.toolchain }}-
49+
${{ runner.os }}-cargo-
50+
${{ runner.os }}-
4751
path: |
4852
~/.cargo/registry
4953
~/.cargo/git
54+
target/debug
5055
target/release
51-
bench:
52-
name: Benchmark
53-
runs-on: ubuntu-latest
54-
steps:
55-
- uses: actions/checkout@v4
56-
- name: setup (rustup)
57-
run: rustup default nightly && rustup update
5856
- name: cargo (bench)
57+
if: matrix.toolchain == 'nightly'
5958
run: cargo bench --features full -v --workspace
60-
test:
61-
name: Test
62-
strategy:
63-
matrix:
64-
toolchain: [ stable, nightly ]
65-
runs-on: ubuntu-latest
66-
steps:
67-
- uses: actions/checkout@v4
68-
- run: rustup default ${{ matrix.toolchain }} && rustup update
69-
- run: cargo test --features full -v --workspace
59+
- name: cargo (test) [full]
60+
id: test
61+
run: cargo test --features full -v --workspace

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ thiserror = "1"
2727
[workspace.package]
2828
authors = ["Joe McCain III <jo3mccain@icloud.com>",]
2929
categories = [ ]
30-
description = "This project focuses on providing concrete abstractions of musical objects discussed within the neo-Riemannian theory."
30+
description = "This crate focuses on building a music theory library that can be used to generate music theory data structures and algorithms."
3131
edition = "2021"
32-
homepage = "https://github.com/FL03/triad/wiki"
32+
homepage = "https://github.com/FL03/rstmt/wiki"
3333
keywords = [ "music" ]
3434
license = "Apache-2.0"
3535
readme = "README.md"
36-
repository = "https://github.com/FL03/triad.git"
37-
version = "0.0.1"
36+
repository = "https://github.com/FL03/rstmt.git"
37+
version = "0.0.2"
3838

3939
[profile.dev]
4040
opt-level = 0

core/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ test = true
5858
lazy_static.workspace = true
5959
paste.workspace = true
6060
smart-default.workspace = true
61-
61+
thiserror.workspace = true
6262
[dependencies.num]
6363
default-features = false
6464
version = "0.4"
@@ -82,9 +82,6 @@ default-features = false
8282
features = ["derive"]
8383
version = "0.26"
8484

85-
[dev-dependencies]
86-
lazy_static.workspace = true
87-
8885
[package.metadata.docs.rs]
8986
all-features = true
9087
rustc-args = ["--cfg", "docsrs"]

core/src/chords/chord.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Appellation: chord <module>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
*/
5+
use super::ChordData;
6+
7+
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
8+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9+
pub struct Chord<S>
10+
where
11+
S: ChordData,
12+
{
13+
pub(crate) len: usize,
14+
pub(crate) notes: S,
15+
}
16+
17+
impl<S> Chord<S>
18+
where
19+
S: ChordData,
20+
{
21+
pub fn new() -> Self
22+
where
23+
S: Default,
24+
{
25+
Self {
26+
len: 0,
27+
notes: Default::default(),
28+
}
29+
}
30+
31+
pub fn from_notes(notes: S) -> Self {
32+
Self {
33+
len: notes.len(),
34+
notes,
35+
}
36+
}
37+
38+
pub fn from_iter<I>(iter: I) -> Self
39+
where
40+
I: IntoIterator<Item = S::Elem>,
41+
S: Default,
42+
{
43+
let mut notes = S::default();
44+
for note in iter {
45+
notes.push(note);
46+
}
47+
Self::from_notes(notes)
48+
}
49+
50+
pub fn get(&self, idx: usize) -> &S::Elem {
51+
self.notes.get(idx)
52+
}
53+
54+
pub fn len(&self) -> usize {
55+
debug_assert_eq!(
56+
self.len,
57+
self.notes.len(),
58+
"Chord length is inconsistent with notes length"
59+
);
60+
self.len
61+
}
62+
63+
pub fn push(&mut self, note: S::Elem) {
64+
self.len += 1;
65+
self.notes.push(note);
66+
}
67+
}

core/src/chords/dyad.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Appellation: dyad <module>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
*/
5+
use crate::notes::Note;
6+
use crate::{Intervals, Pair};
7+
8+
fn _interval<A, B>(lhs: A, rhs: B) -> Intervals
9+
where
10+
A: core::ops::Sub<B, Output = Intervals>,
11+
{
12+
lhs - rhs
13+
}
14+
15+
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
16+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
17+
pub struct Dyad {
18+
chord: Pair<Note>,
19+
interval: Intervals,
20+
}
21+
22+
impl Dyad {
23+
pub fn new(src: Note, tgt: Note) -> Self {
24+
let chord = Pair::new(src, tgt);
25+
let interval = Intervals::dist(src, tgt);
26+
Self { chord, interval }
27+
}
28+
29+
pub fn from_tuple((lhs, rhs): (Note, Note)) -> Self {
30+
let chord = Pair::new(lhs, rhs);
31+
let interval = Intervals::dist(lhs, rhs);
32+
Self { chord, interval }
33+
}
34+
35+
pub const fn chord(&self) -> &Pair<Note> {
36+
&self.chord
37+
}
38+
39+
pub fn chord_mut(&mut self) -> &mut Pair<Note> {
40+
&mut self.chord
41+
}
42+
43+
pub const fn interval(&self) -> &Intervals {
44+
&self.interval
45+
}
46+
47+
pub fn interval_mut(&mut self) -> &mut Intervals {
48+
&mut self.interval
49+
}
50+
}

core/src/chords/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Appellation: chord <module>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
*/
5+
#[doc(inline)]
6+
pub use self::{chord::Chord, dyad::Dyad};
7+
8+
pub(crate) mod chord;
9+
pub(crate) mod dyad;
10+
11+
pub(crate) mod prelude {
12+
pub use super::chord::*;
13+
pub use super::dyad::*;
14+
}
15+
16+
pub trait Container {
17+
type Elem;
18+
}
19+
20+
impl<T> Container for Vec<T> {
21+
type Elem = T;
22+
}
23+
24+
/// [ChordData] provides common methods for viable representations of chords.
25+
/// Typically, implementations of [ChordData] describe linear data-structures
26+
/// such as arrays, vectors, or slices.
27+
pub trait ChordData {
28+
type Elem;
29+
30+
fn get(&self, idx: usize) -> &Self::Elem;
31+
32+
fn len(&self) -> usize;
33+
34+
fn push(&mut self, elem: Self::Elem);
35+
}

0 commit comments

Comments
 (0)