Skip to content

Commit

Permalink
save the state for the undo plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
abique committed Sep 17, 2024
1 parent 6bc4f1a commit 02933b2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/core-plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ namespace clap {
ClapOStream os(stream);
yas::binary_oarchive ar(os);
ar & _parameters;

std::vector<uint8_t> extra = stateSaveExtra();
ar & extra;
} catch (...) {
return false;
}
Expand All @@ -138,6 +141,11 @@ namespace clap {
#endif
yas::binary_iarchive ar(is);
ar & _parameters;

std::vector<uint8_t> extra;
ar & extra;
if (!stateLoadExtra(extra))
return false;
} catch (...) {
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/core-plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <memory>
#include <optional>

#include <yas/binary_iarchive.hpp>
#include <yas/binary_oarchive.hpp>

#include <clap/helpers/param-queue.hh>
#include <clap/helpers/plugin.hh>
#include <clap/helpers/reducing-param-queue.hxx>
Expand Down Expand Up @@ -148,6 +151,9 @@ namespace clap {
bool stateSave(const clap_ostream *stream) noexcept override;
bool stateLoad(const clap_istream *stream) noexcept override;

virtual std::vector<uint8_t> stateSaveExtra() noexcept { return {}; }
virtual bool stateLoadExtra(const std::vector<uint8_t>& data) noexcept { return true; }

#ifndef CLAP_PLUGINS_HEADLESS
//-----------------//
// clap_plugin_gui //
Expand Down
12 changes: 12 additions & 0 deletions plugins/plugs/undo-test/undo-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,16 @@ namespace clap {
super::onGuiInvoke(method, args);
}
#endif

std::vector<uint8_t> UndoTest::stateSaveExtra() noexcept {
return std::vector<uint8_t>((const uint8_t *)&_state, (const uint8_t *)(&_state + 1));
}

bool UndoTest::stateLoadExtra(const std::vector<uint8_t> &data) noexcept {
if (data.size() != sizeof(_state))
return false;
_state = *(const uint32_t *)data.data();
return true;
}

} // namespace clap
3 changes: 3 additions & 0 deletions plugins/plugs/undo-test/undo-test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace clap {

bool init() noexcept override;

std::vector<uint8_t> stateSaveExtra() noexcept override;
bool stateLoadExtra(const std::vector<uint8_t> &data) noexcept override;

bool implementsUndo() const noexcept override;
void undoGetDeltaProperties(clap_undo_delta_properties_t *properties) noexcept override;
bool undoCanUseDeltaFormatVersion(clap_id format_version) noexcept override;
Expand Down

0 comments on commit 02933b2

Please sign in to comment.