tempomap.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. This file is part of QTau
  3. Copyright (C) 2013-2018 Tobias "Tomoko" Platen <tplaten@posteo.de>
  4. Copyright (C) 2013 digited <https://github.com/digited>
  5. Copyright (C) 2010-2013 HAL@ShurabaP <https://github.com/haruneko>
  6. QTau is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. SPDX-License-Identifier: GPL-3.0+
  17. */
  18. #include <QAbstractItemModel>
  19. #include <QJsonArray>
  20. #include <QMap>
  21. #ifndef TEMPOMAP_H
  22. #define TEMPOMAP_H
  23. struct fraction {
  24. int numerator;
  25. int denominator;
  26. };
  27. struct tempoindex {
  28. int pos;
  29. int type;
  30. };
  31. enum tmlabel {
  32. TM_BPM = 0,
  33. TM_SIG = 1,
  34. TM_ALL = 2,
  35. };
  36. class TempoMap : public QAbstractItemModel {
  37. QMap<int, float> _tempo;
  38. QMap<int, fraction> _time;
  39. QList<tempoindex> _index;
  40. QMap<int, float> _origTempo;
  41. QMap<int, fraction> _origTime;
  42. QList<tempoindex> _origIndex;
  43. void updateIndexList();
  44. public:
  45. TempoMap();
  46. void addTempo(int pos, float tempo);
  47. void addTimeSignature(int pos, int numerator, int denominator);
  48. void removeEventAt(int index);
  49. void removeTempoForBar(int pos);
  50. void removeTimeSignatureForBar(int pos);
  51. fraction getTimeSignatureForBar(int pos);
  52. //
  53. QModelIndex index(int row, int column,
  54. const QModelIndex &parent = QModelIndex()) const;
  55. QModelIndex parent(const QModelIndex &child) const;
  56. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  57. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  58. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  59. //
  60. void beginEditing();
  61. void toJson(QJsonArray &array);
  62. void fromJson(QJsonArray &array);
  63. void undo();
  64. bool getBar(int pulses, float &time, int &bar, int end);
  65. float getBPMforBar(int bar);
  66. QString getLabel(int bar, tmlabel mode);
  67. bool setLabel(tmlabel mode, int bar, QString label);
  68. };
  69. #endif // TEMPOMAP_H