bng syntax rules & poc
This commit is contained in:
parent
903e3ebc64
commit
9ed583e4e4
4 changed files with 138 additions and 0 deletions
44
poc/poc.yml
Normal file
44
poc/poc.yml
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# fixed
|
||||||
|
instruments:
|
||||||
|
# instrument name
|
||||||
|
sine:
|
||||||
|
# fixed
|
||||||
|
expr: sin(2*PI*f*t) # instrument formula (f is the frequency in Hertz, t is the time in seconds)
|
||||||
|
square:
|
||||||
|
expr: v*abs(sin(2*PI*f*t))
|
||||||
|
# fixed
|
||||||
|
vars:
|
||||||
|
# name of the variable
|
||||||
|
v: 1 # initial value of the variable
|
||||||
|
channels:
|
||||||
|
melody:
|
||||||
|
instr: sine
|
||||||
|
score:
|
||||||
|
aabc.
|
||||||
|
'rt°y
|
||||||
|
+d+d+d---
|
||||||
|
/ff/f\\
|
||||||
|
ab>c<ba
|
||||||
|
;this is a comment (or lyrics whatever),
|
||||||
|
s:df
|
||||||
|
(3deff)
|
||||||
|
(deff)
|
||||||
|
[ffe]
|
||||||
|
{1-cos((PI*x)/2),acced}
|
||||||
|
abbc!o5cc!v15feed!l4fedd!t60hdd
|
||||||
|
# rest: .
|
||||||
|
# pizz.: '°
|
||||||
|
# volume: +-
|
||||||
|
# length: /\
|
||||||
|
# octave: ><
|
||||||
|
# comment?: ;,
|
||||||
|
# start here: ':'
|
||||||
|
# glissando: {EXPR, score}
|
||||||
|
# loop: ()
|
||||||
|
# loop with count: (COUNT, score)
|
||||||
|
# tuple: []
|
||||||
|
# modifier: !
|
||||||
|
# volume modifier prefix: v
|
||||||
|
# octave modifier prefix: o
|
||||||
|
# length modifier prefix: l
|
||||||
|
# tempo modifier prefix: t
|
|
@ -0,0 +1,42 @@
|
||||||
|
use fasteval::Instruction;
|
||||||
|
|
||||||
|
mod lex;
|
||||||
|
|
||||||
|
pub(super) enum Atom {
|
||||||
|
Note(u8),
|
||||||
|
Rest,
|
||||||
|
StartHere,
|
||||||
|
Modifier(Modifier),
|
||||||
|
QuickModifier(QuickModifier),
|
||||||
|
Wrapper(WrapperKind, Vec<Atom>),
|
||||||
|
EmptyWrapper(WrapperKind),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) enum Modifier {
|
||||||
|
Volume(u8),
|
||||||
|
Octave(u8),
|
||||||
|
Length(u8),
|
||||||
|
Tempo(u16),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) enum QuickModifier {
|
||||||
|
Volume(bool),
|
||||||
|
Octave(bool),
|
||||||
|
Length(bool),
|
||||||
|
Pizz(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) enum WrapperKind {
|
||||||
|
Loop(u8),
|
||||||
|
Tuple,
|
||||||
|
Slope(SlopeModifier, Instruction),
|
||||||
|
Comment,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) enum SlopeModifier {
|
||||||
|
Note,
|
||||||
|
Volume,
|
||||||
|
Octave,
|
||||||
|
Length,
|
||||||
|
Tempo,
|
||||||
|
}
|
50
src/bng/score/lex.rs
Normal file
50
src/bng/score/lex.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use super::{Atom, Modifier, WrapperKind};
|
||||||
|
const MORE: bool = true;
|
||||||
|
const LESS: bool = false;
|
||||||
|
const ON: bool = true;
|
||||||
|
const OFF: bool = false;
|
||||||
|
|
||||||
|
struct WrappingTokens;
|
||||||
|
impl WrappingTokens {
|
||||||
|
const PARENTHESES: (char, char) = ('(', ')');
|
||||||
|
const SQUARE_BRACKETS: (char, char) = ('[', ']');
|
||||||
|
const BRACKETS: (char, char) = ('{', '}');
|
||||||
|
const SEMICOLON_COMMA: (char, char) = (';', ',');
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Token<T> {
|
||||||
|
fn token(self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Token<(char, char)> for WrapperKind {
|
||||||
|
fn token(self) -> (char, char) {
|
||||||
|
match self {
|
||||||
|
Self::Loop(_) => WrappingTokens::PARENTHESES,
|
||||||
|
Self::Tuple => WrappingTokens::SQUARE_BRACKETS,
|
||||||
|
Self::Slope(_, _) => WrappingTokens::BRACKETS,
|
||||||
|
WrapperKind::Comment => WrappingTokens::SEMICOLON_COMMA,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Token<char> for Modifier {
|
||||||
|
fn token(self) -> char {
|
||||||
|
match self {
|
||||||
|
Self::Volume(_) => 'v',
|
||||||
|
Self::Octave(_) => 'o',
|
||||||
|
Self::Length(_) => 'l',
|
||||||
|
Self::Tempo(_) => 't',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Token<char> for Atom {
|
||||||
|
fn token(self) -> char {
|
||||||
|
match self {
|
||||||
|
Atom::Rest => '.',
|
||||||
|
Atom::StartHere => ':',
|
||||||
|
Atom::Modifier(_) => '!',
|
||||||
|
_ => unimplemented!("not a singleton"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
|
#![feature(unsize)]
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
mod bng;
|
mod bng;
|
||||||
mod cli;
|
mod cli;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// println!("{}", option_env!("TEST").unwrap_or("ok"));
|
||||||
let args = cli::BngCli::parse();
|
let args = cli::BngCli::parse();
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
println!("{:?}", args);
|
println!("{:?}", args);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue