implement Sequencer/Timeline's system variable instead of Session::info()

This commit is contained in:
falsycat 2022-08-18 10:31:10 +09:00
parent da4e566ef9
commit b7085b6ec5
3 changed files with 12 additions and 19 deletions

View File

@ -21,8 +21,6 @@ class Sequencer : public nf7::File::Interface {
class Session;
class Lambda;
struct Period { uint64_t begin, end; };
enum Flag : uint8_t {
kNone = 0,
kCustomItem = 1 << 0, // uses UpdateItem() to draw an item on timeline if enable
@ -98,14 +96,6 @@ class Sequencer::Session {
// thread-safe
virtual void Finish() noexcept = 0;
struct Info final {
public:
uint64_t time;
uint64_t begin;
uint64_t end;
};
virtual const Info& info() const noexcept = 0;
};
class Sequencer::Lambda : public nf7::Context {

View File

@ -175,8 +175,6 @@ class Adaptor::Session final : public nf7::Sequencer::Session {
parent_ = nullptr;
}
const Info& info() const noexcept override { return parent_->info(); }
private:
std::shared_ptr<nf7::Sequencer::Session> parent_;

View File

@ -736,10 +736,7 @@ class TL::Session final : public Sequencer::Session,
if (item) {
assert(lambda);
const auto& t = item->timing();
info_.time = time_;
info_.begin = t.begin();
info_.end = t.end();
ResetSystemVar(*item);
lambda->Run(shared_from_this());
last_active_ = nf7::Env::Clock::now();
@ -765,8 +762,6 @@ class TL::Session final : public Sequencer::Session,
}
}
const Info& info() const noexcept override { return info_; }
std::chrono::system_clock::time_point lastActive() const noexcept { return last_active_; }
bool done() const noexcept { return done_; }
uint64_t time() const noexcept { return time_; }
@ -786,7 +781,17 @@ class TL::Session final : public Sequencer::Session,
bool done_ = false;
uint64_t layer_ = 0;
Info info_;
void ResetSystemVar(TL::Item& item) noexcept {
const auto& t = item.timing();
vars_["_begin"] = static_cast<nf7::Value::Integer>(t.begin());
vars_["_end"] = static_cast<nf7::Value::Integer>(t.end());
vars_["_time"] = static_cast<nf7::Value::Integer>(time_);
vars_["_timef"] =
static_cast<nf7::Value::Scalar>(time_-t.begin()) /
static_cast<nf7::Value::Scalar>(t.dur());
}
};
void TL::Lambda::Handle(std::string_view name, const nf7::Value& v,
const std::shared_ptr<Node::Lambda>&) noexcept {