zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

Recorder.cpp (2200B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   Recorder.cpp - Records sound to a file
      5   Copyright (C) 2002-2005 Nasca Octavian Paul
      6   Author: Nasca Octavian Paul
      7 
      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.
     12 */
     13 
     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"
     21 
     22 namespace zyn {
     23 
     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}
     42 };
     43 #undef rObject
     44 
     45 Recorder::Recorder(const SYNTH_T &synth_)
     46     :status(0), notetrigger(0),synth(synth_)
     47 {}
     48 
     49 Recorder::~Recorder()
     50 {
     51     if(recording() == 1)
     52         stop();
     53 }
     54 
     55 int Recorder::preparefile(std::string filename_, int overwrite)
     56 {
     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;
     63     }
     64 
     65     Nio::waveNew(new WavFile(filename_, synth.samplerate, 2));
     66 
     67     status = 1; //ready
     68 
     69     return 0;
     70 }
     71 
     72 void Recorder::start()
     73 {
     74     notetrigger = 0;
     75     status      = 2; //recording
     76 }
     77 
     78 void Recorder::stop()
     79 {
     80     Nio::waveStop();
     81     Nio::waveStart();
     82     status = 0;
     83 }
     84 
     85 void Recorder::pause()
     86 {
     87     status = 0;
     88     Nio::waveStop();
     89 }
     90 
     91 int Recorder::recording()
     92 {
     93     if((status == 2) && (notetrigger != 0))
     94         return 1;
     95     else
     96         return 0;
     97 }
     98 
     99 void Recorder::triggernow()
    100 {
    101     if(status == 2) {
    102         if(notetrigger != 1)
    103             Nio::waveStart();
    104         notetrigger = 1;
    105     }
    106 }
    107 
    108 //TODO move recorder inside nio system
    109 }