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.

92 lines
1.9KB

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