Add support for reading waveform selection in LUA

This commit is contained in:
rr- 2017-05-28 17:43:17 +02:00 committed by Thomas Goyne
parent 21f704f138
commit 4791222ab3
2 changed files with 26 additions and 0 deletions

View File

@ -30,3 +30,13 @@ Returns: 4 values, all numbers.
4. External leading of text in pixels.
---
Getting the audio waveform selection position and duration
function aegisub.get_audio_selection()
Returns: 2 values, all numbers.
1. Position of the selection, in milliseconds.
2. End of the selection, in milliseconds.
---

View File

@ -40,6 +40,8 @@
#include "ass_style.h"
#include "async_video_provider.h"
#include "auto4_lua_factory.h"
#include "audio_controller.h"
#include "audio_timing.h"
#include "command/command.h"
#include "compat.h"
#include "include/aegisub/context.h"
@ -255,6 +257,19 @@ namespace {
return 4;
}
int lua_get_audio_selection(lua_State *L)
{
const agi::Context *c = get_context(L);
if (!c || !c->audioController || !c->audioController->GetTimingController()) {
lua_pushnil(L);
return 1;
}
const TimeRange range = c->audioController->GetTimingController()->GetActiveLineRange();
push_value(L, range.begin());
push_value(L, range.end());
return 2;
}
int project_properties(lua_State *L)
{
const agi::Context *c = get_context(L);
@ -457,6 +472,7 @@ namespace {
set_field<get_file_name>(L, "file_name");
set_field<get_translation>(L, "gettext");
set_field<project_properties>(L, "project_properties");
set_field<lua_get_audio_selection>(L, "get_audio_selection");
// store aegisub table to globals
lua_settable(L, LUA_GLOBALSINDEX);