QJackRcd 1.0.4
Simple turnkey Jack recorder
recorder.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  Copyright (C) 2011 - Olivier ROUITS <olivier.rouits@free.fr>
00003 
00004  This program is free software; you can redistribute it and/or modify
00005  it under the terms of the GNU General Public License as published by
00006  the Free Software Foundation; either version 2 of the License, or
00007  (at your option) any later version.
00008 
00009  This program is distributed in the hope that it will be useful,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  GNU General Public License for more details.
00013 
00014  You should have received a copy of the GNU General Public License
00015  along with this program; if not, write to the
00016  Free Software Foundation, Inc.,
00017  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  ***************************************************************************/
00027 #ifndef RECORDER_H
00028 #define RECORDER_H
00029 
00030 #include <jack/jack.h>
00031 #include <jack/ringbuffer.h>
00032 #include <sndfile.h>
00033 #include <QString>
00034 #include <QThread>
00035 #include <QMutex>
00036 #include <QWaitCondition>
00037 #include <QQueue>
00038 #include <QDir>
00039 
00040 
00046 class Recorder: public QThread
00047 {
00048     Q_OBJECT
00049 
00050     QString jackName;
00051     QQueue<jack_port_id_t> jackPortRegQueue;
00052 
00053     SNDFILE *sndFile;
00054     float *currentBuffer;
00055     float *alternateBuffer;
00056 
00057     QDir dirPath;
00058     int diskSpace;
00059 
00060     QString currentFilePath;
00061     QString processFilePath;
00062     QString processCmdLine;
00063 
00064     QMutex dataReadyMutex;
00065     QWaitCondition dataReady;
00066 
00067     jack_client_t *jackClient;
00068     jack_ringbuffer_t *jackRingBuffer;
00069     jack_port_t *jackInputPort1;
00070     jack_port_t *jackInputPort2;
00071 
00072     float pauseLevel;
00073     int pauseActivationMax;
00074     int pauseActivationDelay;
00075     int pauseActivationCount;
00076     bool splitMode;
00077 
00078     float leftLevel;
00079     float rightLevel;
00080 
00081     int overruns;
00082     int sampleRate;
00083 
00084     bool recording;
00085     bool shutdown;
00086 
00087     void computeDiskSpace();
00088     void computeFilePath();
00089     void computePauseActivationMax();
00090 
00091     void newFile();
00092     void closeFile();
00093     void processFile();
00094 
00095     void switchBuffer();
00096     void readCurrentBuffer();
00097     void computeCurrentBufferLevels();
00098     void writeAlternateBuffer();
00099     void fadeoutAlternateBuffer();
00100     void fadeinAlternateBuffer();
00101 
00102     void checkJackAutoConnect();
00103     QString getJackConnections(jack_port_t* jackPort);
00104     void setJackConnections(QString cnxLine, jack_port_t* jackPort);
00105 
00106 protected:
00107 
00108     void run();
00109     bool isFile() { return sndFile != NULL; }
00110     bool isPauseLevel() { return leftLevel <= pauseLevel && rightLevel <= pauseLevel; }
00111     void setShutdown(bool value) { shutdown = value; }
00112 
00113 public:
00114 
00115     Recorder(QString jackName);
00116     ~Recorder();
00117 
00118     int jackProcess(jack_nframes_t nframes);
00119     int jackSync(jack_transport_state_t state, jack_position_t *pos);
00120     void jackPortReg(jack_port_id_t port_id, int reg);
00121     void jackShutdown();
00122 
00123     QString getJackConnections1() {return getJackConnections(jackInputPort1);}
00124     QString getJackConnections2() {return getJackConnections(jackInputPort2);}
00125     void setJackConnections1(QString cnxLine) {setJackConnections(cnxLine, jackInputPort1);}
00126     void setJackConnections2(QString cnxLine) {setJackConnections(cnxLine, jackInputPort2);}
00127 
00128     QString getJackName() {return jackName; }
00129     bool isShutdown() { return shutdown; }
00130     void setRecording(bool value) { recording = value; }
00131     bool isRecording() { return recording; }
00132     bool isPaused() { return pauseActivationCount > pauseActivationMax; }
00133     void setPauseActivationDelay(int secs) {pauseActivationDelay = secs;}
00134     int getPauseActivationDelay() {return pauseActivationDelay;}
00135     void setSplitMode(bool split) { splitMode = split; }
00136     bool isSplitMode() { return splitMode; }
00137     QString getCurrentFilePath() { return currentFilePath; }
00138     QString getProcessFilePath() { return processFilePath; }
00139     void setProcessCmdLine(QString cmdLine) { processCmdLine = cmdLine; }
00140     QString getProcessCmdLine() { return processCmdLine; }
00141     int getDiskSpace() { return diskSpace; }
00142     int getOverruns() { return overruns; }
00143     void setPauseLevel(float level) { pauseLevel = level; }
00144     float getPauseLevel() { return pauseLevel; }
00145     float getLeftLevel() { return leftLevel; }
00146     float getRightLevel() { return rightLevel; }
00147 
00148 signals:
00149     void statusChanged();
00150 };
00151 
00152 #endif // RECORDER_H
 All Classes Files Functions Defines