From 78c3ef4f9066818e43ad0fe038b546b30ede3738 Mon Sep 17 00:00:00 2001 From: eumagga0x2a Date: Wed, 29 Aug 2018 18:31:28 +0200 Subject: [PATCH] [tinyPy] Rename method to set audio gain to stay compatible with scripts created by older versions --- .../tinyPy/src/ADM_pyAvidemux.h | 3 ++- .../tinyPy/src/ADM_pyAvidemuxAudio.cpp | 10 +++++++- .../tinyPy/src/PythonScriptWriter.cpp | 4 +-- .../ADM_scriptEngines/tinyPy/src/adm_gen.cpp | 25 +++++++++++++++++-- .../tinyPy/src/binding/adm.admPyClass | 1 + 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemux.h b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemux.h index f30f24b8a5..0b0c9063e1 100644 --- a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemux.h +++ b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemux.h @@ -44,7 +44,8 @@ int pyGetNormalizeLevel(IEditor *editor); void pySetNormalizeMode(IEditor *editor, int mode); void pySetNormalizeValue(IEditor *editor, int value); void pySetNormalizeLevel(IEditor *editor, int level); -int pySetNormalize(IEditor *, int track, int mode, int gain100, int maxlevel); +int pySetNormalize(IEditor *, int track, int mode, int gain100); +int pySetNormalize2(IEditor *, int track, int mode, int gain100, int maxlevel); int pySetFilm2Pal(IEditor *,int track,int onoff); int pySetPal2Film(IEditor *,int track,int onoff); /* Info */ diff --git a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemuxAudio.cpp b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemuxAudio.cpp index ad81f247a5..fe51b95014 100644 --- a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemuxAudio.cpp +++ b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/ADM_pyAvidemuxAudio.cpp @@ -211,7 +211,7 @@ int pyGetNormalizeLevel(IEditor *editor,int dex) \brief */ -int pySetNormalize(IEditor *editor, int dex, int mode, int value, int level) +int pySetNormalize2(IEditor *editor, int dex, int mode, int value, int level) { ADM_GAINMode m; int32_t gain, max; @@ -223,7 +223,15 @@ int pySetNormalize(IEditor *editor, int dex, int mode, int value, int level) max = (int32_t)level; return editor->setAudioFilterNormalise(dex,m,gain,max); } +/** + \fn pySetNormalize + \brief preserve compatibility to project scripts created by older versions +*/ +int pySetNormalize(IEditor *editor, int dex, int mode, int value) +{ + return pySetNormalize2(editor, dex, mode, value, -30); +} /** \fn \brief diff --git a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/PythonScriptWriter.cpp b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/PythonScriptWriter.cpp index 0f44ae2667..82c3f0b312 100644 --- a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/PythonScriptWriter.cpp +++ b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/PythonScriptWriter.cpp @@ -86,7 +86,7 @@ void PythonScriptWriter::loadVideo(const char* path) void PythonScriptWriter::setAudioGain(int trackIndex, ADM_GAINMode gainMode, int32_t gainValue, int32_t maxLevel) { - *(this->_stream) << "adm.audioSetNormalize(" << trackIndex << ", " << gainMode << ", " << gainValue << ", " << maxLevel << ")" << std::endl; + *(this->_stream) << "adm.audioSetNormalize2(" << trackIndex << ", " << gainMode << ", " << gainValue << ", " << maxLevel << ")" << std::endl; } void PythonScriptWriter::setAudioMixer(int trackIndex, CHANNEL_CONF mixer) @@ -109,7 +109,7 @@ void PythonScriptWriter::setAudioDrc(int trackIndex, bool active) } void PythonScriptWriter::setAudioShift(int trackIndex, bool active,int32_t value) { - *(this->_stream) << "adm.audioSetShift(" << trackIndex << ", " << active << "," << value << ")" << std::endl; + *(this->_stream) << "adm.audioSetShift(" << trackIndex << ", " << active << ", " << value << ")" << std::endl; } diff --git a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/adm_gen.cpp b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/adm_gen.cpp index 4b97681f84..98dad769a2 100644 --- a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/adm_gen.cpp +++ b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/adm_gen.cpp @@ -414,8 +414,24 @@ static tp_obj zzpy_appendVideo(TP) int r = editor->appendFile(p0); return tp_number(r); } -// audioSetNormalize -> int pySetNormalize (IEditor int int int int) +// audioSetNormalize -> int pySetNormalize (IEditor int int int) static tp_obj zzpy_audioSetNormalize(TP) + { + tp_obj self = tp_getraw(tp); + IScriptEngine *engine = (IScriptEngine*)tp_get(tp, tp->builtins, tp_string("userdata")).data.val; + IEditor *editor = engine->editor(); + TinyParams pm(tp); + void *me = (void *)pm.asThis(&self, ADM_PYID_AVIDEMUX); + + IEditor *p0 = editor; + int p1 = pm.asInt(); + int p2 = pm.asInt(); + int p3 = pm.asInt(); + int r = pySetNormalize(p0,p1,p2,p3); + return tp_number(r); +} +// audioSetNormalize2 -> int pySetNormalize2 (IEditor int int int int) +static tp_obj zzpy_audioSetNormalize2(TP) { tp_obj self = tp_getraw(tp); IScriptEngine *engine = (IScriptEngine*)tp_get(tp, tp->builtins, tp_string("userdata")).data.val; @@ -428,7 +444,7 @@ static tp_obj zzpy_audioSetNormalize(TP) int p2 = pm.asInt(); int p3 = pm.asInt(); int p4 = pm.asInt(); - int r = pySetNormalize(p0,p1,p2,p3,p4); + int r = pySetNormalize2(p0,p1,p2,p3,p4); return tp_number(r); } // audioSetDrc -> int pySetDrc (IEditor int int ) @@ -699,6 +715,10 @@ tp_obj zzpy__pyAdm_get(tp_vm *vm) { return tp_method(vm, self, zzpy_audioSetNormalize); } + if (!strcmp(key, "audioSetNormalize2")) + { + return tp_method(vm, self, zzpy_audioSetNormalize2); + } if (!strcmp(key, "audioSetDrc")) { return tp_method(vm, self, zzpy_audioSetDrc); @@ -809,6 +829,7 @@ static tp_obj zzpy__pyAdm_help(TP) engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioEncoding(IEditor, int)\n"); engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "appendVideo(str)\n"); engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioSetNormalize(IEditor,int,int,int)\n"); + engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioSetNormalize2(IEditor,int,int,int,int)\n"); engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioSetDrc(IEditor,int,int)\n"); engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "videoCodec(str, couples)\n"); engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "audioSetMixer(int,str)\n"); diff --git a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/binding/adm.admPyClass b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/binding/adm.admPyClass index a396c70c12..34c5702bdb 100644 --- a/avidemux_plugins/ADM_scriptEngines/tinyPy/src/binding/adm.admPyClass +++ b/avidemux_plugins/ADM_scriptEngines/tinyPy/src/binding/adm.admPyClass @@ -28,6 +28,7 @@ /* METHOD */ int pySetPal2Film:audioSetPal2Film(int,int) /* METHOD */ int pySetFilm2Pal:audioSetFilm2Pal(int,int) /* METHOD */ int pySetNormalize:audioSetNormalize(int,int,int) +/* METHOD */ int pySetNormalize:audioSetNormalize2(int,int,int,int) /* METHOD */ int pySetDrc:audioSetDrc(int,int) /* METHOD */ int pySetAudioShift:audioSetShift(int,int,int) #