Skip to content

Commit

Permalink
Merge pull request #12 from AlexanderARodin/dev
Browse files Browse the repository at this point in the history
test audio-server lib
  • Loading branch information
AlexanderARodin authored Feb 14, 2024
2 parents 08eff9f + e653103 commit f857d61
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 53 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
# audio_server = { path = "../audio_server" }
audio_server = { git = "https://github.com/AlexanderARodin/audio_server.git", branch="main" }

raalog = { git = "https://github.com/AlexanderARodin/raalog.git", tag="v0.2.0" }
call_list = { git = "https://github.com/AlexanderARodin/call_list.git", branch="main" }

Expand Down
156 changes: 103 additions & 53 deletions src/test_view.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
use egui::Color32;

use audio_server::AudioServer;
use audio_server::{ AudioServer, Config, Exec };
use raalog::log;


static SF_PIANO: &'static [u8] = include_bytes!("../SoundFonts/Piano Grand.SF2");
static SF_STRINGS: &'static [u8] = include_bytes!("../SoundFonts/String Marcato.SF2");
//static SF_ORGAN: &'static [u8] = include_bytes!("../../SoundFonts/Organ Chorus.SF2");
static TEST_XXX: &str = r#"
autoexec = [
'stop',
{ setup = 'NoSynth' },
'start',
]
[Sequence]
notes = [
[1 , 'on', 90, 80 ],
0.5, [1 , 'off', 90, 80 ],
[1 , 'on', 91, 80 ],
0.5, [1 , 'off', 91, 80 ],
[1 , 'on', 92, 80 ],
0.5, [1 , 'off', 92, 80 ],
[1 , 'on', 91, 80 ],
0.5, [1 , 'off', 91, 80 ],
1.0, [1 , 'off', 92, 80 ],
]
transpose = 7
speed = 2.0
"#;
static sf_list:[&[u8];2] = [SF_PIANO,SF_STRINGS];

