Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Dump.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Dump.cpp - It dumps the notes to a text file
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <stdlib.h>
  18. #include <time.h>
  19. #include "Util.h"
  20. #include "Dump.h"
  21. Dump dump;
  22. Dump::Dump()
  23. {
  24. file = NULL;
  25. tick = 0;
  26. k = 0;
  27. keyspressed = 0;
  28. }
  29. Dump::~Dump()
  30. {
  31. if(file != NULL) {
  32. int duration = tick * synth->buffersize_f / synth->samplerate_f;
  33. fprintf(
  34. file,
  35. "\n# statistics: duration = %d seconds; keyspressed = %d\n\n\n\n",
  36. duration,
  37. keyspressed);
  38. fclose(file);
  39. }
  40. }
  41. void Dump::startnow()
  42. {
  43. if(file != NULL)
  44. return; //the file is already open
  45. if(config.cfg.DumpNotesToFile != 0) {
  46. if(config.cfg.DumpAppend != 0)
  47. file = fopen(config.cfg.DumpFile.c_str(), "a");
  48. else
  49. file = fopen(config.cfg.DumpFile.c_str(), "w");
  50. if(file == NULL)
  51. return;
  52. if(config.cfg.DumpAppend != 0)
  53. fprintf(file, "%s", "#************************************\n");
  54. time_t tm = time(NULL);
  55. fprintf(file, "#date/time = %s\n", ctime(&tm));
  56. fprintf(file, "#1 tick = %g milliseconds\n",
  57. synth->buffersize_f * 1000.0f / synth->samplerate_f);
  58. fprintf(file, "SAMPLERATE = %d\n", synth->samplerate);
  59. fprintf(file, "TICKSIZE = %d #samples\n", synth->buffersize);
  60. fprintf(file, "\n\nSTART\n");
  61. }
  62. }
  63. void Dump::inctick()
  64. {
  65. tick++;
  66. }
  67. void Dump::dumpnote(char chan, char note, char vel)
  68. {
  69. if(file == NULL)
  70. return;
  71. if(note == 0)
  72. return;
  73. if(vel == 0)
  74. fprintf(file, "n %d -> %d %d \n", tick, chan, note); //note off
  75. else
  76. fprintf(file, "N %d -> %d %d %d \n", tick, chan, note, vel); //note on
  77. if(vel != 0)
  78. keyspressed++;
  79. #ifndef JACKAUDIOOUT
  80. if(k++ > 25) {
  81. fflush(file);
  82. k = 0;
  83. }
  84. #endif
  85. }
  86. void Dump::dumpcontroller(char chan, unsigned int type, int par)
  87. {
  88. if(file == NULL)
  89. return;
  90. switch(type) {
  91. case C_pitchwheel:
  92. fprintf(file, "P %d -> %d %d\n", tick, chan, par);
  93. break;
  94. default:
  95. fprintf(file, "C %d -> %d %d %d\n", tick, chan, type, par);
  96. break;
  97. }
  98. #ifndef JACKAUDIOOUT
  99. if(k++ > 25) {
  100. fflush(file);
  101. k = 0;
  102. }
  103. #endif
  104. }