summaryrefslogtreecommitdiff
path: root/note_compiler/parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'note_compiler/parser.cpp')
-rw-r--r--note_compiler/parser.cpp95
1 files changed, 46 insertions, 49 deletions
diff --git a/note_compiler/parser.cpp b/note_compiler/parser.cpp
index 05985de..98c65ac 100644
--- a/note_compiler/parser.cpp
+++ b/note_compiler/parser.cpp
@@ -5,24 +5,11 @@
#include "programs.h"
#include "util.h"
#include "../synth/defines.h"
+#include "../synth/fixed.h"
-Parser::Parser()
+void init_oscs(int n_osc, oscillator_t *osc)
{
- n_osc=0;
- osc=NULL;
- env=NULL;
-}
-
-Parser::~Parser()
-{
- uninit_stuff();
-}
-
-void Parser::init_stuff()
-{
- env=new env_settings_t[n_osc];
- osc=new oscillator_t[n_osc];
for (int i=0;i<n_osc;i++)
{
osc[i].n_osc=n_osc;
@@ -50,8 +37,13 @@ void Parser::init_stuff()
osc[i].vibrato_lfo=0;
osc[i].vibrato_lfo_const=true;
osc[i].have_custom_wave=false;
-
-
+ }
+}
+
+void init_envs(int n_osc, env_settings_t *env)
+{
+ for (int i=0;i<n_osc;i++)
+ {
env[i].attack=0;
env[i].attack_const=true;
env[i].decay=0;
@@ -63,7 +55,10 @@ void Parser::init_stuff()
env[i].hold=true;
env[i].hold_const=true;
}
+}
+void init_filter(filter_params_t &filter)
+{
filter.enabled=false;
filter.enabled_const=true;
filter.env_amount=0;
@@ -88,21 +83,9 @@ void Parser::init_stuff()
filter.trem_lfo=0;
filter.trem_lfo_const=true;
}
-void Parser::uninit_stuff()
-{
- if (osc)
- {
- for (int i=0;i<n_osc;i++)
- delete [] osc[i].fm_strength;
-
- delete [] osc;
- osc=NULL;
- }
- if (env)
- delete [] env;
-}
-string Parser::extract_array_name(string s)
+
+string extract_array_name(string s)
{
size_t p;
p=s.find('[');
@@ -112,7 +95,7 @@ string Parser::extract_array_name(string s)
return s;
}
-int Parser::extract_array_index(string s, int dim)
+int extract_array_index(string s, int dim)
{
size_t p=-1,p2;
for (int i=0;i<dim;i++)
@@ -127,8 +110,17 @@ int Parser::extract_array_index(string s, int dim)
return atoi(s.substr(p+1,p2-p-1).c_str());
}
-void Parser::parse(string fn)
+
+
+program_t parse(string fn)
{
+ int n_osc=0;
+ oscillator_t *osc=NULL;
+ env_settings_t *env=NULL;
+ filter_params_t filter;
+ fixed_t sync_factor;
+ bool sync_factor_const=true;
+
char buf[2000];
string line;
string var;
@@ -141,8 +133,9 @@ void Parser::parse(string fn)
int ind,ind2=0;
int state;
-
- uninit_stuff();
+
+ program_t result;
+
ifstream f;
f.open(fn.c_str());
@@ -192,7 +185,12 @@ void Parser::parse(string fn)
if (n_osc<=0) throw string("invalid number of oscillators");
- init_stuff();
+ //init stuff
+ env=new env_settings_t[n_osc];
+ osc=new oscillator_t[n_osc];
+ init_oscs(n_osc, osc);
+ init_envs(n_osc, env);
+ init_filter(filter);
state=1;
break;
@@ -433,22 +431,21 @@ void Parser::parse(string fn)
}
}
}
+
+ result.n_osc=n_osc;
+ result.osc=osc;
+ result.env=env;
+ result.filter=filter;
+ result.sync_factor=sync_factor;
+ result.sync_factor_const=sync_factor_const;
+
}
else
throw string ("could not open '"+fn+"'");
+
+ return result;
+ //no uninit / free of osc and env here, as it must be done by the caller
}
-program_t Parser::get_result()
-{
- program_t r;
-
- r.n_osc=n_osc;
- r.osc=osc;
- r.env=env;
- r.filter=filter;
- r.sync_factor=sync_factor;
- r.sync_factor_const=sync_factor_const;
-
- return r;
-}
+