static TEST_SEQ: &str = r#"
[workflows]
play-once = [
{ load = 'Sequence.notes' },
'play',
]
play-loopA = [
{ speed = { '0.5' = { load = 'Sequence.notes' } } },
'play-loop',
]
play-loopB = [
{ transpose = { 7 = { load = 'Sequence.notes' } } },
'play-loop',
]
play-loopC = [
{ transpose = { 7 = { speed = { '0.5' = { load = 'Sequence.notes' } } } } },
{ speed = { 2 = { transpose = { -5 = { load = 'Sequence.notes' } } } } },
'play-loop',
]
[Sequence]
notes = [
[1 , 'on', 90, 80 ],
0.5, [1 , 'off', 90, 80 ],
[1 , 'on', 91, 80 ],
[1 , 'on', 91, 50 ],
0.5, [1 , 'off', 91, 80 ],
[1 , 'on', 92, 80 ],
[1 , 'on', 92, 90 ],
0.5, [1 , 'off', 92, 80 ],
[1 , 'on', 91, 80 ],
[1 , 'on', 91, 50 ],
0.5, [1 , 'off', 91, 80 ],
1.0, [1 , 'off', 92, 80 ],
]
Expand Down Expand Up @@ -77,8 +75,8 @@ impl TestView {
pub fn updateUI(&mut self, ui: &mut egui::Ui) {
let b = ui.button("rrr");
if b.clicked() {
let cfg = audio_server::Config::CoreConfigFromStr( TEST_XXX, Vec::new() );
if let Err(e) = self.audio.load_config(&cfg) {
let core_cfg = Config::CoreConfigFromStr( TEST_XXX, sf_list.to_vec() );
if let Err(e) = self.audio.load_config(&core_cfg) {
log::error(&e.to_string());
}
}
Expand Down Expand Up @@ -112,9 +110,9 @@ impl TestView {
let btn = ui.button(btn_txt);
if btn.clicked() {
if self.audio.state() == "inactive" {
let _ = self.audio.exec("start");
self.doExec( &Exec::CoreExec( "start" ) );
}else{
let _ = self.audio.exec("stop");
self.doExec( &Exec::CoreExec( "stop" ) );
}
}
});
Expand All @@ -124,33 +122,27 @@ impl TestView {
ui.horizontal( |ui| {
let btnN = ui.button( "None" );
if btnN.clicked(){
let setup = "[AudioSource]\nName = 'None'";
self.applySetup( setup, None );
self.doExec( &Exec::CoreExec( "None" ) );
}
let btnS = ui.button( "SimpleSynth" );
if btnS.clicked(){
let setup = "[AudioSource]\nName = 'Simple'";
self.applySetup( setup, None );
self.doExec( &Exec::CoreExec( "Simple" ) );
}
let btnRA = ui.button( "RustySynt - Strings" );
if btnRA.clicked(){
let setup = "[AudioSource]\nName = 'RustySynth'";
self.applySetup( setup, Some(SF_STRINGS) );
self.doExec( &Exec::CoreExec( "rstString" ) );
}
let btnRB = ui.button( "RustySynt - Piano" );
if btnRB.clicked(){
let setup = "[AudioSource]\nName = 'RustySynth'";
self.applySetup( setup, Some(SF_PIANO) );
self.doExec( &Exec::CoreExec( "rstPiano" ) );
}
let btnRA = ui.button( "Sequencer:Simple" );
if btnRA.clicked(){
let setup = "[AudioSource]\nName = 'Sequencer'\n[AudioSource.Sequencer]\nMainVoice = 'Simple'";
self.applySetup( setup, None );
self.doExec( &Exec::CoreExec( "sqSimple" ) );
}
let btnRA = ui.button( "Sequencer:RustySynt - Strings" );
if btnRA.clicked(){
let setup = "[AudioSource]\nName = 'Sequencer'\n[AudioSource.Sequencer]\nMainVoice = 'RustySynth'";
self.applySetup( setup, Some(SF_STRINGS) );
self.doExec( &Exec::CoreExec( "sqString" ) );
}
});
ui.separator();
Expand All @@ -159,40 +151,46 @@ impl TestView {
ui.horizontal( |ui| {
let btnO = ui.button( "[-]" );
if btnO.clicked(){
self.applySetup( TEST_SEQ, None );
self.doExec( "play once" );
self.applySetup( TEST_SEQ );
self.doExec( &Exec::OrdinaryExec( "play-once" ));
}
let btnO0 = ui.button( "[+]" );
if btnO0.clicked(){
self.applySetup( TEST_SEQ, None );
self.doExec( "play loop" );
self.applySetup( TEST_SEQ );
self.doExec( &Exec::OrdinaryExec( "play-loopA" ));
}
let mut test_txt;
test_txt = "seq auto";
let btnO1 = ui.button( "[@]" );
if btnO1.clicked(){
self.doExec( test_txt );
self.applySetup( TEST_SEQ );
self.doExec( &Exec::OrdinaryExec( "play-loopB" ));
}
let btn33 = ui.button( "[!]" );
if btn33.clicked(){
self.applySetup( TEST_SEQ );
self.doExec( &Exec::OrdinaryExec( "play-loopC" ));
}
ui.separator();
test_txt = "[1 , 'on', 60, 127 ]";
let btnA = ui.button( test_txt );
if btnA.clicked(){
self.doExec( test_txt );
self.doExec( &Exec::DBG( "midi", test_txt ) );
}
test_txt = "[1 , 'on', 67, 64 ]";
let btnA1 = ui.button( test_txt );
if btnA1.clicked(){
self.doExec( test_txt );
self.doExec( &Exec::DBG( "midi", test_txt ) );
}
test_txt = "[1 , 'on', 71, 1 ]";
let btnA2 = ui.button( test_txt );
if btnA2.clicked(){
self.doExec( test_txt );
self.doExec( &Exec::DBG( "midi", test_txt ) );
}
test_txt = "[1 , 'off', 60, 1 ]";
let btnB = ui.button( test_txt );
if btnB.clicked(){
self.doExec( test_txt );
self.doExec( &Exec::DBG( "midi", test_txt ) );
}
});

Expand All @@ -202,15 +200,67 @@ impl TestView {
}
}

fn doExec(&mut self, cmd: &str ) {
if let Err(e) = self.audio.exec( cmd ) {
fn doExec(&mut self, config: &Exec ) {
if let Err(e) = self.audio.exec( &config ) {
log::error(&e.to_string());
}
}
fn applySetup(&mut self, setup: &str, data: Option<&[u8]> ) {

fn applySetup(&mut self, setup: &str ) {
let cfg = Config::OrdinaryConfigFromStr( &setup );
if let Err(e) = self.audio.load_config(&cfg) {
log::error(&e.to_string());
}
/*
if let Err(e) = self.audio.config(setup, data ) {
log::error(&e.to_string());
}
*/
}
}

static TEST_XXX: &str = r#"
[workflows]
start = [ 'start' ]
stop = [ 'stop' ]
autoexec = [
'stop',
{ AudioSource = { Sequencer = { Rusty = '1' } } },
'start',
]
None = [
'stop',
{ AudioSource = 'None' },
'start',
]
Simple = [
'stop',
{ AudioSource = 'Simple' },
'start',
]
rstString = [
'stop',
{ AudioSource = { Rusty = '1' } },
'start',
]
rstPiano = [
'stop',
{ AudioSource = { Rusty = '0' } },
'start',
]
sqSimple = [
'stop',
{ AudioSource = { Sequencer = 'Simple' } },
'start',
]
sqString = [
'stop',
{ AudioSource = { Sequencer = { Rusty = '1' } } },
'start',
]
sqPiano = [
'stop',
{ AudioSource = { Sequencer = { Rusty = '0' } } },
'start',
]
"#;

0 comments on commit f857d61

Please sign in to comment.