drumaxxrender.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Renders a Drumaxx state with LYNX's engine like the round-67 EXEC harness drives the DLL (verification harness,
  2. // REA_rodada67 §9): drumaxxrender <state.bin> <out.f32> <length> <rate> [blk=N] [note=start,key,initVol,finalVol,cents ...]
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <fstream>
  6. #include <iterator>
  7. #include <string>
  8. #include <vector>
  9. #include "core/Drumaxx.h"
  10. int main (int argc, char** argv)
  11. {
  12. if (argc < 5)
  13. {
  14. std::fprintf (stderr, "usage: drumaxxrender state.bin out.f32 length rate [blk=N] [note=s,k,iv,fv,cents ...]\n");
  15. return 2;
  16. }
  17. std::ifstream in (argv[1], std::ios::binary);
  18. const std::vector<std::uint8_t> state ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
  19. const int length = std::atoi (argv[3]);
  20. const double rate = std::atof (argv[4]);
  21. int blk = 512;
  22. std::vector<lynx::drumaxx::RefNote> notes;
  23. for (int i = 5; i < argc; ++i)
  24. {
  25. const std::string a = argv[i];
  26. if (a.rfind ("blk=", 0) == 0)
  27. blk = std::atoi (a.c_str() + 4);
  28. else if (a.rfind ("note=", 0) == 0)
  29. {
  30. lynx::drumaxx::RefNote n;
  31. if (std::sscanf (a.c_str() + 5, "%d,%d,%lf,%lf,%lf", &n.start, &n.key, &n.initVol, &n.finalVol, &n.pitchOffset) == 5)
  32. notes.push_back (n);
  33. }
  34. }
  35. const auto out = lynx::drumaxx::renderReference (state, notes, rate, length, blk);
  36. if (out.empty())
  37. {
  38. std::fprintf (stderr, "state not usable\n");
  39. return 1;
  40. }
  41. std::FILE* f = std::fopen (argv[2], "wb");
  42. if (f == nullptr)
  43. return 1;
  44. std::fwrite (out.data(), sizeof (float), out.size(), f);
  45. std::fclose (f);
  46. return 0;
  47. }