Utils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef UTILS_H
  19. #define UTILS_H
  20. #include <QObject>
  21. #include <QVector>
  22. #include <QString>
  23. #include <QPoint>
  24. #include <QSize>
  25. #include <QPair>
  26. #include <QVariant>
  27. #define STR(x) QVariant(x).toString()
  28. void __devlog__(QString logtype,QString filename,int line,QString msg);
  29. #define DEVLOG_ERROR(msg) {if(__devloglevel__>=1) __devlog__ ("ERROR",__FILE__,__LINE__,msg);}
  30. #define DEVLOG_WARNING(msg) {if(__devloglevel__>=2) __devlog__ ("WARNING",__FILE__,__LINE__,msg);}
  31. #define DEVLOG_DEBUG(msg) {if(__devloglevel__>=3) __devlog__ ("DEBUG",__FILE__,__LINE__,msg);}
  32. #define DEVLOG_INFO(msg) {if(__devloglevel__>=4) __devlog__ ("INFO",__FILE__,__LINE__,msg);}
  33. const QString c_qtau_name = QStringLiteral("QTau");
  34. const QString c_qtau_ver = QStringLiteral("α1");
  35. /* Pulses Per Quarter note - standard timing resolution of a MIDI sequencer,
  36. needs to be divisible by 16 and 3 to support 1/64 notes and triplets.
  37. Used to determine note offset (in bars/seconds) and duration */
  38. const int c_midi_ppq = 480;
  39. const int c_zoom_num = 17;
  40. const int cdef_zoom_index = 4;
  41. const int cdef_note_height = 14;
  42. const int c_zoom_note_widths[c_zoom_num] = {16, 32, 48, 64, 80,
  43. 96, 112, 128, 144, 160,
  44. 176, 208, 240, 304, 368, 480, 608};
  45. class TempoMap;
  46. //stores score global values
  47. //TODO replace with proper class
  48. struct SNoteSetup {
  49. QSize note; // gui dimensions (in pixels)
  50. int baseOctave;
  51. int numOctaves;
  52. int numBars;
  53. int* barScreenOffsets;
  54. TempoMap* tmap;
  55. inline int getBarForScreenOffset(int x)
  56. {
  57. for(int i=0;i<numBars;i++)
  58. {
  59. if(barScreenOffsets[i]>=x)
  60. {
  61. return i;
  62. }
  63. }
  64. //this is a error
  65. return -1;
  66. }
  67. int quantize; // 1/x note length, used as unit of offset for singing notes
  68. int length; // 1/x singing note length unit (len=4 means 1/4, 2/4 etc +1/4)
  69. int octHeight;
  70. SNoteSetup() : note(c_zoom_note_widths[cdef_zoom_index], cdef_note_height),
  71. baseOctave(1), numOctaves(8),numBars(128), tmap(0), quantize(32), length(32),
  72. octHeight(note.height() * 12) {}
  73. };
  74. //----------------------------------------------------
  75. enum class ELog : char {
  76. none,
  77. info,
  78. debug,
  79. error,
  80. success
  81. };
  82. enum class EColor : char {
  83. none,
  84. green,
  85. red
  86. };
  87. #define MAXRECENTFILES 8
  88. //#define DEFAULT_SAMPLERATE 44100
  89. #endif // UTILS_H