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.

87 lines
1.6KB

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