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.

93 lines
2.0KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Recorder.cpp - Records sound to a 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 <sys/stat.h>
  18. #include "Recorder.h"
  19. #include "WavFile.h"
  20. #include "../globals.h"
  21. #include "../Nio/Nio.h"
  22. Recorder::Recorder(const SYNTH_T &synth_)
  23. :status(0), notetrigger(0),synth(synth_)
  24. {}
  25. Recorder::~Recorder()
  26. {
  27. if(recording() == 1)
  28. stop();
  29. }
  30. int Recorder::preparefile(std::string filename_, int overwrite)
  31. {
  32. if(!overwrite) {
  33. struct stat fileinfo;
  34. int statr;
  35. statr = stat(filename_.c_str(), &fileinfo);
  36. if(statr == 0) //file exists
  37. return 1;
  38. }
  39. Nio::waveNew(new WavFile(filename_, synth.samplerate, 2));
  40. status = 1; //ready
  41. return 0;
  42. }
  43. void Recorder::start()
  44. {
  45. notetrigger = 0;
  46. status = 2; //recording
  47. }
  48. void Recorder::stop()
  49. {
  50. Nio::waveStop();
  51. Nio::waveStart();
  52. status = 0;
  53. }
  54. void Recorder::pause()
  55. {
  56. status = 0;
  57. Nio::waveStop();
  58. }
  59. int Recorder::recording()
  60. {
  61. if((status == 2) && (notetrigger != 0))
  62. return 1;
  63. else
  64. return 0;
  65. }
  66. void Recorder::triggernow()
  67. {
  68. if(status == 2) {
  69. if(notetrigger != 1)
  70. Nio::waveStart();
  71. notetrigger = 1;
  72. }
  73. }
  74. //TODO move recorder inside nio system