Skip to content

Commit 60fce68

Browse files
authored
Merge pull request #6 from FL03/v0.1.2
V0.1.2
2 parents 8f3fa1c + a590d9e commit 60fce68

28 files changed

Lines changed: 1824 additions & 228 deletions

contained/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ scsys = { features = ["derive"], version = "0.1.41" }
2727
# Standard dependencies
2828
anyhow = "1"
2929
clap = { features = ["cargo", "derive", "env"], version = "4" }
30+
futures = "0.3"
3031
serde = { features = ["derive"], version = "1" }
3132
serde_json = "1"
3233
smart-default = "0.6"

contained/examples/basic.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,38 @@
55
*/
66
extern crate contained;
77

8-
fn main() {}
8+
use contained::turing::{
9+
Configurable, Configuration, Machine, Move, Program, Programatic, Tape, Turing,
10+
};
11+
use contained::{Resultant, State, States};
12+
13+
fn main() -> Resultant {
14+
let alphabet = vec!["a", "b", "c"];
15+
16+
let tape = Tape::new(alphabet.clone());
17+
let mut cnf = Configuration::norm(tape)?;
18+
19+
// Setup the program
20+
let final_state = State::from(&States::invalid());
21+
let mut program = Program::new(alphabet, final_state);
22+
// Instruction set; turn ["a", "b", "c"] into ["c", "a", "a"]
23+
program.insert((State::default(), "a", State::default(), "c", Move::Right).into())?;
24+
program.insert((State::default(), "b", State::default(), "a", Move::Right).into())?;
25+
program.insert(
26+
(
27+
State::default(),
28+
"c",
29+
State::from(&States::invalid()),
30+
"a",
31+
Move::Left,
32+
)
33+
.into(),
34+
)?;
35+
36+
let a = Machine::new("a", program.clone())?;
37+
let res = a.execute(&mut cnf)?;
38+
assert_eq!(res.tape().tape().clone(), vec!["c", "a", "a"]);
39+
println!("{:?}", res);
40+
41+
Ok(())
42+
}

contained/examples/neo.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Appellation: basic <example>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
Description: ... summary ...
5+
*/
6+
extern crate contained;
7+
8+
use contained::neo::{Triad, Triadic, Triads};
9+
use contained::turing::{Configuration, Program, Programatic, Turing};
10+
use contained::{cmp::Note, Resultant, State, States};
11+
12+
fn main() -> Resultant {
13+
let triad = Triad::new(0.into(), Triads::Diminshed);
14+
15+
let alphabet: Vec<Note> = triad.clone().into_iter().collect();
16+
let mut cnf: Configuration<Note> = triad.config();
17+
18+
// Setup the program
19+
let final_state = State::from(&States::invalid());
20+
let mut program = Program::new(alphabet, final_state);
21+
// Instruction set; turn ["C", "D#", "F#"] into ["F#", "D#", "D#"]
22+
program.insert(
23+
(
24+
State::default(),
25+
0.into(),
26+
State::default(),
27+
6.into(),
28+
1.into(),
29+
)
30+
.into(),
31+
)?;
32+
program.insert(
33+
(
34+
State::default(),
35+
3.into(),
36+
State::default(),
37+
3.into(),
38+
1.into(),
39+
)
40+
.into(),
41+
)?;
42+
program.insert(
43+
(
44+
State::default(),
45+
6.into(),
46+
State::from(&States::invalid()),
47+
3.into(),
48+
2.into(),
49+
)
50+
.into(),
51+
)?;
52+
53+
let res = triad.machine(program)?.execute(&mut cnf)?;
54+
println!("{:?}", res);
55+
56+
Ok(())
57+
}

