1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Rosegarden 5 A MIDI and audio sequencer and musical notation editor. 6 Copyright 2000-2021 the Rosegarden development team. 7 8 Other copyrights also apply to some parts of this work. Please 9 see the AUTHORS file and individual file headers for details. 10 11 This program is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public License as 13 published by the Free Software Foundation; either version 2 of the 14 License, or (at your option) any later version. See the file 15 COPYING included with this distribution for more information. 16 */ 17 18 #ifndef RG_FITTOBEATSCOMMAND_H 19 #define RG_FITTOBEATSCOMMAND_H 20 21 #include "document/Command.h" 22 #include "base/Event.h" 23 #include "base/Composition.h" 24 #include <QCoreApplication> 25 #include <QString> 26 #include <map> 27 28 29 namespace Rosegarden 30 { 31 32 // @class FitToBeatsCommand 33 // @remarks Implements the command "Fit Existing Beats to Beat Segment". 34 // @author Tom Breton (Tehom) 35 class FitToBeatsCommand : public NamedCommand 36 { 37 Q_DECLARE_TR_FUNCTIONS(Rosegarden::FitToBeatsCommand) 38 39 public: 40 FitToBeatsCommand(Segment *grooveSegment); 41 42 ~FitToBeatsCommand() override; 43 getGlobalName()44 static QString getGlobalName() 45 { return tr("Fit Existing Beats to Beat Segment"); } 46 47 void execute() override; 48 void unexecute() override; 49 50 private: 51 typedef std::map<timeT, tempoT> TempoMap; 52 typedef std::pair<timeT, tempoT> TempoChange; 53 typedef std::vector<RealTime> vecRealTime; 54 55 void initialise(Segment *s); 56 void changeAllTempi(TempoMap newTempi); 57 void changeSegments(SegmentMultiSet oldSegments, 58 SegmentMultiSet newSegments); 59 60 static int 61 getBeatRealTimes(Segment *s, vecRealTime &beatRealTimes); 62 static TempoChange 63 getTempoChange(Composition &composition, int i); 64 static void 65 getCurrentTempi(Composition &composition, TempoMap &Tempos); 66 67 Composition *m_composition; 68 69 SegmentMultiSet m_oldSegments; 70 SegmentMultiSet m_newSegments; 71 // !!! These don't need to be maps but they do need to associate 72 // with a timeT. Could just use a TempoChange. 73 TempoMap m_oldTempi; 74 TempoMap m_newTempi; 75 bool m_executed; 76 }; 77 78 } 79 80 #endif 81