Skip to content

Commit

Permalink
Free engine (#613)
Browse files Browse the repository at this point in the history
* glue for free engine

* fix free-engine command

* sync with server after engine dealloc. might help with cpu spikes when switching engines
  • Loading branch information
catfact authored and tehn committed Oct 22, 2018
1 parent 6843b36 commit ec29ae9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions matron/src/oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ void o_load_engine(const char *name) {
lo_send(remote_addr, "/engine/load/name", "s", name);
}

void o_free_engine() {
lo_send(remote_addr, "/engine/free", "");
}

void o_send_command(const char *name, lo_message msg) {
char *path;
// FIXME: better not to allocate here
Expand Down
2 changes: 2 additions & 0 deletions matron/src/oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ extern void o_unlock_descriptors();

// load a named audio processing engine
extern void o_load_engine(const char *name);
// free engine
extern void o_free_engine(void);

// request list of engine names
extern void o_request_engine_report(void);
Expand Down
13 changes: 13 additions & 0 deletions matron/src/weaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static int _midi_send(lua_State *l);
/// engines
static int _request_engine_report(lua_State *l);
static int _load_engine(lua_State *l);
static int _free_engine(lua_State *l);
/// commands
static int _send_command(lua_State *l);
static int _start_poll(lua_State *l);
Expand Down Expand Up @@ -239,6 +240,8 @@ void w_init(void) {
lua_register(lvm, "report_engines", &_request_engine_report);
// load a named engine
lua_register(lvm, "load_engine", &_load_engine);
// free engine
lua_register(lvm, "free_engine", &_free_engine);

// send an indexed command
lua_register(lvm, "send_command", &_send_command);
Expand Down Expand Up @@ -1093,6 +1096,16 @@ int _load_engine(lua_State *l) {
return 0;
}

int _free_engine(lua_State *l) {
if (lua_gettop(l) != 0) {
return luaL_error(l, "wrong number of arguments");
}

o_free_engine();
lua_settop(l, 0);
return 0;
}

int _send_command(lua_State *l) {
int nargs = lua_gettop(l);
if (nargs < 1) {
Expand Down
3 changes: 2 additions & 1 deletion sc/core/Crone.sc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ Crone {

// @function /engine/free
'/engine/free':OSCFunc.new({
if(engine.notNil, { engine.free; });
postln("attempt to free engine");
if(engine.notNil, { postln("freeing engine"); engine.deinit; });
}, '/engine/free'),

// @function /engine/load/name
Expand Down
1 change: 1 addition & 0 deletions sc/core/CroneEngine.sc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CroneEngine {
});
// subclass should implement free, and this method should also be called in a routine
this.free;
Crone.server.sync;
doneCallback.value(this);
}

Expand Down

0 comments on commit ec29ae9

Please sign in to comment.