1 /**************************************************************************** 2 ** Copyright (c) 2019, Adel Kara Slimane <adel.ks@zegrapher.com> 3 ** 4 ** This file is part of ZeGrapher's source code. 5 ** 6 ** ZeGrapher is free software: you may copy, redistribute and/or modify it 7 ** under the terms of the GNU General Public License as published by the 8 ** Free Software Foundation, either version 3 of the License, or (at your 9 ** option) any later version. 10 ** 11 ** This file is distributed in the hope that it will be useful, but 12 ** WITHOUT ANY WARRANTY; without even the implied warranty of 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 ** General Public License for more details. 15 ** 16 ** You should have received a copy of the GNU General Public License 17 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 18 ** 19 ****************************************************************************/ 20 21 22 23 #include "Widgets/pareqcontroller.h" 24 ParEqController(QList<ParEqWidget * > * list)25ParEqController::ParEqController(QList<ParEqWidget *> *list) 26 { 27 parEqs = list; 28 29 freq = INIT_FREQ; 30 period = INIT_INCR_PERIOD; 31 32 ratio = (double)(1000.0/freq)/(double)(period); 33 34 animationTimer.setInterval(1000.0/INIT_FREQ); 35 36 connect(&animationTimer, SIGNAL(timeout()), this, SLOT(nextAnimationFrame())); 37 38 animationTimer.start(); 39 } 40 nextAnimationFrame()41void ParEqController::nextAnimationFrame() 42 { 43 bool update = false; 44 45 for(int i = 0 ; i < parEqs->size(); i++) 46 { 47 if(parEqs->at(i)->isAnimated() && parEqs->at(i)->isPlaying()) 48 { 49 parEqs->at(i)->nextFrame(); 50 update = true; 51 } 52 } 53 54 if(update) 55 emit animationUpdate(); 56 } 57 newParEqAdded()58void ParEqController::newParEqAdded() 59 { 60 parEqs->last()->setRatio(ratio); 61 } 62 63 updateRatioInParEq()64void ParEqController::updateRatioInParEq() 65 { 66 for(int i = 0; i < parEqs->size(); i++) 67 { 68 parEqs->at(i)->setRatio(ratio); 69 } 70 } 71 72 setUpdateFreq(int Hz)73void ParEqController::setUpdateFreq(int Hz) 74 { 75 freq = Hz; 76 ratio = (double)(1000.0/freq)/(double)(period); 77 animationTimer.setInterval(1000.0/Hz); 78 updateRatioInParEq(); 79 } 80 setIncrPeriod(int msecs)81void ParEqController::setIncrPeriod(int msecs) 82 { 83 period = msecs; 84 ratio = (double)(1000.0/freq)/(double)(period); 85 updateRatioInParEq(); 86 } 87 88 89