13
0

lua bindings for track/bus and session creation

This commit is contained in:
Robin Gareus 2016-04-24 00:25:34 +02:00
parent f8936ebcb1
commit f317451609
2 changed files with 94 additions and 3 deletions

View File

@ -496,6 +496,13 @@ LuaBindings::common (lua_State* L)
.addFunction ("n_ports", &IO::n_ports)
.endClass ()
.deriveWSPtrClass <RouteGroup, SessionObject> ("RouteGroupPtr")
.endClass ()
.beginClass <RouteGroup> ("RouteGroup")
// stub RouteGroup* is needed for new_audio_track()
.endClass ()
.deriveWSPtrClass <Route, SessionObject> ("Route")
.addCast<Track> ("to_track")
.addFunction ("set_name", &Route::set_name)
@ -866,6 +873,13 @@ LuaBindings::common (lua_State* L)
.addConst ("Start", ARDOUR::RegionPoint(Start))
.addConst ("End", ARDOUR::RegionPoint(End))
.addConst ("SyncPoint", ARDOUR::RegionPoint(SyncPoint))
.endNamespace ()
.beginNamespace ("TrackMode")
.addConst ("Normal", ARDOUR::TrackMode(Start))
.addConst ("NonLayered", ARDOUR::TrackMode(NonLayered))
.addConst ("Destructive", ARDOUR::TrackMode(Destructive))
.endNamespace ()
.endNamespace ();
luabridge::getGlobalNamespace (L)
@ -949,6 +963,10 @@ LuaBindings::common (lua_State* L)
.addFunction ("current_start_frame", &Session::current_start_frame)
.addFunction ("current_end_frame", &Session::current_end_frame)
.addFunction ("actively_recording", &Session::actively_recording)
.addFunction ("new_audio_track", &Session::new_audio_track)
.addFunction ("new_audio_route", &Session::new_audio_route)
.addFunction ("new_midi_track", &Session::new_midi_track)
.addFunction ("new_midi_route", &Session::new_midi_route)
.addFunction ("get_routes", &Session::get_routes)
.addFunction ("get_tracks", &Session::get_tracks)
.addFunction ("name", &Session::name)

View File

@ -126,7 +126,7 @@ static void init ()
assert (!event_loop);
event_loop = new MyEventLoop ("lua");
EventLoop::set_event_loop_for_thread (event_loop);
SessionEvent::create_per_thread_pool ("lua", 512);
SessionEvent::create_per_thread_pool ("lua", 4096);
static LuaReceiver lua_receiver;
@ -153,6 +153,45 @@ static void unset_session ()
set_session (NULL);
}
static Session * _create_session (string dir, string state, uint32_t rate)
{
AudioEngine* engine = AudioEngine::instance ();
if (!engine->current_backend ()) {
if (!engine->set_backend ("None (Dummy)", "Unit-Test", "")) {
std::cerr << "Cannot create Audio/MIDI engine\n";
return 0;
}
}
if (!engine->current_backend ()) {
std::cerr << "Cannot create Audio/MIDI engine\n";
return 0;
}
if (engine->running ()) {
engine->stop ();
}
std::string s = Glib::build_filename (dir, state + statefile_suffix);
if (Glib::file_test (dir, Glib::FILE_TEST_EXISTS)) {
std::cerr << "Session already exists: " << s << "\n";
return 0;
}
engine->set_sample_rate (rate);
init_post_engine ();
if (engine->start () != 0) {
std::cerr << "Cannot start Audio/MIDI engine\n";
return 0;
}
Session* session = new Session (*engine, dir, state);
return session;
}
static Session * _load_session (string dir, string state)
{
AudioEngine* engine = AudioEngine::instance ();
@ -203,6 +242,37 @@ static Session * _load_session (string dir, string state)
return session;
}
static Session* create_session (string dir, string state, uint32_t rate)
{
Session* s = 0;
if (_session) {
cerr << "Session already open" << "\n";
return 0;
}
try {
s = _create_session (dir, state, rate);
} catch (failed_constructor& e) {
cerr << "failed_constructor: " << e.what () << "\n";
return 0;
} catch (AudioEngine::PortRegistrationFailure& e) {
cerr << "PortRegistrationFailure: " << e.what () << "\n";
return 0;
} catch (exception& e) {
cerr << "exception: " << e.what () << "\n";
return 0;
} catch (...) {
cerr << "unknown exception.\n";
return 0;
}
Glib::usleep (1000000); // allow signal propagation, callback/thread-pool setup
if (!s) {
return 0;
}
set_session (s);
s->DropReferences.connect_same_thread (session_connections, &unset_session);
return s;
}
static Session* load_session (string dir, string state)
{
Session* s = 0;
@ -225,8 +295,10 @@ static Session* load_session (string dir, string state)
cerr << "unknown exception.\n";
return 0;
}
Glib::usleep (1000000); // allo signal propagation, callback/thread-pool setup
assert (s);
Glib::usleep (1000000); // allow signal propagation, callback/thread-pool setup
if (!s) {
return 0;
}
set_session (s);
s->DropReferences.connect_same_thread (session_connections, &unset_session);
return s;
@ -278,6 +350,7 @@ static void setup_lua ()
luabridge::getGlobalNamespace (L)
.beginNamespace ("_G")
.addFunction ("create_session", &create_session)
.addFunction ("load_session", &load_session)
.addFunction ("close_session", &close_session)
.addFunction ("sleep", &delay)