Skip to content

Commit fcf4ebb

Browse files
authored
Merge pull request #36 from mimaraka/develop
v2.0-alpha2.1
2 parents e8f3417 + f35cf0c commit fcf4ebb

File tree

119 files changed

+2953
-1640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+2953
-1640
lines changed

curve_editor/@Curve Editor.tra

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local idx,t=math.modf(gp"index")
66
local st=gp(idx)
77
local ed=gp(idx+1)
88
local par=gp"param"
9-
return ce.getcurve(0,par,t,st,ed) or ce.getcurve(1,par,t,st,ed) or ce.getcurve(2,par,t,st,ed) or ce.getcurve(5,par,t,st,ed) or gp"default"
9+
return ce.getcurve(0,par,t,st,ed) or ce.getcurve(1,par,t,st,ed) or ce.getcurve(2,-par,t,st,ed) or ce.getcurve(5,par-524288,t,st,ed) or gp"default"
1010

1111

1212
@Type1(中間点無視)
@@ -15,7 +15,7 @@ return ce.getcurve(0,par,t,st,ed) or ce.getcurve(1,par,t,st,ed) or ce.getcurve(2
1515
local ce=require"curve_editor"
1616
local gp=obj.getpoint
1717
local par=gp"param"
18-
return ce.getcurve(0,par,gp"totalindex",gp(0),gp(1)) or ce.getcurve(1,par,gp"totalindex",gp(0),gp(1)) or ce.getcurve(2,par,gp"totalindex",gp(0),gp(1)) or ce.getcurve(5,par,gp"totalindex",gp(0),gp(1)) or gp"default"
18+
return ce.getcurve(0,par,gp"totalindex",gp(0),gp(1)) or ce.getcurve(1,par,gp"totalindex",gp(0),gp(1)) or ce.getcurve(2,-par,gp"totalindex",gp(0),gp(1)) or ce.getcurve(5,par-524288,gp"totalindex",gp(0),gp(1)) or gp"default"
1919

2020

2121
@Type1(補間)
@@ -24,7 +24,7 @@ local ce=require"curve_editor"
2424
local gp=obj.getpoint
2525
local par=gp"param"
2626
local prog=gp"totalindex"
27-
prog=ce.getcurve(0,par,prog,0,1) or ce.getcurve(1,par,prog,0,1) or ce.getcurve(2,par,prog,0,1) or ce.getcurve(5,par,t,st,ed) or prog
27+
prog=ce.getcurve(0,par,prog,0,1) or ce.getcurve(1,par,prog,0,1) or ce.getcurve(2,-par,prog,0,1) or ce.getcurve(5,par-524288,t,st,ed) or prog
2828
local num=gp"num"
2929

3030
local function interpolate(idx,t)

curve_editor/config.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace cved {
2828
show_velocity_graph_ = false;
2929
align_handle_ = true;
3030
ignore_autosaver_warning_ = false;
31-
separator_ = global::SEPARATOR_WIDTH;
31+
separator_pos_ = 1.;
3232
preset_size_ = 50;
3333

3434
// AviUtlのディレクトリの取得
@@ -55,20 +55,20 @@ namespace cved {
5555
}
5656
}
5757

58-
bool Config::set_theme_id(ThemeId theme_id) noexcept {
59-
switch (theme_id) {
58+
bool Config::set_theme(ThemeId theme) noexcept {
59+
switch (theme) {
6060
case ThemeId::System:
6161
case ThemeId::Dark:
6262
case ThemeId::Light:
63-
pref_.theme_id = theme_id;
63+
pref_.theme = theme;
6464
return true;
6565

6666
default:
6767
return false;
6868
}
6969
}
7070

71-
const char* Config::get_edit_mode_str(EditMode edit_mode) const noexcept {
71+
const char* Config::get_edit_mode_dispname(EditMode edit_mode) const noexcept {
7272
using StringId = StringTable::StringId;
7373

7474
if (!string_table.loaded()) return nullptr;
@@ -97,12 +97,12 @@ namespace cved {
9797
}
9898
}
9999

100-
const char* Config::get_edit_mode_str() const noexcept {
101-
return get_edit_mode_str(edit_mode_);
100+
const char* Config::get_edit_mode_dispname() const noexcept {
101+
return get_edit_mode_dispname(edit_mode_);
102102
}
103103

104104
bool Config::set_apply_mode(EditMode edit_mode, ApplyMode apply_mode) noexcept {
105-
if (mkaul::in_range((size_t)apply_mode, 0u, (size_t)ApplyMode::NumApplyMode - 1u, true)) {
105+
if (mkaul::in_range((size_t)apply_mode, 0u, (size_t)ApplyMode::NumApplyMode - 1u)) {
106106
apply_mode_[(size_t)edit_mode] = apply_mode;
107107
return true;
108108
}
@@ -130,15 +130,15 @@ namespace cved {
130130
}
131131

132132
bool Config::set_edit_mode(EditMode edit_mode) noexcept {
133-
if (mkaul::in_range((uint32_t)edit_mode, 0u, (uint32_t)EditMode::NumEditMode - 1u, true)) {
133+
if (mkaul::in_range((uint32_t)edit_mode, 0u, (uint32_t)EditMode::NumEditMode - 1u)) {
134134
edit_mode_ = edit_mode;
135135
return true;
136136
}
137137
else return false;
138138
}
139139

140-
void Config::set_separator(int separator) noexcept {
141-
separator_ = std::max(separator, global::SEPARATOR_WIDTH);
140+
void Config::set_separator_pos(double separator_pos) noexcept {
141+
separator_pos_ = mkaul::clamp(separator_pos, 0., 1.);
142142
}
143143

144144
void Config::set_preset_size(int) noexcept {
@@ -173,7 +173,7 @@ namespace cved {
173173
if (data.contains(GET_KEY(show_y_label_))) set_show_y_label(data[GET_KEY(show_y_label_)]);
174174
if (data.contains(GET_KEY(align_handle_))) set_align_handle(data[GET_KEY(align_handle_)]);
175175
if (data.contains(GET_KEY(ignore_autosaver_warning_))) set_ignore_autosaver_warning(data[GET_KEY(ignore_autosaver_warning_)]);
176-
if (data.contains(GET_KEY(separator_))) set_separator(data[GET_KEY(separator_)]);
176+
if (data.contains(GET_KEY(separator_pos_))) set_separator_pos(data[GET_KEY(separator_pos_)]);
177177
if (data.contains(GET_KEY(preset_size_))) set_preset_size(data[GET_KEY(preset_size_)]);
178178
}
179179
catch (const json::exception&) {
@@ -201,7 +201,7 @@ namespace cved {
201201
{GET_KEY(show_velocity_graph_), show_velocity_graph_},
202202
{GET_KEY(align_handle_), align_handle_},
203203
{GET_KEY(ignore_autosaver_warning_), ignore_autosaver_warning_},
204-
{GET_KEY(separator_), separator_},
204+
{GET_KEY(separator_pos_), separator_pos_},
205205
{GET_KEY(preset_size_), preset_size_}
206206
};
207207

curve_editor/config.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace cved {
3030
bool show_velocity_graph_ = false;
3131
bool align_handle_ = false;
3232
bool ignore_autosaver_warning_ = false;
33-
int separator_ = 0;
33+
double separator_pos_ = 0.;
3434
int preset_size_ = 0;
3535

3636
std::filesystem::path dir_aviutl_;
@@ -42,14 +42,14 @@ namespace cved {
4242
auto get_language() const noexcept { return pref_.language; }
4343
bool set_language(Language language) noexcept;
4444

45-
auto get_theme_id() const noexcept { return pref_.theme_id; }
46-
bool set_theme_id(ThemeId theme_id) noexcept;
45+
auto get_theme() const noexcept { return pref_.theme; }
46+
bool set_theme(ThemeId theme) noexcept;
4747

4848
auto get_edit_mode() const noexcept { return edit_mode_; }
4949
bool set_edit_mode(EditMode edit_mode) noexcept;
5050

51-
const char* get_edit_mode_str(EditMode edit_mode) const noexcept;
52-
const char* get_edit_mode_str() const noexcept;
51+
const char* get_edit_mode_dispname(EditMode edit_mode) const noexcept;
52+
const char* get_edit_mode_dispname() const noexcept;
5353

5454
auto get_layout_mode() const noexcept { return layout_mode_; }
5555
bool set_layout_mode(LayoutMode layout_mode) noexcept;
@@ -123,11 +123,14 @@ namespace cved {
123123
auto get_enable_animation() const noexcept { return pref_.enable_animation; }
124124
void set_enable_animation(bool enable_animation) noexcept { pref_.enable_animation = enable_animation; }
125125

126+
auto get_word_wrap() const noexcept { return pref_.word_wrap; }
127+
void set_word_wrap(bool word_wrap) noexcept { pref_.word_wrap = word_wrap; }
128+
126129
auto get_ignore_autosaver_warning() const noexcept { return ignore_autosaver_warning_; }
127130
void set_ignore_autosaver_warning(bool ignore_autosaver_warning) noexcept { ignore_autosaver_warning_ = ignore_autosaver_warning; }
128131

129-
auto get_separator() const noexcept { return separator_; }
130-
void set_separator(int separator) noexcept;
132+
auto get_separator_pos() const noexcept { return separator_pos_; }
133+
void set_separator_pos(double separator_pos) noexcept;
131134

132135
auto get_preset_size() const noexcept { return preset_size_; }
133136
void set_preset_size(int preset_size) noexcept;

curve_editor/constants.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
namespace cved {
88
namespace global {
9-
inline constexpr int SEPARATOR_WIDTH = 8;
10-
inline constexpr size_t IDCURVE_MAX_N = 524288u;
9+
inline constexpr size_t CURVE_ID_MAX = 524288u;
1110

1211
inline constexpr auto CURVE_NAME_NORMAL = "normal";
1312
inline constexpr auto CURVE_NAME_VALUE = "value";
@@ -17,11 +16,16 @@ namespace cved {
1716
inline constexpr auto CURVE_NAME_LINEAR = "linear";
1817
inline constexpr auto CURVE_NAME_SCRIPT = "script";
1918

19+
inline constexpr auto MODIFIER_NAME_DISCRETIZATION = "discretization";
20+
inline constexpr auto MODIFIER_NAME_NOISE = "noise";
21+
inline constexpr auto MODIFIER_NAME_SINE_WAVE = "sine_wave";
22+
inline constexpr auto MODIFIER_NAME_SQUARE_WAVE = "square_wave";
23+
2024
inline constexpr auto PLUGIN_NAME = "Curve Editor";
2125
inline constexpr auto PLUGIN_VERSION = mkaul::Version{
2226
mkaul::VersionNumber{2},
2327
mkaul::PreviewType{mkaul::PreviewType::Type::Alpha},
24-
mkaul::VersionNumber{2, 0, 1}
28+
mkaul::VersionNumber{2, 1}
2529
};
2630
inline constexpr auto PLUGIN_DEVELOPER = "mimaraka";
2731
inline constexpr auto PLUGIN_TRANSLATOR = "Deepdive";

curve_editor/curve.hpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
#pragma once
22

3-
#include <mkaul/graphics.hpp>
4-
5-
6-
7-
namespace cved {
8-
// カーブ(抽象クラス)
9-
class Curve {
10-
bool locked_ = false;
11-
12-
public:
13-
virtual ~Curve() noexcept = default;
14-
15-
// カーブの値を取得
16-
virtual double curve_function(double progress, double start, double end) const noexcept = 0;
17-
virtual double get_value(double progress, double start, double end) const noexcept;
18-
double get_velocity(double progress, double start, double end) const noexcept;
19-
virtual void clear() noexcept = 0;
20-
virtual void lock() noexcept { locked_ = true; }
21-
virtual void unlock() noexcept { locked_ = false; }
22-
auto is_locked() const noexcept { return locked_; }
23-
virtual bool is_default() const noexcept = 0;
24-
constexpr virtual std::string get_type() const noexcept = 0;
25-
};
26-
} // namespace cved
3+
#include "curve_normal.hpp"
4+
#include "curve_value.hpp"
5+
#include "curve_bezier.hpp"
6+
#include "curve_elastic.hpp"
7+
#include "curve_bounce.hpp"
8+
#include "curve_linear.hpp"
9+
#include "curve_script.hpp"

curve_editor/curve.cpp renamed to curve_editor/curve_base.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "curve.hpp"
1+
#include "curve_base.hpp"
22

33

44

@@ -21,4 +21,10 @@ namespace cved {
2121
}
2222
return (get_value(prog_after, start, end) - get_value(prog_before, start, end)) * TMP;
2323
}
24+
25+
nlohmann::json Curve::create_json() const noexcept {
26+
nlohmann::json data;
27+
data["type"] = get_type();
28+
return data;
29+
}
2430
}

curve_editor/curve_base.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include "curve_id_manager.hpp"
4+
#include <mkaul/graphics.hpp>
5+
#include <nlohmann/json.hpp>
6+
7+
8+
9+
namespace cved {
10+
// カーブ(抽象クラス)
11+
class Curve {
12+
bool locked_;
13+
const uint32_t id_;
14+
15+
public:
16+
Curve() noexcept :
17+
id_{global::id_manager.create_id(this)},
18+
locked_{false}
19+
{}
20+
virtual ~Curve() noexcept {
21+
global::id_manager.remove_id(id_);
22+
}
23+
24+
// カーブの値を取得
25+
virtual double curve_function(double progress, double start, double end) const noexcept = 0;
26+
virtual double get_value(double progress, double start, double end) const noexcept;
27+
double get_velocity(double progress, double start, double end) const noexcept;
28+
virtual void clear() noexcept = 0;
29+
virtual void lock() noexcept { locked_ = true; }
30+
virtual void unlock() noexcept { locked_ = false; }
31+
auto is_locked() const noexcept { return locked_; }
32+
virtual bool is_default() const noexcept = 0;
33+
auto get_id() const noexcept { return id_; }
34+
constexpr virtual std::string get_type() const noexcept = 0;
35+
virtual nlohmann::json create_json() const noexcept;
36+
virtual bool load_json(const nlohmann::json& data) noexcept = 0;
37+
};
38+
} // namespace cved

curve_editor/curve_bezier.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ namespace cved {
6060
const double inside_sqrt = 9. * tmp3 * tmp3 - 12. * tmp4 * tmp2;
6161
const double t_1 = (-3. * tmp3 + std::sqrt(inside_sqrt)) / (6. * tmp2);
6262
const double t_2 = (-3. * tmp3 - std::sqrt(inside_sqrt)) / (6. * tmp2);
63-
if (mkaul::real_in_range(t_1, 0., 1., true)) {
63+
if (mkaul::real_in_range(t_1, 0., 1.)) {
6464
t = t_1;
6565
}
66-
else if (mkaul::real_in_range(t_2, 0., 1., true)) {
66+
else if (mkaul::real_in_range(t_2, 0., 1.)) {
6767
t = t_2;
6868
}
6969
}
@@ -86,13 +86,13 @@ namespace cved {
8686
double re_t1 = r_2 * std::cos(theta + std::numbers::pi * 2. / 3.) - tmp5;
8787
double re_t2 = r_2 * std::cos(theta + std::numbers::pi * 4. / 3.) - tmp5;
8888

89-
if (mkaul::real_in_range(re_t0, 0., 1., true)) {
89+
if (mkaul::real_in_range(re_t0, 0., 1.)) {
9090
t = re_t0;
9191
}
92-
else if (mkaul::real_in_range(re_t1, 0., 1., true)) {
92+
else if (mkaul::real_in_range(re_t1, 0., 1.)) {
9393
t = re_t1;
9494
}
95-
else if (mkaul::real_in_range(re_t2, 0., 1., true)) {
95+
else if (mkaul::real_in_range(re_t2, 0., 1.)) {
9696
t = re_t2;
9797
}
9898
}
@@ -102,10 +102,10 @@ namespace cved {
102102
double t0 = -tmp7 - tmp5;
103103
double t1 = 2. * tmp7 - tmp5;
104104

105-
if (mkaul::real_in_range(t0, 0., 1., true)) {
105+
if (mkaul::real_in_range(t0, 0., 1.)) {
106106
t = t0;
107107
}
108-
else if (mkaul::real_in_range(t1, 0., 1., true)) {
108+
else if (mkaul::real_in_range(t1, 0., 1.)) {
109109
t = t1;
110110
}
111111
}
@@ -175,7 +175,7 @@ namespace cved {
175175
DEFAULT_HANDLE_XY * width, DEFAULT_HANDLE_XY * height
176176
};
177177
handle_right_ = {
178-
- DEFAULT_HANDLE_XY * width, - DEFAULT_HANDLE_XY * height
178+
- DEFAULT_HANDLE_XY * width, - DEFAULT_HANDLE_XY * height
179179
};
180180
}
181181

@@ -298,4 +298,37 @@ namespace cved {
298298

299299
return std::format("{:.2f}, {:.2f}, {:.2f}, {:.2f}", x1, y1, x2, y2);
300300
}
301+
302+
nlohmann::json BezierCurve::create_json() const noexcept {
303+
auto data = GraphCurve::create_json();
304+
data["handle_left"] = {
305+
handle_left_.x, handle_left_.y
306+
};
307+
data["handle_right"] = {
308+
handle_right_.x, handle_right_.y
309+
};
310+
return data;
311+
}
312+
313+
bool BezierCurve::load_json(const nlohmann::json& data) noexcept {
314+
if (!GraphCurve::load_json(data)) {
315+
return false;
316+
}
317+
try {
318+
auto left_x = data.at("handle_left")[0].get<double>();
319+
auto left_y = data.at("handle_left")[1].get<double>();
320+
auto right_x = data.at("handle_right")[0].get<double>();
321+
auto right_y = data.at("handle_right")[1].get<double>();
322+
auto width = anchor_end().x - anchor_start().x;
323+
if (!mkaul::real_in_range(left_x, 0., width) or !mkaul::real_in_range(right_x, -width, 0.)) {
324+
return false;
325+
}
326+
handle_left_ = mkaul::Point{ left_x, left_y };
327+
handle_right_ = mkaul::Point{ right_x, right_y };
328+
}
329+
catch (const nlohmann::json::exception&) {
330+
return false;
331+
}
332+
return true;
333+
}
301334
}

curve_editor/curve_bezier.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace cved {
1919
bool pt_fixed = false,
2020
GraphCurve* prev = nullptr,
2121
GraphCurve* next = nullptr,
22-
mkaul::Point<double> handle_left = mkaul::Point{ 0., 0. },
23-
mkaul::Point<double> handle_right = mkaul::Point{ 0., 0. }
22+
mkaul::Point<double> handle_left = mkaul::Point{ DEFAULT_HANDLE_XY, DEFAULT_HANDLE_XY },
23+
mkaul::Point<double> handle_right = mkaul::Point{ -DEFAULT_HANDLE_XY, -DEFAULT_HANDLE_XY }
2424
) noexcept;
2525

2626
// コピーコンストラクタ
@@ -49,6 +49,9 @@ namespace cved {
4949

5050
std::string make_param() const noexcept;
5151

52+
nlohmann::json create_json() const noexcept override;
53+
bool load_json(const nlohmann::json& data) noexcept override;
54+
5255
template <class Archive>
5356
void save(Archive& archive, const std::uint32_t) const {
5457
archive(

0 commit comments

Comments
 (0)