Skip to content

Commit 9946575

Browse files
committed
ベジェが正しく反映されないバグを修正
1 parent 8dc958d commit 9946575

10 files changed

+141
-65
lines changed

@Curve Editor.tra

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ local ed=gpt(idx+1)
1313
local par=gpt"param"
1414
--�x�W�F
1515
if (-2147483647 <= par and par <= -12368443) or (12368443 <= par and par <= 2147483646) then
16-
return curve_editor.getresult(0,par,ratio,st,ed)
16+
return curve_editor.getcurve(0,par,ratio,st,ed)
1717
--�x�W�F(����)
1818
elseif 1 <= par and par <= 1024 then
19-
return curve_editor.getresult(1,par,ratio,st,ed)
19+
return curve_editor.getcurve(1,par,ratio,st,ed)
2020
else
2121
return gpt"default"
2222
end
@@ -35,17 +35,17 @@ local gpt=obj.getpoint
3535
local par=gpt"param"
3636
--�x�W�F
3737
if (-2147483647 <= par and par <= -12368443) or (12368443 <= par and par <= 2147483646) then
38-
return curve_editor.getresult(0,par,gpt"totalindex",gpt(0),gpt(1))
38+
return curve_editor.getcurve(0,par,gpt"totalindex",gpt(0),gpt(1))
3939
--�x�W�F(����)
4040
elseif 1 <= par and par <= 1024 then
41-
return curve_editor.getresult(1,par,gpt"totalindex",gpt(0),gpt(1))
41+
return curve_editor.getcurve(1,par,gpt"totalindex",gpt(0),gpt(1))
4242
else
4343
return gpt"default"
4444
end
4545

4646

4747
@���̑�
48-
--param:40000000
48+
--param:0
4949
local modname="curve_editor"
5050
if not package.loaded[modname] then
5151
package.preload[modname]=package.loadlib(modname .. ".auf","luaopen_" .. modname)
@@ -57,12 +57,12 @@ local idx,ratio=math.modf(gpt"index")
5757
local st=gpt(idx)
5858
local ed=gpt(idx+1)
5959
local par=gpt"param"
60-
return curve_editor.getresult(2,par,ratio,st,ed)
60+
return curve_editor.getcurve(3,par,ratio,st,ed)
6161

6262

6363
@���̑�(���ԓ_����)
6464
--twopoint
65-
--param:40000000
65+
--param:0
6666
local modname="curve_editor"
6767
if not package.loaded[modname] then
6868
package.preload[modname]=package.loadlib(modname .. ".auf","luaopen_" .. modname)
@@ -71,4 +71,4 @@ if not package.loaded[modname] then
7171
end
7272
local gpt=obj.getpoint
7373
local par=gpt"param"
74-
return curve_editor.getresult(2,par,gpt"totalindex",gpt(0),gpt(1))
74+
return curve_editor.getcurve(2,par,gpt"totalindex",gpt(0),gpt(1))

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,33 @@ AviUtlを起動後、メインウィンドウの「表示」メニューから
3535
グラフ上の何もないところをダブルクリックすると制御点が追加され、制御点上で再度ダブルクリックすると削除されます。
3636

3737

