Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/BeatReferee.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca>
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 Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef MARSYAS_BEATREFEREE_H
00020 #define MARSYAS_BEATREFEREE_H
00021 
00022 #include <time.h>
00023 #include <marsyas/system/MarSystem.h>
00024 
00025 namespace Marsyas
00026 {
00077 class BeatReferee: public MarSystem
00078 {
00079 private:
00080   //Add specific controls needed by this MarSystem.
00081   void addControls();
00082   MarControlPtr ctrl_mutedAgents_; //control with the enable flags of the overall BeatAgent pool.
00083   MarControlPtr ctrl_firstHypotheses_;
00084   MarControlPtr ctrl_inductionTime_;
00085   MarControlPtr ctrl_inductionEnabler_;
00086   MarControlPtr ctrl_hopSize_;
00087   MarControlPtr ctrl_srcFs_;
00088   MarControlPtr ctrl_maxPeriod_;
00089   MarControlPtr ctrl_minPeriod_;
00090   MarControlPtr ctrl_agentControl_;
00091   MarControlPtr ctrl_beatDetected_;
00092   MarControlPtr ctrl_tickCount_;
00093   MarControlPtr ctrl_obsoleteFactor_;
00094   MarControlPtr ctrl_childrenScoreFactor_;
00095   MarControlPtr ctrl_bestFactor_;
00096   MarControlPtr ctrl_eqPhase_;
00097   MarControlPtr ctrl_eqPeriod_;
00098   MarControlPtr ctrl_corFactor_;
00099   MarControlPtr ctrl_child1Factor_;
00100   MarControlPtr ctrl_child2Factor_;
00101   MarControlPtr ctrl_child3Factor_;
00102   MarControlPtr ctrl_backtrace_;
00103   MarControlPtr ctrl_logFile_;
00104   MarControlPtr ctrl_logFileName_;
00105   MarControlPtr ctrl_lostFactor_;
00106   MarControlPtr ctrl_soundFileSize_;
00107   MarControlPtr ctrl_bestFinalAgentHistory_;
00108   MarControlPtr ctrl_nonCausal_;
00109   MarControlPtr ctrl_triggerInduction_;
00110   MarControlPtr ctrl_triggerInductionExternalRequest_;
00111   MarControlPtr ctrl_gtInductionMode_;
00112   MarControlPtr ctrl_gtBeatsFile_;
00113   MarControlPtr ctrl_triggerGtTolerance_;
00114   MarControlPtr ctrl_curBestScore_;
00115   MarControlPtr ctrl_adjustment_;
00116   MarControlPtr ctrl_inductionMode_;
00117   MarControlPtr ctrl_beatTransitionTol_;
00118   MarControlPtr ctrl_destFileName_;
00119   MarControlPtr ctrl_triggerTimesFile_;
00120   MarControlPtr ctrl_resetAfterNewInduction_;
00121   MarControlPtr ctrl_resetFeatWindow_;
00122   MarControlPtr ctrl_supervisedTriggerThres_;
00123 
00124   mrs_natural triggerCount_;
00125   mrs_bool lastGTFalsePos_;
00126   mrs_real beatTransitionTol_;
00127   mrs_natural frames2SecsAdjustment_;
00128   mrs_realvec considerAgentTransitionBeat_;
00129   mrs_realvec considerFatherTransitionBeat_;
00130   mrs_realvec generationCount_;
00131   mrs_natural bestAgentBeforeTrigger_;
00132   mrs_natural backtraceEndTime_;
00133   mrs_natural   triggerGtTolerance_;
00134   mrs_real lastGTFileBeat_;
00135   mrs_natural lastGTBeatPos_;
00136   mrs_string gtBeatsFile_;
00137   mrs_natural lostGTBeatsCount_;
00138   mrs_string inductionMode_;
00139   mrs_bool startTracking_;
00140   mrs_bool startSystem_;
00141   mrs_natural triggerInductionTime_;
00142   mrs_bool processInduction_;
00143   mrs_bool triggerInduction_;
00144   mrs_realvec agentsJustCreated_;
00145   mrs_realvec bestFinalAgentHistory_;
00146   mrs_natural bestFinalAgent_;
00147   mrs_bool nonCausal_;
00148   mrs_natural maxNrBeats_;
00149   mrs_realvec agentsHistory_;
00150   mrs_realvec agentsFamilyHist_;
00151   mrs_natural soundFileSize_;
00152   mrs_natural lostFactor_;
00153   mrs_bool backtrace_;
00154   mrs_bool logFile_;
00155   mrs_string logFileName_;
00156   mrs_string logFileUnits_;
00157   mrs_natural nrAgents_;
00158   mrs_natural lastBeatTime_;
00159   mrs_natural minPeriod_;
00160   mrs_natural maxPeriod_;
00161   mrs_realvec agentControl_;
00162   mrs_realvec historyCount_; //number of (system) outputed beats by each agent
00163   mrs_realvec historyBeatTimes_;
00164   mrs_realvec score_; //score of each agent
00165   mrs_realvec lastPeriods_; //last tempo hypothesis of each agent
00166   mrs_realvec lastPhases_; //last phase hypothesis of each agent
00167   mrs_realvec firstHypotheses_;
00168   mrs_realvec beatCounter_;
00169   mrs_realvec mutedAgents_;
00170   mrs_realvec mutedAgentsTmp_;
00171   mrs_realvec inductionEnabler_;
00172   mrs_real bestScore_;
00173   mrs_natural inductionTime_;
00174   mrs_natural bestAgentIndex_;
00175   mrs_natural timeElapsed_;
00176   mrs_natural outputCount_;
00177   mrs_real obsoleteFactor_;
00178   mrs_real childrenScoreFactor_;
00179   mrs_real bestFactor_;
00180   mrs_natural eqPhase_;
00181   mrs_natural eqPeriod_;
00182   mrs_realvec initPeriod_;
00183   mrs_natural hopSize_;
00184   mrs_real srcFs_;
00185   mrs_real corFactor_;
00186   mrs_real child1Factor_;
00187   mrs_real child2Factor_;
00188   mrs_real child3Factor_;
00189   mrs_natural timeBeforeKilling_;
00190   mrs_natural lastBeatPeriod_;
00191   mrs_realvec missedBeatsCount_;
00192   mrs_string triggerTimesFile_;
00193   mrs_realvec triggerTimes_;
00194   mrs_realvec transitionTimes_;
00195   mrs_realvec transitionsConsidered_;
00196   mrs_bool resetAfterNewInduction_;
00197   std::vector <mrs_real> supervisedBestScores_;
00198   std::vector <mrs_real> supervisedBestScoresMeans_;
00199   mrs_natural lastTriggerInductionTime_;
00200   mrs_real lastBestScoreMeanDiff_;
00201   mrs_real supervisedTriggerThres_;
00202   mrs_bool triggerInductionExternalRequest_;
00203 
00204   void myUpdate(MarControlPtr sender);
00205 
00206 public:
00207   BeatReferee(std::string name);
00208   BeatReferee(const BeatReferee& a);
00209   ~BeatReferee();
00210   MarSystem* clone() const;
00211 
00212   void initialization();
00213   void myProcess(realvec& in, realvec& out);
00214   void updateAgentHypothesis(mrs_natural agentIndex, mrs_natural oldPeriod,
00215                              mrs_natural prevBeat, mrs_natural error);
00216   mrs_natural createNewAgent(mrs_natural newPeriod, mrs_natural firstBeat,
00217                              mrs_real newScore, mrs_real beatCount, mrs_natural fatherAgent = -1);
00218   void grantPoolSpace(mrs_natural callAgent, mrs_real newAgentScore);
00219   void grantPoolSpace2(mrs_natural callAgent, mrs_natural nrRequired, mrs_realvec newAgentsScore);
00220   mrs_natural getWorstAgent(mrs_natural callAgent);
00221   void setNewHypothesis(mrs_natural agentIndex, mrs_natural newPeriod, mrs_natural nextBeat);
00222   mrs_natural calcFirstBeat(mrs_natural initPeriod, mrs_natural initPhase);
00223   mrs_natural calcFirstBacktracedBeat(mrs_natural initPeriod, mrs_natural initPhase);
00224   void resetSystem(mrs_natural saveAgent);
00225   void killAgent(mrs_natural agentIndex, mrs_string motif, mrs_natural callAgent = -1);
00226   void createChildren(mrs_natural agentIndex, mrs_natural oldPeriod, mrs_natural prevBeat, mrs_natural error,
00227                       mrs_real agentScore, mrs_real beatCount);
00228   mrs_realvec calculateNewHypothesis(mrs_natural agentIndex, mrs_natural oldPeriod,
00229                                      mrs_natural prevBeat, mrs_natural error);
00230   mrs_realvec calcChildrenHypothesis(mrs_natural oldPeriod, mrs_natural prevBeat, mrs_natural error);
00231   mrs_natural getFirstAliveAgent();
00232   void calcAbsoluteBestScore();
00233   mrs_natural calcNewPeriod(mrs_natural oldPeriod, mrs_natural error, mrs_real beta);
00234   void debugCreateFile();
00235   void debugAddEvent(mrs_string ibtEvent, mrs_natural agentIndex, mrs_natural period, mrs_natural lastBeat,
00236                      mrs_real score, mrs_real bestScore, mrs_natural callAgent = -1);
00237   void debugAddMsg(mrs_string ibtMsg);
00238   void checkAndKillEqualAgents(mrs_natural agentIndex);
00239   mrs_natural existEqualAgents(mrs_natural agentIndex, mrs_natural agentPeriod, mrs_natural agentPhase);
00240   mrs_natural existEqualBetterAgents(mrs_natural agentIndex, mrs_natural agentPeriod, mrs_natural agentPhase, mrs_real newAgentScore);
00241   mrs_realvec getEqualAgents(mrs_natural agentIndex, mrs_natural agentPeriod, mrs_natural agentPhase);
00242   mrs_natural checkBeatInGTFile();
00243   mrs_bool isGTFileInLine(mrs_string line);
00244   mrs_natural getBestSimilarAgent(mrs_natural newAgentPeriod, mrs_natural newAgentInitPhase, mrs_real newAgentScore);
00245   mrs_natural getBestSimilarAgent2(mrs_natural newAgentPeriod, mrs_natural newAgentInitPhase);
00246   mrs_natural getBestSimilarAgent3(mrs_natural newAgentPeriod, mrs_realvec completedClustersPer);
00247   void grantPoolSpaceForTriggerAgents(mrs_realvec triggerAgentsHypotheses);
00248   mrs_realvec clusterIBIs();
00249   void handleAgentsTansition(mrs_natural agent);
00250   void cleanAgentAndFatherTransitionFlags(mrs_natural agentIndex);
00251   mrs_bool loadTriggerTimes(mrs_string triggerTimesFile);
00252 
00253 };
00254 
00255 }//namespace Marsyas
00256 
00257 #endif