_stats_avg[0] = _stats_avg[1] = _stats_max[0] = _stats_max[1] = _stats_cnt = 0;
#endif
-#ifndef NDEBUG
lua.Print.connect (sigc::mem_fun (*this, &LuaProc::lua_print));
-#endif
// register session object
lua_State* L = lua.getState ();
LuaBindings::stddef (L);
void
LuaProc::lua_print (std::string s) {
std::cout <<"LuaProc: " << s << "\n";
+ PBD::error << "LuaProc: " << s << "\n";
}
bool
LuaProc::load_script ()
{
assert (!_lua_dsp); // don't allow to re-initialize
+ LuaPluginInfoPtr lpi;
// TODO: refine APIs; function arguments..
// - perform channel-map in ardour (silent/scratch buffers) ?
try {
LuaScriptInfoPtr lsi = LuaScripting::script_info (_script);
- LuaPluginInfoPtr lpi (new LuaPluginInfo (lsi));
+ lpi = LuaPluginInfoPtr (new LuaPluginInfo (lsi));
assert (lpi);
set_info (lpi);
_mempool.set_name ("LuaProc: " + lsi->name);
;
}
}
+ lpi->_is_instrument = _has_midi_input;
_ctrl_params.clear ();
int32_t audio_out;
int32_t midi_out = 0; // TODO handle _has_midi_output
- if (in.n_midi() > 0 && audio_in == 0) {
- audio_out = 2; // prefer stereo version if available.
- } else {
- audio_out = audio_in;
- }
-
+ // preferred setting (provided by plugin_insert)
+ assert (out.n_audio () > 0);
+ audio_out = out.n_audio ();
for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
assert (i.value ().type () == LUA_TTABLE);
audio_out = -1;
bool found = false;
+ float penalty = 9999;
+ const int preferred_out = out.n_audio ();
+
+#define FOUNDCFG(nch) { \
+ float p = fabsf ((float)(nch) - preferred_out); \
+ if ((nch) > preferred_out) { p *= 1.1; } \
+ if (p < penalty) { \
+ audio_out = (nch); \
+ penalty = p; \
+ found = true; \
+ } \
+}
+
for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
assert (i.value ().type () == LUA_TTABLE);
luabridge::LuaRef io (i.value ());
if (possible_in == 0) {
/* no inputs, generators & instruments */
if (possible_out == -1) {
- /* any configuration possible, provide stereo output */
- audio_out = 2;
- found = true;
+ /* any configuration possible, stereo output */
+ FOUNDCFG (preferred_out);
} else if (possible_out == -2) {
/* invalid, should be (0, -1) */
- audio_out = 2;
- found = true;
+ FOUNDCFG (preferred_out);
} else if (possible_out < -2) {
- /* variable number of outputs. -> whatever */
- audio_out = 2;
- found = true;
+ /* variable number of outputs up to -N, */
+ FOUNDCFG (min (-possible_out, preferred_out));
} else {
/* exact number of outputs */
- audio_out = possible_out;
- found = true;
+ FOUNDCFG (possible_out);
}
}
/* wildcard for input */
if (possible_out == -1) {
/* out must match in */
- audio_out = audio_in;
- found = true;
+ FOUNDCFG (audio_in);
} else if (possible_out == -2) {
/* any configuration possible, pick matching */
- audio_out = audio_in;
- found = true;
+ FOUNDCFG (preferred_out);
} else if (possible_out < -2) {
/* explicitly variable number of outputs, pick maximum */
- audio_out = -possible_out;
- found = true;
+ FOUNDCFG (max (-possible_out, preferred_out));
+ /* and try min, too, in case the penalty is lower */
+ FOUNDCFG (min (-possible_out, preferred_out));
} else {
/* exact number of outputs */
- audio_out = possible_out;
- found = true;
+ FOUNDCFG (possible_out);
}
}
if (possible_out == -1) {
/* any configuration possible, pick matching */
- audio_out = audio_in;
- found = true;
+ FOUNDCFG (preferred_out);
} else if (possible_out == -2) {
/* invalid. interpret as (-1, -1) */
- audio_out = audio_in;
- found = true;
+ FOUNDCFG (preferred_out);
} else if (possible_out < -2) {
- /* explicitly variable number of outputs, pick maximum */
- audio_out = -possible_out;
- found = true;
+ /* invalid, interpret as (<-2, <-2)
+ * variable number of outputs up to -N, */
+ FOUNDCFG (min (-possible_out, preferred_out));
} else {
/* exact number of outputs */
- audio_out = possible_out;
- found = true;
+ FOUNDCFG (possible_out);
}
}
if (audio_in > -possible_in && imprecise == NULL) {
/* request is too large */
} else if (possible_out == -1) {
- /* any output configuration possible, provide stereo out */
- audio_out = 2;
- found = true;
+ /* any output configuration possible */
+ FOUNDCFG (preferred_out);
} else if (possible_out == -2) {
/* invalid. interpret as (<-2, -1) */
- audio_out = 2;
- found = true;
+ FOUNDCFG (preferred_out);
} else if (possible_out < -2) {
- /* explicitly variable number of outputs, pick stereo */
- audio_out = 2;
- found = true;
+ /* variable number of outputs up to -N, */
+ FOUNDCFG (min (-possible_out, preferred_out));
} else {
/* exact number of outputs */
- audio_out = possible_out;
- found = true;
+ FOUNDCFG (possible_out);
}
}
if (possible_in && (possible_in == audio_in)) {
/* exact number of inputs ... must match obviously */
if (possible_out == -1) {
- /* any output configuration possible, provide stereo output */
- audio_out = 2;
- found = true;
+ /* any output configuration possible */
+ FOUNDCFG (preferred_out);
} else if (possible_out == -2) {
/* invalid. interpret as (>0, -1) */
- audio_out = 2;
- found = true;
+ FOUNDCFG (preferred_out);
} else if (possible_out < -2) {
- /* explicitly variable number of outputs, pick maximum */
- audio_out = -possible_out;
- found = true;
+ /* > 0, < -2 is not specified
+ * interpret as up to -N */
+ FOUNDCFG (min (-possible_out, preferred_out));
} else {
/* exact number of outputs */
- audio_out = possible_out;
- found = true;
+ FOUNDCFG (possible_out);
}
}
-
- if (found) {
- break;
- }
}
if (!found && imprecise) {
imprecise->set (DataType::AUDIO, possible_in);
if (possible_out == -1 || possible_out == -2) {
- audio_out = 2;
- found = true;
+ FOUNDCFG (2);
} else if (possible_out < -2) {
/* explicitly variable number of outputs, pick maximum */
- audio_out = -possible_out;
- found = true;
+ FOUNDCFG (min (-possible_out, preferred_out));
} else {
/* exact number of outputs */
- audio_out = possible_out;
- found = true;
- }
-
- if (found) {
- // ideally we'll keep iterating and take the "best match"
- // whatever "best" means:
- // least unconnected inputs, least silenced inputs,
- // closest match of inputs == outputs
- break;
+ FOUNDCFG (possible_out);
}
+ // ideally we'll also find the closest, best matching
+ // input configuration with minimal output penalty...
}
}
(*_lua_dsp)(in_map, out_map, nframes);
}
} catch (luabridge::LuaException const& e) {
+ PBD::error << "LuaException: " << e.what () << "\n";
#ifndef NDEBUG
- printf ("LuaException: %s\n", e.what ());
+ std::cerr << "LuaException: " << e.what () << "\n";
#endif
return -1;
}
LuaBindings::common (LG);
LuaBindings::dsp (LG);
-#ifndef NDEBUG
lua_gui->Print.connect (sigc::mem_fun (*this, &LuaProc::lua_print));
-#endif
-
lua_gui->do_command ("function ardour () end");
lua_gui->do_command (_script);