![]() |
Mixxx
|
00001 /*************************************************************************** 00002 enginebuffer.h - description 00003 ------------------- 00004 begin : Wed Feb 20 2002 00005 copyright : (C) 2002 by Tue and Ken Haste Andersen 00006 email : 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef ENGINEBUFFER_H 00019 #define ENGINEBUFFER_H 00020 00021 #include <qapplication.h> 00022 #include <QMutex> 00023 #include "defs.h" 00024 #include "engine/engineobject.h" 00025 #include "trackinfoobject.h" 00026 #include "configobject.h" 00027 #include "rotary.h" 00028 //for the writer 00029 //#include <QtCore> 00030 00031 class EngineControl; 00032 class BpmControl; 00033 class RateControl; 00034 class LoopingControl; 00035 class ReadAheadManager; 00036 class ControlObject; 00037 class ControlPushButton; 00038 class ControlObjectThreadMain; 00039 class ControlBeat; 00040 class ControlTTRotary; 00041 class ControlPotmeter; 00042 class CachingReader; 00043 class EngineBufferScale; 00044 class EngineBufferScaleLinear; 00045 class EngineBufferScaleST; 00046 class EngineWorkerScheduler; 00047 00048 struct Hint; 00049 00054 // Length of audio beat marks in samples 00055 const int audioBeatMarkLen = 40; 00056 00057 // Temporary buffer length 00058 const int kiTempLength = 200000; 00059 00060 // Rate at which the playpos slider is updated (using a sample rate of 44100 Hz): 00061 const int kiUpdateRate = 10; 00062 // Number of kiUpdateRates that go by before we update BPM. 00063 const int kiBpmUpdateRate = 40 / kiUpdateRate; //about 2.5 updates per sec 00064 00065 // End of track mode constants 00066 const int TRACK_END_MODE_STOP = 0; 00067 const int TRACK_END_MODE_NEXT = 1; 00068 const int TRACK_END_MODE_LOOP = 2; 00069 const int TRACK_END_MODE_PING = 3; 00070 00071 //vinyl status constants 00072 //XXX: move this to vinylcontrol.h once thread startup is moved 00073 const int VINYL_STATUS_DISABLED = 0; 00074 const int VINYL_STATUS_OK = 1; 00075 const int VINYL_STATUS_WARNING = 2; 00076 const int VINYL_STATUS_ERROR = 3; 00077 00078 const int ENGINE_RAMP_DOWN = -1; 00079 const int ENGINE_RAMP_NONE = 0; 00080 const int ENGINE_RAMP_UP = 1; 00081 00082 //const int kiRampLength = 3; 00083 00084 class EngineBuffer : public EngineObject 00085 { 00086 Q_OBJECT 00087 public: 00088 EngineBuffer(const char *_group, ConfigObject<ConfigValue> *_config); 00089 ~EngineBuffer(); 00090 bool getPitchIndpTimeStretch(void); 00091 00092 void bindWorkers(EngineWorkerScheduler* pWorkerScheduler); 00093 00094 // Add an engine control to the EngineBuffer 00095 void addControl(EngineControl* pControl); 00096 00098 double getRate(); 00100 double getBpm(); 00102 void setOtherEngineBuffer(EngineBuffer *); 00103 00106 void setNewPlaypos(double); 00107 00108 void process(const CSAMPLE *pIn, const CSAMPLE *pOut, const int iBufferSize); 00109 00110 const char* getGroup(); 00111 bool isTrackLoaded(); 00112 TrackPointer getLoadedTrack() const; 00113 00114 public slots: 00115 void slotControlPlay(double); 00116 void slotControlPlayFromStart(double); 00117 void slotControlJumpToStartAndStop(double); 00118 void slotControlStop(double); 00119 void slotControlStart(double); 00120 void slotControlEnd(double); 00121 void slotControlSeek(double); 00122 void slotControlSeekAbs(double); 00123 00124 // Request that the EngineBuffer load a track. Since the process is 00125 // asynchronous, EngineBuffer will emit a trackLoaded signal when the load 00126 // has completed. 00127 void slotLoadTrack(TrackPointer pTrack); 00128 00129 void slotEjectTrack(double); 00130 00131 signals: 00132 void trackLoaded(TrackPointer pTrack); 00133 void trackLoadFailed(TrackPointer pTrack, QString reason); 00134 void trackUnloaded(TrackPointer pTrack); 00135 00136 private slots: 00137 void slotTrackLoaded(TrackPointer pTrack, 00138 int iSampleRate, int iNumSamples); 00139 void slotTrackLoadFailed(TrackPointer pTrack, 00140 QString reason); 00141 00142 private: 00143 void setPitchIndpTimeStretch(bool b); 00144 00145 void updateIndicators(double rate, int iBufferSize); 00146 00147 void hintReader(const double rate, 00148 const int iSourceSamples); 00149 00150 void ejectTrack(); 00151 00152 // Lock for modifying local engine variables that are not thread safe, such 00153 // as m_engineControls and m_hintList 00154 QMutex m_engineLock; 00155 00157 const char* group; 00158 ConfigObject<ConfigValue>* m_pConfig; 00159 00161 LoopingControl* m_pLoopingControl; 00162 00164 RateControl* m_pRateControl; 00165 00167 BpmControl* m_pBpmControl; 00168 00169 QList<EngineControl*> m_engineControls; 00170 00173 ReadAheadManager* m_pReadAheadManager; 00174 00176 EngineBuffer* m_pOtherEngineBuffer; 00177 00178 // The reader used to read audio files 00179 CachingReader* m_pReader; 00180 00181 // List of hints to provide to the CachingReader 00182 QList<Hint> m_hintList; 00183 00185 double filepos_play; 00187 double rate_old; 00189 long int file_length_old; 00191 int file_srate_old; 00194 QMutex pause; 00196 int m_iSamplesCalculated; 00197 int m_iUiSlowTick; 00198 00199 ControlObject* m_pTrackSamples; 00200 ControlObject* m_pTrackSampleRate; 00201 00202 ControlPushButton *playButton, *buttonBeatSync, *playStartButton, *stopStartButton, *stopButton; 00203 ControlObjectThreadMain *playButtonCOT, *playStartButtonCOT, *stopStartButtonCOT, *m_pTrackEndCOT, *stopButtonCOT; 00204 ControlObject *fwdButton, *backButton; 00205 00206 ControlObject *rateEngine; 00207 ControlObject *visualBpm; 00208 ControlObject *m_pMasterRate; 00209 ControlPotmeter *playposSlider; 00210 ControlPotmeter *visualPlaypos; 00211 ControlObject *m_pSampleRate; 00212 ControlPushButton *m_pKeylock; 00213 00214 ControlPushButton *m_pEject; 00215 00217 ControlObject *m_pTrackEnd; 00218 00219 // Whether or not to repeat the track when at the end 00220 ControlPushButton* m_pRepeat; 00221 00222 ControlObject *m_pVinylStatus; //Status of vinyl control 00223 ControlObject *m_pVinylSeek; 00224 00226 ControlPushButton *startButton, *endButton; 00227 00229 EngineBufferScale *m_pScale; 00231 EngineBufferScaleLinear *m_pScaleLinear; 00233 EngineBufferScaleST *m_pScaleST; 00234 // Indicates whether the scaler has changed since the last process() 00235 bool m_bScalerChanged; 00236 00239 float m_fLastSampleValue[2]; 00241 bool m_bLastBufferPaused; 00242 float m_fRampValue; 00243 int m_iRampState; 00244 //int m_iRampIter; 00245 00246 TrackPointer m_pCurrentTrack; 00247 /*QFile df; 00248 QTextStream writer;*/ 00249 CSAMPLE* m_pDitherBuffer; 00250 unsigned int m_iDitherBufferReadIndex; 00251 }; 00252 00253 #endif