improve Node/Network to use nf7::FileBase
This commit is contained in:
parent
4e3cd1463e
commit
e01039b74e
@ -31,7 +31,7 @@ class FileBase : public nf7::File {
|
||||
nf7::File(t, env), feats_(std::move(feats)) {
|
||||
}
|
||||
|
||||
nf7::File* Find(std::string_view name) const noexcept override final {
|
||||
nf7::File* Find(std::string_view name) const noexcept override {
|
||||
for (auto feat : feats_) {
|
||||
if (auto ret = feat->Find(name)) {
|
||||
return ret;
|
||||
@ -39,12 +39,12 @@ class FileBase : public nf7::File {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
void Handle(const nf7::File::Event& ev) noexcept override final {
|
||||
void Handle(const nf7::File::Event& ev) noexcept override {
|
||||
for (auto feat : feats_) {
|
||||
feat->Handle(ev);
|
||||
}
|
||||
}
|
||||
void Update() noexcept override final {
|
||||
void Update() noexcept override {
|
||||
for (auto feat : feats_) {
|
||||
feat->Update();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
namespace nf7::gui {
|
||||
|
||||
std::string GetContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
inline std::string GetContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
auto f = ctx.env().GetFile(ctx.initiator());
|
||||
|
||||
const auto initiator =
|
||||
@ -22,7 +22,7 @@ std::string GetContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
return initiator + " " + buf;
|
||||
}
|
||||
|
||||
std::string GetParentContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
inline std::string GetParentContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
if (auto parent = ctx.parent()) {
|
||||
return nf7::gui::GetContextDisplayName(*parent);
|
||||
} else if (ctx.depth() == 0) {
|
||||
@ -32,7 +32,7 @@ std::string GetParentContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void ContextStack(const nf7::Context& ctx) noexcept {
|
||||
inline void ContextStack(const nf7::Context& ctx) noexcept {
|
||||
for (auto p = ctx.parent(); p; p = p->parent()) {
|
||||
auto f = ctx.env().GetFile(p->initiator());
|
||||
|
||||
|
@ -36,8 +36,10 @@ class Popup {
|
||||
template <typename T>
|
||||
class PopupWrapper : public nf7::FileBase::Feature, private nf7::gui::Popup {
|
||||
public:
|
||||
PopupWrapper(const char* name, T& content, ImGuiWindowFlags flags = 0) noexcept :
|
||||
nf7::gui::Popup(name, flags), content_(&content) {
|
||||
PopupWrapper() = delete;
|
||||
PopupWrapper(const char* name, const char* title, T& content,
|
||||
ImGuiWindowFlags flags = 0) noexcept :
|
||||
nf7::gui::Popup(name, flags), title_(title), content_(&content) {
|
||||
}
|
||||
PopupWrapper(const PopupWrapper&) = delete;
|
||||
PopupWrapper(PopupWrapper&&) = delete;
|
||||
@ -50,6 +52,7 @@ class PopupWrapper : public nf7::FileBase::Feature, private nf7::gui::Popup {
|
||||
}
|
||||
void Update() noexcept override {
|
||||
if (nf7::gui::Popup::Begin()) {
|
||||
ImGui::TextUnformatted(title_);
|
||||
if (content_->Update()) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
onDone();
|
||||
@ -62,6 +65,8 @@ class PopupWrapper : public nf7::FileBase::Feature, private nf7::gui::Popup {
|
||||
std::function<void()> onDone = []() { };
|
||||
|
||||
private:
|
||||
const char* title_;
|
||||
|
||||
T* const content_;
|
||||
};
|
||||
|
||||
|
@ -61,14 +61,14 @@ class Life<T>::Ref final {
|
||||
}
|
||||
}
|
||||
|
||||
operator bool() noexcept {
|
||||
return !!data_;
|
||||
operator bool() const noexcept {
|
||||
return !!data_->ptr;
|
||||
}
|
||||
T& operator*() noexcept {
|
||||
T& operator*() const noexcept {
|
||||
assert(data_->ptr);
|
||||
return *data_->ptr;
|
||||
}
|
||||
T* operator->() noexcept {
|
||||
T* operator->() const noexcept {
|
||||
return &**this;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ namespace nf7 {
|
||||
|
||||
class MementoRecorder final {
|
||||
public:
|
||||
MementoRecorder() = delete;
|
||||
MementoRecorder(nf7::Memento* mem) noexcept :
|
||||
mem_(mem), tag_(mem? mem->Save(): nullptr) {
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_node.hh"
|
||||
#include "common/gui_resizer.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/node.hh"
|
||||
#include "common/ptr_selector.hh"
|
||||
#include "common/value.hh"
|
||||
@ -54,7 +55,8 @@ class Imm final : public nf7::File, public nf7::DirItem, public nf7::Node {
|
||||
};
|
||||
|
||||
Imm(Env& env, Type type = kInteger, nf7::Value&& v = nf7::Value::Integer {0}) noexcept :
|
||||
File(kType, env), DirItem(DirItem::kNone), mem_(*this, {type, std::move(v)}) {
|
||||
nf7::File(kType, env), nf7::DirItem(DirItem::kNone),
|
||||
life_(*this), mem_(*this, {type, std::move(v)}) {
|
||||
input_ = {"in"};
|
||||
output_ = {"out"};
|
||||
}
|
||||
@ -80,6 +82,7 @@ class Imm final : public nf7::File, public nf7::DirItem, public nf7::Node {
|
||||
std::shared_ptr<Node::Lambda> CreateLambda(const std::shared_ptr<Node::Lambda>&) noexcept override;
|
||||
|
||||
void UpdateNode(Node::Editor&) noexcept override;
|
||||
void UpdateEditor(Node::Editor&, float w) noexcept;
|
||||
|
||||
File::Interface* interface(const std::type_info& t) noexcept override {
|
||||
return InterfaceSelector<
|
||||
@ -87,6 +90,8 @@ class Imm final : public nf7::File, public nf7::DirItem, public nf7::Node {
|
||||
}
|
||||
|
||||
private:
|
||||
nf7::Life<Imm> life_;
|
||||
|
||||
struct Data final {
|
||||
public:
|
||||
Data(Type t, nf7::Value&& v) noexcept : type(t), value(std::move(v)) {
|
||||
@ -97,7 +102,7 @@ class Imm final : public nf7::File, public nf7::DirItem, public nf7::Node {
|
||||
};
|
||||
nf7::GenericMemento<Data> mem_;
|
||||
|
||||
void UpdateEditor(Node::Editor&, float w) noexcept;
|
||||
|
||||
void ChangeType(Type) noexcept;
|
||||
|
||||
static const char* StringifyType(Type t) noexcept {
|
||||
@ -120,20 +125,20 @@ class Imm::Lambda final : public Node::Lambda,
|
||||
public std::enable_shared_from_this<Imm::Lambda> {
|
||||
public:
|
||||
Lambda(Imm& f, const std::shared_ptr<Node::Lambda>& parent) noexcept :
|
||||
Node::Lambda(f, parent), imm_(&f) {
|
||||
Node::Lambda(f, parent), f_(f.life_) {
|
||||
}
|
||||
|
||||
void Handle(std::string_view name, const nf7::Value&,
|
||||
const std::shared_ptr<Node::Lambda>& caller) noexcept override {
|
||||
if (!f_) return;
|
||||
if (name == "in") {
|
||||
if (!env().GetFile(initiator())) return;
|
||||
caller->Handle("out", imm_->mem_.data().value, shared_from_this());
|
||||
caller->Handle("out", f_->mem_.data().value, shared_from_this());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Imm* const imm_;
|
||||
nf7::Life<Imm>::Ref f_;
|
||||
};
|
||||
std::shared_ptr<Node::Lambda> Imm::CreateLambda(
|
||||
const std::shared_ptr<Node::Lambda>& parent) noexcept {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,7 @@
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_dnd.hh"
|
||||
#include "common/gui_node.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
#include "common/memento.hh"
|
||||
#include "common/node.hh"
|
||||
@ -48,7 +49,8 @@ class Ref final : public nf7::File, public nf7::Node {
|
||||
Ref(Env& env, Path&& path = {"initial", "path"},
|
||||
std::vector<std::string>&& in = {},
|
||||
std::vector<std::string>&& out = {}) noexcept :
|
||||
File(kType, env),
|
||||
nf7::File(kType, env),
|
||||
life_(*this),
|
||||
log_(std::make_shared<nf7::LoggerRef>()),
|
||||
mem_(*this, {*this, std::move(path), std::move(in), std::move(out)}) {
|
||||
}
|
||||
@ -98,6 +100,8 @@ class Ref final : public nf7::File, public nf7::Node {
|
||||
}
|
||||
|
||||
private:
|
||||
nf7::Life<Ref> life_;
|
||||
|
||||
std::shared_ptr<nf7::LoggerRef> log_;
|
||||
|
||||
const char* popup_ = nullptr;
|
||||
@ -167,12 +171,12 @@ class Ref::Lambda final : public Node::Lambda,
|
||||
static constexpr size_t kMaxDepth = 1024;
|
||||
|
||||
Lambda(Ref& f, const std::shared_ptr<Node::Lambda>& parent) :
|
||||
Node::Lambda(f, parent), ref_(&f), log_(f.log_) {
|
||||
Node::Lambda(f, parent), f_(f.life_), log_(f.log_) {
|
||||
}
|
||||
|
||||
void Handle(std::string_view name, const Value& v,
|
||||
const std::shared_ptr<Node::Lambda>& caller) noexcept override {
|
||||
if (!env().GetFile(initiator())) return;
|
||||
if (!f_) return;
|
||||
|
||||
auto parent = this->parent();
|
||||
if (!parent) return;
|
||||
@ -186,7 +190,7 @@ class Ref::Lambda final : public Node::Lambda,
|
||||
log_->Error("stack overflow");
|
||||
return;
|
||||
}
|
||||
base_ = ref_->target().CreateLambda(shared_from_this());
|
||||
base_ = f_->target().CreateLambda(shared_from_this());
|
||||
}
|
||||
base_->Handle(name, v, shared_from_this());
|
||||
}
|
||||
@ -199,7 +203,8 @@ class Ref::Lambda final : public Node::Lambda,
|
||||
}
|
||||
|
||||
private:
|
||||
Ref* const ref_;
|
||||
nf7::Life<Ref>::Ref f_;
|
||||
|
||||
std::shared_ptr<nf7::LoggerRef> log_;
|
||||
|
||||
std::shared_ptr<Node::Lambda> base_;
|
||||
|
@ -49,8 +49,11 @@ class Call final : public nf7::FileBase, public nf7::Sequencer {
|
||||
Sequencer::kParamPanel),
|
||||
life_(*this),
|
||||
callee_(*this, "callee", callee),
|
||||
callee_editor_(*this, [](auto& t) { return t.flags().contains("nf7::Node"); }),
|
||||
callee_popup_("CalleeEditorPopup", callee_editor_),
|
||||
callee_editor_(*this,
|
||||
[](auto& t) { return t.flags().contains("nf7::Node"); }),
|
||||
callee_popup_("CalleeEditorPopup",
|
||||
"Sequencer/Call: replacing callee...",
|
||||
callee_editor_),
|
||||
mem_(*this, Data {*this, expects}){
|
||||
callee_.onChildMementoChange = [this]() {
|
||||
mem_.Commit();
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "common/gui_popup.hh"
|
||||
#include "common/gui_timeline.hh"
|
||||
#include "common/gui_window.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/memento.hh"
|
||||
#include "common/memento_recorder.hh"
|
||||
#include "common/node.hh"
|
||||
@ -71,6 +72,7 @@ class TL final : public nf7::File, public nf7::DirItem, public nf7::Node {
|
||||
ItemId next = 1,
|
||||
const nf7::gui::Window* win = nullptr) noexcept :
|
||||
nf7::File(kType, env), nf7::DirItem(nf7::DirItem::kMenu),
|
||||
life_(*this),
|
||||
length_(length), layers_(std::move(layers)), next_(next),
|
||||
win_(*this, "Timeline Editor", win), tl_("timeline"),
|
||||
popup_add_item_(*this), popup_config_(*this) {
|
||||
@ -108,6 +110,8 @@ class TL final : public nf7::File, public nf7::DirItem, public nf7::Node {
|
||||
}
|
||||
|
||||
private:
|
||||
nf7::Life<TL> life_;
|
||||
|
||||
nf7::SquashedHistory history_;
|
||||
|
||||
std::shared_ptr<TL::Lambda> lambda_;
|
||||
@ -588,7 +592,7 @@ class TL::Lambda final : public Node::Lambda,
|
||||
public:
|
||||
Lambda() = delete;
|
||||
Lambda(TL& f, const std::shared_ptr<Node::Lambda>& parent) noexcept :
|
||||
Node::Lambda(f, parent), owner_(&f) {
|
||||
Node::Lambda(f, parent), owner_(f.life_) {
|
||||
}
|
||||
|
||||
void Handle(std::string_view, const nf7::Value&,
|
||||
@ -608,7 +612,7 @@ class TL::Lambda final : public Node::Lambda,
|
||||
|
||||
std::pair<TL::Item*, std::shared_ptr<Sequencer::Lambda>> GetNext(
|
||||
uint64_t& layer_idx, uint64_t layer_until, uint64_t t) noexcept {
|
||||
if (aborted_ || !env().GetFile(initiator())) {
|
||||
if (aborted_ || !owner_) {
|
||||
return {nullptr, nullptr};
|
||||
}
|
||||
layer_until = std::min(layer_until, owner_->layers_.size());
|
||||
@ -637,9 +641,7 @@ class TL::Lambda final : public Node::Lambda,
|
||||
}
|
||||
}
|
||||
void EmitResults(const std::unordered_map<std::string, nf7::Value>& vars) noexcept {
|
||||
if (!env().GetFile(initiator())) {
|
||||
return;
|
||||
}
|
||||
if (!owner_) return;
|
||||
auto caller = parent();
|
||||
for (const auto& name : owner_->seq_outputs_) {
|
||||
auto itr = vars.find(name);
|
||||
@ -661,7 +663,7 @@ class TL::Lambda final : public Node::Lambda,
|
||||
}
|
||||
|
||||
private:
|
||||
TL* const owner_;
|
||||
nf7::Life<TL>::Ref const owner_;
|
||||
|
||||
std::atomic<bool> aborted_ = false;
|
||||
|
||||
@ -787,7 +789,7 @@ class TL::Session final : public Sequencer::Session,
|
||||
void TL::Lambda::Handle(std::string_view name, const nf7::Value& v,
|
||||
const std::shared_ptr<Node::Lambda>&) noexcept {
|
||||
if (name == "_exec") {
|
||||
if (!env().GetFile(initiator())) return;
|
||||
if (!owner_) return;
|
||||
const auto t_max = owner_->length_-1;
|
||||
|
||||
uint64_t t;
|
||||
|
Loading…
x
Reference in New Issue
Block a user