contained/src/cmp/chord.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Appellation: chord <module>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
Description: A chord is any set of notes played simultaneously; for our considerations, allow a chord to represent the alphabet of a Turing machine or automata.
5+
6+
*/
7+
use crate::cmp::Note;
8+
use crate::ArrayLike;
9+
use serde::{Deserialize, Serialize};
10+
use smart_default::SmartDefault;
11+
use strum::{Display, EnumString, EnumVariantNames};
12+
13+
/// [Chord] is a wrapper for a [Vec] of [Note]
14+
#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
15+
pub struct Chord(Vec<Note>);
16+
17+
impl Chord {
18+
pub fn new(chord: impl IntoIterator<Item = Note>) -> Self {
19+
Self(Vec::from_iter(chord))
20+
}
21+
pub fn chord(&self) -> &Self {
22+
self
23+
}
24+
}
25+
26+
impl ArrayLike for Chord {
27+
type Data = Note;
28+
29+
fn content(&self) -> &Vec<Self::Data> {
30+
&self.0
31+
}
32+
33+
fn mut_content(&mut self) -> &mut Vec<Self::Data> {
34+
&mut self.0
35+
}
36+
}
37+
38+
impl IntoIterator for Chord {
39+
type Item = Note;
40+
41+
type IntoIter = std::vec::IntoIter<Self::Item>;
42+
43+
fn into_iter(self) -> Self::IntoIter {
44+
self.0.into_iter()
45+
}
46+
}
47+
48+
pub trait ChordFactor {
49+
fn factor(&self) -> &ChordFactors
50+
where
51+
Self: Sized;
52+
fn note(&self) -> &Note
53+
where
54+
Self: Sized;
55+
}
56+
57+
#[derive(
58+
Clone,
59+
Debug,
60+
Deserialize,
61+
Display,
62+
EnumString,
63+
EnumVariantNames,
64+
Eq,
65+
Hash,
66+
Ord,
67+
PartialEq,
68+
PartialOrd,
69+
Serialize,
70+
SmartDefault,
71+
)]
72+
#[repr(i64)]
73+
#[strum(serialize_all = "snake_case")]
74+
pub enum ChordFactors {
75+
#[default]
76+
Root(Note) = 0,
77+
Third(Note) = 1,
78+
Fifth(Note) = 2,
79+
}
80+
81+
pub type Root = Note;
82+
pub type Third = Note;
83+
pub type Fifth = Note;
84+
85+
#[cfg(test)]
86+
mod test {
87+
use super::*;
88+
89+
#[test]
90+
fn test_chords() {
91+
let a = vec![0.into(), 3.into(), 8.into()];
92+
let mut b = Chord::default();
93+
assert!(b.is_empty());
94+
b.append(&mut a.clone());
95+
assert_eq!(b.len(), 3);
96+
}
97+
98+
#[test]
99+
fn test_chord_factors() {
100+
let a = ChordFactors::default();
101+
assert_eq!(a, ChordFactors::Root(Default::default()))
102+
}
103+
}

contained/src/cmp/clef.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Appellation: clef <module>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
Description:
5+
A clef, placed on the far left-hand side of the staff or stave, signals which notes are represented by the respective staff.
6+
*/
7+
use serde::{Deserialize, Serialize};
8+
use strum::{Display, EnumString, EnumVariantNames};
9+
10+
#[derive(
11+
Clone,
12+
Copy,
13+
Debug,
14+
Default,
15+
Deserialize,
16+
Display,
17+
EnumString,
18+
EnumVariantNames,
19+
Eq,
20+
Hash,
21+
PartialEq,
22+
PartialOrd,
23+
Serialize,
24+
)]
25+
#[repr(i64)]
26+
#[strum(serialize_all = "snake_case")]
27+
pub enum Clef {
28+
Alto = 0,
29+
Bass = 1,
30+
#[default]
31+
Treble = 2,
32+
}
33+
34+
impl From<Clef> for i64 {
35+
fn from(data: Clef) -> i64 {
36+
data as i64
37+
}
38+
}
39+
40+
impl From<i64> for Clef {
41+
fn from(data: i64) -> Clef {
42+
match data {
43+
0 => Clef::Alto,
44+
1 => Clef::Bass,
45+
_ => Clef::Treble,
46+
}
47+
}
48+
}

contained/src/cmp/epoch.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Appellation: epoch <module>
3+
Contrib: FL03 <jo3mccain@icloud.com>
4+
Description: ... Summary ...
5+
*/
6+
use scsys::prelude::{SerdeDisplay, Timestamp};
7+
use serde::{Deserialize, Serialize};
8+
9+
/// An [Epoch] consists of a start time and optionally, a duration (seconds). If None, the system assumes an infinite duration
10+
#[derive(
11+
Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, SerdeDisplay, Serialize,
12+
)]
13+
pub struct Epoch(i64, Option<i64>);
14+
15+
impl Epoch {
16+
pub fn new(ts: i64, duration: Option<i64>) -> Self {
17+
Self(ts, duration)
18+
}
19+
}
20+
21+
impl Default for Epoch {
22+
fn default() -> Self {
23+
Self::new(Timestamp::default().into(), Some(1000))
24+
}
25+
}

0 commit comments

Comments
 (0)