Skip to content

Commit

Permalink
Dm/init (#770)
Browse files Browse the repository at this point in the history
* do not log imports

* update ui

* 2d parsing might be ready to try

* WIP

* csv working...gotta think about it

* working on init

* new years eve

* 1d and 2d csv working

* WIP

* tests passing

* ready to update docs

* WIP

* hrm maybe no need to track first x in watch?

* only create file if needed

* readme

* improve logging on watch

* improve new

* csv2d tests passing

* cleanup

* add back csv1d

* demo working

* demo working

* wip

* some lints
  • Loading branch information
xasopheno committed Mar 12, 2023
1 parent fcb1eb9 commit 13e0fa9
Show file tree
Hide file tree
Showing 67 changed files with 1,123 additions and 561 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A language for composing mictoronal music built in Rust. You might find this language useful if you want to make cool sounds and impress your friends/pets/plants.

This language does not require familiarity with either microtonal music or computer programming, but experience with either will certainly help.
This language is designed to be easy to use, and you don't need any prior knowledge of microtonal music or computer programming. However, experience in either area will certainly be helpful.

The **WereSoCool CLI** is availble on **macOS**, **Linux** and **Windows**. You can also explore the language in a Firefox or Chrome browser on a desktop computer in the [WereSoCool Playground](https://www.weresocool.org/playground). Live coding in the browser currently only works on desktop in a Firefox or Chrome browser.

Expand All @@ -12,7 +12,7 @@ If you want to learn how to make cool sounds using WereSoCool, you'll find cool
at [weresocool.org](https://www.weresocool.org/).


My recommended approach to learning the language is to do the tutorials in order and write your own composition after completing each one. I'm currently working on additional documentation as well as a record I've made using WereSoCool featuring a great band. Stay tuned.
I recommend following the tutorials in order and writing your own composition after completing each one. Additional documentation is currently being worked on, as well as a record featuring a great band, so stay tuned.

On mobile, you can still view the tutorials, but you won't be able to hear anything.

Expand Down
2 changes: 2 additions & 0 deletions ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ num-integer = "0.1.44"
polynomials = "0.2.4"
meval = "0.2.0"
csv = "1.1.6"
hamcrest2 = "0.3.0"
peekread = "0.1.1"

[features]
default=["app"]
Expand Down
7 changes: 6 additions & 1 deletion ast/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::datagen::Scale;
use crate::Term;
use num_rational::Rational64;

Expand All @@ -14,10 +15,14 @@ pub enum Op {
Id(String),
Tag(String),
//
CSV {
CSV1d {
path: String,
scale: Option<Rational64>,
},
CSV2d {
path: String,
scales: Vec<Scale>,
},
//
FunctionCall {
name: String,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions ast/src/datagen/2d_test_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2.5,1.0
1.0,2.0
1.5,2.0
6 changes: 4 additions & 2 deletions ast/src/datagen/test.rs → ast/src/datagen/csv1d_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ mod eeg_test {
use num_rational::Rational64;

use crate::{
datagen::{csv_to_normalform, eeg_data_to_normal_form, eeg_datum_to_point_op, CsvData},
datagen::mod_1d::{
csv1d_to_normalform, eeg_data_to_normal_form, eeg_datum_to_point_op, CsvData,
},
NameSet, NormalForm, PointOp,
};
#[test]
Expand Down Expand Up @@ -55,7 +57,7 @@ mod eeg_test {
}
#[test]
fn test_csv_to_normalform() {
let result = csv_to_normalform(
let result = csv1d_to_normalform(
"./src/datagen/test_data.csv",
Some(Rational64::new(200_000_000_000_000, 1)),
)
Expand Down
161 changes: 161 additions & 0 deletions ast/src/datagen/csv2d_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#[cfg(test)]
mod csv2d_tests {
use hamcrest2::prelude::*;
use num_rational::Rational64;

use crate::{datagen::*, NameSet, NormalForm, PointOp};

#[test]
fn test_get_data_2d() {
let result = get_data2d("./src/datagen/2d_test_data.csv".to_string()).unwrap();

let expected = vec![vec![2.5, 1.0], vec![1.0, 2.0], vec![1.5, 2.0]];

assert_that!(&result, contains(expected).exactly());
}

#[test]
fn test_point_to_point_op() {
let mut names = NameSet::new();
names.insert("2d_test_data.csv".to_string());

let result = point_to_point_op(
&vec![1.0, 2.0],
None,
&vec![
Scale {
axis: Axis::F,
value: Rational64::new(2, 1),
},
Scale {
axis: Axis::L,
value: Rational64::new(1, 2),
},
],
"2d_test_data.csv",
);
let expected = Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(2, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(2, 1),
}),
],
});

assert_eq!(result, expected);
}

#[test]
fn test_csv_data_to_normal_form() {
let csv_data = vec![vec![1.0, 1.0], vec![1.0, 1.0], vec![1.0, 1.0]];

let mut names = NameSet::new();
let filename = "2d_test_data.csv";
let scales = vec![
Scale {
axis: Axis::F,
value: Rational64::new(2, 1),
},
Scale {
axis: Axis::L,
value: Rational64::new(1, 2),
},
];
names.insert(filename.to_string());

let result = csv_data_to_normal_form(&csv_data, scales, "2d_test_data.csv");
let expected = Term::Op(Op::Sequence {
operations: vec![
Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(2, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(1, 1),
}),
],
}),
Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(2, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(1, 1),
}),
],
}),
Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(2, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(1, 1),
}),
],
}),
],
});

assert_eq!(result, expected);
}

#[test]
fn test_csv1d_to_normalform() {
let scales = vec![
Scale {
axis: Axis::F,
value: Rational64::new(2, 1),
},
Scale {
axis: Axis::L,
value: Rational64::new(1, 2),
},
];

let result = csv2d_to_normalform("./src/datagen/2d_test_data.csv", scales).unwrap();

let mut names = NameSet::new();
names.insert("2d_test_data.csv".to_string());
let expected = Term::Op(Op::Sequence {
operations: vec![
Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(5, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(1, 1),
}),
],
}),
Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(2, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(2, 1),
}),
],
}),
Term::Op(Op::Compose {
operations: vec![
Term::Op(Op::TransposeA {
a: Rational64::new(3, 1),
}),
Term::Op(Op::Length {
m: Rational64::new(2, 1),
}),
],
}),
],
});
assert_eq!(result, expected);
}
}

0 comments on commit 13e0fa9

Please sign in to comment.