38-
詳しい使用方法は[Wiki](https://github.com/mimaraka/aviutl-plugin-curve_editor/wiki)をご覧ください。
38+
詳しい使用方法は[Wiki](https://github.com/mimaraka/aviutl-plugin-curve_editor/wiki)をご覧ください。
39+
40+
## スクリプトから使用する(スクリプト開発者向け)
41+
以下のようにして`curve_editor`を読み込み、`getcurve()`関数を使用することでスクリプトからカーブの値を取得することができます。
42+
43+
```lua
44+
local modname="curve_editor"
45+
if not package.loaded[modname] then
46+
package.preload[modname]=package.loadlib(modname .. ".auf","luaopen_" .. modname)
47+
require(modname)
48+
package.preload[modname]=nil
49+
end
50+
```
51+
```
52+
curve_editor.getcurve(モード番号, パラメータ値, 進捗(0~1), 開始値, 終了値)
53+
```
54+
55+
モード番号については以下のようになっています:
56+
| 番号 | モード |
57+
| :---: | :---: |
58+
| 0 | ベジェ |
59+
| 1 | ベジェ(複数) |
60+
| 2 | (未実装) |
61+
| 3 | 振動 |
62+
| 4 | バウンス |
63+
64+
パラメータ値については、数値を指定するものであれば「カーブの数値をコピー」からコピーできる値を、IDを指定するものであればIDを入力します。
3965

4066
## 動作環境
4167
| OS | AviUtl | 拡張編集 |

curve_editor/cve_class.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ namespace cve {
108108
bool is_data_valid();
109109

110110
// 数値を読み取る
111-
virtual void read_number(int number, Static_Array<Curve_Points, CVE_POINT_MAX>& points);
112-
virtual void read_number(int number) { read_number(number, ctpts); }
111+
virtual bool read_number(int number, Static_Array<Curve_Points, CVE_POINT_MAX>& points);
112+
virtual bool read_number(int number) { return read_number(number, ctpts); }
113113

114114
virtual void move_handle(const Point_Address& pt_address, const POINT& pt_graph, bool init);
115115
};
@@ -168,19 +168,22 @@ namespace cve {
168168
double func_elastic(double t, double f, double k, double a, double st, double ed);
169169

170170
public:
171-
double freq;
172171
double ampl;
172+
double freq;
173173
double dec;
174-
bool invert;
174+
175+
bool reverse;
175176

176177
Curve_Elastic() { initialize(); }
177178

178179
void initialize();
179180
void pt_in_ctpt(const POINT& pt_client, Point_Address* pt_address);
180181
void move_handle(const Point_Address pt_address, const POINT& pt_graph);
181182
void draw_curve(Bitmap_Buffer* bitmap_buffer, const RECT& rect_wnd, int drawing_mode);
183+
double pt_to_param(int pt_graph_val, int idx_param);
184+
void param_to_pt(POINT* pt_graph, int idx_pt);
182185
int create_number();
183-
void read_number(int number, double* f, double* k, double* a);
186+
bool read_number(int number, double* f, double* k, double* a, bool* rev);
184187
double create_result(int number, double ratio, double st, double ed);
185188
};
186189

curve_editor/cve_control.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void cve::Button_Switch::set_status(BOOL bl)
376376

377377

378378
//---------------------------------------------------------------------
379-
// ウィンドウプロシージャ(Value)
379+
// ウィンドウプロシージャ(パラメータ)
380380
//---------------------------------------------------------------------
381381
LRESULT cve::Button_Param::wndproc(HWND hw, UINT msg, WPARAM wparam, LPARAM lparam)
382382
{
@@ -400,7 +400,7 @@ LRESULT cve::Button_Param::wndproc(HWND hw, UINT msg, WPARAM wparam, LPARAM lpar
400400
break;
401401

402402
case cve::Mode_Elastic:
403-
str_param = "Freq : " + std::to_string(g_curve_elastic.freq).substr(0, 5);
403+
str_param = std::to_string(g_curve_elastic.create_number());
404404
param = const_cast<LPTSTR>(str_param.c_str());
405405
break;
406406
}

curve_editor/cve_curve.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ bool cve::Curve::is_data_valid()
990990
//---------------------------------------------------------------------
991991
// 1次元値を読み取る
992992
//---------------------------------------------------------------------
993-
void cve::Curve::read_number(int number, Static_Array<Curve_Points, CVE_POINT_MAX>& points)
993+
bool cve::Curve::read_number(int number, Static_Array<Curve_Points, CVE_POINT_MAX>& points)
994994
{
995995
// -2147483647 ~ -12368443:ベジェが使用
996996
// -12368442 ~ -1:IDが使用
@@ -1006,9 +1006,7 @@ void cve::Curve::read_number(int number, Static_Array<Curve_Points, CVE_POINT_MA
10061006
else if (12368443 <= number && number <= 2147483646) {
10071007
num = (int64_t)number + (int64_t)2122746762;
10081008
}
1009-
else return;
1010-
1011-
1009+
else return false;
10121010

10131011
clear(points);
10141012

@@ -1022,6 +1020,8 @@ void cve::Curve::read_number(int number, Static_Array<Curve_Points, CVE_POINT_MA
10221020
points[1].pt_left.y *= CVE_GRAPH_RESOLUTION / 100;
10231021
points[0].pt_right.y -= (int32_t)(2.73 * CVE_GRAPH_RESOLUTION);
10241022
points[1].pt_left.y -= (int32_t)(2.73 * CVE_GRAPH_RESOLUTION);
1023+
1024+
return true;
10251025
}
10261026

10271027

@@ -1045,13 +1045,13 @@ double cve::Curve::get_bezier_value(double ratio, Static_Array<Curve_Points, CVE
10451045
// 区間ごとの制御点1のX座標(相対値、0~1)
10461046
double x1 = (points[i].pt_right.x - points[i].pt_center.x) / (double)(points[i + 1].pt_center.x - points[i].pt_center.x);
10471047
// 区間ごとの制御点1のY座標(実際の値)
1048-
double y1 = points[i].pt_right.y - points[i].pt_center.y;
1048+
double y1 = points[i].pt_right.y - points[i].pt_center.y / (double)(points[i + 1].pt_center.y - points[i].pt_center.y);
10491049
// 区間ごとの制御点2のX座標(相対値、0~1)
10501050
double x2 = (points[i + 1].pt_left.x - points[i].pt_center.x) / (double)(points[i + 1].pt_center.x - points[i].pt_center.x);
10511051
// 区間ごとの制御点2のY座標(相対値)
1052-
double y2 = points[i + 1].pt_left.y - points[i].pt_center.y;
1052+
double y2 = points[i + 1].pt_left.y - points[i].pt_center.y / (double)(points[i + 1].pt_center.y - points[i].pt_center.y);
10531053

1054-
// 区間ごとの始値、終値(相対値ではなく、実際の値)
1054+
// 区間ごとの始値、終値(相対値ではなく、グラフの値)
10551055
double st2 = points[i].pt_center.y;
10561056
double ed2 = points[i + 1].pt_center.y;
10571057

curve_editor/cve_curve_bezier.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int cve::Curve_Bezier::create_number()
4545
}
4646
// 計算
4747
result = 6600047 * (pt[1].y + 273) + 65347 * pt[1].x + 101 * (pt[0].y + 273) + pt[0].x - 2147483647;
48+
if (result >= -12368442)
49+
result += 24736885;
4850
return result;
4951
}
5052

@@ -114,20 +116,10 @@ double cve::Curve_Bezier::create_result(int number, double ratio, double st, dou
114116
// 1 ~ 12368442:IDが使用
115117
// 12368443 ~ 2147483646:ベジェが使用
116118
// 2147483647 :不使用
117-
118-
119-
// 進捗が0~1の範囲外であった場合
120-
if (ratio < 0)
121-
return st;
122-
else if (ratio > 1)
123-
return ed;
124-
// 数値が範囲外であった場合
125-
else if (-12368442 <= number && number <= 12368442 || number <= 2147483647)
119+
120+
Static_Array<Curve_Points, CVE_POINT_MAX> ctpts_buffer;
121+
if (!read_number(number, ctpts_buffer))
126122
return st + (ed - st) * ratio;
127-
else {
128-
Static_Array<Curve_Points, CVE_POINT_MAX> ctpts_buffer;
129-
read_number(number, ctpts_buffer);
130123

131-
return st + get_bezier_value(ratio, ctpts_buffer) * (ed - st) / (double)CVE_GRAPH_RESOLUTION;
132-
}
124+
return st + get_bezier_value(MINMAX_LIMIT(ratio, 0, 1.0), ctpts_buffer) * (ed - st) / (double)CVE_GRAPH_RESOLUTION;
133125
}

curve_editor/cve_curve_elastic.cpp

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
#include "cve_header.hpp"
88

9-
#define CVE_ELASTIC_FREQ_MAX 100
10-
#define CVE_ELASTIC_FREQ_DEFAULT 5.0
11-
#define CVE_ELASTIC_DECAY_DEFAULT 10.0
9+
#define CVE_ELASTIC_FREQ_DEFAULT 8.0
10+
#define CVE_ELASTIC_DECAY_DEFAULT 6.0
1211
#define CVE_ELASTIC_AMP_DEFAULT 1.0
13-
#define CVE_ELASTIC_SMOOTH_COEF 1.94
1412

1513

1614

@@ -78,6 +76,41 @@ double cve::Curve_Elastic::func_elastic(double t, double f, double k, double a,
7876

7977

8078

79+
//---------------------------------------------------------------------
80+
// ポイント -> パラメータ
81+
// pt_graph_val : 変換するポイントのグラフ座標(xまたはy)
82+
// idx_param : パラメータのインデックス(0: ampl, 1: freq, 2: dec)
83+
//---------------------------------------------------------------------
84+
double cve::Curve_Elastic::pt_to_param(int pt_graph_val, int idx_param)
85+
{
86+
// Amp
87+
if (idx_param == 0) {
88+
return (MINMAX_LIMIT(pt_graph_val, CVE_GRAPH_RESOLUTION / 2, CVE_GRAPH_RESOLUTION) - CVE_GRAPH_RESOLUTION * 0.5) / (CVE_GRAPH_RESOLUTION * 0.5);
89+
}
90+
// Freq
91+
else if (idx_param == 1) {
92+
return MIN_LIMIT(2.0 / (MIN_LIMIT(pt_graph_val, 10) / (double)CVE_GRAPH_RESOLUTION), 2.0);
93+
}
94+
// Decay
95+
else {
96+
return -10.0 * std::log(-(MINMAX_LIMIT(pt_graph_val, 0, (int)(CVE_GRAPH_RESOLUTION * 0.5 - 1)) / (CVE_GRAPH_RESOLUTION * 0.5)) + 1.0) + 1.0;
97+
}
98+
}
99+
100+
101+
102+
//---------------------------------------------------------------------
103+
// パラメータ -> ポイント
104+
// pt_graph : 変換するポイントのグラフ座標
105+
// idx_pt : ポイントのインデックス(0: 振幅(左), 1: 振幅(右), 2: 振動数・減衰)
106+
//---------------------------------------------------------------------
107+
void cve::Curve_Elastic::param_to_pt(POINT* pt_graph, int idx_pt)
108+
{
109+
110+
}
111+
112+
113+
81114
//---------------------------------------------------------------------
82115
// 指定した座標がポイント・ハンドルの内部に存在しているか
83116
//---------------------------------------------------------------------
@@ -128,18 +161,16 @@ void cve::Curve_Elastic::pt_in_ctpt(const POINT& pt_client, Point_Address* pt_ad
128161
//---------------------------------------------------------------------
129162
void cve::Curve_Elastic::move_handle(const Point_Address pt_address, const POINT& pt_graph)
130163
{
131-
int x;
132164
switch (pt_address.index) {
133165
// 振幅
134166
case 0:
135-
ampl = (MINMAX_LIMIT(pt_graph.y, CVE_GRAPH_RESOLUTION / 2, CVE_GRAPH_RESOLUTION) - CVE_GRAPH_RESOLUTION * 0.5) / (CVE_GRAPH_RESOLUTION * 0.5);
167+
ampl = pt_to_param(pt_graph.y, 0);
136168
break;
137169

138170
// 振動数, 減衰
139171
case 1:
140-
x = MIN_LIMIT(pt_graph.x, 10);
141-
freq = MIN_LIMIT(2.0 / (x / (double)CVE_GRAPH_RESOLUTION), 2.0);
142-
dec = -10.0 * std::log(-(MINMAX_LIMIT(pt_graph.y, 0, (int)(CVE_GRAPH_RESOLUTION * 0.5)) / (CVE_GRAPH_RESOLUTION * 0.5)) + 1.0) + 1.0;
172+
freq = pt_to_param(pt_graph.x, 1);
173+
dec = pt_to_param(pt_graph.y, 2);
143174
break;
144175
}
145176
}
@@ -239,25 +270,47 @@ void cve::Curve_Elastic::draw_curve(Bitmap_Buffer* bitmap_buffer, const RECT& re
239270
//---------------------------------------------------------------------
240271
int cve::Curve_Elastic::create_number()
241272
{
273+
int result;
242274
int f = (int)(2000 / freq);
243275
int a = (int)(100 * ampl);
244276
int k = -(int)(100 * (std::exp(-(dec - 1.0) * 0.1) - 1.0));
245-
return a + k * 101 + f * 101 * 1001;
277+
result = 1 + a + k * 101 + f * 101 * 1001;
278+
if (reverse)
279+
result *= -1;
280+
return result;
246281
}
247282

248283

249284

250285
//---------------------------------------------------------------------
251286
// 数値を読み取り
252287
//---------------------------------------------------------------------
253-
void cve::Curve_Elastic::read_number(int number, double* f, double* k, double* a)
288+
bool cve::Curve_Elastic::read_number(int number, double* f, double* k, double* a, bool* rev)
254289
{
255-
*f = std::floor(number / (101 * 1001));
256-
*k = std::floor((number - *f * 101 * 1001) / 101);
257-
*a = std::floor(number - *f * 101 * 1001 - *k * 101);
290+
// -2147483647 ~ -10211202:バウンスが使用
291+
// -10211201 ~ -1:振動が使用
292+
// 0 :不使用
293+
// 1 ~ 10211201:振動が使用
294+
// 10211202 ~ 2147483646:バウンスが使用
295+
// 2147483647 :不使用
296+
297+
int num;
298+
if (ISINRANGEEQ(number, -10211201, -1)) {
299+
*rev = true;
300+
num = -number - 1;
301+
}
302+
else if (ISINRANGEEQ(number, 1, 10211201)) {
303+
*rev = false;
304+
num = number - 1;
305+
}
306+
else return false;
307+
*f = std::floor(num / (101 * 1001));
308+
*k = std::floor((num - *f * 101 * 1001) / 101);
309+
*a = std::floor(num - *f * 101 * 1001 - *k * 101);
258310
*f = 2.0 / MIN_LIMIT(*f * 0.001, 0.001);
259311
*k = -10.0 * std::log(-*k * 0.01 + 1.0) + 1.0;
260312
*a = MINMAX_LIMIT(*a, 0, 100) * 0.01;
313+
return true;
261314
}
262315

263316

@@ -267,14 +320,13 @@ void cve::Curve_Elastic::read_number(int number, double* f, double* k, double* a
267320
//---------------------------------------------------------------------
268321
double cve::Curve_Elastic::create_result(int number, double ratio, double st, double ed)
269322
{
270-
271-
if (number >= 0) {
272-
273-
}
274-
else {
275-
276-
}
277323
double f, k, a;
278-
read_number(number, &f, &k, &a);
279-
return func_elastic(ratio, f, k, a, st, ed);
324+
bool rev;
325+
if (!read_number(number, &f, &k, &a, &rev))
326+
return st + (ed - st) * ratio;
327+
328+
if (rev)
329+
return func_elastic(MINMAX_LIMIT(1.0 - ratio, 0, 1.0), f, k, a, ed, st);
330+
else
331+
return func_elastic(MINMAX_LIMIT(ratio, 0, 1.0), f, k, a, st, ed);
280332
}

curve_editor/cve_func_filter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ void ini_load_configs(FILTER* fp)
163163
g_curve_normal.ctpts[0].pt_right.y = fp->exfunc->ini_load_int(fp, "y1", (int)(CVE_GRAPH_RESOLUTION * CVE_POINT_DEFAULT_1));
164164
g_curve_normal.ctpts[1].pt_left.x = MINMAX_LIMIT(fp->exfunc->ini_load_int(fp, "x2", (int)(CVE_GRAPH_RESOLUTION * CVE_POINT_DEFAULT_2)), 0, CVE_GRAPH_RESOLUTION);
165165
g_curve_normal.ctpts[1].pt_left.y = fp->exfunc->ini_load_int(fp, "y2", (int)(CVE_GRAPH_RESOLUTION * CVE_POINT_DEFAULT_2));
166+
166167
g_config.separator = fp->exfunc->ini_load_int(fp, "separator", CVE_SEPARATOR_WIDTH);
167168
g_config.edit_mode = (cve::Edit_Mode)fp->exfunc->ini_load_int(fp, "edit_mode", cve::Mode_Bezier);
168169
g_config.layout_mode = (cve::Config::Layout_Mode)fp->exfunc->ini_load_int(fp, "layout_mode", cve::Config::Vertical);

curve_editor/cve_lua.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int get_result(lua_State* L)
6262
// 関数テーブル
6363
//---------------------------------------------------------------------
6464
static luaL_Reg functions[] = {
65-
{ "getresult", get_result },
65+
{ "getcurve", get_result },
6666
{ nullptr, nullptr }
6767
};
6868

0 commit comments

Comments
 (0)