48 lines
1.8 KiB
C++
48 lines
1.8 KiB
C++
#include <cstdlib>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <memory>
|
|
#include <raylib.h>
|
|
#include <rlgl.h>
|
|
#include <luma.hpp>
|
|
#include <vamp_zero/library.hpp>
|
|
#include <vamp_zero/score.hpp>
|
|
|
|
namespace {
|
|
class score_view final : public luma::control {
|
|
public:
|
|
score_view(luma::application& app, vamp_zero::score_document score, std::string output, std::size_t page, bool& saved)
|
|
: app_{app}, score_{std::move(score)}, output_{std::move(output)}, page_{page}, saved_{saved} {}
|
|
auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override { return {976,484}; }
|
|
auto draw(luma::draw_context& context, luma::theme const&) const -> void override {
|
|
vamp_zero::draw_score_page(context, bounds(), score_, page_);
|
|
rlDrawRenderBatchActive();
|
|
auto image = LoadImageFromScreen();
|
|
saved_ = ExportImage(image, output_.c_str());
|
|
UnloadImage(image);
|
|
app_.request_stop();
|
|
}
|
|
private:
|
|
luma::application& app_;
|
|
vamp_zero::score_document score_;
|
|
std::string output_;
|
|
std::size_t page_;
|
|
bool& saved_;
|
|
};
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc < 3) { std::cerr << "Usage: vamp-render-score input.json output.png [page]\n"; return 2; }
|
|
auto input = std::ifstream{argv[1]};
|
|
auto json = std::string{std::istreambuf_iterator<char>{input},std::istreambuf_iterator<char>{}};
|
|
auto score = vamp_zero::parse_score_document(json,argv[1]);
|
|
if (!score) { std::cerr << score.error().describe() << '\n'; return 1; }
|
|
auto app = luma::application{{.title="Notation Regression",.display={.width=976,.height=484,.target_fps=30,.fullscreen=false}}};
|
|
auto saved = false;
|
|
auto root = app.set_root(std::make_unique<score_view>(app,std::move(*score),argv[2],argc>3 ? std::stoul(argv[3]) : 0,saved));
|
|
if (!root) return 1;
|
|
auto ran = app.run();
|
|
return ran && saved ? 0 : 1;
|
|
}
|