summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-01-10 20:39:51 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-01-11 14:24:49 +0100
commitdb04e2fb861ed7ccef5a7339e9860ca5c2590a7c (patch)
tree4f2e2efe0f403981ae0d2ad47319dd1e253182f0
parente32591388a18c8226e61b8f88b031ed7c88ca153 (diff)
In-synth-cli can now (re)load programs. maybe SEGFAULTING?
-rw-r--r--TODO5
-rw-r--r--synth/channel.cpp6
-rw-r--r--synth/channel.h1
-rw-r--r--synth/globals.cpp2
-rw-r--r--synth/globals.h2
-rw-r--r--synth/in_synth_cli.cpp13
-rw-r--r--synth/load.cpp47
-rw-r--r--synth/load.h2
-rw-r--r--synth/main.cpp40
9 files changed, 78 insertions, 40 deletions
diff --git a/TODO b/TODO
index 845f723..03a1783 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,12 @@
+!!! SEGFAULT beim laden einer nicht-existenten datei per in-synth-cli
+ wenn man danach die noten spielen will. nicht reproduzierbar
+
TODO für den synth
o bei envelopes: releasephase abschalten (bei sustain bleiben)
o programme on-the-fly (um)laden
+ beim entladen des alten programms: ggf. shared objekt löschen
+
o RAM aufräumen?
o beide parser: envelopes von oscs mit out=0 standardmäßig deaktivieren
diff --git a/synth/channel.cpp b/synth/channel.cpp
index dbfcc48..61ea6de 100644
--- a/synth/channel.cpp
+++ b/synth/channel.cpp
@@ -435,6 +435,12 @@ void Channel::kill_program(int prog)
it++;
}
+void Channel::maybe_reload_program(int prog)
+{
+ if (program==prog)
+ curr_prg=program_settings[prog];
+}
+
void Channel::release_all()
{
list<NoteSkel*>::iterator it;
diff --git a/synth/channel.h b/synth/channel.h
index c0eee5c..826d752 100644
--- a/synth/channel.h
+++ b/synth/channel.h
@@ -29,6 +29,7 @@ class Channel
void release_all();
void panic();
void kill_program(int prog);
+ void maybe_reload_program(int prog);
void set_real_portamento_frames();
void set_portamento_time(int val);
void set_portamento(int val);
diff --git a/synth/globals.cpp b/synth/globals.cpp
index 427eebe..96a56d5 100644
--- a/synth/globals.cpp
+++ b/synth/globals.cpp
@@ -56,6 +56,8 @@ string programfile[128];
program_t *program_settings;
bool program_lock[128];
+program_t default_program;
+
Channel *channel[N_CHANNELS];
diff --git a/synth/globals.h b/synth/globals.h
index b91efef..b89813d 100644
--- a/synth/globals.h
+++ b/synth/globals.h
@@ -67,6 +67,8 @@ extern string programfile[128];
extern program_t *program_settings;
extern bool program_lock[128];
+extern program_t default_program;
+
extern Channel *channel[N_CHANNELS];
diff --git a/synth/in_synth_cli.cpp b/synth/in_synth_cli.cpp
index 4334978..a21e1f7 100644
--- a/synth/in_synth_cli.cpp
+++ b/synth/in_synth_cli.cpp
@@ -8,6 +8,7 @@
#include "util.h"
#include "communication.h"
#include "globals.h"
+#include "load.h"
using namespace std;
@@ -49,8 +50,16 @@ void lock_and_load_program(int prg_no, string file)
{
do_request(prg_no, true);
- //TODO load the program
- usleep(5000000);
+ if (load_program(file,program_settings[prg_no]))
+ {
+ cout << "success" << endl;
+ programfile[prg_no]=file;
+ }
+ else
+ cout << "failed" << endl;
+
+ for (int i=0;i<N_CHANNELS;i++)
+ channel[i]->maybe_reload_program(prg_no);
do_request(prg_no, false);
}
diff --git a/synth/load.cpp b/synth/load.cpp
index 9b80106..b60c535 100644
--- a/synth/load.cpp
+++ b/synth/load.cpp
@@ -7,6 +7,8 @@
#include "util.h"
#include "globals.h"
+#include "parser.h"
+#include "note_loader.h"
using namespace std;
@@ -196,3 +198,48 @@ void read_config(const char *cfg, bool complain=true)
output_warning("WARNING: could not open config file '"+string(cfg)+"'.\nignoring this file...");
}
}
+
+bool load_program(string file, program_t& prog)
+{
+ if (file!="")
+ {
+ try
+ {
+ prog=parse(file);
+
+ // try to load the appropriate .so file
+ if (access( (file+".so").c_str(), R_OK ) == 0)
+ {
+ try
+ {
+ load_note_from_so(file+".so", prog);
+ output_verbose("NOTE: loaded shared object for program '"+file+"'");
+ }
+ catch (string err)
+ {
+ output_note("NOTE: could not load shared object '"+file+".so"+"':\n"
+ " "+err+"\n"
+ " this is not fatal, the note has been loaded properly, but generic\n"
+ " unoptimized (slow) code will be used.");
+ }
+ }
+
+ return true;
+ }
+ catch (string err)
+ {
+ output_warning("WARNING: error parsing '"+file+"': "+err+"\n"
+ " this is not fatal, but the program has NOT been loaded! defaulting to a\n"
+ " simple program and going on...");
+ prog=default_program;
+
+ return false;
+ }
+ }
+ else
+ {
+ prog=default_program;
+
+ return true;
+ }
+}
diff --git a/synth/load.h b/synth/load.h
index 9724e92..1597fc9 100644
--- a/synth/load.h
+++ b/synth/load.h
@@ -2,10 +2,12 @@
#define __LOAD_H__
#include <string>
+#include "programs.h"
using namespace std;
void add_dir(string directory, bool complain=true);
void read_config(const char *cfg, bool complain=true);
+bool load_program(string file, program_t& prog);
#endif
diff --git a/synth/main.cpp b/synth/main.cpp
index d063d41..2aaf406 100644
--- a/synth/main.cpp
+++ b/synth/main.cpp
@@ -6,15 +6,14 @@
#include "jack.h"
#include "load.h"
#include "cli.h"
-#include "parser.h"
#include "channel.h"
#include "fixed.h"
#include "programs.h"
#include "defines.h"
#include "globals.h"
-#include "note_loader.h"
#include "in_synth_cli.h"
#include "communication.h"
+#include "note_loader.h"
using namespace std;
@@ -76,7 +75,6 @@ int main(int argc, char** argv)
int i,j;
- program_t default_program;
init_default_program(default_program);
//two possible divisions by zero are avoided, because
@@ -108,41 +106,7 @@ int main(int argc, char** argv)
{
program_lock[i]=false;
- if (programfile[i]!="")
- {
- try
- {
- program_settings[i]=parse(programfile[i]);
-
- // try to load the appropriate .so file
- if (access( (programfile[i]+".so").c_str(), R_OK ) == 0)
- {
- try
- {
- load_note_from_so(programfile[i]+".so", program_settings[i]);
- output_verbose("NOTE: loaded shared object for program '"+programfile[i]+"'");
- }
- catch (string err)
- {
- output_note("NOTE: could not load shared object '"+programfile[i]+".so"+"':\n"
- " "+err+"\n"
- " this is not fatal, the note has been loaded properly, but generic\n"
- " unoptimized (slow) code will be used.");
- }
- }
- }
- catch (string err)
- {
- output_warning("WARNING: error parsing '"+programfile[i]+"': "+err+"\n"
- " this is not fatal, but the program has NOT been loaded! defaulting to a\n"
- " simple program and going on...");
- program_settings[i]=default_program;
- }
- }
- else
- {
- program_settings[i]=default_program;
- }
+ load_program(programfile[i],program_settings[i]);
}
for (i=0;i<N_WAVEFORMS;i++)