Change ALSA device default to 'default' from hw:0
[zynaddsubfx-code.git] / src / Misc / Recorder.cpp
blobad2b17b852b7fc8a444235a398a78bbb81889dcf
1 /*
2 ZynAddSubFX - a software synthesizer
4 Recorder.cpp - Records sound to a file
5 Copyright (C) 2002-2005 Nasca Octavian Paul
6 Author: Nasca Octavian Paul
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
14 #include <rtosc/ports.h>
15 #include <rtosc/port-sugar.h>
16 #include <sys/stat.h>
17 #include "Recorder.h"
18 #include "WavFile.h"
19 #include "../globals.h"
20 #include "../Nio/Nio.h"
22 namespace zyn {
24 #define rObject Recorder
25 const rtosc::Ports Recorder::ports = {
26 {"preparefile:s", rDoc("Init WAV file"), 0,
27 rBOIL_BEGIN
28 obj->preparefile(rtosc_argument(msg, 0).s, 1);
29 rBOIL_END },
30 {"start:", rDoc("Start recording"), 0,
31 rBOIL_BEGIN
32 obj->start();
33 rBOIL_END },
34 {"stop:", rDoc("Stop recording"), 0,
35 rBOIL_BEGIN
36 obj->stop();
37 rBOIL_END },
38 {"pause:", rDoc("Pause recording"), 0,
39 rBOIL_BEGIN;
40 obj->pause();
41 rBOIL_END}
43 #undef rObject
45 Recorder::Recorder(const SYNTH_T &synth_)
46 :status(0), notetrigger(0),synth(synth_)
49 Recorder::~Recorder()
51 if(recording() == 1)
52 stop();
55 int Recorder::preparefile(std::string filename_, int overwrite)
57 if(!overwrite) {
58 struct stat fileinfo;
59 int statr;
60 statr = stat(filename_.c_str(), &fileinfo);
61 if(statr == 0) //file exists
62 return 1;
65 Nio::waveNew(new WavFile(filename_, synth.samplerate, 2));
67 status = 1; //ready
69 return 0;
72 void Recorder::start()
74 notetrigger = 0;
75 status = 2; //recording
78 void Recorder::stop()
80 Nio::waveStop();
81 Nio::waveStart();
82 status = 0;
85 void Recorder::pause()
87 status = 0;
88 Nio::waveStop();
91 int Recorder::recording()
93 if((status == 2) && (notetrigger != 0))
94 return 1;
95 else
96 return 0;
99 void Recorder::triggernow()
101 if(status == 2) {
102 if(notetrigger != 1)
103 Nio::waveStart();
104 notetrigger = 1;
108 //TODO move recorder inside nio system