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.

84 lines
1.5KB

  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
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #include <sys/stat.h>
  12. #include "Recorder.h"
  13. #include "WavFile.h"
  14. #include "../globals.h"
  15. #include "../Nio/Nio.h"
  16. Recorder::Recorder(const SYNTH_T &synth_)
  17. :status(0), notetrigger(0),synth(synth_)
  18. {}
  19. Recorder::~Recorder()
  20. {
  21. if(recording() == 1)
  22. stop();
  23. }
  24. int Recorder::preparefile(std::string filename_, int overwrite)
  25. {
  26. if(!overwrite) {
  27. struct stat fileinfo;
  28. int statr;
  29. statr = stat(filename_.c_str(), &fileinfo);
  30. if(statr == 0) //file exists
  31. return 1;
  32. }
  33. Nio::waveNew(new WavFile(filename_, synth.samplerate, 2));
  34. status = 1; //ready
  35. return 0;
  36. }
  37. void Recorder::start()
  38. {
  39. notetrigger = 0;
  40. status = 2; //recording
  41. }
  42. void Recorder::stop()
  43. {
  44. Nio::waveStop();
  45. Nio::waveStart();
  46. status = 0;
  47. }
  48. void Recorder::pause()
  49. {
  50. status = 0;
  51. Nio::waveStop();
  52. }
  53. int Recorder::recording()
  54. {
  55. if((status == 2) && (notetrigger != 0))
  56. return 1;
  57. else
  58. return 0;
  59. }
  60. void Recorder::triggernow()
  61. {
  62. if(status == 2) {
  63. if(notetrigger != 1)
  64. Nio::waveStart();
  65. notetrigger = 1;
  66. }
  67. }
  68. //TODO move recorder inside nio system