slayerrender.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Renders FL Slayer parameters with LYNX's engine exactly like the round-68 EXEC harness drives the DLL (verification
  2. // harness, REA_rodada68 §7): slayerrender <dll> <out.f32> <length> <rate> p0,p1,…,p28 [blk=N] [tempo=T]
  3. // [note=start,key,velocity,release ...] [midi=s,st,d1,d2] [param=s,index,integer]. Writes interleaved stereo float32 (raw engine output).
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <sstream>
  7. #include <string>
  8. #include <vector>
  9. #include "core/Slayer.h"
  10. int main (int argc, char** argv)
  11. {
  12. if (argc < 6)
  13. {
  14. std::fprintf (stderr, "usage: slayerrender dll out.f32 length rate p0,…,p28 [blk=N] [tempo=T] [note=s,k,v,off ...]\n");
  15. return 2;
  16. }
  17. const int length = std::atoi (argv[3]);
  18. const double rate = std::atof (argv[4]);
  19. std::vector<int> params;
  20. {
  21. std::stringstream ss (argv[5]);
  22. std::string item;
  23. while (std::getline (ss, item, ','))
  24. params.push_back (std::atoi (item.c_str()));
  25. }
  26. lynx::slayer::RefOptions opt;
  27. std::vector<lynx::slayer::RefNote> notes;
  28. for (int i = 6; i < argc; ++i)
  29. {
  30. const std::string a = argv[i];
  31. if (a.rfind ("blk=", 0) == 0)
  32. opt.block = std::atoi (a.c_str() + 4);
  33. else if (a.rfind ("tempo=", 0) == 0)
  34. opt.tempo = std::atof (a.c_str() + 6);
  35. else if (a.rfind ("midi=", 0) == 0)
  36. {
  37. std::array<int, 4> m {};
  38. if (std::sscanf (a.c_str() + 5, "%d,%d,%d,%d", &m[0], &m[1], &m[2], &m[3]) == 4)
  39. opt.midi.push_back (m);
  40. }
  41. else if (a.rfind ("param=", 0) == 0)
  42. {
  43. std::array<int, 3> q {};
  44. if (std::sscanf (a.c_str() + 6, "%d,%d,%d", &q[0], &q[1], &q[2]) == 3)
  45. opt.params.push_back (q);
  46. }
  47. else if (a.rfind ("peek=", 0) == 0)
  48. opt.peek.push_back ((int) std::strtol (a.c_str() + 5, nullptr, 16));
  49. else if (a.rfind ("note=", 0) == 0)
  50. {
  51. lynx::slayer::RefNote n;
  52. if (std::sscanf (a.c_str() + 5, "%d,%d,%d,%d", &n.start, &n.key, &n.velocity, &n.release) >= 3)
  53. notes.push_back (n);
  54. }
  55. }
  56. const auto out = lynx::slayer::renderReference (params, argv[1], notes, rate, length, opt);
  57. if (out.empty())
  58. {
  59. std::fprintf (stderr, "not usable\n");
  60. return 1;
  61. }
  62. std::FILE* f = std::fopen (argv[2], "wb");
  63. if (f == nullptr)
  64. return 1;
  65. std::fwrite (out.data(), sizeof (float), out.size(), f);
  66. std::fclose (f);
  67. return 0;
  68. }